From: marcelveldt Date: Sat, 9 Nov 2019 01:33:45 +0000 (+0100) Subject: more frontend refactoring X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=5209608a0552c7ed58b65b8ed894998455a9ae57;p=music-assistant-server.git more frontend refactoring --- diff --git a/frontend/package-lock.json b/frontend/package-lock.json index f331637d..1665965a 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -4526,6 +4526,11 @@ "is-symbol": "^1.0.2" } }, + "es6-object-assign": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", + "integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw=" + }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -12150,6 +12155,11 @@ } } }, + "vue-directive-long-press": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/vue-directive-long-press/-/vue-directive-long-press-1.1.0.tgz", + "integrity": "sha512-OHhR4N1kuuKaK87SPmqkcm5Y81HjXgv5DfWr96flIkTYveWps1AozKiNrabsIirq+ibSZWFr3IUr0en+Ce3fAA==" + }, "vue-eslint-parser": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-5.0.0.tgz", @@ -12220,6 +12230,14 @@ "resolved": "https://registry.npmjs.org/vue-loading-overlay/-/vue-loading-overlay-3.2.0.tgz", "integrity": "sha512-QBHa+vwcQ3k3oKp4pucP7RHWHSQvgVWFlDFqSaXLu+kCuEv1PZCoerAo1T04enF5y9yMFCqh7L9ChrWHy7HYvA==" }, + "vue-long-click": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/vue-long-click/-/vue-long-click-0.0.4.tgz", + "integrity": "sha512-1/8KMsON6k8ebGqOhBZKU69EWlTLv4+LUluwUxTMNYno9t7ztk8j6rNVwewbp9hULktEoe+jBnxMFBngsPQCaQ==", + "requires": { + "vue": "^2.5.22" + } + }, "vue-observe-visibility": { "version": "0.4.6", "resolved": "https://registry.npmjs.org/vue-observe-visibility/-/vue-observe-visibility-0.4.6.tgz", @@ -12271,6 +12289,19 @@ "vue-resize": "^0.4.5" } }, + "vue2-touch-events": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/vue2-touch-events/-/vue2-touch-events-2.0.0.tgz", + "integrity": "sha512-t4LyihIieUif96RDMgRllrt/1qRE8Zu0dZoyqOAqAttx/TWynIshBQ8TumCj1xhog5EDaIgsihuVA6hPnssCLQ==" + }, + "vuejs-logger": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/vuejs-logger/-/vuejs-logger-1.5.3.tgz", + "integrity": "sha512-jw+AQ+IMJBz18fA4opHsqaU7P7yQNugoGywT6i3DCd1BWqg9eUx03Fr21kayqGcP4dxUwhVkkjuOyeirxLJC8g==", + "requires": { + "es6-object-assign": "1.1.0" + } + }, "vuetify": { "version": "2.1.7", "resolved": "https://registry.npmjs.org/vuetify/-/vuetify-2.1.7.tgz", diff --git a/frontend/package.json b/frontend/package.json index ca122b67..b663fe6e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -28,11 +28,15 @@ "register-service-worker": "^1.6.2", "roboto-fontface": "*", "vue": "^2.6.10", + "vue-directive-long-press": "^1.1.0", "vue-i18n": "^8.0.0", "vue-loading-overlay": "^3.2.0", + "vue-long-click": "0.0.4", "vue-observe-visibility": "^0.4.6", "vue-router": "^3.1.3", "vue-virtual-scroller": "^1.0.0-rc.2", + "vue2-touch-events": "^2.0.0", + "vuejs-logger": "1.5.3", "vuetify": "^2.1.0", "vuex": "^3.0.1" }, diff --git a/frontend/src/components/ContextMenu.vue b/frontend/src/components/ContextMenu.vue index 490a9907..0a76d22d 100644 --- a/frontend/src/components/ContextMenu.vue +++ b/frontend/src/components/ContextMenu.vue @@ -31,7 +31,7 @@ :hideproviders="false" :hidelibrary="true" :hidemenu="true" - :onclickHandler="playlistSelected" + :onclickHandler="addToPlaylist" > @@ -100,7 +100,7 @@ export default Vue.extend({ if (mediaItem.in_library.length === 0) { menuItems.push({ label: 'add_library', - action: 'add_library', + action: 'toggle_library', icon: 'favorite_border' }) } @@ -108,7 +108,7 @@ export default Vue.extend({ if (mediaItem.in_library.length > 0) { menuItems.push({ label: 'remove_library', - action: 'remove_library', + action: 'toggle_library', icon: 'favorite' }) } @@ -169,9 +169,9 @@ export default Vue.extend({ for (let item of this.curItem.provider_ids) { trackProviders.push(item.provider) } - let playlists = await this.$server.getData('playlists') + let playlists = await this.$server.getData('library/playlists') let items = [] - for (var playlist of playlists.items) { + for (var playlist of playlists['items']) { if ( playlist.is_editable && (!this.curPlaylist || playlist.item_id !== this.curPlaylist.item_id) @@ -189,8 +189,14 @@ export default Vue.extend({ itemCommand (cmd) { if (cmd === 'info') { // show media info + let endpoint = '' + if (this.curItem.media_type === 1) endpoint = 'artists' + if (this.curItem.media_type === 2) endpoint = 'albums' + if (this.curItem.media_type === 3) endpoint = 'tracks' + if (this.curItem.media_type === 4) endpoint = 'playlists' + if (this.curItem.media_type === 5) endpoint = 'radios' this.$router.push({ - path: '/' + this.curItem.media_type + '/' + this.curItem.item_id, + path: '/' + endpoint + '/' + this.curItem.item_id, query: { provider: this.curItem.provider } }) this.visible = false @@ -202,40 +208,37 @@ export default Vue.extend({ return this.showPlaylistsMenu() } else if (cmd === 'remove_playlist') { // remove track from playlist - this.playlistAddRemove( + this.removeFromPlaylist( this.curItem, this.curPlaylist.item_id, 'playlist_remove' ) this.visible = false + } else if (cmd === 'toggle_library') { + // add/remove to/from library + this.$server.toggleLibrary(this.curItem) + this.visible = false } else { // assume play command this.$server.playItem(this.curItem, cmd) this.visible = false } }, - playlistSelected (playlistobj) { - this.playlistAddRemove( - this.curItem, - playlistobj.item_id, - 'playlist_add' - ) - this.visible = false + addToPlaylist (playlistObj) { + /// add track to playlist + let endpoint = 'playlists/' + playlistObj.item_id + '/tracks' + this.$server.putData(endpoint, this.curItem) + .then(result => { + this.visible = false + }) }, - playlistAddRemove (track, playlistId, action = 'playlist_add') { - /// add or remove track on playlist - let endpoint = 'track/' + track.item_id - let params = { - provider: track.provider, - action: action, - action_details: playlistId - } - this.$server.getData(endpoint, params) + removeFromPlaylist (track, playlistId) { + /// remove track from playlist + let endpoint = 'playlists/' + playlistId + '/tracks' + this.$server.deleteData(endpoint, track) .then(result => { // reload listing - if (action === 'playlist_remove') { - this.$server.$emit('refresh_listing') - } + this.$server.$emit('refresh_listing') }) } } diff --git a/frontend/src/components/ListviewItem.vue b/frontend/src/components/ListviewItem.vue index eec96b11..03025b44 100644 --- a/frontend/src/components/ListviewItem.vue +++ b/frontend/src/components/ListviewItem.vue @@ -1,6 +1,7 @@