Quellcode durchsuchen

Added button on rooms to make rooms private or not.

KrisVos130 vor 9 Jahren
Ursprung
Commit
cfe6cc2954
4 geänderte Dateien mit 66 neuen und 11 gelöschten Zeilen
  1. 1 1
      app/client/app.css
  2. 9 0
      app/client/client.js
  3. 11 6
      app/client/templates/room.html
  4. 45 4
      app/server/server.js

+ 1 - 1
app/client/app.css

@@ -1148,7 +1148,7 @@ nav form input[type="image"]{
 .about a{
     color: white;
 }
-#play, #pause, #skip, #shuffle, #sync {
+#play, #pause, #skip, #shuffle, #sync, #unlock, #lock {
     cursor: pointer;
 }
 .delete-room {

+ 9 - 0
app/client/client.js

@@ -456,6 +456,12 @@ Template.room.events({
             }
         }
     },
+    "click #lock": function() {
+        Meteor.call("lockRoom", Session.get("type"));
+    },
+    "click #unlock": function() {
+        Meteor.call("unlockRoom", Session.get("type"));
+    },
     "click #side-panel": function(e) {
         Meteor.setTimeout(function() {
         var elem = document.getElementById('chat');
@@ -928,6 +934,9 @@ Template.room.helpers({
     paused: function() {
         return Session.get("state") === "paused";
     },
+    private: function() {
+        return Rooms.findOne({type: Session.get("type")}).private === true;
+    },
     report: function() {
         return Session.get("reportObj");
     },

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

@@ -6,16 +6,21 @@
                 <div class="col-md-9" id="station-main">
                     <nav>
                         <div id="room-icons">
-                            <a class="back" href="/"><i class="fa fa-chevron-left"></i></a>
-                            <i class="fa fa-refresh fa-1" id="sync"></i>
+                            <a class="back" href="/"><i class="fa fa-chevron-left" title="Go back to the dashboard."></i></a>
+                            <i class="fa fa-refresh fa-1" id="sync" title="Synchronise to the proper duration in this video."></i>
                             {{#if isAdmin}}
                                 {{#if paused}}
-                                    <i class="fa fa-play fa-1" id="play"></i>
+                                    <i class="fa fa-play fa-1" id="play" title="Un-pause this room."></i>
                                 {{else}}
-                                    <i class="fa fa-pause fa-1" id="pause"></i>
+                                    <i class="fa fa-pause fa-1" id="pause" title="Pause this room."></i>
+                                {{/if}}
+                                <i class="fa fa-step-forward fa-1" id="skip" title="Skip this song."></i>
+                                <i class="fa fa-random fa-1" id="shuffle" title="Shuffle this room's playlist."></i>
+                                {{#if private}}
+                                    <i class="fa fa-lock fa-1" id="unlock" title="Unlock this room."></i>
+                                {{else}}
+                                    <i class="fa fa-unlock fa-1" id="lock" title="Lock this room."></i>
                                 {{/if}}
-                                <i class="fa fa-step-forward fa-1" id="skip"></i>
-                                <i class="fa fa-random fa-1" id="shuffle"></i>
                             {{/if}}
                         </div>
 

+ 45 - 4
app/server/server.js

@@ -115,7 +115,7 @@ function Station(type) {
     Meteor.publish(type, function() {
         return undefined;
     });
-    var _this = this;
+    var self = this;
     var startedAt = Date.now();
     var playlist = Playlists.findOne({type: type});
     var songs = playlist.songs;
@@ -134,7 +134,7 @@ function Station(type) {
     Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}, users: 0}});
 
     this.skipSong = function() {
-        _this.voted = [];
+        self.voted = [];
         voteNum = 0;
         Rooms.update({type: type}, {$set: {votes: 0}});
         songs = Playlists.findOne({type: type}).songs;
@@ -167,7 +167,7 @@ function Station(type) {
     this.shufflePlaylist = function() {
         voteNum = 0;
         Rooms.update({type: type}, {$set: {votes: 0}});
-        _this.voted = [];
+        self.voted = [];
         songs = Playlists.findOne({type: type}).songs;
         currentSong = 0;
         Playlists.update({type: type}, {$set: {"songs": []}});
@@ -196,7 +196,7 @@ function Station(type) {
             timer.pause();
         }
         timer = new Timer(function() {
-            _this.skipSong();
+            self.skipSong();
         }, songs[currentSong].duration * 1000);
     };
 
@@ -224,6 +224,29 @@ function Station(type) {
     };
     this.type = type;
 
+    var private = Rooms.findOne({type: type}).private;
+
+    if (typeof private !== "boolean") {
+        Rooms.update({type: type}, {$set: {"private": false}});
+        private = false;
+    }
+
+    this.private = private;
+
+    this.unlock = function() {
+        if (self.private) {
+            self.private = false;
+            Rooms.update({type: type}, {$set: {"private": false}});
+        }
+    };
+
+    this.lock = function() {
+        if (!self.private) {
+            self.private = true;
+            Rooms.update({type: type}, {$set: {"private": true}});
+        }
+    };
+
     this.songTimer();
     this.voted = [];
 }
@@ -464,6 +487,24 @@ function isBanned() {
 
 
 Meteor.methods({
+    lockRoom: function(type) {
+        if (isAdmin() && !isBanned()) {
+            getStation(type, function(station){
+                station.lock();
+            });
+        } else {
+            throw new Meteor.Error(403, "Invalid permissions.");
+        }
+    },
+    unlockRoom: function(type) {
+        if (isAdmin() && !isBanned()) {
+            getStation(type, function(station){
+                station.unlock();
+            });
+        } else {
+            throw new Meteor.Error(403, "Invalid permissions.");
+        }
+    },
     banUser: function(username, period, reason) {
         if (isAdmin() && !isBanned()) {
             var user = Meteor.user();