Check if value exist in database and alert message - angularjs

I have a data base containing following data
I have a textbox to enter chqNo. How to display the status according to chqNo entered in textbox.Foreg: If we enter 5 it should alert "cancelled" otherwise "active" on textbox onchange() using angularJs

Assuming you have cheque information fetched from database and stored in a $scope object in angularjs.
$scope.chequeInfo = [
{chqNo: 1, custName : 'Bikash', status : 'active'},
{chqNo: 2, custName : 'Bikash', status : 'active'},
{chqNo: 3, custName : 'Bikash', status : 'active'},
{chqNo: 4, custName : 'Bikash', status : 'active'},
{chqNo: 5, custName : 'Bikash', status : 'cancelled'}
];
$scope.onChqChange = function(chqNo) {
angular.forEach($scope.chequeInfo, function(cheque) {
if(cheque.chqNo === chqNo) {
alert(cheque.status);
}
});
};
Bound the method to your HTML as:
<input type="number" ng-model="chqNo" ng-change="onChqChange(chqNo)"/>
See the Working demo here.

Related

How do I make two functions of a function based views communicate with each other in django?

I am new to Django and working on a project. I have to communicate two functions of views in Django.
views.py
#login_required
def likepost(request,id):
post = NewPost.objects.get(id = id)
is_like = False
for like in post.likepost.all():
if like == request.user and request.method == "POST":
is_like = True
break
if not is_like:
post.likepost.add(request.user)
else:
post.likepost.remove(request.user)
return JsonResponse({
"is_like" : is_like,
})
This is my likepage function which I want to call in my index function. The index function has been given below.
def index(request):
posts = NewPost.objects.all().order_by("-timestamp")
page = Paginator(posts,3)
page_req = request.GET.get('page')
page_view = page.get_page(page_req)
num = "a" * page_view.paginator.num_pages
is_like = likepost(posts.id)
if request.user.is_authenticated:
if request.method == "POST":
post = NewPostForm(request.POST)
user = request.user
timestamp = datetime.now()
if post.is_valid:
post = post.save(commit=False)
postdata = NewPost(post=post,user=user,timestamp=timestamp)
postdata.save()
# return Response({"message" : "Post created successfully 😊!"})
return render(request,"network/index.html",{
"post" : post,
# "user" : user,
# "posts" : posts,
"timestamp" : timestamp,
"page_view" : page_view,
"num" : num,
"is_like" : is_like,
})
# JsonResponse(posts, safe=False)
else:
post = NewPostForm()
return render(request,"network/index.html",{
"post" : post,
"posts" : posts,
"page_view" : page_view,
"num" : num,
"is_like" : is_like,
})
return render(request,"network/index.html",{
"posts" : posts,
"page_view" : page_view,
"num" : num,
"is_like" : is_like,
})
Although I have id attribute in my model, it gives the following error.
How can I fix it? I want to make a like button.
To fix the issue you just add user to is_like = likepost(posts.user.id).I think you need to query post by the user id not just the posts.id,so hopefully it should work now.
def index(request):
posts = NewPost.objects.all().order_by("-timestamp")
page = Paginator(posts,3)
page_req = request.GET.get('page')
page_view = page.get_page(page_req)
num = "a" * page_view.paginator.num_pages
is_like = likepost(posts.user.id)
if request.user.is_authenticated:
if request.method == "POST":
post = NewPostForm(request.POST)
user = request.user
timestamp = datetime.now()
if post.is_valid:
post = post.save(commit=False)
postdata = NewPost(post=post,user=user,timestamp=timestamp)
postdata.save()
# return Response({"message" : "Post created successfully 😊!"})
return render(request,"network/index.html",{
"post" : post,
# "user" : user,
# "posts" : posts,
"timestamp" : timestamp,
"page_view" : page_view,
"num" : num,
"is_like" : is_like,
})
# JsonResponse(posts, safe=False)
else:
post = NewPostForm()
return render(request,"network/index.html",{
"post" : post,
"posts" : posts,
"page_view" : page_view,
"num" : num,
"is_like" : is_like,
})
return render(request,"network/index.html",{
"posts" : posts,
"page_view" : page_view,
"num" : num,
"is_like" : is_like,
})

Paytm checksum mismatch in ios swift4

I am Integrating paytm gateway in ios app when I generating checksum through api calling and pass this checksum with below param in web view
WEB VIEW is loading with Parms:
{
"CALLBACK_URL" = "https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=SJ-1552029210215";
"CHANNEL_ID" = WAP;
CHECKSUMHASH = "FRMuR8LLFvg3wkIf6gp4BqVnNigr6WvUaSm9EVJIJo6Z5RicUvU7acRGZlEfK1FGoeNSqN53R0OphttHFnJuZ0lKeAZDvrG7Pr5ZnlzTEUw=";
"CUST_ID" = 64;
EMAIL = "jitu123#gmail.com";
"INDUSTRY_TYPE_ID" = Retail;
MID = rxazcv89315285244163;
"MOBILE_NO" = 566789877;
"ORDER_ID" = "SJ-1552029210215";
"TXN_AMOUNT" = "246.0";
WEBSITE = WEBSTAGING;
}
I am getting back below response
{
"ORDERID" : "SJ-1552029210215",
"MID" : "rxazcv89315285244163",
"TXNAMOUNT" : "246.00",
"BANKTXNID" : "",
"RESPCODE" : "330",
"STATUS" : "TXN_FAILURE",
"CURRENCY" : "INR",
"RESPMSG" : "Paytm checksum mismatch."
}
how can i solve paytm checksum mismatch issue???

