Pārlūkot izejas kodu

Added differentitation between Community Stations and Official Stations

theflametrooper 8 gadi atpakaļ
vecāks
revīzija
7cd452e689

+ 2 - 0
backend/index.js

@@ -20,6 +20,7 @@ async.waterfall([
 				(next) => cache.hset('stations', '7dbf25fd-b10d-6863-2f48-637f6014b162', cache.schemas.station({
 					name: 'edm',
 					genres: ['edm'],
+					type: 'official',
 					displayName: 'EDM',
 					description: 'EDM Music',
 					playlist: [
@@ -29,6 +30,7 @@ async.waterfall([
 				(next) => cache.hset('stations', '79cedff1-5341-7f0e-6542-50491c4797b4', cache.schemas.station({
 					name: 'chill',
 					genres: ['chill'],
+					type: 'official',
 					displayName: 'Chill',
 					description: 'Chill Music',
 					playlist: [

+ 17 - 4
backend/logic/actions/stations.js

@@ -66,7 +66,22 @@ function initializeAndReturnStation (stationId, cb) {
 			});
 		}, true);
 
-		cb(null, station);
+		// will need to be added once station namespace thing is decided
+		// function generatePlaylist(arr) {
+		// 	station.playlist = [];
+		// 	return arr.reduce((promise, id) => {
+		// 		return promise.then(() => {
+		// 			return globals.db.models.song.findOne({ id }, (err, song) => {
+		// 				if (err) throw err;
+		// 				station.playlist.push(song);
+		// 			});
+		// 		});
+		// 	}, Promise.resolve());
+		// }
+
+		// generatePlaylist(station.playlist).then(() => {
+		// 	cb(null, station);
+		// });
 	});
 }
 
@@ -84,8 +99,6 @@ module.exports = {
 		// and it should probably just a different cache table then 'stations'
 		cache.hgetall('stations', (err, stations) => {
 
-			console.log('all', stations)
-
 			if (err && err !== true) {
 				return cb({
 					status: 'error',
@@ -197,7 +210,7 @@ module.exports = {
 
 	addSong: (session, station, song, cb) => {
 
-		// if (!session.logged_in) return cb({ status: 'failure', message: 'You must be logged in to add a song' });
+		if (!session.logged_in) return cb({ status: 'failure', message: 'You must be logged in to add a song' });
 
 		const params = [
 			'part=snippet,contentDetails,statistics,status',

+ 1 - 0
backend/logic/db/schemas/user.js

@@ -1,5 +1,6 @@
 module.exports = {
 	username: { type: String, required: true },
+	admin: { type: Boolean, default: false,required: true },
 	email: {
 		verified: { type: Boolean, default: false, required: true },
 		verificationToken: String,

+ 1 - 1
backend/logic/io.js

@@ -55,7 +55,7 @@ module.exports = {
 						let cb = arguments[arguments.length - 1];
 
 						// load the session from the cache
-						/*if (socket.sessionId !== undefined)*/ cache.hget('sessions', socket.sessionId, (err, session) => {
+						cache.hget('sessions', socket.sessionId, (err, session) => {
 							if (err && err !== true) {
 								return cb({
 									status: 'error',

+ 12 - 5
frontend/App.vue

@@ -21,7 +21,10 @@
 				likes: [],
 				dislikes: [],
 				loggedIn: false,
-				stations: []
+				stations: {
+					official: [],
+					community: []
+				}
 			}
 		},
 		methods: {
@@ -36,7 +39,10 @@
 				let socket = this.socket = io(window.location.protocol + '//' + res);
 				socket.on("ready", status => this.loggedIn = status);
 				socket.emit("stations.index", data => {
-					if (data.status === "success") this.stations = data.stations;
+					if (data.status === "success")  data.stations.forEach(station => {
+						if (station.type == 'official') this.stations.official.push(station);
+						else this.stations.community.push(station);
+					});
 				});
 			});
 		},
@@ -64,12 +70,13 @@
 				});
 			},
 			'joinStation': function (id) {
-				this.socket.emit('stations.join', id, (result) => {
-					this.stations.find(station => station.id === id).users = result.userCount;
+				let mergedStations = this.stations.community.concat(this.stations.official);
+				this.socket.emit('stations.join', id, result => {
+					mergedStations.find(station => station.id === id).users = result.userCount;
 				});
 			},
 			'leaveStation': function () {
-				this.socket.emit('stations.leave', (result) => {
+				this.socket.emit('stations.leave', result => {
 					//this.stations.find(station => station.id === id).users = result.userCount;
 				});
 			}

+ 1 - 1
frontend/components/Station/Station.vue

@@ -248,7 +248,7 @@
 				this.playVideo();
 			});*/
 
-			lofig.get('socket.url', function(res) {
+			lofig.get('socket.url', res => {
 				_this.stationSocket = io(window.location.protocol + '//' + res + '/' + _this.$route.params.id);
 
 				_this.stationSocket.on("connected", (data) => {

+ 19 - 2
frontend/components/pages/Home.vue

@@ -53,9 +53,26 @@
 			</div>
 		</div>
 		<div class="group">
-			<!--<div class="group-title">{{group.name}}</div>-->
+			<div class="group-title">Official Stations</div>
 			<div class="group-stations">
-				<div class="stations-station" v-for="station in $parent.stations" v-link="{ path: '/' + station.name }" @click="this.$dispatch('joinStation', station.id)">
+				<div class="stations-station" v-for="station in $parent.stations.official" v-link="{ path: '/' + station.name }" @click="this.$dispatch('joinStation', station.id)">
+					<img class="station-image" :src="station.playlist[station.currentSongIndex].thumbnail" />
+					<div class="station-info">
+						<div class="station-grid-left">
+							<h3>{{ station.displayName }}</h3>
+							<p>{{ station.description }}</p>
+						</div>
+						<div class="station-grid-right">
+							<div>{{ station.userCount }}&nbsp;&nbsp;<i class="fa fa-user" aria-hidden="true"></i></div>
+						</div>
+					</div>
+				</div>
+			</div>
+		</div>
+		<div class="group" v-if="$parent.stations.community.length">
+			<div class="group-title">Community Stations</div>
+			<div class="group-stations">
+				<div class="stations-station" v-for="station in $parent.stations.community" v-link="{ path: '/community/' + station.name }" @click="this.$dispatch('joinStation', station.id)">
 					<img class="station-image" :src="station.playlist[station.currentSongIndex].thumbnail" />
 					<div class="station-info">
 						<div class="station-grid-left">