How to display record information from my Firebase database? - angularjs

I have in my database this node :
I have this select list
I would search events that its startdate matches the select item from the select list.
I try this code to show the evets that matches 'today' startdate:
//Switch label of selected item :
switch($scope.search.dateOption.label)
{
case 'Today':
{
var reff = new Firebase("https://event-application.firebaseio.com/event");
reff.orderByChild("startdate").startAt((new Date()).toISOString())
.on("child_added", function(snapshot) {
console.log(snapshot.key())
var a= snapshot.key() ;
reff.orderByChild("id").equalTo(a).on("child_added", function(snapshot) {
console.log(snapshot);
});
})
}
break;
}
'console.log(snapshot.key())' works well :
But when i try to display all the record information, nothing is displayed.
Can someone help me please.

Related

Update inventory after purchase

I have an array of objects, which means I get multiple items (products) from a database.
And I want to update after a site purchase on all products purchased inventory, download 1 from the 'nimcar' field
I'm probably having trouble accessing the objects.
I arranged the code into a whole code.
This is a process that happens on the last page after payment is received, I want to update the inventory of the products.
The process I presented here is to get from the database where the order name is listed, from a reference field containing the products it purchased, which are in the purchase basket, and the purchase basket has a reference field containing the product ID.
I was thinking about the process of getting the product ID
Hhazmana.muzarim.muzarim._id
Then update the ID to the 'nimcar' -1 field
$w.onReady(function () {
var id = $w("#dynamicDataset").getCurrentItem()._id;
wixData.queryReferenced("hazmanot", id, "muzarim")
.then((results) => {
if (results.items.length > 0) {
var firstItem = results.items
console.log(firstItem );
var myObj, i;
myObj = firstItem
for (i in myObj.muzarim) {
var id2 = myObj.muzarim
// console.log(id2);
wixData.get("muzarim", id2)
.then((item) => {
item.nimcar = Number(item.nimcar - 1)
wixData.update("muzarim", item)
.catch((err) => {
let errorMsg = err;
})
});
}
} else {
}
});
});
That's how it prints it for me:
0: "{\"muzarim\":\"7c3e8acd-a7a9-4819-b687-8b1ca06a984b\",\"_id\":\"53904a0d-c3b6-4337-b09d-b779fb0aea1e\",\"_owner\":\"ae269d04-1741-4200-bc92-2e27c7d549cd\",\"hazmanot\":\"af7ba985-f2ed-4bcf-a033-51e36b9298c1\",\"_createdDate\":\"2019-11-21T15:05:03.590Z\",\"lakoh\":\"e005f170-edcf-4694-80b7-496ab3534643\",\"_updatedDate\":\"2019-11-21T15:05:03.590Z\",\"sach\":1,\"camut\":1,\"title\":\"בית מזוזה\"}"
1: "{\"muzarim\":\"e29358d3-a74b-410a-8b41-44679f70ad05\",\"_id\":\"05b7540e-85c6-4eaa-b86b-6f4a466ed57e\",\"_owner\":\"ae269d04-1741-4200-bc92-2e27c7d549cd\",\"hazmanot\":\"3cd1eec3-c586-47b2-a1d4-2b4671c0dd2e\",\"_createdDate\":\"2019-08-21T13:43:38.884Z\",\"lakoh\":\"e005f170-edcf-4694-80b7-496ab3534643\",\"_updatedDate\":\"2019-08-21T13:43:38.884Z\",\"sach\":1200,\"camut\":1,\"title\":\"יין הסיומים\"}"
2: "{\"muzarim\":\"17a8e414-aaeb-4b0f-ae49-a4e5107ad132\",\"_id\":\"6fb545da-ac30-4304-92f9-930b49f87039\",\"_owner\":\"ae269d04-1741-4200-bc92-2e27c7d549cd\",\"hazmanot\":\"2894c50d-07e8-467e-b0f5-a37889a99fad\",\"_createdDate\":\"2019-08-21T13:41:19.197Z\",\"lakoh\":\"e005f170-edcf-4694-80b7-496ab3534643\",\"_updatedDate\":\"2019-08-21T13:41:19.197Z\",\"sach\":7200,\"camut\":1,\"title\":\"סט קדושת יצחק\"}"
3: "{\"muzarim\":\"17a8e414-aaeb-4b0f-ae49-a4e5107ad132\",\"_id\":\"a5ac5af4-03ee-4b88-9929-dc69e9dc0e04\",\"_owner\":\"ae269d04-1741-4200-bc92-2e27c7d549cd\",\"hazmanot\":\"993ed276-f7e1-4741-a038-69ad2b50cc91\",\"_createdDate\":\"2019-08-21T13:40:02.242Z\",\"lakoh\":\"e005f170-edcf-4694-80b7-496ab3534643\",\"_updatedDate\":\"2019-08-21T13:40:02.242Z\",\"sach\":7200,\"camut\":1,\"title\":\"סט קדושת יצחק\"}"

