Page 1 of 2

User ID specific data

Posted: Wed Dec 31, 2014 11:49 pm
by murad

Hi,

I am trying to build a simple sales report app , Where the user login and view his related data, I have 2 collections , Users and Test1 which is the sales database.
I have created a column in Test1 which is the user _id from users collection.

Now I have created a local storage parameter so when the user login it saves the user id to the second screen which is the report screen
I have mapped the services as attached but still returning all data.
Do i miss some steps ?

Appreciate your support Image Image Image


User ID specific data

Posted: Thu Jan 01, 2015 3:11 am
by Yurii Orishchuk

Hi Murad,

For your case you just need to click on "where" JS button and add following JS code:

pre

var whereObject = {"UserID": value};

return JSON.stringify(whereObject);

/pre

Also i can suggest you to use Pointer type instead of string to link two collections.

See details here: http://devcenter.appery.io/documentat...

Regards.


User ID specific data

Posted: Thu Jan 01, 2015 2:19 pm
by murad

Hi Yurii ,

Thanks you so much it worked perfectly :)

One quick question , in the pagination how can I make the next button disappear at the end of data records ? I have it now and at the end of the grid it keeps pressing next here is the screenshot
Image


User ID specific data

Posted: Thu Jan 01, 2015 10:25 pm
by Yurii Orishchuk

Hi Murad,

You can read more info about pagination here: http://devcenter.appery.io/tutorials/...

There describes how to use "limit" "skip" and "total".

But there is no information about how to get "total". Here is way to get it:

  1. Clone "list" service for collection you need.

  2. Rename it with name "......count".

  3. Open "request" service tab.

  4. Add "count" parameter with value "1".
    Details: http://prntscr.com/5ndzqs/direct

  5. Navigate to "test" service tab and click "test". And you will see response with all items in your collection.
    Detais: http://prntscr.com/5ne0cx/direct

  6. Now you can use this service to populate "total" variable. And use this variable as described in given above tutorial.

    Regards.
    .


User ID specific data

Posted: Fri Jan 02, 2015 11:53 pm
by murad

Hi Yuri ,

For the total , I used the same query service , Tested and is its returning the correct count see pic.Now I need the VAR to be use
d in the Next button so the next but will disappear after end of report , What is the required code to be amended in the "Next "button event ? Image Image


User ID specific data

Posted: Sat Jan 03, 2015 9:37 pm
by murad

please note that I have used the UserID int "where " so the query returns only items related to the user , What i need is to return the total count for each user so the next button disappears automatically at the end of pages.

many thanks for your great support :)


User ID specific data

Posted: Sun Jan 04, 2015 10:43 pm
by murad

Hi Yuri ,

Worked well thank you .
now I need to complete the search ,I have built the search screen and want to return search results based on 2 input values combined with the UserID which is stored in the local storage after successful login

I wrote this code in the " where button " but still returning undesired results which is the whole collection search , What should i do with this code ?

return '{"$or":[{"Area":{"$regex":"^'+value+'", "$options":"i"}},{"ItemDescription":{"$regex":"^'+value+'", "$options":"i"}}]}{"$and":[{"UserID ": "' + Apperyio.storage._id.get() + '"}';

Image


User ID specific data

Posted: Sun Jan 04, 2015 11:54 pm
by Yurii Orishchuk

Hi Murad,

Glad you get it work.

Also i can suggest you to use whereObject instead of whereString it's very clear to work with. Where string - is so much hard to write correctly.

Also you should use logic operators to combine several conditions.

Here is example for your case:

precode

var whereObject = {
$and: [
{"UserID": Apperyio.storage._id.get()},

Code: Select all

     {$or: [ 
         {"Area": {"$regex": value, "$options": "i"} }, 
         {"ItemDescription": {"$regex": value, "$options": "i"} }, 
     ]} 
 ] 

};
return JSON.stringify(whereObject);

/code/pre

Regards.


User ID specific data

Posted: Tue Jan 06, 2015 2:00 pm
by murad

Thanks Allot worked again :)

I know that appery DB don't support offline log-in, If the user logged in and didn't logout just click the ipad home button is it going to keep the session in the multi tasking if the app pressed again ?


User ID specific data

Posted: Fri Jan 09, 2015 5:46 am
by Yurii Orishchuk

Hi Murad,

If you store your sessionToken in localStorage - it will store session if you leave app.. And even after you reboot your phone.

Regards.