Retrieve Data from a Label in a Collapsible Set for Use in a Query

This forum contains topics that were moved from Get Satisfaction
Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Retrieve Data from a Label in a Collapsible Set for Use in a Query

Post by Louis Adekoya »

I have a checkbox that I wish to bind to a boelean in one of my db collections. The checkbox is within a collapsible set that displays several records, so there are many instances of the checkbox on the page, each for a different record. See screenshot:

Image

My where clause for my query service is: return '{ $and: [ { "prayee": "'+value+'" }, { "sender": "' + localStorage.getItem("userId") + '" } ] }';

The Before Send mapping for the service is as shown below:

Image

When I test this service by invoking it from a button and checking the console, I see that the prayee parameter is being set to the default text for the my hidden label. I am expecting the query to be run several times, one for each prayee (user id from each instance of the hidden label). I have made sure to run my query service after the service that populates the hidden label.

How can I query the database using each user in my collapsible set as the prayee parameter (and the current logged-in user in a LSV as the sender parameter)?

Notes:

  1. This query service queries a collection called Prayed, which has three columns, prayed (the boolean); sender and prayed, the last two of which are pointers to the users collection. Sender and Prayee are members of the same group in a GroupMember collection.

  2. I started creating this app before models were introduced, so I am not using them in the app.

Pavel Zarudniy
Posts: 0
Joined: Mon Jul 06, 2015 8:56 am

Retrieve Data from a Label in a Collapsible Set for Use in a Query

Post by Pavel Zarudniy »

Hi Louis,
You can collect data in each block of Collapsible Set by using Javascript code like this
code
Apperyio("<collasibleset_name>")&#46;children()&#46;each(function() {
&#46;&#46;&#46;
}
);
/code
where - is Collapsible Set component name
Internal function will be called for each block, with setting context (this)

Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Retrieve Data from a Label in a Collapsible Set for Use in a Query

Post by Louis Adekoya »

Hi Pavel,

Thanks. I've been searching through this forum to try to find an example of what you suggest, but so far I haven't found one. If there's a post or tutorial you can point me to please, that would be great, thanks.

Also, I can see how your suggestion might be useful to perform actions on the contents of the collapsible set but I'm struggling to see how I might use it exactly. Can you please advise first of all if my where clause and/or mapping are correct/required and how the code you have suggested might fit in with them? Remember that what I am trying to do is to get each checkbox in my set to show the corresponding value from the db if a value exists for that combination of sender and prayee.

Any additional help would be appreciated as I am kind of stuck at the moment, although I will keep searching and trying.

Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Retrieve Data from a Label in a Collapsible Set for Use in a Query

Post by Louis Adekoya »

Any further advice Pavel? I haven't made any headway with this. I have been trying the code above for something else and can't quite get my head around how to use it for what I need. I am not familiar with JS but I'm able to follow good examples or tutorials to good effect, so if there is any resource you can point me to, or any further example you can give me, I should be okay to take it from there.

Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Retrieve Data from a Label in a Collapsible Set for Use in a Query

Post by Louis Adekoya »

Can anyone else help me with this please? I'm stuck and unable to complete my app development because of this issue.

Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Retrieve Data from a Label in a Collapsible Set for Use in a Query

Post by Louis Adekoya »

Hi guys, I raised this over a week ago and as I've said this is a blocking issue for me. Please respond.

A couple of things I have tried.

  1. I tried invoking my query service on the expand event of the collapsible block. When I do this and expand a block in test, it goes into a loop and I have to kill the appery platform. The JS in my query where clause is something like (different variations of):

    code
    Apperyio("collSetGrpMembers")&#46;children()&#46;each(function() {
    var vPrayee = $(this)&#46;closest()&#46;find('[name="lblHiddenUser"]');
    var vPrayeeText = vPrayee&#46;text();

    return '{ $and: [ { "prayee": "'+vPrayeeText+'" }, { "sender": "' + value + '" } ] }';

    }
    );
    /code

  2. I have also tried invoking the service when the service that populates my page completes or is successful. No loop this time but by sevice is reported to be a bad request - it is as if the prayee parameter is not being set.

    Another way to describe what I want to achieve is that I want to run my query individually for each block in my collapsible set, using a value held in a label with that block. Please let me know how to do this so I can proceed with my app. Thanks.

Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Retrieve Data from a Label in a Collapsible Set for Use in a Query

Post by Louis Adekoya »

Hi Yurii,

Thanks for your reply to my support request. I have tried to follow your steps, using the generic service code you posted here: https://getsatisfaction.com/apperyio/....

The image below shows what I have done and the issues I'm having. I hope that I am close but I can't seem to get past these issues. Please advise. Thanks.

Image

Edit: Here's the code below for easy reference:

code
Appery&#46;CombineResponses = Appery&#46;createClass(null, {
init : function(requestOptions) {
this&#46;__requestOptions = $&#46;extend({}, requestOptions);
},
process : function(settings) {
var signedInUser = localStorage&#46;getItem("userId");
var currentGroup = localStorage&#46;getItem("myactivegroup");
var currentSecondLevelElement = 0;
var resultObject;
var onSecondLevelSuccess = function(data){
if(data){
&#47;&#47;Insert in appropriate first level listItem recived second level list&#46;
resultObject[currentSecondLevelElement - 1]&#46;prayee = data;
};
currentSecondLevelElement++;
if(currentSecondLevelElement > resultObject&#46;length){
&#47;&#47;Print generic service response to console(for debug purpose)&#46;
console&#46;log("generic result");
console&#46;log(resultObject);
&#47;&#47;Return resultObject as generic service result when all second level requests are done
settings&#46;success(resultObject);
settings&#46;complete('success');
return;
};
var whereObjectForSecondLevelList = {
prayee: {
"collName": "
users",
"id": resultObject[currentSecondLevelElement - 1]&#46;id
},
sender: {
"collName": "users",
"
id": signedInUser
}
};
&#47;&#47;Ivoke second level service to get all second level items belongs to current firstLevel item&#46;
adura_Prayed_query_service&#46;execute({data: {where: JSON&#46;stringify(whereObjectForSecondLevelList)}, success: onSecondLevelSuccess});
};

Code: Select all

     var onFirstLevelReady = function(data){ 
         console&#46;log("firstLevelResponse"); 
         resultObject = data; 
         &#47;&#47;Run first iteration for secondLevel&#46; 
         onSecondLevelSuccess(); 
     }; 
     &#47;&#47;Invoke first level item&#46; 
     adura_GroupMember_query_service&#46;execute({data:{"group_id":currentGroup}},{success: onFirstLevelReady}); 
 } 

});

/code

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Retrieve Data from a Label in a Collapsible Set for Use in a Query

Post by Yurii Orishchuk »

Hi Louis,

Thanks for your screen shot:

1 Yes you can add any variables that you need for logic that you want to implement.

2 Not sure about the code(it's hidden with rectangle).

3 Yes you can add any parameters to the filter criteria.. But you need to combine them with "AND" or "OR" logic.
Details: https://devcenter.appery.io/documenta...

4 Yes you invoke it incorrectly. You need to invoke "datasource"(it's an instance of service on the page).
Example of the datasource: http://prntscr.com/7umrlz/direct

Regards.

Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Retrieve Data from a Label in a Collapsible Set for Use in a Query

Post by Louis Adekoya »

Thanks Yurii. I've given up on this particular feature for now but may revisit later.

Post Reply