Browse Source

Nearly done with the reports. Working on GUI now.

Wesley McCann 9 years ago
parent
commit
26cfb6b218
5 changed files with 86 additions and 77 deletions
  1. 12 1
      app/client/app.css
  2. 27 25
      app/client/client.js
  3. 34 7
      app/client/templates/admin.html
  4. 1 15
      app/client/templates/stations.html
  5. 12 29
      app/server/server.js

+ 12 - 1
app/client/app.css

@@ -267,6 +267,17 @@ ul {
   padding-bottom: 10px;
   text-align: center;
 }
+
+.admin-container div a {
+  text-decoration: none;
+  font-size: 22px;
+  padding-left: 5px;
+  vertical-align: top;
+}
+
+.admin-container div a:hover {
+  text-decoration: none;
+}
 .admin-container h1 {
   margin: 0;
   display: inline-block;
@@ -1406,4 +1417,4 @@ nav form input[type="image"]{
 
 #doorbell-email{
     color: black;
-}
+}

+ 27 - 25
app/client/client.js

@@ -678,30 +678,25 @@ Template.room.events({
         }
     },
     "click #report-song-button": function() {
-        var reports = {
-          room : Session.get("type"),
-          report : [{
-            song : Session.get("currentSong").mid,
-            type : [],
-            reason : [],
-          }]
-        };
-        var report = reports.report;
+        var room = Session.get("type");
+        var reportData = {};
+        reportData.song = Session.get("currentSong").mid;
+        reportData.type = [];
+        reportData.reason = [];
 
         $(".report-layer-1 > .checkbox input:checked").each(function(){
-          console.log(this.id);
-          report.type.push(this.id);
+          reportData.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);
+          reportData.reason.push(this.id);
         });
 
