Browse Source

added upvoting feature to feedback

Akira Laine 9 years ago
parent
commit
7088cbf806

+ 4 - 0
app/client/scripts/events.js

@@ -224,6 +224,10 @@ Template.feedback.events({
             Meteor.call("sendFeedback", $("#feedback_message").val());
             $("#feedback_message").val("");
         }
+    },
+    "click .upvote": function(){
+        var message = $(this).parent("card").prevObject[0].message;
+        Meteor.call("upvoteFeedback", message)
     }
 });
 

+ 10 - 0
app/client/stylesheets/app.css

@@ -79,3 +79,13 @@ main p.flow-text{
     margin: 0px 0 10px 0px;
     width: 155px;
 }
+
+.login-btn{
+    margin: 10px 0 0 10px;
+}
+
+.upvote{
+    float: right;
+    color: #00C853;
+    cursor: pointer;
+}

+ 1 - 0
app/client/templates/feedback.html

@@ -12,6 +12,7 @@
                         </div>
                         <div class="card-action">
                             <a class="lowercase" href="/u/{{username}}">{{username}}</a>
+                            {{upvotes}}<i class="material-icons upvote">thumb_up</i>
                         </div>
                     </div>
                 </div>

+ 1 - 1
app/client/templates/login.html

@@ -20,7 +20,7 @@
                     <i class="material-icons right">send</i>
                 </button>
             </form>
-            <button id="github-login" class="btn waves-effect waves-light grey social">Login With GitHub</button>
+            <button id="github-login" class="btn waves-effect waves-light grey login-btn">Login With GitHub</button>
         </div>
     </main>
     {{> footer}}

+ 1 - 1
app/client/templates/register.html

@@ -25,7 +25,7 @@
                     <i class="material-icons right">send</i>
                 </button>
             </form>
-            <button id="github-login" class="btn waves-effect waves-light grey social">Login With GitHub</button>
+            <button id="github-login" class="btn waves-effect waves-light grey login-btn">Login With GitHub</button>
         </div>
     </main>
     {{> footer}}

+ 6 - 0
app/database/schemas.js

@@ -168,6 +168,12 @@ Schemas.Feedback = new SimpleSchema({
     "messages.$.message": {
         type: String,
         label: "Feedback message"
+    },
+    "messages.$.upvotes": {
+        type: Number,
+        defaultValue: 0,
+        min: 0,
+        label: "Number of upvotes for a particualar feedback"
     }
 })
 

+ 7 - 1
app/server/server.js

@@ -1153,10 +1153,16 @@ Meteor.methods({
                 if (res.content.indexOf("true") > -1) {
                     return true;
                 } else {
-                    Feedback.update({}, {$push: {messages: {username: Meteor.user().profile.username, message: message}}});
+                    Feedback.update({}, {$push: {messages: {username: Meteor.user().profile.username, message: message, upvotes: 0}}});
                 }
             });
         }
+    },
+    upvoteFeedback: function(message){
+        if(!isBanned()){
+            //Check if the upvotedBy array in the feedback object contains user, if so, pull. Else, push.
+            Feedback.update({"messages.message": message}, {$inc: {"messages.$.upvotes": 1}});
+        }
     }
 });