owntone-server/htdocs/assets/PageSearchLibrary.js
2023-12-14 20:00:28 +00:00

2 lines
13 KiB
JavaScript

import{_ as P,a3 as A,e as f,r as p,o as a,c as m,a as s,h as O,j as S,Z as T,d,w as l,F as B,f as D,g as c,k as u,t as n}from"./index.js";import{C as E,T as M}from"./TabsSearch.js";import{C as N}from"./ContentWithHeading.js";import{G as h}from"./GroupByList.js";import{L as V}from"./ListAlbums.js";import{L as W}from"./ListArtists.js";import{L as F}from"./ListComposers.js";import{L as G}from"./ListPlaylists.js";import{L as H}from"./ListTracks.js";import"./CoverArtwork.js";import"./ModalDialogAlbum.js";import"./ModalDialogArtist.js";import"./ModalDialogComposer.js";import"./ModalDialogPlaylist.js";import"./spotify-web-api.js";const R={name:"PageSearchLibrary",components:{ContentText:E,ContentWithHeading:N,ListAlbums:V,ListArtists:W,ListComposers:F,ListPlaylists:G,ListTracks:H,TabsSearch:M},data(){return{albums:new h,artists:new h,audiobooks:new h,composers:new h,playlists:new h,podcasts:new h,search_query:"",tracks:new h}},computed:{recent_searches(){return this.$store.state.recent_searches},show_albums(){return this.$route.query.type&&this.$route.query.type.includes("album")},show_all_albums_button(){return this.albums.total>this.albums.items.length},show_all_artists_button(){return this.artists.total>this.artists.items.length},show_all_audiobooks_button(){return this.audiobooks.total>this.audiobooks.items.length},show_all_composers_button(){return this.composers.total>this.composers.items.length},show_all_playlists_button(){return this.playlists.total>this.playlists.items.length},show_all_podcasts_button(){return this.podcasts.total>this.podcasts.items.length},show_all_tracks_button(){return this.tracks.total>this.tracks.items.length},show_artists(){return this.$route.query.type&&this.$route.query.type.includes("artist")},show_audiobooks(){return this.$route.query.type&&this.$route.query.type.includes("audiobook")},show_composers(){return this.$route.query.type&&this.$route.query.type.includes("composer")},show_playlists(){return this.$route.query.type&&this.$route.query.type.includes("playlist")},show_podcasts(){return this.$route.query.type&&this.$route.query.type.includes("podcast")},show_tracks(){return this.$route.query.type&&this.$route.query.type.includes("track")}},watch:{$route(t,r){this.search(t)}},mounted(){this.search(this.$route)},methods:{search(t){if(!t.query.query||t.query.query===""){this.search_query="",this.$refs.search_field.focus();return}this.search_query=t.query.query,this.searchMusic(t.query),this.searchAudiobooks(t.query),this.searchPodcasts(t.query),this.$store.commit(A,t.query.query)},searchMusic(t){if(t.type.indexOf("track")<0&&t.type.indexOf("artist")<0&&t.type.indexOf("album")<0&&t.type.indexOf("playlist")<0)return;const r={type:t.type,media_kind:"music"};t.query.startsWith("query:")?r.expression=t.query.replace(/^query:/u,"").trim():r.query=t.query,t.limit&&(r.limit=t.limit,r.offset=t.offset),f.search(r).then(({data:_})=>{this.tracks=new h(_.tracks),this.artists=new h(_.artists),this.albums=new h(_.albums),this.composers=new h(_.composers),this.playlists=new h(_.playlists)})},searchAudiobooks(t){if(t.type.indexOf("audiobook")<0)return;const r={type:"album",media_kind:"audiobook"};t.query.startsWith("query:")?r.expression=t.query.replace(/^query:/u,"").trim():r.expression=`((album includes "${t.query}" or artist includes "${t.query}") and media_kind is audiobook)`,t.limit&&(r.limit=t.limit,r.offset=t.offset),f.search(r).then(({data:_})=>{this.audiobooks=new h(_.albums)})},searchPodcasts(t){if(t.type.indexOf("podcast")<0)return;const r={type:"album",media_kind:"podcast"};t.query.startsWith("query:")?r.expression=t.query.replace(/^query:/u,"").trim():r.expression=`((album includes "${t.query}" or artist includes "${t.query}") and media_kind is podcast)`,t.limit&&(r.limit=t.limit,r.offset=t.offset),f.search(r).then(({data:_})=>{this.podcasts=new h(_.albums)})},new_search(){this.search_query&&(this.$router.push({name:"search-library",query:{limit:3,offset:0,query:this.search_query,type:"track,artist,album,playlist,audiobook,podcast,composer"}}),this.$refs.search_field.blur())},open_search_tracks(){this.$router.push({name:"search-library",query:{query:this.$route.query.query,type:"track"}})},open_search_artists(){this.$router.push({name:"search-library",query:{query:this.$route.query.query,type:"artist"}})},open_search_albums(){this.$router.push({name:"search-library",query:{query:this.$route.query.query,type:"album"}})},open_search_composers(){this.$router.push({name:"search-library",query:{query:this.$route.query.query,type:"tracks"}})},open_search_playlists(){this.$router.push({name:"search-library",query:{query:this.$route.query.query,type:"playlist"}})},open_search_audiobooks(){this.$router.push({name:"search-library",query:{query:this.$route.query.query,type:"audiobook"}})},open_search_podcasts(){this.$router.push({name:"search-library",query:{query:this.$route.query.query,type:"podcast"}})},open_composer(t){this.$router.push({name:"music-composer-albums",params:{name:t.name}})},open_playlist(t){this.$router.push({name:"playlist",params:{id:t.id}})},open_recent_search(t){this.search_query=t,this.new_search()},open_track_dialog(t){this.selected_track=t,this.show_track_details_modal=!0},open_album_dialog(t){this.selected_album=t,this.show_album_details_modal=!0},open_artist_dialog(t){this.selected_artist=t,this.show_artist_details_modal=!0},open_composer_dialog(t){this.selected_composer=t,this.show_composer_details_modal=!0},open_playlist_dialog(t){this.selected_playlist=t,this.show_playlist_details_modal=!0}}},j={class:"section pb-0"},z={class:"container"},U={class:"columns is-centered"},Z={class:"column is-four-fifths"},I={class:"field"},J={class:"control is-expanded has-icons-left"},K=["placeholder"],Q=s("code",null,"query:",-1),X=["textContent"],Y={class:"tags mt-4"},$=["onClick","textContent"],tt=["textContent"],st={key:0,class:"level"},et={class:"level-item"},ot=["textContent"],rt=["textContent"],lt=["textContent"],at={key:0,class:"level"},nt={class:"level-item"},it=["textContent"],ut=["textContent"],ct=["textContent"],ht={key:0,class:"level"},_t={class:"level-item"},pt=["textContent"],mt=["textContent"],dt=["textContent"],yt={key:0,class:"level"},bt={class:"level-item"},kt=["textContent"],ft=["textContent"],wt=["textContent"],gt={key:0,class:"level"},Ct={class:"level-item"},qt=["textContent"],xt=["textContent"],vt=["textContent"],Lt={key:0,class:"level"},Pt={class:"level-item"},At=["textContent"],Ot=["textContent"],St=["textContent"],Tt={key:0,class:"level"},Bt={class:"level-item"},Dt=["textContent"],Et=["textContent"];function Mt(t,r,_,Nt,o,e){const w=p("mdicon"),g=p("i18n-t"),C=p("tabs-search"),q=p("list-tracks"),y=p("content-with-heading"),b=p("content-text"),x=p("list-artists"),k=p("list-albums"),v=p("list-composers"),L=p("list-playlists");return a(),m("div",null,[s("section",j,[s("div",z,[s("div",U,[s("div",Z,[s("form",{onSubmit:r[1]||(r[1]=O((...i)=>e.new_search&&e.new_search(...i),["prevent"]))},[s("div",I,[s("p",J,[S(s("input",{ref:"search_field","onUpdate:modelValue":r[0]||(r[0]=i=>o.search_query=i),class:"input is-rounded is-shadowless",type:"text",placeholder:t.$t("page.search.placeholder"),autocomplete:"off"},null,8,K),[[T,o.search_query]]),d(w,{class:"icon is-left",name:"magnify",size:"16"})]),d(g,{tag:"p",class:"help has-text-centered",keypath:"page.search.help",scope:"global"},{query:l(()=>[Q]),help:l(()=>[s("a",{href:"https://owntone.github.io/owntone-server/smart-playlists/",target:"_blank",textContent:n(t.$t("page.search.expression"))},null,8,X)]),_:1})])],32),s("div",Y,[(a(!0),m(B,null,D(e.recent_searches,i=>(a(),m("a",{key:i,class:"tag",onClick:Vt=>e.open_recent_search(i),textContent:n(i)},null,8,$))),128))])])])])]),d(C,{query:o.search_query},null,8,["query"]),e.show_tracks&&o.tracks.total?(a(),c(y,{key:0,class:"pt-0"},{"heading-left":l(()=>[s("p",{class:"title is-4",textContent:n(t.$t("page.search.tracks"))},null,8,tt)]),content:l(()=>[d(q,{tracks:o.tracks},null,8,["tracks"])]),footer:l(()=>[e.show_all_tracks_button?(a(),m("nav",st,[s("p",et,[s("a",{class:"button is-light is-small is-rounded",onClick:r[2]||(r[2]=(...i)=>e.open_search_tracks&&e.open_search_tracks(...i)),textContent:n(t.$t("page.search.show-tracks",o.tracks.total,{count:t.$filters.number(o.tracks.total)}))},null,8,ot)])])):u("",!0)]),_:1})):u("",!0),e.show_tracks&&!o.tracks.total?(a(),c(b,{key:1,class:"pt-0"},{content:l(()=>[s("p",null,[s("i",{textContent:n(t.$t("page.search.no-tracks"))},null,8,rt)])]),_:1})):u("",!0),e.show_artists&&o.artists.total?(a(),c(y,{key:2},{"heading-left":l(()=>[s("p",{class:"title is-4",textContent:n(t.$t("page.search.artists"))},null,8,lt)]),content:l(()=>[d(x,{artists:o.artists,hide_group_title:!0},null,8,["artists"])]),footer:l(()=>[e.show_all_artists_button?(a(),m("nav",at,[s("p",nt,[s("a",{class:"button is-light is-small is-rounded",onClick:r[3]||(r[3]=(...i)=>e.open_search_artists&&e.open_search_artists(...i)),textContent:n(t.$t("page.search.show-artists",o.artists.total,{count:t.$filters.number(o.artists.total)}))},null,8,it)])])):u("",!0)]),_:1})):u("",!0),e.show_artists&&!o.artists.total?(a(),c(b,{key:3},{content:l(()=>[s("p",null,[s("i",{textContent:n(t.$t("page.search.no-artists"))},null,8,ut)])]),_:1})):u("",!0),e.show_albums&&o.albums.total?(a(),c(y,{key:4},{"heading-left":l(()=>[s("p",{class:"title is-4",textContent:n(t.$t("page.search.albums"))},null,8,ct)]),content:l(()=>[d(k,{albums:o.albums,hide_group_title:!0},null,8,["albums"])]),footer:l(()=>[e.show_all_albums_button?(a(),m("nav",ht,[s("p",_t,[s("a",{class:"button is-light is-small is-rounded",onClick:r[4]||(r[4]=(...i)=>e.open_search_albums&&e.open_search_albums(...i)),textContent:n(t.$t("page.search.show-albums",o.albums.total,{count:t.$filters.number(o.albums.total)}))},null,8,pt)])])):u("",!0)]),_:1})):u("",!0),e.show_albums&&!o.albums.total?(a(),c(b,{key:5},{content:l(()=>[s("p",null,[s("i",{textContent:n(t.$t("page.search.no-albums"))},null,8,mt)])]),_:1})):u("",!0),e.show_composers&&o.composers.total?(a(),c(y,{key:6},{"heading-left":l(()=>[s("p",{class:"title is-4",textContent:n(t.$t("page.search.composers"))},null,8,dt)]),content:l(()=>[d(v,{composers:o.composers},null,8,["composers"])]),footer:l(()=>[e.show_all_composers_button?(a(),m("nav",yt,[s("p",bt,[s("a",{class:"button is-light is-small is-rounded",onClick:r[5]||(r[5]=(...i)=>e.open_search_composers&&e.open_search_composers(...i)),textContent:n(t.$t("page.search.show-composers",o.composers.total,{count:t.$filters.number(o.composers.total)}))},null,8,kt)])])):u("",!0)]),_:1})):u("",!0),e.show_composers&&!o.composers.total?(a(),c(b,{key:7},{content:l(()=>[s("p",null,[s("i",{textContent:n(t.$t("page.search.no-composers"))},null,8,ft)])]),_:1})):u("",!0),e.show_playlists&&o.playlists.total?(a(),c(y,{key:8},{"heading-left":l(()=>[s("p",{class:"title is-4",textContent:n(t.$t("page.search.playlists"))},null,8,wt)]),content:l(()=>[d(L,{playlists:o.playlists},null,8,["playlists"])]),footer:l(()=>[e.show_all_playlists_button?(a(),m("nav",gt,[s("p",Ct,[s("a",{class:"button is-light is-small is-rounded",onClick:r[6]||(r[6]=(...i)=>e.open_search_playlists&&e.open_search_playlists(...i)),textContent:n(t.$t("page.search.show-playlists",o.playlists.total,{count:t.$filters.number(o.playlists.total)}))},null,8,qt)])])):u("",!0)]),_:1})):u("",!0),e.show_playlists&&!o.playlists.total?(a(),c(b,{key:9},{content:l(()=>[s("p",null,[s("i",{textContent:n(t.$t("page.search.no-playlists"))},null,8,xt)])]),_:1})):u("",!0),e.show_podcasts&&o.podcasts.total?(a(),c(y,{key:10},{"heading-left":l(()=>[s("p",{class:"title is-4",textContent:n(t.$t("page.search.podcasts"))},null,8,vt)]),content:l(()=>[d(k,{albums:o.podcasts},null,8,["albums"])]),footer:l(()=>[e.show_all_podcasts_button?(a(),m("nav",Lt,[s("p",Pt,[s("a",{class:"button is-light is-small is-rounded",onClick:r[7]||(r[7]=(...i)=>e.open_search_podcasts&&e.open_search_podcasts(...i)),textContent:n(t.$t("page.search.show-podcasts",o.podcasts.total,{count:t.$filters.number(o.podcasts.total)}))},null,8,At)])])):u("",!0)]),_:1})):u("",!0),e.show_podcasts&&!o.podcasts.total?(a(),c(b,{key:11},{content:l(()=>[s("p",null,[s("i",{textContent:n(t.$t("page.search.no-podcasts"))},null,8,Ot)])]),_:1})):u("",!0),e.show_audiobooks&&o.audiobooks.total?(a(),c(y,{key:12},{"heading-left":l(()=>[s("p",{class:"title is-4",textContent:n(t.$t("page.search.audiobooks"))},null,8,St)]),content:l(()=>[d(k,{albums:o.audiobooks},null,8,["albums"])]),footer:l(()=>[e.show_all_audiobooks_button?(a(),m("nav",Tt,[s("p",Bt,[s("a",{class:"button is-light is-small is-rounded",onClick:r[8]||(r[8]=(...i)=>e.open_search_audiobooks&&e.open_search_audiobooks(...i)),textContent:n(t.$t("page.search.show-audiobooks",o.audiobooks.total,{count:t.$filters.number(o.audiobooks.total)}))},null,8,Dt)])])):u("",!0)]),_:1})):u("",!0),e.show_audiobooks&&!o.audiobooks.total?(a(),c(b,{key:13},{content:l(()=>[s("p",null,[s("i",{textContent:n(t.$t("page.search.no-audiobooks"))},null,8,Et)])]),_:1})):u("",!0)])}const $t=P(R,[["render",Mt]]);export{$t as default};