浏览代码

Added way to add songs to default playlists.

KrisVos130 9 年之前
父节点
当前提交
0d235c8f19
共有 2 个文件被更改,包括 72 次插入0 次删除
  1. 35 0
      app/app.js
  2. 37 0
      app/templates/admin.html

+ 35 - 0
app/app.js

@@ -363,6 +363,21 @@ if (Meteor.isClient) {
         }, 50);
 
     });
+
+    Template.admin.events({
+        "submit form": function(e){
+            e.preventDefault();
+            var genre = e.target.genre.value;
+            var type = e.target.type.value;
+            var id = e.target.id.value;
+            var title = e.target.title.value;
+            var artist = e.target.artist.value;
+            var songData = {type: type, id: id, title: title, artist: artist};
+            Meteor.call("addPlaylistSong", genre, songData, function(err, res) {
+                console.log(err, res);
+            });
+        }
+    });
 }
 
 if (Meteor.isServer) {
@@ -395,6 +410,7 @@ if (Meteor.isServer) {
     }
 
     var room_types = ["edm", "nightcore"];
+    var songsArr = [];
 
     room_types.forEach(function(type) {
         if (Playlists.find({type: type}).fetch().length === 0) {
@@ -418,6 +434,7 @@ if (Meteor.isServer) {
         }
 
         function skipSong() {
+            songs = Playlists.find({type: type}).fetch()[0].songs;
             if (currentSong < (songs.length - 1)) {
                 currentSong++;
             } else currentSong = 0;
@@ -480,6 +497,20 @@ if (Meteor.isServer) {
                 });
             }
             return true;
+        },
+        addPlaylistSong: function(type, songData) {
+            type = type.toLowerCase();
+            if (room_types.indexOf(type) !== -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}}});
+                    return true;
+                } else {
+                    throw new Meteor.error(403, "Invalid data.");
+                }
+            } else {
+                throw new Meteor.error(403, "Invalid genre.");
+            }
         }
     });
 }
@@ -488,6 +519,10 @@ Router.route("/", {
     template: "home"
 });
 
+Router.route("/admin", {
+    template: "admin"
+});
+
 Router.route("/:type", {
     template: "room"
 });

+ 37 - 0
app/templates/admin.html

@@ -0,0 +1,37 @@
+<template name="admin">
+    <div class="landing">
+
+        <form>
+            <label for="genre">Song Genre</label>
+            <select name="genre" id="genre">
+                <option name="edm" id="edm">EDM</option>
+                <option name="nightcore" id="nightcore">Nightcore</option>
+            </select>
+            <label for="type">Song Type</label>
+            <select name="type" id="type">
+                <option name="youtube" id="youtube">YouTube</option>
+                <option name="soundcloud" id="soundcloud">SoundCloud</option>
+            </select>
+            <label for="id">Song ID</label>
+            <input name="id" id="id" type="text" />
+            <label for="id">Song Artist</label>
+            <input name="artist" id="artist" type="text" />
+            <label for="title">Song Title</label>
+            <input name="title" id="title" type="text" />
+            <button type="submit">Submit</button>
+        </form>
+
+        <ul class="bg-bubbles">
+            <li></li>
+            <li></li>
+            <li></li>
+            <li></li>
+            <li></li>
+            <li></li>
+            <li></li>
+            <li></li>
+            <li></li>
+            <li></li>
+        </ul>
+    </div>
+</template>