Page 1 of 1

Exporting slider value to database

Posted: Wed May 07, 2014 7:36 pm
by R2R

I'm trying to create a rating/feedback system for each page of content in my app.
On each page I have a slider UI element and a Submit Rating button. I'd like each user/visitor to that page to select a rating on the slider (0-5) and when s/he clicks Submit Rating, the value of the slider gets stored in a variable "contentPg1". I'd like to have a database on the backend with a column that includes the name of the variable and another column that includes its value. I'd like this data to update each time a user submits feedback. If the same user updates the feedback, the already created row (entry) in the database would get updated, but if a new user provides feedback, a new row is added. Is this possible? If so, how would I get this done? Here's a screenshot of how the rating panel looks like:

Image


Exporting slider value to database

Posted: Wed May 07, 2014 8:15 pm
by Kateryna Grynko

Hi Artur,

You would need 3 services to write/read/update data.

First read Database record for a specific user, as a service result check if the record is found:preif(localSrorage.getItem("myValue")){
update.execute();
} else{
create.execute();
}/pre


Exporting slider value to database

Posted: Wed May 07, 2014 8:26 pm
by R2R

Katya, thanks for responding and the suggestion, but let's take it one step at a time because I have no idea where to begin to create these 3 services.

Let's not worry about duplicate ratings for the same user for now.

I have a "User" database with one user (me) and a login service. Do I need to create another database for the rating/feedback information? If so, would I add two columns (e.g. content_ID, rating)? Then what?


Exporting slider value to database

Posted: Wed May 07, 2014 9:26 pm
by R2R

Katya, I think I'm getting somewhere on this. I've created the three services:

1) UserFeedback_User_Feedback_read_service
2) UserFeedback_User_Feedback_update_service
3) UserFeedback_User_Feedback_create_service

Each one has different Request parameters by default, but all of them have the column names (e.g. contentID, rating) I created in the database as parameters. I don't think that's right. Can you help me define the parameters and mappings for these services? Remember, the slider UI element (rating 0-5) and the contentID (I'm not sure what to do with this) are the data I want to collect in the database. The contentID should be associated with each unique page in the app (page1, page 2, page3, etc.), so my database should look like this:

Image


Exporting slider value to database

Posted: Wed May 07, 2014 9:28 pm
by Kateryna Grynko

Artur,

1) You don't have to create a new Database, you can use a collection to store this data. Create a collection with fields 'content_ID', 'rating', 'user' (here user id for this rating will be stored).

2) Here is how to add services to your app: http://docs.appery.io/documentation/b...


Exporting slider value to database

Posted: Wed May 07, 2014 10:22 pm
by R2R

Katya, I was able to successfully create the "Create" service and all the mappings. After testing, the collection had an extra row with the content_ID and the ratingValue. I exported it to .cvs and got the data a need. This is awesome!
Tomorrow I'm gonna work on the "Read" and "Update" services as I don't want to create a duplicate entry/row for the same user rating the same content.

Thanks for your help!


Exporting slider value to database

Posted: Thu May 08, 2014 4:22 pm
by R2R

Hello Katya, this morning I was able to create the createService and show three items in the collection: 1) user_ID 2) content_ID 3) rating Value

This was a success, so I then added the other two services as follows:

I also created the readService and updateService. My readService is set up as follows:

Request: X-Appery-Database-Id, X-Appery-Session-Token, _id, user_ID, content_ID

Response: user_ID, content_ID, _id, _createdAt, _updatedAt, acl

My updateService is set up as follows:

Request: X-Appery-Database-Id, X-Appery-Session-Token, _id, user_ID, content_ID, acl,

Response: _updatedAt

I add two events in the Data tab on the page where my feedback slider is:

  1. userFeedbackReadService Error Invoke service userFeedbackCreateService
    2) userFeedbackReadService Success Invoke service userFeedbackUpdateService

The action on the button is:
btnSubmit Click Invoke service userFeedbackReadService

I'm not getting any entries in the collection when testing.
What am I missing?