Browse Source

Additional changes to the reports DB.

Wesley McCann 9 years ago
parent
commit
56aa04a954
3 changed files with 75 additions and 80 deletions
  1. 31 74
      app/client/client.js
  2. 0 1
      app/client/templates/room.html
  3. 44 5
      app/server/server.js

+ 31 - 74
app/client/client.js

@@ -670,76 +670,30 @@ Template.room.events({
         }
     },
     "click #report-song-button": function() {
-        var report = {};
-
-        report.reportType = $(".checkbox")
-        report.reportSongB = $("#report-song").is(":checked");
-        report.reportTitleB = $("#report-title").is(":checked");
-        report.reportAuthorB = $("#report-author").is(":checked");
-        report.reportDurationB = $("#report-duration").is(":checked");
-        report.reportAudioB = $("#report-audio").is(":checked");
-        report.reportAlbumartB = $("#report-albumart").is(":checked");
-        report.reportOtherB = $("#report-other").is(":checked");
-
-        if (report.reportSongB) {
-            report.reportSong = {};
-            report.reportSong.notPlayingB = $("#report-song-not-playing").is(":checked");
-            report.reportSong.doesNotExistB = $("#report-song-does-not-exist").is(":checked");
-            report.reportSong.otherB = $("#report-song-other").is(":checked");
-            if (report.reportSong.otherB) {
-                report.reportSong.other = $("#report-song-other-ta").val();
-            }
-        }
-        if (report.reportTitleB) {
-            report.reportTitle = {};
-            report.reportTitle.incorrectB = $("#report-title-incorrect").is(":checked");
-            report.reportTitle.inappropriateB = $("#report-title-inappropriate").is(":checked");
-            report.reportTitle.otherB = $("#report-title-other").is(":checked");
-            if (report.reportTitle.otherB) {
-                report.reportTitle.other = $("#report-title-other-ta").val();
-            }
-        }
-        if (report.reportAuthorB) {
-            report.reportAuthor = {};
-            report.reportAuthor.incorrectB = $("#report-author-incorrect").is(":checked");
-            report.reportAuthor.inappropriateB = $("#report-author-inappropriate").is(":checked");
-            report.reportAuthor.otherB = $("#report-author-other").is(":checked");
-            if (report.reportAuthor.otherB) {
-                report.reportAuthor.other = $("#report-author-other-ta").val();
-            }
-        }
-        if (report.reportDurationB) {
-            report.reportDuration = {};
-            report.reportDuration.longB = $("#report-duration-incorrect").is(":checked");
-            report.reportDuration.shortB = $("#report-duration-inappropriate").is(":checked");
-            report.reportDuration.otherB = $("#report-duration-other").is(":checked");
-            if (report.reportDuration.otherB) {
-                report.reportDuration.other = $("#report-duration-other-ta").val();
-            }
-        }
-        if (report.reportAudioB) {
-            report.reportAudio = {};
-            report.reportAudio.inappropriate = $("#report-audio-inappropriate").is(":checked");
-            report.reportAudio.notPlayingB = $("#report-audio-incorrect").is(":checked");
-            report.reportAudio.otherB = $("#report-audio-other").is(":checked");
-            if (report.reportAudio.otherB) {
-                report.reportAudio.other = $("#report-audio-other-ta").val();
-            }
-        }
-        if (report.reportAlbumartB) {
-            report.reportAlbumart = {};
-            report.reportAlbumart.incorrectB = $("#report-albumart-incorrect").is(":checked");
-            report.reportAlbumart.inappropriateB = $("#report-albumart-inappropriate").is(":checked");
-            report.reportAlbumart.notShowingB = $("#report-albumart-inappropriate").is(":checked");
-            report.reportAlbumart.otherB = $("#report-albumart-other").is(":checked");
-            if (report.reportAlbumart.otherB) {
-                report.reportAlbumart.other = $("#report-albumart-other-ta").val();
-            }
-        }
-        if (report.reportOtherB) {
-            report.other = $("#report-other-ta").val();
-        }
-        Meteor.call("submitReport", report, Session.get("id"), function() {
+        var reports = {
+          room : Session.get("type"),
+          report : [{
+            song : Session.get("currentSong").mid,
+            type : [],
+            reason : [],
+          }]
+        };
+        var report = reports.report;
+
+        $(".report-layer-1 > .checkbox input:checked").each(function(){
+          console.log(this.id);
+          report.type.push(this.id);
+          if (this.id == "report-other") {
+            var otherText = $(".other-textarea").val();
+            report.reason.push(otherText);
+          }
+        });
+
+        $(".report-layer-2 input:checked").each(function(){
+          report.reason.push(this.id);
+        });
+
+        Meteor.call("submitReport", reports, Session.get("id"), function() {
             $("#close-modal-r").click();
         });
     }
@@ -1040,10 +994,13 @@ Template.admin.helpers({
           }
       });
       return playlists;
-  }/*,
-  reportsCount: function() {
-
-  }*/
+  },
+  reportsCount: function(room) {
+    room = room.toLowerCase();
+    var reports = Reports.findOne({room:room});
+    console.log(reports);
+    return reports ? reports.length : 0;
+  }
 });
 
 Template.stations.helpers({

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

@@ -179,7 +179,6 @@
             <!-- Report Modal -->
             <div id="reportModal" class="modal fade" role="dialog">
                 <div class="modal-dialog">
-
                     <!-- Modal content-->
                     <div class="modal-content">
                         <div class="modal-body">

+ 44 - 5
app/server/server.js

@@ -623,11 +623,50 @@ Meteor.methods({
         }
     },
     submitReport: function(report, id) {
-        if (!isBanned()) {
-            var obj = report;
-            obj.id = id;
-            Reports.insert(obj);
-        }
+      if (Meteor.userId() && !isBanned()) {
+          type = type.toLowerCase();
+          if (Rooms.find({type: type}).count() === 1) {
+              if (Queues.find({type: type}).count() === 0) {
+                  Queues.insert({type: type, songs: []});
+              }
+              if (songData !== undefined && Object.keys(songData).length === 5 && songData.type !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.img !== undefined) {
+                  songData.duration = getSongDuration(songData.title, songData.artist) || 0;
+                  songData.img = getSongAlbumArt(songData.title, songData.artist) || "";
+                  songData.skipDuration = 0;
+                  songData.likes = 0;
+                  songData.dislikes = 0;
+                  var mid = createUniqueSongId();
+                  if (mid !== undefined) {
+                      songData.mid = mid;
+                      Queues.update({type: type}, {
+                          $push: {
+                              songs: {
+                                  id: songData.id,
+                                  mid: songData.mid,
+                                  title: songData.title,
+                                  artist: songData.artist,
+                                  duration: songData.duration,
+                                  skipDuration: songData.skipDuration,
+                                  likes: songData.likes,
+                                  dislikes: songData.dislikes,
+                                  img: songData.img,
+                                  type: songData.type
+                              }
+                          }
+                      });
+                      return true;
+                  } else {
+                      throw new Meteor.Error(500, "Am error occured.");
+                  }
+              } else {
+                  throw new Meteor.Error(403, "Invalid data.");
+              }
+          } else {
+              throw new Meteor.Error(403, "Invalid genre.");
+          }
+      } else {
+          throw new Meteor.Error(403, "Invalid permissions.");
+      }
     },
     shufflePlaylist: function(type) {
         if (isAdmin() && !isBanned()) {