-        Meteor.call("submitReport", reports, Session.get("id"), function() {
+        console.log(reportData);
+        Meteor.call("submitReport", room, reportData, Session.get("id"), function() {
             $("#close-modal-r").click();
         });
     }
@@ -985,7 +980,7 @@ Template.admin.helpers({
     var queues = Queues.find({}).fetch();
     return queues;
   },
-  users: function(){
+  usersOnline: function(){
       Meteor.call("getUserNum", function(err, num){
           if(err){
               console.log(err);
@@ -994,6 +989,10 @@ Template.admin.helpers({
       });
       return Session.get("userNum");
   },
+  allUsers: function(){
+    var users = Users.find({}).fetch();
+    console.log(users);
+  }
   playlists: function() {
       var playlists = Playlists.find({}).fetch();
       playlists.map(function(playlist) {
@@ -1010,7 +1009,19 @@ Template.admin.helpers({
     room = room.toLowerCase();
     var reports = Reports.findOne({room:room});
     console.log(reports);
-    return reports ? reports.length : 0;
+    return reports && "report" in reports ? reports.report.length : 0;
+  }
+});
+
+Template.admin.events({
+  "click #croom_create": function() {
+      Meteor.call("createRoom", $("#croom_display").val(), $("#croom_tag").val(), function (err, res) {
+          if (err) {
+              alert("Error " + err.error + ": " + err.reason);
+          } else {
+              window.location = "/" + $("#croom_tag").val();
+          }
+      });
   }
 });
 
@@ -1208,15 +1219,6 @@ Template.stations.events({
             }, 10000);
         }
     },
-    "click #croom_create": function() {
-        Meteor.call("createRoom", $("#croom_display").val(), $("#croom_tag").val(), function (err, res) {
-            if (err) {
-                alert("Error " + err.error + ": " + err.reason);
-            } else {
-                window.location = "/" + $("#croom_tag").val();
-            }
-        });
-    },
     "click #get-spotify-info": function() {
         var search = $("#title").val();
         var artistName = $("#artist").val();

+ 34 - 7
app/client/templates/admin.html

@@ -3,12 +3,12 @@
     <div class="landing">
         {{> header}}
           <div class="row" style="margin-top: 20px; height: 100%;">
-            <div class="col-md-5 col-md-offset-1 admin-container" style="height: 50%;">
+            <div class="col-md-6 col-md-offset-1 admin-container" style="height: 80%;">
               <div>
-                <h1>Playlists</h1>
+                <h1>Stations</h1><a href="#" data-toggle="modal" data-target="#addStation">(+)</a>
               </div>
               {{#each playlists}}
-                <p>{{display}} playlist</p>
+                <p>{{display}}</p>
                 <table class="table" style="border-bottom: 1px solid white;">
                   <tr>
                     <th>Songs</th>
@@ -28,15 +28,42 @@
                 </table>
               {{/each}}
             </div>
-            <div class="col-md-4 col-md-offset-1 admin-container" style="height: 30%;">
+            <div class="col-md-3 col-md-offset-1 admin-container" style="height: 80%;">
               <div>
                 <h1>Site statistics</h1>
               </div>
-              <p>Total Users Online: {{users}}</p>
-              <p>Total Registered Users: </p>
+              <p>Total Users Online: {{usersOnline}}</p>
+              <p>Total Registered Users: {{allUsers}}</p>
             </div>
           </div>
+          <div id="addStation" class="modal fade" role="dialog">
+              <div class="modal-dialog">
 
-        {{> bubbles}}
+                  <!-- Modal content-->
+                  <div class="modal-content">
+                      <div class="modal-header">
+                          <button type="button" class="close" data-dismiss="modal">&times;</button>
+                          <h4 class="modal-title">Create new station</h4>
+                      </div>
+                      <div class="modal-body">
+                        <div id="croom_container">
+                          <label for="croom_display" class="croom_label">Room Display Name (eg 'Edm'):</label>
+                          <div class="input-group">
+                            <input type="text" class="croom" id="croom_display" name="croom" required />
+                          </div>
+                          <label for="croom_tag" class="croom_label">Room Tag Name (eg 'edm'):</label>
+                          <div class="input-group">
+                            <input type="text" class="croom" id="croom_tag" name="croom" required />
+                          </div>
+                          <button class="btn btn-warning btn-block" id="croom_create">Create</button>
+                        </div>
+                      </div>
+                      <div class="modal-footer">
+                          <button id="close-modal-a" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+                      </div>
+                  </div>
+
+              </div>
+          </div>
     </div>
 </template>

+ 1 - 15
app/client/templates/stations.html

@@ -49,21 +49,7 @@
           </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>
-              <div class="input-group">
-                  <input type="text" class="croom" id="croom_display" name="croom" required />
-              </div>
-              <label for="croom_tag" class="croom_label">Room Tag Name (eg 'edm'):</label>
-              <div class="input-group">
-                  <input type="text" class="croom" id="croom_tag" name="croom" required />
-              </div>
-              <button class="btn btn-warning btn-block" id="croom_create">Create</button>
-          </div>
-      </div>
+      <!--<button class="btn btn-danger col-md-6 col-md-offset-3" id="rrating" data-toggle="modal" data-target="#confirmModal">Reset Rating</button>-->
 
         <div id="confirmModal" class="modal fade" role="dialog">
             <div class="modal-dialog">

+ 12 - 29
app/server/server.js

@@ -663,42 +663,25 @@ Meteor.methods({
             })
         }
     },
-    submitReport: function(report, id) {
+    submitReport: function(room, reportData) {
       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: []});
+          room = room.toLowerCase();
+          if (Rooms.find({type: room}).count() === 1) {
+              if (Reports.find({room: room}).count() === 0) {
+                  Reports.insert({room: room, report: []});
               }
-              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}, {
+              if (reportData !== undefined) {
+                      Reports.update({room: room}, {
                           $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
+                              report: {
+                                  song: reportData.song,
+                                  type: reportData.type,
+                                  reason: reportData.reason,
+                                  other: reportData.other
                               }
                           }
                       });
                       return true;
-                  } else {
-                      throw new Meteor.Error(500, "Am error occured.");
-                  }
               } else {
                   throw new Meteor.Error(403, "Invalid data.");
               }