Przeglądaj źródła

Re-added loading screen and Rooms to collections.

KrisVos130 9 lat temu
rodzic
commit
fb7dbc3a9d
4 zmienionych plików z 77 dodań i 53 usunięć
  1. 12 0
      app/app.css
  2. 43 26
      app/app.js
  3. 5 0
      app/templates/loading.html
  4. 17 27
      app/templates/room.html

+ 12 - 0
app/app.css

@@ -481,3 +481,15 @@ footer a:hover{
 #croom {
   width: 304px !important;
 }
+
+#spinner {
+  font-size: 200px;
+  color: bisque;
+}
+
+#spinner-container {
+  margin-left: auto;
+  margin-right: auto;
+  width: 200px;
+  margin-top: 10%;
+}

+ 43 - 26
app/app.js

@@ -1,5 +1,6 @@
 History = new Mongo.Collection("history");
 Playlists = new Mongo.Collection("playlists");
+Rooms = new Mongo.Collection("rooms");
 
 if (Meteor.isClient) {
     Meteor.startup(function() {
@@ -107,6 +108,11 @@ if (Meteor.isClient) {
                 })
             });
             $("#stop").show();
+        },
+        "click #croom_create": function() {
+            Meteor.call("createRoom", $("#croom").val(), function (err, res) {
+                console.log(err, res);
+            });
         }
     });
 
@@ -177,6 +183,9 @@ if (Meteor.isClient) {
         },
         artist: function(){
           return Session.get("artist");
+        },
+        loaded: function() {
+            return Session.get("loaded");
         }
     });
 
@@ -324,31 +333,33 @@ if (Meteor.isClient) {
 
         Meteor.subscribe("history");
         Meteor.subscribe("playlists");
+        Meteor.subscribe("rooms", function() {
+            Session.set("loaded", false);
+            console.log(Rooms.find({type: type}).fetch().length);
+            if (Rooms.find({type: type}).count() !== 1) {
+                window.location = "/";
+            } else {
+                Session.set("loaded", true);
+                Meteor.setInterval(function () {
+                    var data = undefined;
+                    var dataCursor = History.find({type: type});
+                    dataCursor.map(function (doc) {
+                        if (data === undefined) {
+                            data = doc;
+                        }
+                    });
+                    if (data !== undefined && data.history.length > size) {
+                        currentSong = data.history[data.history.length - 1];
+                        size = data.history.length;
+                        startSong();
+                    }
+                }, 1000);
 
-        var room_types = ["edm", "nightcore"];
-        if (room_types.indexOf(type) === -1) {
-            window.location = "/";
-        }
-
-        Meteor.setInterval(function() {
-            var data = undefined;
-            var dataCursor = History.find({type: type});
-            dataCursor.map(function(doc) {
-                if (data === undefined) {
-                    data = doc;
-                }
-            });
-            if (data !== undefined && data.history.length > size) {
-                currentSong = data.history[data.history.length-1];
-                size = data.history.length;
-                startSong();
+                Meteor.setInterval(function () {
+                    resizeSeekerbar();
+                }, 50);
             }
-        }, 1000);
-
-        Meteor.setInterval(function() {
-            resizeSeekerbar();
-        }, 50);
-
+        });
     });
 
     Template.admin.events({
@@ -413,11 +424,12 @@ if (Meteor.isServer) {
         }
     }
 
-    var room_types = ["edm", "nightcore"];
+    //var room_types = ["edm", "nightcore"];
     var songsArr = [];
 
 
-    room_types.forEach(function(type) {
+    Rooms.find({}).fetch().forEach(function(room) {
+        var type = room.type;
         if (Playlists.find({type: type}).fetch().length === 0) {
             if (type === "edm") {
                 Playlists.insert({type: type, songs: [
@@ -442,6 +454,7 @@ if (Meteor.isServer) {
         }
 
         function skipSong() {
+            songs = Playlists.find({type: type}).fetch()[0].songs;
             if (currentSong < (songs.length - 1)) {
                 currentSong++;
             } else currentSong = 0;
@@ -489,6 +502,10 @@ if (Meteor.isServer) {
         return Playlists.find({})
     });
 
+    Meteor.publish("rooms", function() {
+        return Rooms.find()
+    });
+
     Meteor.methods({
         createUserMethod: function(formData, captchaData) {
             var verifyCaptchaResponse = reCAPTCHA.verifyCaptcha(this.connection.clientAddress, captchaData);
@@ -507,7 +524,7 @@ if (Meteor.isServer) {
         },
         addPlaylistSong: function(type, songData) {
             type = type.toLowerCase();
-            if (room_types.indexOf(type) !== -1) {
+            if (Rooms.find({type: type}).count() === 1) {
                 if (songData !== undefined && Object.keys(songData).length === 4 && songData.type !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined) {
                     songData.duration = getSongDuration(songData.title);
                     Playlists.update({type: type}, {$push: {songs: {id: songData.id, title: songData.title, artist: songData.artist, duration: songData.duration, type: songData.type}}});

+ 5 - 0
app/templates/loading.html

@@ -0,0 +1,5 @@
+<template name="loading">
+    <div id="spinner-container">
+        <i class="fa fa-spinner fa-pulse" id="spinner"></i>
+    </div>
+</template>

+ 17 - 27
app/templates/room.html

@@ -1,33 +1,23 @@
 <template name="room">
     <div class="landing">
-        <h1 class="room-name">{{{type}}}</h1>
-        <h2 class="room-title">{{{title}}}</h2>
-        <h2 class="room-artist">{{{artist}}}</h2>
-        <div id="seeker-container">
-            <div id="seeker-bar"></div>
-        </div>
-        {{> playlist}}
-        <input type="text" id="song-input">
-        <button type="button" id="search-song" class="button">Search</button>
-        <div id="song-results"></div>
-        <!--src="http://www.youtube.com/embed/XGSy3_Czz8k?autoplay=1&controls=0&autohide=1">-->
+        {{#if loaded}}
+            <h1 class="room-name">{{{type}}}</h1>
+            <h2 class="room-title">{{{title}}}</h2>
+            <h2 class="room-artist">{{{artist}}}</h2>
+            <div id="seeker-container">
+                <div id="seeker-bar"></div>
+            </div>
+            {{> playlist}}
+            <input type="text" id="song-input">
+            <button type="button" id="search-song" class="button">Search</button>
+            <div id="song-results"></div>
+            <!--src="http://www.youtube.com/embed/XGSy3_Czz8k?autoplay=1&controls=0&autohide=1">-->
 
-        <div width="960" height="540" id="player">
-        </div>
-        <h1 class="room-name">{{{type}}}</h1>
-        <h2 class="room-title">{{{title}}}</h2>
-        <h2 class="room-artist">{{{artist}}}</h2>
-        <div id="seeker-container">
-            <div id="seeker-bar"></div>
-        </div>
-        {{> playlist}}
-        <input type="text" id="song-input">
-        <button type="button" id="search-song" class="button">Search</button>
-        <div id="song-results"></div>
-        <!--src="http://www.youtube.com/embed/XGSy3_Czz8k?autoplay=1&controls=0&autohide=1">-->
-
-        <div width="960" height="540" id="player">
-        </div>
+            <div width="960" height="540" id="player">
+            </div>
+        {{else}}
+            {{> loading}}
+        {{/if}}
         <ul class="bg-bubbles">
             <li></li>
             <li></li>