瀏覽代碼

Moved create room to admin page.

KrisVos130 9 年之前
父節點
當前提交
a01c74724a
共有 4 個文件被更改,包括 66 次插入62 次删除
  1. 3 0
      app/app.css
  2. 52 50
      app/app.js
  3. 11 1
      app/templates/admin.html
  4. 0 11
      app/templates/dashboard.html

+ 3 - 0
app/app.css

@@ -675,4 +675,7 @@ footer a:hover{
   margin-right: auto;
   margin-left: auto;
   text-align: center;
+}
+.admin-queue-panel:first-child {
+  margin-top: 100px;
 }

+ 52 - 50
app/app.js

@@ -185,18 +185,6 @@ if (Meteor.isClient) {
         }
     });
 
-    Template.dashboard.events({
-        "click #croom_create": function() {
-            Meteor.call("createRoom", $("#croom").val(), function (err, res) {
-                if (err) {
-                    alert("Error " + err.error + ": " + err.reason);
-                } else {
-                    window.location = "/" + $("#croom").val();
-                }
-            });
-        }
-    });
-
     Template.dashboard.helpers({
       rooms: function() {
         return Rooms.find({});
@@ -424,6 +412,15 @@ if (Meteor.isClient) {
             if (_sound !== undefined) {
                 _sound.stop();
             }
+        },
+        "click #croom_create": function() {
+            Meteor.call("createRoom", $("#croom").val(), function (err, res) {
+                if (err) {
+                    alert("Error " + err.error + ": " + err.reason);
+                } else {
+                    window.location = "/" + $("#croom").val();
+                }
+            });
         }
     });
 
@@ -860,50 +857,55 @@ if (Meteor.isServer) {
             }
         },
         createRoom: function(type) {
-            if (Rooms.find({type: type}).count() === 0) {
-                Rooms.insert({type: type}, function(err) {
-                    if (err) {
-                        throw err;
-                    } else {
-                        if (Playlists.find({type: type}).count() === 1) {
-                            if (History.find({type: type}).count() === 0) {
-                                History.insert({type: type, history: []}, function(err3) {
-                                    if (err3) {
-                                        throw err3;
-                                    } else {
-                                        startStation();
-                                        return true;
-                                    }
-                                });
-                            } else {
-                                startStation();
-                                return true;
-                            }
+            var userData = Meteor.users.find(Meteor.userId());
+            if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
+                if (Rooms.find({type: type}).count() === 0) {
+                    Rooms.insert({type: type}, function(err) {
+                        if (err) {
+                            throw err;
                         } else {
-                            Playlists.insert({type: type, songs: getSongsByType(type)}, function (err2) {
-                                if (err2) {
-                                    throw err2;
+                            if (Playlists.find({type: type}).count() === 1) {
+                                if (History.find({type: type}).count() === 0) {
+                                    History.insert({type: type, history: []}, function(err3) {
+                                        if (err3) {
+                                            throw err3;
+                                        } else {
+                                            startStation();
+                                            return true;
+                                        }
+                                    });
                                 } else {
-                                    if (History.find({type: type}).count() === 0) {
-                                        History.insert({type: type, history: []}, function(err3) {
-                                            if (err3) {
-                                                throw err3;
-                                            } else {
-                                                startStation();
-                                                return true;
-                                            }
-                                        });
+                                    startStation();
+                                    return true;
+                                }
+                            } else {
+                                Playlists.insert({type: type, songs: getSongsByType(type)}, function (err2) {
+                                    if (err2) {
+                                        throw err2;
                                     } else {
-                                        startStation();
-                                        return true;
+                                        if (History.find({type: type}).count() === 0) {
+                                            History.insert({type: type, history: []}, function(err3) {
+                                                if (err3) {
+                                                    throw err3;
+                                                } else {
+                                                    startStation();
+                                                    return true;
+                                                }
+                                            });
+                                        } else {
+                                            startStation();
+                                            return true;
+                                        }
                                     }
-                                }
-                            });
+                                });
+                            }
                         }
-                    }
-                });
+                    });
+                } else {
+                    throw "Room already exists";
+                }
             } else {
-                throw "Room already exists";
+                return false;
             }
             function startStation() {
                 var startedAt = Date.now();

+ 11 - 1
app/templates/admin.html

@@ -2,7 +2,7 @@
     {{> header}}
     <div class="landing row">
         {{#each queues}}
-            <div class="col-md-8 col-md-offset-2 ">
+            <div class="col-md-8 col-md-offset-2 admin-queue-panel">
                 <div class="panel panel-primary">
                     <div class="panel-heading">
                         <h3 class="panel-title">{{type}} review queue</h3>
@@ -41,6 +41,16 @@
             </div>
         {{/each}}
 
+        <div class="col-md-4 col-md-offset-4">
+            <div id="croom_container">
+                <label for="croom" id="croom_label">Room Name:</label>
+                <div class="input-group">
+                    <input type="text" id="croom" name="croom" required />
+                </div>
+                <button class="btn btn-warning btn-block" id="croom_create">Create</button>
+            </div>
+        </div>
+
         <div id="previewModal" class="modal fade" role="dialog">
             <div class="modal-dialog">
                 <!-- Modal content-->

+ 0 - 11
app/templates/dashboard.html

@@ -12,17 +12,6 @@
               </div>
            {{/each}}
         </div>
-        <div class="col-md-4"></div>
-        <div class="col-md-4">
-            <div id="croom_container">
-                <label for="croom" id="croom_label">Room Name:</label>
-                <div class="input-group">
-                    <input type="text" id="croom" name="croom" required />
-                </div>
-                <button class="btn btn-warning btn-block" id="croom_create">Create</button>
-            </div>
-        </div>
-        <div class="col-md-4"></div>
         <ul class="bg-bubbles">
             <li></li>
             <li></li>