Browse Source

Fixed issues with Playlists that Kris brought up

theflametrooper 8 years ago
parent
commit
9e6fc2c7c3

+ 20 - 3
backend/logic/actions/playlists.js

@@ -141,6 +141,23 @@ module.exports = {
 		});
 	},
 
+	updatePlaylistId: (session, oldId, newId, cb) => {
+		db.models.playlist.findOne({ _id: oldId }).exec((err, doc) => {
+			if (err) throw err;
+			doc._id = newId;
+			let newPlaylist = new db.models.playlist(doc);
+			newPlaylist.isNew = true;
+			newPlaylist.save(err => {
+				if (err) console.error(err);
+			});
+			db.models.playlist.remove({ _id: oldId });
+			cache.hdel('playlists', oldId, () => {
+				cache.hset('playlists', newId, doc);
+				return cb({ status: 'success', data: doc });
+			});
+		});
+	},
+
 	promoteSong: (session, playlistId, fromIndex, cb) => {
 		db.models.playlist.findOne({ _id: playlistId }, (err, playlist) => {
 			if (err) throw err;
@@ -184,9 +201,9 @@ module.exports = {
 	remove: (session, _id, cb) => {
 		db.models.playlist.remove({ _id }).exec(err => {
 			if (err) throw err;
-		});
-		cache.hdel('playlists', _id, () => {
-			return cb({ status: 'success', message: 'Playlist successfully removed' });
+			cache.hdel('playlists', _id, () => {
+				return cb({ status: 'success', message: 'Playlist successfully removed' });
+			});
 		});
 	}
 

+ 15 - 1
frontend/components/Modals/Playlists/Edit.vue

@@ -66,6 +66,14 @@
 						<a class='button is-info' @click='renamePlaylist()'>Rename</a>
 					</p>
 				</div>
+				<div class='control is-grouped'>
+					<p class='control is-expanded'>
+						<input class='input' type='text' placeholder='Playlist ID' v-model='playlist._id'>
+					</p>
+					<p class='control'>
+						<a class='button is-info' @click='renamePlaylistId()'>Rename</a>
+					</p>
+				</div>
 			</section>
 			<footer class='modal-card-foot'>
 				<a class='button is-danger' @click='removePlaylist()'>Remove Playlist</a>
@@ -125,6 +133,12 @@
 					if (res.status == 'success') Toast.methods.addToast(res.message, 3000);
 				});
 			},
+			renamePlaylistId: function () {
+				let _this = this;
+				_this.socket.emit('playlists.updatePlaylistId', _this.playlist.oldId, _this.playlist._id, res => {
+					if (res.status == 'success') _this.playlist = res.data;
+				});
+			},
 			removePlaylist: function () {
 				let _this = this;
 				_this.socket.emit('playlists.remove', _this.playlist._id, res => {
@@ -153,7 +167,7 @@
 				if (!!_this.$parent.$parent.socket) {
 					_this.socket = _this.$parent.$parent.socket;
 					_this.socket.emit('playlists.getPlaylist', _this.$parent.playlistBeingEdited, res => {
-						if (res.status == 'success') _this.playlist = res.data;
+						if (res.status == 'success') _this.playlist = res.data; _this.playlist.oldId = res.data._id;
 					});
 					clearInterval(socketInterval);
 				}

+ 10 - 7
frontend/components/Sidebars/Playlist.vue

@@ -7,9 +7,15 @@
 				<ul class='menu-list'>
 					<li v-for='playlist in playlists'>
 						<a href='#'>{{ playlist.displayName }}</a>
-						<a href='#' @click='editPlaylist(playlist._id)'>
-							<i class='material-icons'>edit</i>
-						</a>
+						<!--Will play playlist in community station Kris-->
+						<div class='icons-group'>
+							<a href='#' @click=''>
+								<i class='material-icons'>play_arrow</i>
+							</a>
+							<a href='#' @click='editPlaylist(playlist._id)'>
+								<i class='material-icons'>edit</i>
+							</a>
+						</div>
 					</li>
 				</ul>
 			</aside>
@@ -101,10 +107,7 @@
 		justify-content: space-between;
 	}
 
-	li a {
-		display: flex;
-    	align-items: center;
-	}
+	.icons-group { display: flex; }
 
 	.none-found { text-align: center; }
 </style>