瀏覽代碼

added vote to skip song feature

AkiraLaine 9 年之前
父節點
當前提交
d7cb62ca46
共有 4 個文件被更改,包括 59 次插入4 次删除
  1. 0 4
      app/client/app.css
  2. 24 0
      app/client/client.js
  3. 6 0
      app/client/templates/room.html
  4. 29 0
      app/server/server.js

+ 0 - 4
app/client/app.css

@@ -290,8 +290,6 @@ ul {
     color: white;
     -webkit-transition-duration: 1s;
     transition-duration: 1s;
-    -webkit-transition-timing-function: ease-in-put;
-    transition-timing-function: ease-in-put;
     font-weight: 200;
 }
 
@@ -300,8 +298,6 @@ ul {
     color: white;
     -webkit-transition-duration: 1s;
     transition-duration: 1s;
-    -webkit-transition-timing-function: ease-in-put;
-    transition-timing-function: ease-in-put;
     font-weight: 200;
 }
 

+ 24 - 0
app/client/client.js

@@ -20,6 +20,7 @@ var id = parts.pop();
 var type = id.toLowerCase();
 var resizeSeekerbarInterval;
 var station_c = undefined;
+var songMID;
 
 UI.registerHelper("formatTime", function(seconds) {
     var d = moment.duration(parseInt(seconds), 'seconds');
@@ -251,6 +252,11 @@ Template.room.events({
     "click #dislike": function(e) {
         Meteor.call("dislikeSong", Session.get("currentSong").mid);
     },
+    "click #vote-skip": function(){
+        Meteor.call("voteSkip", type);
+        $("#vote-skip").attr("disabled", true);
+        songMID = Session.get("currentSong").mid;
+    },
     "click #report-prev": function(e) {
         if (Session.get("previousSong") !== undefined) {
             Session.set("reportPrevious", true);
@@ -504,6 +510,13 @@ Template.room.events({
     }
 });
 
+Meteor.setInterval(function(){
+    console.log(Session.get("currentSong").mid);
+    if(songMID !== Session.get("currentSong").mid){
+        $("#vote-skip").attr("disabled", false);
+    }
+}, 1000);
+
 Template.room.onRendered(function() {
     $(document).ready(function() {
         function makeSlider(){
@@ -671,6 +684,17 @@ Template.room.helpers({
         } else {
             return Session.get("currentSongR");
         }
+    },
+    votes: function(){
+        Meteor.setInterval(function(){
+            Meteor.call("getVoteNum", Rooms.findOne({type: id}).type, function(err, num){
+                if(err){
+                    console.log(err);
+                }
+                Session.set("voteNum", num);
+            });
+        }, 1000);
+        return Session.get("voteNum");
     }
 });
 

+ 6 - 0
app/client/templates/room.html

@@ -76,6 +76,9 @@
                             <div class="col-md-2">
                                 <button title="I dislike this song." type="button" id="dislike" class="btn btn-danger btn-lg {{disliked}} action-button"><i class="fa fa-meh-o"> {{dislikes}}</i></button>
                             </div>
+                            <div class="col-md-2">
+                                <button type="button" id="vote-skip" class="btn btn-primary btn-lg action-button"><i class="fa fa-step-forward"></i> <span>{{votes}}</span></button>
+                            </div>
                         {{else}}
                             <div class="col-md-2">
                                 <button title="You need to be logged to smile this song." type="button" class="btn btn-success btn-lg action-button" disabled><i class="fa fa-smile-o"> {{likes}}</i></button>
@@ -83,6 +86,9 @@
                             <div class="col-md-2">
                                 <button title="You need to be logged to dislike this song." type="button" class="btn btn-danger btn-lg action-button" disabled><i class="fa fa-meh-o"> {{dislikes}}</i></button>
                             </div>
+                            <div class="col-md-2">
+                                <button title="You need to be logged to vote to skip this song." type="button" class="btn btn-primary btn-lg action-button" disabled><i class="fa fa-step-forward"></i> <span>{{votes}}</span></button>
+                            </div>
                         {{/if}}
                         <div class="col-md-2">
                             <button title="Report this song!" type="button" id="report-modal" class="btn btn-warning btn-lg report-button action-button" data-toggle="modal" data-target="#reportModal"><i class="fa fa-flag"></i></button>

+ 29 - 0
app/server/server.js

@@ -13,6 +13,7 @@ Meteor.startup(function() {
 Alerts.update({active: true}, {$set: {active: false}}, { multi: true });
 
 var stations = [];
+var voteNum = 0;
 
 var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_";
 function createUniqueSongId() {
@@ -122,6 +123,9 @@ function Station(type) {
     Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}, users: 0}});
 
     this.skipSong = function() {
+        _this.voted = [];
+        voteNum = 0;
+        Rooms.update({type: type}, {$set: {votes: 0}});
         songs = Playlists.findOne({type: type}).songs;
         songs.forEach(function(song, index) {
             if (song.title === currentTitle) {
@@ -150,6 +154,9 @@ function Station(type) {
     };
 
     this.shufflePlaylist = function() {
+        voteNum = 0;
+        Rooms.update({type: type}, {$set: {votes: 0}});
+        _this.voted = [];
         songs = Playlists.findOne({type: type}).songs;
         currentSong = 0;
         Playlists.update({type: type}, {$set: {"songs": []}});
@@ -207,6 +214,7 @@ function Station(type) {
     this.type = type;
 
     this.songTimer();
+    this.voted = [];
 }
 
 function shuffle(array) {
@@ -531,6 +539,27 @@ Meteor.methods({
             throw new Meteor.Error(403, "Invalid permissions.");
         }
     },
+    voteSkip: function(type){
+      if(Meteor.userId()){
+          var user = Meteor.user();
+          getStation(type, function(station){
+              if(station.voted.indexOf(profile.username) !== -1){
+                  station.voted.push(user.profile.username);
+                  voteNum++;
+                  Rooms.update({type: type}, {$set: {votes: voteNum}});
+                  console.log(voteNum);
+                  if(voteNum === 3){
+                      station.skipSong();
+                  }
+              } else{
+                  console.log("Else");
+              }
+          })
+      }
+    },
+    getVoteNum: function(type){
+        return Rooms.findOne({type: type}).votes;
+    },
     submitReport: function(report, id) {
         var obj = report;
         obj.id = id;