R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Exporting slider value to database

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Exporting slider value to database

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

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Exporting slider value to database

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?

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Exporting slider value to database

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Exporting slider value to database

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...

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Exporting slider value to database

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!

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Exporting slider value to database

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?

Return to “Issues”