From ed7af8932ec4117da102c2f604dbe691b41c4f60 Mon Sep 17 00:00:00 2001 From: Ramon Wijnands Date: Tue, 25 Nov 2014 15:01:56 +0100 Subject: [PATCH 1/4] upgraded iron:router to version 1.0.3 --- .meteor/versions | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.meteor/versions b/.meteor/versions index 1225541..f84ccea 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -32,14 +32,14 @@ http@1.0.8 ian:accounts-ui-bootstrap-3@1.1.23 id-map@1.0.1 insecure@1.0.1 -iron:controller@1.0.2 -iron:core@1.0.2 -iron:dynamic-template@1.0.2 -iron:layout@1.0.2 -iron:location@1.0.2 -iron:middleware-stack@1.0.2 -iron:router@1.0.2 -iron:url@1.0.2 +iron:controller@1.0.3 +iron:core@1.0.3 +iron:dynamic-template@1.0.3 +iron:layout@1.0.3 +iron:location@1.0.3 +iron:middleware-stack@1.0.3 +iron:router@1.0.3 +iron:url@1.0.3 jquery@1.0.1 json@1.0.1 launch-screen@1.0.0 From 00940f0e740d085474eb9a1c330ad8e939061576 Mon Sep 17 00:00:00 2001 From: pepf Date: Thu, 27 Nov 2014 20:03:21 +0100 Subject: [PATCH 2/4] Add HypeMachine songs to Suggestions box, changed echonest.js to more general apis.js (including Hype machine) --- .gitignore | 4 + .../components/suggestions/suggestions.html | 1 + client/components/suggestions/suggestions.js | 85 ++++++++++--------- server/{echonest.js => apis.js} | 40 +++++++-- 4 files changed, 86 insertions(+), 44 deletions(-) rename server/{echonest.js => apis.js} (55%) diff --git a/.gitignore b/.gitignore index 8cc5347..af762e7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,11 +7,15 @@ pids *.pid *.seed +#osx +*.DS_Store + # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage +build # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt diff --git a/client/components/suggestions/suggestions.html b/client/components/suggestions/suggestions.html index fd4e6e6..65fdbdd 100644 --- a/client/components/suggestions/suggestions.html +++ b/client/components/suggestions/suggestions.html @@ -20,6 +20,7 @@

  • Jazz
  • Soul
  • Hip Hop
  • +
  • HypeMachine Popular
  • diff --git a/client/components/suggestions/suggestions.js b/client/components/suggestions/suggestions.js index b462ab8..04df7ba 100644 --- a/client/components/suggestions/suggestions.js +++ b/client/components/suggestions/suggestions.js @@ -1,44 +1,23 @@ var refreshSuggestions = function() { - Meteor.call('hotRightNow', Session.get("suggestion-genre"), function(error,result) { + //hack to make calls to Hypemachine API when selecting this "genre" + var apiCall = (Session.get("suggestion-genre") === "hypemPopular") ? Session.get("suggestion-genre") : "hotRightNow"; + Meteor.call(apiCall, Session.get("suggestion-genre"), function(error,result) { if(error) { console.log(error); return; } Session.set("suggestions", result); }); -} +}; -Template.suggestions.created = function() { - Session.set("suggestion-genre","alternative rock"); - refreshSuggestions(); -} - -Template.suggestions.songs = function() { - return Session.get('suggestions'); -} - -Template.suggestions.events = { - 'click button#refreshSuggestions' : refreshSuggestions, - - 'click .suggestion-genres li' : function(e) { - var genre = e.target.text.toLowerCase(); - Session.set("suggestion-genre",genre); - console.log(e); - $(".suggestion-genres li").removeClass("active"); - $(e.currentTarget).addClass("active"); - refreshSuggestions(); - }, - - 'click #addSong': function (e,template) { - var playlistId = Router.current().params._id; - - //prepare query for Youtube - var options = { - part: 'id', - type: 'video', - videoEmbeddable: 'true', - q: this.artist_name + " " + this.title - } - //perform Youtube search using artist and song information - Meteor.call('youtube_search', options, function(error, data) { - if (error) { return false; } +var addSongfromQuery = function(query, playlistId) { + //prepare query for Youtube + var options = { + part: 'id', + type: 'video', + videoEmbeddable: 'true', + q: query + }; + //perform Youtube search using artist and song information + Meteor.call('youtube_search', options, function(error, data) { + if (error) { return false; } //Id from first search result var videoId = data.items[0].id.videoId; @@ -47,7 +26,7 @@ Template.suggestions.events = { var options = { 'part': 'snippet,contentDetails,statistics', 'id': videoId, - } + }; Meteor.call('youtube_videos_list', options); //Put it in current playlist @@ -62,6 +41,36 @@ Template.suggestions.events = { { $push: { songs: songObject} } ); }); +}; + + +Template.suggestions.created = function() { + Session.set("suggestion-genre","alternative rock"); + refreshSuggestions(); +}; + +Template.suggestions.helpers({ + "songs" : function() { + return Session.get("suggestions"); + } +}); + +Template.suggestions.events = { + 'click button#refreshSuggestions' : refreshSuggestions, + + 'click .suggestion-genres li' : function(e) { + var genre = (e.target.getAttribute("data-genre") !== null) ? e.target.getAttribute("data-genre") : e.target.text.toLowerCase(); + Session.set("suggestion-genre",genre); + console.log(e); + $(".suggestion-genres li").removeClass("active"); + $(e.currentTarget).addClass("active"); + refreshSuggestions(); + }, + + 'click #addSong': function (e,template) { + var playlistId = Router.current().params._id; + addSongfromQuery( this.artist_name + " " + this.title, playlistId); + }, -} +}; diff --git a/server/echonest.js b/server/apis.js similarity index 55% rename from server/echonest.js rename to server/apis.js index 3d65d21..cf4425c 100644 --- a/server/echonest.js +++ b/server/apis.js @@ -6,11 +6,11 @@ var ECHONEST_KEY = 'Z9TLXHBRUB49YXCNR'; Meteor.methods({ getArtistInfo: function(artist) { - var artist = encodeURIComponent(artist); - var url = "http://developer.echonest.com/api/v4/artist/profile?api_key="+ECHONEST_KEY+"&name="+artist+"&bucket=hotttnesss&bucket=terms&bucket=images&bucket=songs" - + artist = encodeURIComponent(artist); + var url = "http://developer.echonest.com/api/v4/artist/profile?api_key="+ECHONEST_KEY+"&name="+artist+"&bucket=hotttnesss&bucket=terms&bucket=images&bucket=songs"; + var result; try { - var result = HTTP.get(url); + result = HTTP.get(url); } catch(e) { console.log(e.toString()); return false; @@ -22,8 +22,9 @@ Meteor.methods({ //default genre genre = typeof genre !== 'undefined' ? genre : 'alternative rock'; var url = "http://developer.echonest.com/api/v4/playlist/static?api_key="+ECHONEST_KEY+"&type=genre-radio&genre="+genre+"&results=10&bucket=song_hotttnesss"; + var result; try { - var result = HTTP.get(url); + result = HTTP.get(url); } catch(e) { console.log(e.toString()); return false; @@ -34,8 +35,35 @@ Meteor.methods({ }); return result.data.response.songs; } else { - //console.log(result.content); return false; } + }, + +//Hypem related methods +//Should return data more or less in the same way as the echnonest does, so these +//two methods can be exchanged + hypemPopular: function() { + var url = "http://hypem.com/playlist/popular/3day/json/1/data.js"; + var result; + try { + result = HTTP.get(url); + } catch(e) { + console.log(e.toString()); + return false; + } + if (result.data) { + var nrs = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]; + var songs = nrs.map(function(nr) { + var song = result.data[nr]; + return { artist_name:song.artist, + title:song.title + }; + }); + return songs; + } else { + return false; + } + } + }); From b580af20bc9a75367cabb01af979dad466b9b8b5 Mon Sep 17 00:00:00 2001 From: Ramon Wijnands Date: Sat, 29 Nov 2014 21:24:49 +0000 Subject: [PATCH 3/4] update accounts-ui-bootstrap-3 to 1.1.26 --- .meteor/versions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.meteor/versions b/.meteor/versions index f84ccea..e0a3f28 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -29,7 +29,7 @@ handlebars@1.0.1 html-tools@1.0.2 htmljs@1.0.2 http@1.0.8 -ian:accounts-ui-bootstrap-3@1.1.23 +ian:accounts-ui-bootstrap-3@1.1.26 id-map@1.0.1 insecure@1.0.1 iron:controller@1.0.3 From d5188777e46438afa57ba93f56633e3f2f6a1baf Mon Sep 17 00:00:00 2001 From: Ramon Wijnands Date: Sat, 29 Nov 2014 23:05:39 +0000 Subject: [PATCH 4/4] simplify searchBar with use of a callback function --- client/components/searchbar/searchbar.js | 46 +++++------------------- client/views/playlists/playlist.html | 2 +- client/views/playlists/playlist.js | 18 ++++++++++ 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/client/components/searchbar/searchbar.js b/client/components/searchbar/searchbar.js index a276c2c..4c7c611 100644 --- a/client/components/searchbar/searchbar.js +++ b/client/components/searchbar/searchbar.js @@ -1,38 +1,25 @@ -// initialize active_tab -Session.set('active_tab', 'songs'); - //Initialisation of searchbar component, // template example: -// {{> searchBar lovedToggle=0 viewToggle=0 collection="Playlists" playlistId=this._id }} +// {{> searchBar viewToggle=true callback="searchCallback" }} /*-------------------------- Available parameters - collection (Collection) Name of the collection to add objects to, requires extra code in - the add function, or sh*t will hit the fan (default: Playlists) - playlistId (int) pointer to which playlist songs should be added (required) + callback (string) The name of the helper of the parent template that + will be called when a song has been selected viewToggle (boolean) show/hide the toggle view buttons (default: show) lovedToggle (boolean) show/hide the add songs from loved songs button (default: show) ---------------------------*/ Template.searchBar.created = function( template ) { - //debug purposes - var d = Template.currentData() || {}; //at least return an obj - this.collection = (typeof d.playlistId !== "undefined") ? window[d.collection] : window.Playlists; - this.playlistId = (typeof d.playlistId !== "undefined") ? d.playlistId : null; + var d = this.data; this.lovedToggle = (typeof d.lovedToggle !== "undefined") ? d.lovedToggle : 1; this.viewToggle = (typeof d.viewToggle !== "undefined") ? d.viewToggle : 1; - this.lovedToggleWidth = (this.lovedToggle === 1) ? 1 : 0; this.viewToggleWidth = (this.viewToggle === 1) ? 2 : 0; this.searchBarWidth = 12 - this.lovedToggleWidth - this.viewToggleWidth; - console.log(this); - }; Template.searchBar.helpers({ - isActiveTab: function(route) { - return Session.equals("active_tab", route) ? "active" : ""; - }, lovedSongs: function() { var user = Meteor.user(); if (!user) @@ -47,11 +34,6 @@ Template.searchBar.helpers({ Template.searchBar.events = { - 'click ul.playlist-tabs > li': function (e) { - var li = $(e.currentTarget); - var route = li.data('id'); - Session.set("active_tab", route); - }, 'submit form.youtube-search': function (e) { e.preventDefault(); }, @@ -75,24 +57,14 @@ Template.searchBar.events = { //add search result to Meteor collection 'click .youtube-result, click a.loved': function(e, template) { + $("input.youtube-query").focus(); var videoId = (this.id !== undefined) ? this.id : this._id; - //see if search bar is linked up to a collection - if (!template.collection) { console.warn("no collection defined"); return; } - if (!template.playlistId) { console.warn("no collection id defined"); return; } - - console.log('queue video:', videoId, 'to playlist', template.playlistId); - $("input.youtube-query").focus(); - var songObject = { - "added" : new Date(), - "author" : Meteor.userId(), - "songId" : videoId - }; - template.collection.update( - { _id: template.playlistId}, - { $push: { songs: songObject} } - ); + // callback here + var callbackName = template.data.callback; + var cb = template.view.parentView.parentView.template.__helpers.get(callbackName); + cb(videoId); }, //Loved a song! diff --git a/client/views/playlists/playlist.html b/client/views/playlists/playlist.html index 10d0175..281f140 100644 --- a/client/views/playlists/playlist.html +++ b/client/views/playlists/playlist.html @@ -85,7 +85,7 @@

    Stats

    - {{> searchBar viewToggle=1 collection="Playlists" playlistId=this._id }} + {{> searchBar viewToggle=true callback="searchCallback" }} {{> songs}}
    diff --git a/client/views/playlists/playlist.js b/client/views/playlists/playlist.js index 634ed40..80b6704 100644 --- a/client/views/playlists/playlist.js +++ b/client/views/playlists/playlist.js @@ -177,6 +177,24 @@ Template.playlist.events = { }, }; +Template.playlist.helpers({ + searchCallback: function (videoId) { + // this function will get called from the searchBar template + var playlistId = Template.parentData(1)._id; + + console.log('queue video:', videoId, 'to playlist', playlistId); + var songObject = { + "added" : new Date(), + "author" : Meteor.userId(), + "songId" : videoId + }; + Playlists.update( + { _id: playlistId}, + { $push: { songs: songObject} } + ); + } +}); + Template.updatePlaylistForm.editingDoc = function () { return Playlists.findOne({_id: this._id}); };