angularjs reinitializing arrays gives me "TypeError: Cannot read property 'push' of undefined"

I am running into a peculiar problem.
I have a my view of drop down list as this in HTML:
<div ng-controller='ConfigurableInputController as configurableInput'>
<select class="fixed-input"
ng-model="configurableInput.selectedCriteria"
ng-change="configurableInput.update()"
ng-options="criterion.selected as criterion.name for criterion in configurableInput.criteriaList">
<option value="">--Please select the comparison criteria--</option>
</select>
The above shows me 3 options in drop down list: Store, Channel and Permissions.
When ever I change the option from Store to Channel or Permissions or any combination the view changes (input boxes, certain labels etc.)
My update() method in controller does this:
configurableInput.update = function () {
configurableInput.permission = "";
configurableInput.id1 = "";
configurableInput.id2 = "";
configurableInput.items1 = "";
configurableInput.items2 = "";
configurableInput.defaultValueArray = [];
configurableInput.permissionsArr = [];
}
On selection of the drop down item, I do a ng-click on a button which retrieves information from Db.
There are 2 flavors of methods which are called on ng-click but the one giving me trouble is this one in the Service method:
StoreConfigurableService.$inject = ['$q', '$http', 'ApiBasePath'];
function ConfigurableService($q, $http, ApiBasePath) {
var service = this;
var defaultValueArr = [];
var permissionsArr = [];
var items1 = "";
var items2 = "";
service.retrievePermissions = function (criterion, id1, id2, rlNumber1, rlNumber2) {
$q.all([
$http.get(ApiBasePath + "/" + criterion + "/" + id1 + "/" + rlNumber1),
$http.get(ApiBasePath + "/" + criterion + "/" + id2 + "/" + rlNumber2)
])
.then(function (response) {
items1 = response[0].data;
items2 = response[1].data;
if (criterion === 'Permissions') {
var processed = false;
permissionsArr = makePermissionsArray(permissionsArr, items1, items2, processed);
}
})
.catch(function (errorResponse) {
console.log("Error: " + errorResponse);
throw errorResponse;
});
};
... so on
In my makePermissionsArray() I am doing this:
function makePermissionsArray(arr, items1, items2, processed) {
var map = items1.storePermissions;
var map2 = items2.storePermissions;
var map3 = items1.allPermissions;
for (var key in map) {
arr.push({
'code': key,
'description': map3[key],
'repStorePermission1': map[key],
'repStorePermission2': map2[key]
});
}
}
I get this permissionsArr back to controller through this:
service.getPermissionsArr = function () {
return permissionsArr;
};
NOTE that 'arr' in the argument of method makePermissionsArray() is not initialized because I am getting it by passing permissionsArr in the argument.
Now how the flow goes is:
First I select Store from drop down list, click on button to retrieves configurables for the store. This gives me correct response.
Then I select 'Permissions' from drop down list, click on button to retrieve permission configurables from Db, it gets stuck and does not get me any response.
I thought I am not clearing the arrays correctly in update() method and after some long search I found and changed these array initializing from:
configurableInput.defaultValueArray = [];
configurableInput.permissionsArr = [];
to
configurableInput.defaultValueArray.length = 0;
configurableInput.permissionsArr.length = 0;
in my update() method.
Now what happens is this:
First I select Store from drop down list, click on button to retrieves configurables for the store. This gives me correct response.
Then I select 'Permissions' from drop down list, click on button to retrieves permission configurables from Db, it gives me correct response.
I select Store from drop down list again, click on button and I get correct response.
But when I again select 'Permissions' from drop down list, click on button, it gives me this error - TypeError: Cannot read property 'push' of undefined
Error I get is at this point:
arr.push({
'code': key,
'description': map3[key],
'repStorePermission1': map[key],
'repStorePermission2': map2[key]
});
I am literally tearing my hair out because of this problem. Can someone please help me what's wrong?

Http Post Json - Array

i am selecting a list of doctors that i want to group in a department for rural area. The selected doctors are then pushed into the array and saved to the database. i am able to selected and post to save in the database but there is a bit of flaw i am finding hard to resolve.
My problem is when i select Doctor 1 and Doctor 2 and post to my service, the params sent to my service is counted 3. That is Doctor 1, Doctor 2, Doctor 2. Why is Doctor 2 being duplicated?
selecting doctors
selectDoctors(Doctors){
Doctors.listed = (Doctors.listed) ? false : true;
this.deptList = Doctors
}
submitting group of selected doctors in array
Doctors: Doctors[] = [];
hospital = {
hospital_name : "",
details : [{
id: "",
ward: "",
}]
}
//submit data into array
Object.keys(this.Doctors).filter(key => this.Doctors[key].selected)
.forEach(key => {
this.hospital.details['0'].id = this.Doctors[key].id
this.hospital.details['0'].ward =this.Doctors[key].ward
this.groups.members.push(this.Doctors.['0']);
}
this.http.categorizeDepartment(this.groups)
.subscribe(data => {
});
}
Looks like there's some strange mutation and unnecessary methods being used here that the results are unpredictable. If all you want to do is put selected doctors into a group, you can do like this:
this.groups.members = [
...this.groups.members,
this.Doctors.filter(doctor => doctor.selected)
];
If you also want to add the doctor's info to the first item in the hospital.details array, you can add that too:
let selectedDoctors = this.Doctors.filter(doctor => doctor.selected);
this.groups.members = [...this.groups.members, selectedDoctors];
for (let doctor of selectedDoctors) {
this.hospital.details['0'].id = doctor.id
this.hospital.details['0'].ward = doctor.ward
}

How to remove the summary grouping of particular row in EXTJS

If I apply groupField property in the grid and store, extjs will automatically sort records by groupField.
For example: http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/group-summary-grid.html, it used 'project' as groupField.
My Question is How can I add an extra row, which does not belong to any group, into a grid with groupField. (Like this: http://i59.tinypic.com/30s973l.jpg)
By default group is made for each value from groupField, also for empty groupField (but it appears first). If it is enough for you then you don't have to do anything.
Fiddle: http://jsfiddle.net/tme462tj/
When you want to have behavior like on attached image, then some work has to be done.
To put empty value at the end, you can create convert function for model field (eg: convert: function(v) { return v ? v : defaultDepartment; }). If you want to hide header and summary for this empty group, you can attach event listener to viewready event and hide them using styles:
viewready: function() {
var els = this.getEl().query('.x-grid-group-hd');
els = Ext.Array.filter(els, function(e) { return e.textContent.trim() == defaultDepartment; });
if (els.length !== 1) {
return;
}
var header = Ext.fly(els[0]);
header.setStyle('display', 'none');
var summary = header.up('.x-group-hd-container').down('.x-grid-row-summary');
if (summary) {
summary.setStyle('display', 'none');
}
}
Fiddle: http://jsfiddle.net/hdyokgnx/1/
As per my comment on the accepted solution, this revision makes the grouping header hide permanently for the duration of that grid view.
This solves my problem of needing a grouping grid but with one group that does not have a group header row.
store.load
({
params :
{
arg1 : 1
,arg2 : '2'
}
,callback : function( records, operation, success )
{
var els = me.theGrid.getEl().query('.x-grid-group-hd');
els = Ext.Array.filter( els, function(e)
{
return e.textContent.trim().includes( "*** A SUBSTRING IN GROUPING FIELD ***" );
});
if (els.length !== 1)
{
return;
}
var header = Ext.fly(els[0]);
header.setStyle('display', 'none');
var summary = header.up('.x-group-hd-container').down('.x-grid-row-summary');
if (summary)
{
summary.setStyle('display', 'none');
}
}
});

Extjs 4.2 store.getRange gives data of previously loaded store

I have an extjs store associated with grid class. when I select a class, it gives ClassID of the record.
var ClassData = record.get('ClassID');
console.log(ClassData);
Based on this ClassID I am loading store of next grid:
var Grid = this.getSemGrid();
var Store = Grid.getStore(); // your grid's store
//load store with records having selected class ID
var g = Store.load( {params : {ClassID: ClassData }});
Till here everything is fine.
Once the store is loaded, I am getting all loaded records (Error Area)
var selected = g.getRange(); // getRange = select all records
Then pushing all the values of one field of all records in an array
var Excerpt = []; // start with empty array
Ext.each(selected, function(item) {
// add the fields that you want to include
var Obj = {
third_field: item.get('ExamName')
};
Excerpt.push(Obj); // push this to the array
}, this);
console.log(Excerpt);
Excerpt gives array of previously selected record not the current record.
I have also tried
Store.loadData([],false);
to clear all the loaded data of store before loading it again.
Got this working
var g = Store.load({
params : {ClassID: ClassData },
callback : function(records, operation, success){
var Excerpt = []; // start with empty array
Ext.each(records, function(item) {
// add the fields that you want to include
var Obj = {
third_field: item.get('ExamName')
};
Excerpt.push(Obj); // push this to the array
}, this);
}
});

Resources