فهرست منبع

Lots of fixes to Admin/QueueSongs.vue

theflametrooper 8 سال پیش
والد
کامیت
f8a5e4b524

+ 1 - 1
backend/logic/actions/queueSongs.js

@@ -52,7 +52,7 @@ module.exports = {
 	remove: (session, _id, cb) => {
 		// TODO Require admin/login
 		db.models.queueSong.find({ _id }).remove().exec();
-		cb({ status: 'success', message: 'Song was removed successfully' });
+		return cb({ status: 'success', message: 'Song was removed successfully' });
 	},
 
 	add: (session, id, cb) => {

+ 12 - 13
backend/logic/actions/songs.js

@@ -66,33 +66,32 @@ module.exports = {
 
 	add: (session, song, cb) => {
 		//TODO Require admin/login
-		console.log(session.logged_in);
-		// if (!session.logged_in) return cb({ status: 'failure', message: 'You must be logged in to add a song' });
 		const newSong = new db.models.song(song);
-		newSong.save(err => {
+		db.models.song.findOne({ _id: song._id }, (err, existingSong) => {
 			if (err) throw err;
-			else cb({ status: 'success', message: 'Song has been moved from Queue' })
+			if (!existingSong) newSong.save(err => {
+				if (err) throw err;
+				else cb({ status: 'success', message: 'Song has been moved from Queue' })
+			});
 		});
-		//TODO Check if video already in songs list
-		//TODO Check if video is in queue
-		//TODO Add the song to the appropriate stations
+		//TODO Check if video is in queue and Add the song to the appropriate stations
 	},
 
 	like: (sessionId, songId, cb) => {
 		cache.hget('sessions', sessionId, (err, session) => {
 			cache.hget('userSessions', session.userSessionId, (err, userSession) => {
-				db.models.user.findOne({_id: userSession.userId}, (err, user) => {
+				db.models.user.findOne({ _id: userSession.userId }, (err, user) => {
 					if (user.liked.indexOf(songId) !== -1) return cb({ status: 'failure', message: 'You have already liked this song.' });
 					let dislikes = 0;
 					if (user.disliked.indexOf(songId) !== -1) dislikes = -1;
-					db.models.song.update({_id: songId}, {$inc: {likes: 1, dislikes: dislikes}}, (err) => {
+					db.models.song.update({ _id: songId }, { $inc: { likes: 1, dislikes: dislikes } }, err => {
 						if (!err) {
-							db.models.user.update({_id: userSession.userId}, {$push: {liked: songId}, $pull: {disliked: songId}}, (err) => {
+							db.models.user.update({_id: userSession.userId}, {$push: {liked: songId}, $pull: {disliked: songId}}, err => {
 								if (!err) {
-									console.log(JSON.stringify({songId, userId: userSession.userId}));
+									console.log(JSON.stringify({ songId, userId: userSession.userId }));
 									songs.updateSong(songId, (err, song) => {});
-									cache.pub('song.like', JSON.stringify({songId, userId: userSession.userId, undisliked: (dislikes === -1)}));
-								} else db.models.song.update({_id: songId}, {$inc: {likes: -1, dislikes: -dislikes}}, (err) => {
+									cache.pub('song.like', JSON.stringify({ songId, userId: userSession.userId, undisliked: (dislikes === -1) }));
+								} else db.models.song.update({ _id: songId }, { $inc: { likes: -1, dislikes: -dislikes } }, err => {
 									return cb({ status: 'failure', message: 'Something went wrong while liking this song.' });
 								});
 							});

+ 1 - 1
backend/logic/db/schemas/queueSong.js

@@ -8,5 +8,5 @@ module.exports = {
 	thumbnail: { type: String, required: true },
 	explicit: { type: Boolean, required: true },
 	requestedBy: { type: String, required: true },
-	requestedAt: { type: Date, required: true }
+	requestedAt: { type: Date, default: Date.now(), required: true }
 };

+ 4 - 4
backend/logic/db/schemas/song.js

@@ -6,11 +6,11 @@ module.exports = {
 	duration: { type: Number, required: true },
 	skipDuration: { type: Number, required: true },
 	thumbnail: { type: String, required: true },
-	likes: { type: Number, required: true },
-	dislikes: { type: Number, required: true },
-	explicit: { type: Boolean, required: true },
+	likes: { type: Number, default: 0, required: true },
+	dislikes: { type: Number, default: 0, required: true },
+	explicit: { type: Boolean, default: false, required: true },
 	requestedBy: { type: String, required: true },
 	requestedAt: { type: Date, required: true },
 	acceptedBy: { type: String, required: true },
-	acceptedAt: { type: Date, required: true }
+	acceptedAt: { type: Date, default: Date.now(), required: true }
 };

+ 46 - 25
frontend/components/Admin/QueueSongs.vue

@@ -4,35 +4,27 @@
 			<table class='table is-striped'>
 				<thead>
 					<tr>
+						<td>Thumbnail</td>
 						<td>Title</td>
 						<td>YouTube ID</td>
 						<td>Artists</td>
 						<td>Genres</td>
+						<td>Requested By</td>
 						<td>Options</td>
 					</tr>
 				</thead>
 				<tbody>
 					<tr v-for='(index, song) in songs' track-by='$index'>
 						<td>
-							<p class='control'>
-								<input class='input' type='text' v-model='song.title'>
-							</p>
+							<img class='song-thumbnail' :src='song.thumbnail'>
 						</td>
 						<td>
-							<p class='control'>
-								<input class='input' type='text' v-model='song._id'>
-							</p>
-						</td>
-						<td>
-							<div class='control'>
-								<input v-for='artist in song.artists' track-by='$index' class='input' type='text' v-model='artist'>
-							</div>
-						</td>
-						<td>
-							<div class='control'>
-								<input v-for='genre in song.genres' track-by='$index' class='input' type='text' v-model='genre'>
-							</div>
+							<strong>{{ song.title }}</strong>
 						</td>
+						<td> {{ song._id }} </td>
+						<td><span v-for='artist in song.artists'>{{ artist }}</span></td>
+						<td><span v-for='genre in song.genres'>{{ genre }}</span></td>
+						<td> {{ song.requestedBy }} </td>
 						<td>
 							<a class='button is-primary' @click='edit(song, index)'>Edit</a>
 							<a class='button is-success' @click='add(song)'>Add</a>
@@ -47,6 +39,7 @@
 		<div class='modal-background'></div>
 		<div class='modal-card'>
 			<section class='modal-card-body'>
+
 				<h5 class='has-text-centered'>Video Preview</h5>
 				<div class='video-container'>
 					<div id='player'></div>
@@ -63,13 +56,23 @@
 						</a>
 					</p>
 				</div>
+
 				<h5 class='has-text-centered'>Thumbnail Preview</h5>
 				<img class='thumbnail-preview' :src='editing.song.thumbnail'>
+
 				<label class='label'>Thumbnail URL</label>
 				<p class='control'>
 					<input class='input' type='text' v-model='editing.song.thumbnail'>
 				</p>
+
 				<h5 class='has-text-centered'>Edit Info</h5>
+
+				<p class='control'>
+					<label class='checkbox'>
+						<input type='checkbox' v-model='editing.song.explicit'>
+						Explicit
+					</label>
+				</p>
 				<label class='label'>Song ID</label>
 				<p class='control'>
 					<input class='input' type='text' v-model='editing.song._id'>
@@ -80,11 +83,11 @@
 				</p>
 				<label class='label'>Artists</label>
 				<div class='control'>
-					<input v-for='artist in editing.song.artists' track-by='$index' class='input' type='text' v-model='artist'>
+					<input v-repeat='editing.song.artists' class='input' type='text' v-model='editing.song.artists[$index]'>
 				</div>
 				<label class='label'>Genres</label>
 				<div class='control'>
-					<input v-for='genre in editing.song.genres' track-by='$index' class='input' type='text' v-model='genre'>
+					<input v-repeat='editing.song.genres' class='input' type='text' v-model='editing.song.genres[$index]'>
 				</div>
 				<label class='label'>Song Duration</label>
 				<p class='control'>
@@ -94,10 +97,13 @@
 				<p class='control'>
 					<input class='input' type='text' v-model='editing.song.skipDuration'>
 				</p>
+
 			</section>
 			<footer class='modal-card-foot'>
-				<i class='material-icons save-changes' @click='save(editing.song)'>save</i>
-				<button class='delete' @click='toggleModal()'></button>
+				<a class='button is-success' @click='save(editing.song)'>
+					<i class='material-icons save-changes'>done</i>
+					<span>&nbsp;Save</span>
+				</a>
 			</footer>
 		</div>
 	</div>
@@ -158,10 +164,17 @@
 				});
 			},
 			add: function (song) {
-				this.socket.emit('queueSongs.remove', song._id);
-				this.socket.emit('songs.add', song, res => {
+				this.socket.emit('queueSongs.remove', song._id, res => {
 					if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
 				});
+				this.socket.emit('users.findBySession', res => {
+					if (res.status == 'success') {
+						song.acceptedBy = res.data.username;
+						this.socket.emit('songs.add', song, res => {
+							if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
+						});
+					}
+				});
 			},
 			remove: function (id, index) {
 				this.songs.splice(index, 1);
@@ -217,7 +230,7 @@
 		background-color: rgb(66, 165, 245);
 	}
 
-	.label, h5 {
+	.label, .checkbox, h5 {
 		color: #fff;
 		font-weight: normal;
 	}
@@ -231,7 +244,15 @@
 
 	.save-changes {
 		color: #fff;
-		margin-right: 5px;
-		cursor: pointer;
+	}
+
+	.song-thumbnail {
+		display: block;
+		max-width: 50px;
+		margin: 0 auto;
+	}
+
+	td {
+		vertical-align: middle;
 	}
 </style>

+ 4 - 5
frontend/components/Station/Station.vue

@@ -252,11 +252,10 @@
 			toggleDislike: function() {
 				let _this = this;
 				if (_this.disliked) _this.socket.emit('songs.undislike', _this.currentSong._id, data => {
-						console.log(data);
-					}); else _this.socket.emit('songs.dislike', _this.currentSong._id, data => {
-						console.log(data);
-					});
-				}
+					console.log(data);
+				}); else _this.socket.emit('songs.dislike', _this.currentSong._id, data => {
+					console.log(data);
+				});
 			}
 		},
 		ready: function() {