How to define Typescript Map of key value pair. where key is a number and value is an array of objects

In my angular2 app i want to create a map which takes a number as key and returns an array of objects. I am currently implementing in following way but no luck. How should i implement it or should i use some other data structure for this purpose? I want to use map because maybe its fast?
Declaration
private myarray : [{productId : number , price : number , discount : number}];
priceListMap : Map<number, [{productId : number , price : number , discount : number}]>
= new Map<number, [{productId : number , price : number , discount : number}]>();
Usage
this.myarray.push({productId : 1 , price : 100 , discount : 10});
this.myarray.push({productId : 2 , price : 200 , discount : 20});
this.myarray.push({productId : 3 , price : 300 , discount : 30});
this.priceListMap.set(1 , this.myarray);
this.myarray = null;
this.myarray.push({productId : 1 , price : 400 , discount : 10});
this.myarray.push({productId : 2 , price : 500 , discount : 20});
this.myarray.push({productId : 3 , price : 600 , discount : 30});
this.priceListMap.set(2 , this.myarray);
this.myarray = null;
this.myarray.push({productId : 1 , price : 700 , discount : 10});
this.myarray.push({productId : 2 , price : 800 , discount : 20});
this.myarray.push({productId : 3 , price : 900 , discount : 30});
this.priceListMap.set(3 , this.myarray);
this.myarray = null;
I want to get an array of 3 objects if i use this.priceList.get(1);
First thing, define a type or interface for your object, it will make things much more readable:
type Product = { productId: number; price: number; discount: number };
You used a tuple of size one instead of array, it should look like this:
let myarray: Product[];
let priceListMap : Map<number, Product[]> = new Map<number, Product[]>();
So now this works fine:
myarray.push({productId : 1 , price : 100 , discount : 10});
myarray.push({productId : 2 , price : 200 , discount : 20});
myarray.push({productId : 3 , price : 300 , discount : 30});
priceListMap.set(1 , this.myarray);
myarray = null;
(code in playground)
The most simple way is to use Record type Record<number, productDetails>
interface productDetails {
productId : number ,
price : number ,
discount : number
};
const myVar : Record<number, productDetails> = {
1: {
productId : number ,
price : number ,
discount : number
}
}
you can also skip creating dictionary altogether. i used below approach to same problem .
mappedItems: {};
items.forEach(item => {
if (!mappedItems[item.key]) {
mappedItems[item.key] = [];
}
mappedItems[item.key].push({productId : item.productId , price : item.price , discount : item.discount}));
});

set selected item in select by name in controller of angularjs

I am working on angularjs , Where I need to set selected item by name in selected item.
How DO i do that . I can set item by index but how do i do with itemname
Eg : on load I am setting 1st item as selected item
$scope.internalRoles = data;
$scope.internalItemSelected = $scope.internalRoles[0];
and Data is like
data = [{id : 1 , roleName : "admin"}
,{id : 2 , roleName : "superadmin"}]
Now I want to set selected item on basis on roleName
$scope.internalItemSelected = $scope.internalRoles["superadmin"] ;//based on roleName
But its not working.
How do i set it by name ?
You can write a extension for your array:
Array.prototype.findItem = function (searchFor) {
return this.find(function(item){
return item['roleName'] === searchFor;
});
};
Then call it with:
$scope.internalItemSelected = $scope.internalRoles.findItem("superadmin");
You can also pass 'roleName' as a property of extension to make it more general in use.
Hi if u wants to set name from the selected item then directly do like this
$scope.internalRoles = data;
$scope.internalItemSelected = $scope.internalRoles[0].roleName;
console.log($scope.internalItemSelected);

AngularJS Drag and Drop

If I have a JSON like below ..
$scope.pools = [ {id: 1, poolName : 'Pool1', env : 'Env1', executionMode: 'Both',
modelets: [{id: 'm1', name : 'MM1', status : 'active', capacity : '1 GB'},
{id: 'm2', name : 'MM2', status : 'active', capacity : '1 GB'},
{id: 'm3', name : 'MM3', status : 'active', capacity : '1 GB'}]},
{id: 2, poolName : 'Pool2', env : 'Env2', executionMode: 'Both',
modelets: [{id: 'm4', name : 'MR1', status : 'active', capacity : '1 GB'},
{id: 'm5', name : 'MR2', status : 'active', capacity : '1 GB'}]
}
];
and I have to drag and drop the modelet from one pool to another. for example, if I am dragging m3 from pool1 to and dropping it into modelets of pool2, then m3 should be removed from pool1.modelets and it should be added into pool2.modelets and vice-versa.
Note : I am trying it using http://codef0rmer.github.io/angular-dragdrop/#/
Please provide me effective solution. Thanks in adnavce.
Finally, I got something which is working fine in this case ...
We need to do below changes in draggable element.
<div class="btn btn-primary" data-drag="true" data-jqyoui-options="{revert: 'invalid'}" ng-model="pool.modelets" jqyoui-draggable="{index: {{$index}},animate:true}" ng-hide="!modelet.name">{{modelet.name}}</div>
updated fiddler is working fine.

Resources