From 970981ccc1fc8f4ef50910d50d57a2f241073067 Mon Sep 17 00:00:00 2001 From: An Phan Date: Sat, 4 Jun 2016 20:29:23 +0800 Subject: [PATCH] Finish Playlist download, starting Fav download --- .../API/Download/PlaylistController.php | 23 +++++++++++++++++++ app/Http/routes.php | 1 + .../main-wrapper/main-content/favorites.vue | 17 ++++++++++++++ .../main-wrapper/main-content/index.vue | 8 +++++++ .../main-wrapper/main-content/playlist.vue | 17 ++++++++++++++ .../js/components/shared/album-item.vue | 4 ++-- .../js/components/shared/artist-item.vue | 2 +- resources/assets/js/stores/playlist.js | 18 ++++++++++++--- 8 files changed, 84 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/API/Download/PlaylistController.php b/app/Http/Controllers/API/Download/PlaylistController.php index e69de29b..6b948cc8 100644 --- a/app/Http/Controllers/API/Download/PlaylistController.php +++ b/app/Http/Controllers/API/Download/PlaylistController.php @@ -0,0 +1,23 @@ +download(Download::from($playlist)); + } +} diff --git a/app/Http/routes.php b/app/Http/routes.php index 6255e468..4b7b6fab 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -57,6 +57,7 @@ Route::group(['prefix' => 'api', 'namespace' => 'API'], function () { Route::get('songs', 'SongController@download'); Route::get('album/{album}', 'AlbumController@download'); Route::get('artist/{artist}', 'ArtistController@download'); + Route::get('playlist/{playlist}', 'PlaylistController@download'); }); }); }); diff --git a/resources/assets/js/components/main-wrapper/main-content/favorites.vue b/resources/assets/js/components/main-wrapper/main-content/favorites.vue index 738b3895..5fda6e4e 100644 --- a/resources/assets/js/components/main-wrapper/main-content/favorites.vue +++ b/resources/assets/js/components/main-wrapper/main-content/favorites.vue @@ -13,6 +13,13 @@ {{ meta.songCount }} {{ meta.songCount | pluralize 'song' }} • {{ meta.totalLength }} + @@ -57,7 +64,9 @@ import isMobile from 'ismobilejs'; import favoriteStore from '../../../stores/favorite'; + import sharedStore from '../../../stores/shared'; import playback from '../../../services/playback'; + import download from '../../../services/download'; import hasSongList from '../../../mixins/has-song-list'; export default { @@ -66,6 +75,7 @@ data () { return { state: favoriteStore.state, + sharedState: sharedStore.state, isPhone: isMobile.phone, showingControls: false, }; @@ -78,6 +88,13 @@ shuffle() { playback.queueAndPlay(this.state.songs, true); }, + + /** + * Download all favorite songs. + */ + download() { + download.fromFavorites(); + }, }, }; diff --git a/resources/assets/js/components/main-wrapper/main-content/index.vue b/resources/assets/js/components/main-wrapper/main-content/index.vue index dc989fca..7be82596 100644 --- a/resources/assets/js/components/main-wrapper/main-content/index.vue +++ b/resources/assets/js/components/main-wrapper/main-content/index.vue @@ -115,6 +115,14 @@ font-size: $fontSize; color: $color2ndText; margin: 12px 0 0 2px; + + a { + color: #fff; + + &:hover { + color: $colorHighlight; + } + } } .buttons { diff --git a/resources/assets/js/components/main-wrapper/main-content/playlist.vue b/resources/assets/js/components/main-wrapper/main-content/playlist.vue index 6d41cca8..dc91bc1c 100644 --- a/resources/assets/js/components/main-wrapper/main-content/playlist.vue +++ b/resources/assets/js/components/main-wrapper/main-content/playlist.vue @@ -13,6 +13,13 @@ {{ meta.songCount }} {{ meta.songCount | pluralize 'song' }} • {{ meta.totalLength }} + @@ -57,7 +64,9 @@ import isMobile from 'ismobilejs'; import playlistStore from '../../../stores/playlist'; + import sharedStore from '../../../stores/shared'; import playback from '../../../services/playback'; + import download from '../../../services/download'; import hasSongList from '../../../mixins/has-song-list'; export default { @@ -66,6 +75,7 @@ data() { return { playlist: playlistStore.stub, + sharedState: sharedStore.state, isPhone: isMobile.phone, showingControls: false, }; @@ -107,6 +117,13 @@ this.$root.loadMainView('queue'); }); }, + + /** + * Download all songs in the current playlist. + */ + download() { + return download.fromPlaylist(this.playlist); + }, }, }; diff --git a/resources/assets/js/components/shared/album-item.vue b/resources/assets/js/components/shared/album-item.vue index 60fbbe60..8cd4d042 100644 --- a/resources/assets/js/components/shared/album-item.vue +++ b/resources/assets/js/components/shared/album-item.vue @@ -22,10 +22,10 @@ {{ album.playCount }} {{ album.playCount | pluralize 'play' }} - + - + diff --git a/resources/assets/js/components/shared/artist-item.vue b/resources/assets/js/components/shared/artist-item.vue index c674f7af..dca8295a 100644 --- a/resources/assets/js/components/shared/artist-item.vue +++ b/resources/assets/js/components/shared/artist-item.vue @@ -16,7 +16,7 @@ {{ artist.playCount }} {{ artist.playCount | pluralize 'play' }} - + diff --git a/resources/assets/js/stores/playlist.js b/resources/assets/js/stores/playlist.js index c2df0a3c..78efd1f0 100644 --- a/resources/assets/js/stores/playlist.js +++ b/resources/assets/js/stores/playlist.js @@ -20,7 +20,7 @@ export default { init(playlists) { this.all = playlists; - each(this.all, this.getSongs); + each(this.all, this.objectifySongs); }, /** @@ -41,13 +41,25 @@ export default { this.state.playlists = value; }, + /** + * Objectify all songs in the playlist. + * (Initially, a playlist only contain the song IDs). + * + * @param {Object} playlist + */ + objectifySongs(playlist) { + playlist.songs = songStore.byIds(playlist.songs); + }, + /** * Get all songs in a playlist. * + * @param {Object} + * * return {Array.} */ getSongs(playlist) { - return (playlist.songs = songStore.byIds(playlist.songs)); + return playlist.songs; }, /** @@ -86,7 +98,7 @@ export default { http.post('playlist', { name, songs }, response => { const playlist = response.data; playlist.songs = songs; - this.getSongs(playlist); + this.objectifySongs(playlist); this.add(playlist); cb && cb();