Browse Source

Fixed updating of Queue Songs functionality

theflametrooper 8 years ago
parent
commit
e32e86ec60
2 changed files with 21 additions and 20 deletions
  1. 12 18
      backend/logic/actions/queueSongs.js
  2. 9 2
      frontend/components/Admin/QueueSongs.vue

+ 12 - 18
backend/logic/actions/queueSongs.js

@@ -31,29 +31,21 @@ module.exports = {
 		});
 	},
 
-	update: (session, id, updatedSong, cb) => {
+	update: (session, _id, updatedSong, cb) => {
 		//TODO Require admin/login
 		//TODO Check if id and updatedSong is valid
-		db.models.queueSong.findOne({ id }, function(err, queueSong) {
+		db.models.queueSong.findOne({ _id }, (err, currentSong) => {
 			if (err) throw err;
-			// List of properties that are allowed to be changed
-			const updatableProperties = ['id', 'title', 'artists', 'genres', 'thumbnail', 'explicit', 'duration', 'skipDuration'];
-			//TODO Check if new id, if any, is already in use in queue or on rotation
+			// TODO Check if new id, if any, is already in use in queue or on rotation
 			let updated = false;
-			for (let prop in queueSong) {
-				if (updatableProperties.indexOf(prop) !== -1 && updatedSong.hasOwnProperty('prop') && updatedSong[prop] !== queueSong[prop]) {
-					queueSong[prop] = updatedSong[prop];
-					updated = true;
-				}
+			for (let prop in updatedSong) if (updatedSong[prop] !== currentSong[prop]) currentSong[prop] = updatedSong[prop]; updated = true;
+			if (!updated) return cb({ status: 'error', message: 'No properties changed' });
+			else {
+				currentSong.save(err => {
+					if (err) throw err;
+					return cb({ status: 'success', message: 'Successfully updated the queued song' });
+				});
 			}
-			if (!updated) return cb({ status: 'failure', message: 'No properties changed' });
-
-			queueSong.save((err) => {
-				if (err) return cb({ status: 'failure', message: 'Couldn\'t save to Database' });
-
-				return cb({ status: 'success', message: 'Successfully updated the queueSong object' });
-			});
-
 		});
 	},
 
@@ -173,6 +165,8 @@ module.exports = {
 			(newSong, next) => {
 				const song = new db.models.queueSong(newSong);
 
+				// check if song already exists
+
 				song.save(err => {
 
 					if (err) {

+ 9 - 2
frontend/components/Admin/QueueSongs.vue

@@ -96,7 +96,7 @@
 				</p>
 			</section>
 			<footer class='modal-card-foot'>
-				<i class='material-icons save-changes' @click=''>save</i>
+				<i class='material-icons save-changes' @click='save(editing.song)'>save</i>
 				<button class='delete' @click='toggleModal()'></button>
 			</footer>
 		</div>
@@ -143,13 +143,20 @@
 		methods: {
 			toggleModal: function () {
 				this.isEditActive = !this.isEditActive;
-				this.pauseVideo();
+				this.video.settings('stop');
 			},
 			edit: function (song, index) {
 				this.editing = { index, song };
 				this.video.player.loadVideoById(song._id);
 				this.isEditActive = true;
 			},
+			save: function (song) {
+				let _this = this;
+				this.socket.emit('queueSongs.update', song._id, song, function (res) {
+					if (res.status == 'success' || res.status == 'error') Toast.methods.addToast(res.message, 2000);
+					_this.toggleModal();
+				});
+			},
 			add: function (song) {
 				this.socket.emit('queueSongs.remove', song._id);
 				this.socket.emit('songs.add', song, res => {