diff --git a/both/collections.js b/both/collections.js index b7c8c90..ede2a78 100644 --- a/both/collections.js +++ b/both/collections.js @@ -215,3 +215,64 @@ 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 { + // figure out if this is allowed or not :D + return; + } + } + } +}); +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..57d329e --- /dev/null +++ b/client/views/radios/radio.html @@ -0,0 +1,35 @@ + + + + {{> searchBar viewToggle=0 collection="Playlists" playlistId=this._id }} + + {{#each radioSongs}} + {{> radioSong}} + {{/each}} + + + {{title}} + Stuff + + + + + + + + + + + {{song.snippet.title}} + Added by xxx on xxx + + + {{#each votes}} + {{> circleAvatar}} + {{/each}} + + + + + + diff --git a/client/views/radios/radio.js b/client/views/radios/radio.js new file mode 100644 index 0000000..3fa0147 --- /dev/null +++ b/client/views/radios/radio.js @@ -0,0 +1,28 @@ +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; + }, +}); + +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()} } + ); + } +}); 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({}); +});
Stuff
{{song.snippet.title}}