Browse Source

Added removing of Stations in Admin

theflametrooper 8 years ago
parent
commit
6d3221e993
2 changed files with 20 additions and 8 deletions
  1. 14 7
      backend/logic/actions/stations.js
  2. 6 1
      frontend/components/Admin/Stations.vue

+ 14 - 7
backend/logic/actions/stations.js

@@ -22,23 +22,23 @@ const defaultSong = {
 	thumbnail: 'https://i.scdn.co/image/2ddde58427f632037093857ebb71a67ddbdec34b'
 };
 
-cache.sub('station.locked', (stationName) => {
+cache.sub('station.locked', stationName => {
 	io.to(`station.${stationName}`).emit("event:station.locked");
 });
 
-cache.sub('station.unlocked', (stationName) => {
+cache.sub('station.unlocked', stationName => {
 	io.to(`station.${stationName}`).emit("event:station.unlocked");
 });
 
-cache.sub('station.pause', (stationName) => {
+cache.sub('station.pause', stationName => {
 	io.to(`station.${stationName}`).emit("event:station.pause");
 });
 
-cache.sub('station.resume', (stationName) => {
+cache.sub('station.resume', stationName => {
 	io.to(`station.${stationName}`).emit("event:station.resume");
 });
 
-cache.sub('station.create', (stationId) => {
+cache.sub('station.create', stationId => {
 	stations.initializeAndReturnStation(stationId, (err, station) => {
 		//TODO Emit to homepage and admin station page
 		if (!err) {
@@ -174,7 +174,7 @@ module.exports = {
 		});
 	},
 
-	lock: (session, stationId, cb) => {
+	lock: (sessionId, stationId, cb) => {
 		//TODO Require admin
 		stations.initializeAndReturnStation(stationId, (err, station) => {
 			if (err && err !== true) {
@@ -188,7 +188,7 @@ module.exports = {
 		});
 	},
 
-	unlock: (session, stationId, cb) => {
+	unlock: (sessionId, stationId, cb) => {
 		//TODO Require admin
 		stations.initializeAndReturnStation(stationId, (err, station) => {
 			if (err && err !== true) {
@@ -202,6 +202,13 @@ module.exports = {
 		});
 	},
 
+	remove: (sessionId, stationId, cb) => {
+		cache.hdel('stations', stationId, () => {
+			// TODO: Update Mongo
+			return cb({ status: 'success', message: 'Station successfully removed' });
+		});
+	},
+
 	create: (sessionId, data, cb) => {
 		//TODO Require admin
 		async.waterfall([

+ 6 - 1
frontend/components/Admin/Stations.vue

@@ -34,7 +34,7 @@
 							</p>
 						</td>
 						<td>
-							<a class="button is-danger" @click="stations.splice(index, 1)">Remove</a>
+							<a class="button is-danger" @click="removeStation(index)">Remove</a>
 						</td>
 					</tr>
 				</tbody>
@@ -140,6 +140,11 @@
 					console.log(result);
 				});
 			},
+			removeStation: function (index) {
+				this.socket.emit('stations.remove', this.stations[index]._id, res => {
+					if (res.status == 'success') this.stations.splice(index, 1); Toast.methods.addToast(res.message, 2000);
+				});
+			},
 			addGenre: function () {
 				if ($("#new-genre").val() !== "") this.newStation.genres.push($("#new-genre").val());
 				else Toast.methods.addToast('Genre cannot be empty', 2000);