Skip to content

Commit

Permalink
Fix undefined images
Browse files Browse the repository at this point in the history
Pluck removed from lodash
  • Loading branch information
AlexBeauchemin committed Feb 13, 2016
1 parent 106a27f commit 3b99500
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/client/templates/components/playlist-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<a href="#" data-action="downvote" class="{{hasDownvote currentUser}}"><i class="material-icons">thumb_down</i></a>
</div>
{{/if}}
<img src="{{song.data.thumbnails.default.url}}" alt="" class="circle">
<img src="{{getImage song.data.thumbnails.default.url}}" alt="" class="circle">
<div class="info">
<p><a href="{{getLink}}" target="_blank">{{song.data.title}}</a></p>
{{#if song.user}}
Expand Down
5 changes: 5 additions & 0 deletions app/client/templates/components/playlist-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Template.PlaylistItem.rendered = function() {
};

Template.PlaylistItem.helpers({
getImage(img) {
if (img) return img;
return '/album-default.jpg';
},

getLink() {
const id = _.get(this, 'song.id');
const link = _.get(this, 'song.data.link');
Expand Down
12 changes: 10 additions & 2 deletions app/collections/radios/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if (Meteor.isClient) {
}

if (Meteor.isServer) {
const PLAYLIST_SONG_LIMIT = 300;
let Helpers = App.collectionHelpers.radio;

Meteor.methods({
Expand Down Expand Up @@ -146,7 +147,7 @@ if (Meteor.isServer) {
if (Helpers.isSongBlocked(radioId, song.id)) throw new Meteor.Error(500, 'This song is blocked');
if (Helpers.isUserBlocked(radioId, song.user)) throw new Meteor.Error(500, 'Sorry, you cannot add songs to this radio');

if (radio.playlist.length >= 100) throw new Meteor.Error(500, 'Sorry, the playlist is full');
if (radio.playlist.length >= PLAYLIST_SONG_LIMIT) throw new Meteor.Error(500, 'Sorry, the playlist is full');

if (!Helpers.isOwner(radioId)) {
if (Helpers.hasUserReachedLimit(radio)) throw new Meteor.Error(500, 'You have reached your limit for this radio. Please try again later');
Expand Down Expand Up @@ -177,6 +178,7 @@ if (Meteor.isServer) {
let guestRadios = [];
let guestUsers = [];
let toDelete;
let toDeleteArr = [];

Radios.find({isGuest: true}).forEach(function(radio) {
guestRadios.push({id: radio._id, user: radio.users[0]});
Expand All @@ -190,8 +192,14 @@ if (Meteor.isServer) {
return guestUsers.indexOf(radio.user) !== -1;
});

_.map(toDelete, (item) => {
toDeleteArr.push(item.id);
});

//TODO: test this and clean up the toDeleteArr (pluck not working anymore)

if (!_.isEmpty(toDelete)) {
Radios.remove({'_id': {'$in': _.pluck(toDelete, 'id')}});
Radios.remove({'_id': {'$in': toDeleteArr}});
}
},

Expand Down

0 comments on commit 3b99500

Please sign in to comment.