Skip to content

Commit

Permalink
add radio collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayman committed Nov 23, 2014
1 parent a31ecb6 commit 7d9358a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
60 changes: 60 additions & 0 deletions both/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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
3 changes: 3 additions & 0 deletions client/views/radios/radio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template name="radio">
Radio
</template>
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({});
});

0 comments on commit 7d9358a

Please sign in to comment.