Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions both/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
11 changes: 10 additions & 1 deletion both/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
});

Expand Down Expand Up @@ -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();
Expand Down
35 changes: 35 additions & 0 deletions client/views/radios/radio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template name="radio">
<div class="row">
<div class="col-md-8">
{{> searchBar viewToggle=0 collection="Playlists" playlistId=this._id }}

{{#each radioSongs}}
{{> radioSong}}
{{/each}}
</div>
<div class="col-md-4">
<h1>{{title}}</h1>
<p>Stuff</p>
</div>
</div>
</template>

<template name="radioSong">
<div class="row">
<div class="col-md-1">
<img src="{{song.snippet.thumbnails.default.url}}" class="img-responsive" alt="Responsive image">
</div>
<div class="col-md-6">
<p><strong>{{song.snippet.title}}</strong></p>
<small>Added by xxx on xxx</small>
</div>
<div class="col-md-4">
{{#each votes}}
{{> circleAvatar}}
{{/each}}
</div>
<div class="col-md-1">
<button data-action="voteup"><span class="glyphicon glyphicon-chevron-up"></span></button>
</div>
</div>
</template>
28 changes: 28 additions & 0 deletions client/views/radios/radio.js
Original file line number Diff line number Diff line change
@@ -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()} }
);
}
});
8 changes: 8 additions & 0 deletions server/lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ Meteor.publish("playlistsByUser", function(userId) {
);
}
});


Meteor.publish("allradios", function () {
return Radios.find({});
});
Meteor.publish("allradiosongs", function () {
return RadioSongs.find({});
});