Browse Source

Fixed likes/dislikes messing up.

KrisVos130 9 years ago
parent
commit
f322dbfa5f
3 changed files with 66 additions and 18 deletions
  1. 11 0
      app/client/client.js
  2. 38 2
      app/client/templates/stations.html
  3. 17 16
      app/server/server.js

+ 11 - 0
app/client/client.js

@@ -783,10 +783,13 @@ Template.stations.events({
         Session.set("genre", $(e.toElement).data("genre"));
         Session.set("type", "queue");
         $("#type").val(this.type);
+        $("#mid").val(this.mid);
         $("#artist").val(this.artist);
         $("#title").val(this.title);
         $("#img").val(this.img);
         $("#id").val(this.id);
+        $("#likes").val(this.likes);
+        $("#dislikes").val(this.dislikes);
         $("#duration").val(this.duration);
         $("#skip-duration").val(this.skipDuration);
     },
@@ -795,13 +798,19 @@ Template.stations.events({
         Session.set("genre", $(e.toElement).data("genre"));
         Session.set("type", "playlist");
         $("#type").val(this.type);
+        $("#mid").val(this.mid);
         $("#artist").val(this.artist);
         $("#title").val(this.title);
         $("#img").val(this.img);
         $("#id").val(this.id);
+        $("#likes").val(this.likes);
+        $("#dislikes").val(this.dislikes);
         $("#duration").val(this.duration);
         $("#skip-duration").val(this.skipDuration);
     },
+    "click #rreset_confirm": function(e){
+        Meteor.call("resetRating");
+    },
     "click .add-song-button": function(e){
         var genre = $(e.toElement).data("genre") || $(e.toElement).parent().data("genre");
         Meteor.call("addSongToPlaylist", genre, this);
@@ -897,6 +906,8 @@ Template.stations.events({
     "click #save-song-button": function() {
         var newSong = {};
         newSong.id = $("#id").val();
+        newSong.likes = $("#likes").val();
+        newSong.dislikes = $("#dislikes").val();
         newSong.title = $("#title").val();
         newSong.artist = $("#artist").val();
         newSong.img = $("#img").val();

+ 38 - 2
app/client/templates/stations.html

@@ -17,6 +17,8 @@
                                   <th>Artist(s)</th>
                                   <th>Type</th>
                                   <th>Id</th>
+                                  <th>Likes</th>
+                                  <th>Dislikes</th>
                                   <th>Img</th>
                                   <th>Preview</th>
                                   <th>Edit</th>
@@ -31,6 +33,8 @@
                                       <td>{{artist}}</td>
                                       <td>{{type}}</td>
                                       <td>{{id}}</td>
+                                      <td>{{likes}}</td>
+                                      <td>{{dislikes}}</td>
                                       <td class="column-small"><a href="{{img}}" target="_blank"><button class="btn btn-primary preview-button">Preview Image</button></a></td>
                                       <td class="column-small"><button class="btn btn-primary preview-button" data-toggle="modal" data-target="#previewModal">Preview</button></td>
                                       <td class="column-small"><button class="btn btn-primary edit-queue-button" data-genre="{{../type}}" data-toggle="modal" data-target="#editModal">Edit</button></td>
@@ -55,10 +59,13 @@
                       <table class="table table-striped">
                           <thead>
                           <tr>
+                              <th>Mid</th>
                               <th>Title</th>
                               <th>Artist(s)</th>
                               <th>Type</th>
                               <th>Id</th>
+                              <th>Likes</th>
+                              <th>Dislikes</th>
                               <th>Img</th>
                               <th>Preview</th>
                               <th>Edit</th>
@@ -68,10 +75,13 @@
                           <tbody>
                           {{#each songs}}
                           <tr>
-                              <th scope="row">{{title}}</th>
+                              <th scope="row">{{mid}}</th>
+                              <th>{{title}}</th>
                               <td>{{artist}}</td>
                               <td>{{type}}</td>
                               <td>{{id}}</td>
+                              <td>{{likes}}</td>
+                              <td>{{dislikes}}</td>
                               <td class="column-small"><a href="{{img}}" target="_blank"><button class="btn btn-primary preview-button">Preview Image</button></a></td>
                               <td class="column-small"><button class="btn btn-primary preview-button" data-toggle="modal" data-target="#previewModal">Preview</button></td>
                               <td class="column-small"><button class="btn btn-primary edit-playlist-button" data-genre="{{../type}}" data-toggle="modal" data-target="#editModal">Edit</button></td>
@@ -85,6 +95,8 @@
           </div>
       {{/each}}
 
+        <button class="btn btn-danger col-md-6 col-md-offset-3" id="rrating" data-toggle="modal" data-target="#confirmModal">Reset Rating</button>
+
       <div class="col-md-4 col-md-offset-4">
           <div id="croom_container">
               <label for="croom_display" class="croom_label">Room Display Name (eg 'Edm'):</label>
@@ -99,6 +111,24 @@
           </div>
       </div>
 
+        <div id="confirmModal" class="modal fade" role="dialog">
+            <div class="modal-dialog">
+                <!-- Modal content-->
+                <div class="modal-content">
+                    <div class="modal-header">
+                        <button type="button" class="close" data-dismiss="modal">&times;</button>
+                        <h4 class="modal-title">Confirm</h4>
+                    </div>
+                    <div class="modal-body">
+                        <button id="rreset_confirm" class="btn btn-danger">Reset All Ratings</button>
+                    </div>
+                    <div class="modal-footer">
+                        <button id="close-modal" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+                    </div>
+                </div>
+            </div>
+        </div>
+
       <div id="previewModal" class="modal fade" role="dialog">
           <div class="modal-dialog">
               <!-- Modal content-->
@@ -136,6 +166,8 @@
                           <option name="youtube" id="youtube">YouTube</option>
                           <option name="soundcloud" id="soundcloud">SoundCloud</option>
                       </select>
+                      <label for="mid" class="song-input-label">Song MID</label>
+                      <input class="song-input" name="mid" id="mid" type="text" />
                       <label for="id" class="song-input-label">Song ID</label>
                       <input class="song-input" name="id" id="id" type="text" />
                       <label for="id" class="song-input-label">Song Artist</label>
@@ -144,8 +176,12 @@
                       <input class="song-input" name="title" id="title" type="text" />
                       <label for="title" class="song-input-label">Song Duration</label>
                       <input class="song-input" name="duration" id="duration" type="number" />
-                      <label class="song-input-label">Skip Duration</label>
+                      <label for="skip-duration" class="song-input-label">Skip Duration</label>
                       <input class="song-input" id="skip-duration" type="number" />
+                      <label for="likes" class="song-input-label">Likes</label>
+                      <input class="song-input" id="likes" type="number"/>
+                      <label for="dislikes" class="song-input-label">Dislikes</label>
+                      <input class="song-input" id="dislikes" type="number"/>
                       <label for="img" class="song-input-label">Song Image</label>
                       <input class="song-input" name="img" id="img" type="text" />
                       <button type="button" id="get-spotify-info" class="button">Get Spotify Data</button>

+ 17 - 16
app/server/server.js

@@ -141,16 +141,6 @@ function Station(type) {
                 songs[currentSong].mid = newSong.mid;
                 Playlists.update({type: type, "songs": songs[currentSong]}, {$set: {"songs.$": newSong}});
             }
-            if (songs[currentSong].likes === undefined) {
-                var newSong = songs[currentSong];
-                newSong.likes = 0;
-                Playlists.update({type: type, "songs": newSong}, {$set: {"songs.$": newSong}});
-            }
-            if (songs[currentSong].dislikes === undefined) {
-                var newSong = songs[currentSong];
-                newSong.dislikes = 0;
-                Playlists.update({type: type, "songs": newSong}, {$set: {"songs.$": newSong}});
-            }
             currentTitle = songs[currentSong].title;
             Playlists.update({type: type}, {$set: {lastSong: currentSong}});
             Rooms.update({type: type}, {$set: {timePaused: 0}});
@@ -168,12 +158,6 @@ function Station(type) {
             if (song.mid === undefined) {
                 song.mid = createUniqueSongId();
             }
-            if (song.likes === undefined) {
-                song.likes = 0;
-            }
-            if (song.dislikes === undefined) {
-                song.dislikes = 0;
-            }
             Playlists.update({type: type}, {$push: {"songs": song}});
         });
         currentTitle = songs[currentSong].title;
@@ -439,6 +423,23 @@ function isAdmin() {
 }
 
 Meteor.methods({
+    resetRating: function() {
+        if (isAdmin()) {
+            stations.forEach(function (station) {
+                var type = station.type;
+                var temp_songs = Playlists.findOne({type: type}).songs;
+                Playlists.update({type: type}, {$set: {"songs": []}});
+                temp_songs.forEach(function (song) {
+                    song.likes = 0;
+                    song.dislikes = 0;
+                    Playlists.update({type: type}, {$push: {"songs": song}});
+                });
+            });
+            Meteor.users.update({}, {$set: {"profile.liked": [], "profile.disliked": []}}, {multi: true});
+        } else {
+            throw Meteor.Error(403, "Invalid permissions.");
+        }
+    },
     removeAlerts: function() {
         if (isAdmin()) {
             Alerts.update({active: true}, {$set: {active: false}}, { multi: true });