From 7d9358a8fef4aba41b0413a4ca69947459ba3701 Mon Sep 17 00:00:00 2001 From: Ramon Wijnands Date: Fri, 21 Nov 2014 21:09:46 +0000 Subject: [PATCH 1/3] add radio collection --- both/collections.js | 60 ++++++++++++++++++++++++++++++++++ both/router.js | 11 ++++++- client/views/radios/radio.html | 3 ++ server/lib/publish.js | 8 +++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 client/views/radios/radio.html diff --git a/both/collections.js b/both/collections.js index b7c8c90..bf975f1 100644 --- a/both/collections.js +++ b/both/collections.js @@ -215,3 +215,63 @@ PlayCountsSchema = new SimpleSchema({ }); PlayCounts = new Meteor.Collection('playCounts') PlayCounts.attachSchema(PlayCountsSchema); + +//Radio schema +RadioSchema = new SimpleSchema({ + title: { + type: String, + label: "Radio title", + max: 100, + }, + cover: { + type: String, + label: "Cover url", + regEx: SimpleSchema.RegEx.Url, + optional: true, + }, + tags: { + type: String, + label: "Tags", + optional: true, + }, + description: { + type: String, + label: "A brief description of your radio", + optional: true, + max: 500 + }, + + currentSong: { + type: String, // RadioSongId + optional: true, + }, +}); +Radios = new Meteor.Collection('Radios'); +Radios.attachSchema(RadioSchema); + +//RadioSong schema +RadioSongSchema = new SimpleSchema({ + radioId: { + type: String, + denyUpdate: true, + }, + songId: { + type: String, + denyUpdate: true, + }, + votes: { + type: [String], // array of userIds + // Force value to be [current user] upon insert + autoValue: function() { + if (this.isInsert) { + return [this.userId]; + } else if (this.isUpsert) { + return { $setOnInsert: [this.userId] }; + } else { + this.unset(); + } + } + } +}); +RadioSongs = new Meteor.Collection('RadioSongs'); +RadioSongs.attachSchema(RadioSongSchema); diff --git a/both/router.js b/both/router.js index e032eb8..52fb8a3 100644 --- a/both/router.js +++ b/both/router.js @@ -14,7 +14,9 @@ Router.plugin('dataNotFound', {notFoundTemplate: 'NotFound'}); // global configuration Router.waitOn(function() { return [ - Meteor.subscribe('allusers') + Meteor.subscribe('allusers'), + Meteor.subscribe('allradios'), + Meteor.subscribe('allradiosongs'), ]; }); @@ -66,6 +68,13 @@ Router.map(function() { }, }); + this.route('radio', { + path: '/radios/:_id', + data: function() { + return Radios.findOne(this.params._id); + }, + }); + this.route('loved', { subscriptions: function() { var user = Meteor.user(); diff --git a/client/views/radios/radio.html b/client/views/radios/radio.html new file mode 100644 index 0000000..a6a4630 --- /dev/null +++ b/client/views/radios/radio.html @@ -0,0 +1,3 @@ + diff --git a/server/lib/publish.js b/server/lib/publish.js index 2759f35..1d92511 100644 --- a/server/lib/publish.js +++ b/server/lib/publish.js @@ -69,3 +69,11 @@ Meteor.publish("playlistsByUser", function(userId) { ); } }); + + +Meteor.publish("allradios", function () { + return Radios.find({}); +}); +Meteor.publish("allradiosongs", function () { + return RadioSongs.find({}); +}); From 8468dfc2119248847582ba009bb9f9fbcbf42e70 Mon Sep 17 00:00:00 2001 From: Ramon Wijnands Date: Sun, 23 Nov 2014 14:20:35 +0000 Subject: [PATCH 2/3] add simple layout --- client/views/radios/radio.html | 34 +++++++++++++++++++++++++++++++++- client/views/radios/radio.js | 17 +++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 client/views/radios/radio.js diff --git a/client/views/radios/radio.html b/client/views/radios/radio.html index a6a4630..a1a1a4e 100644 --- a/client/views/radios/radio.html +++ b/client/views/radios/radio.html @@ -1,3 +1,35 @@ + + diff --git a/client/views/radios/radio.js b/client/views/radios/radio.js new file mode 100644 index 0000000..03f13ea --- /dev/null +++ b/client/views/radios/radio.js @@ -0,0 +1,17 @@ +Template.radio.helpers({ + radioSongs: function () { + var radioSongs = RadioSongs.find({radioId: this._id}).fetch(); + + _.each(radioSongs, function (rs) { + var songInfo = Songs.findOne({_id: rs.songId}); + + rs.votes = _.map(rs.votes, function (vote) { + return Meteor.users.findOne({_id: vote}); + }); + + rs.song = songInfo; + }); + + return radioSongs; + }, +}); From ddac089cd6735d9c8536ce2fba013a87596c9e12 Mon Sep 17 00:00:00 2001 From: Ramon Wijnands Date: Fri, 28 Nov 2014 17:37:10 +0000 Subject: [PATCH 3/3] add (insecure) voting --- both/collections.js | 3 ++- client/views/radios/radio.html | 2 +- client/views/radios/radio.js | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/both/collections.js b/both/collections.js index bf975f1..ede2a78 100644 --- a/both/collections.js +++ b/both/collections.js @@ -268,7 +268,8 @@ RadioSongSchema = new SimpleSchema({ } else if (this.isUpsert) { return { $setOnInsert: [this.userId] }; } else { - this.unset(); + // figure out if this is allowed or not :D + return; } } } diff --git a/client/views/radios/radio.html b/client/views/radios/radio.html index a1a1a4e..57d329e 100644 --- a/client/views/radios/radio.html +++ b/client/views/radios/radio.html @@ -29,7 +29,7 @@

{{title}}

{{/each}}
- +
diff --git a/client/views/radios/radio.js b/client/views/radios/radio.js index 03f13ea..3fa0147 100644 --- a/client/views/radios/radio.js +++ b/client/views/radios/radio.js @@ -15,3 +15,14 @@ Template.radio.helpers({ return radioSongs; }, }); + +Template.radioSong.events({ + 'click [data-action="voteup"]': function (e, template) { + var id = template.data._id; + console.log('voting for', id); + RadioSongs.update( + { _id: id }, + { $addToSet : {'votes': Meteor.userId()} } + ); + } +});