[web] Change to template literals

This commit is contained in:
Alain Nussbaumer 2023-11-23 20:23:40 +01:00
parent 5cd63294a2
commit 406c87f765
13 changed files with 71 additions and 115 deletions

View File

@ -151,21 +151,17 @@ export default {
protocol = 'wss://' protocol = 'wss://'
} }
let wsUrl = let wsUrl = `${protocol + window.location.hostname}:${
protocol +
window.location.hostname +
':' +
vm.$store.state.config.websocket_port vm.$store.state.config.websocket_port
}`
if (import.meta.env.DEV && import.meta.env.VITE_OWNTONE_URL) { if (import.meta.env.DEV && import.meta.env.VITE_OWNTONE_URL) {
// If we are running in development mode, construct the websocket url // If we are running in development mode, construct the websocket url
// from the host of the environment variable VITE_OWNTONE_URL // from the host of the environment variable VITE_OWNTONE_URL
const owntoneUrl = new URL(import.meta.env.VITE_OWNTONE_URL) const owntoneUrl = new URL(import.meta.env.VITE_OWNTONE_URL)
wsUrl = wsUrl = `${protocol + owntoneUrl.hostname}:${
protocol +
owntoneUrl.hostname +
':' +
vm.$store.state.config.websocket_port vm.$store.state.config.websocket_port
}`
} }
const socket = new ReconnectingWebSocket(wsUrl, 'notify', { const socket = new ReconnectingWebSocket(wsUrl, 'notify', {

View File

@ -40,7 +40,7 @@ export default {
playSource(source) { playSource(source) {
this.stopAudio() this.stopAudio()
this._context.resume().then(() => { this._context.resume().then(() => {
this._audio.src = String(source || '') + '?x=' + Date.now() this._audio.src = `${String(source || '')}?x=${Date.now()}`
this._audio.crossOrigin = 'anonymous' this._audio.crossOrigin = 'anonymous'
this._audio.load() this._audio.load()
}) })

View File

@ -44,7 +44,7 @@ export default {
}, },
alt_text() { alt_text() {
return this.artist + ' - ' + this.album return `${this.artist} - ${this.album}`
}, },
caption() { caption() {

View File

@ -78,7 +78,7 @@ export default {
play() { play() {
this.$emit('close') this.$emit('close')
webapi.player_play_expression( webapi.player_play_expression(
'composer is "' + this.composer.name + '" and media_kind is music', `composer is "${this.composer.name}" and media_kind is music`,
false false
) )
}, },
@ -86,14 +86,14 @@ export default {
queue_add() { queue_add() {
this.$emit('close') this.$emit('close')
webapi.queue_expression_add( webapi.queue_expression_add(
'composer is "' + this.composer.name + '" and media_kind is music' `composer is "${this.composer.name}" and media_kind is music`
) )
}, },
queue_add_next() { queue_add_next() {
this.$emit('close') this.$emit('close')
webapi.queue_expression_add_next( webapi.queue_expression_add_next(
'composer is "' + this.composer.name + '" and media_kind is music' `composer is "${this.composer.name}" and media_kind is music`
) )
}, },

View File

@ -49,7 +49,7 @@ export default {
play() { play() {
this.$emit('close') this.$emit('close')
webapi.player_play_expression( webapi.player_play_expression(
'path starts with "' + this.directory + '" order by path asc', `path starts with "${this.directory}" order by path asc`,
false false
) )
}, },
@ -57,14 +57,14 @@ export default {
queue_add() { queue_add() {
this.$emit('close') this.$emit('close')
webapi.queue_expression_add( webapi.queue_expression_add(
'path starts with "' + this.directory + '" order by path asc' `path starts with "${this.directory}" order by path asc`
) )
}, },
queue_add_next() { queue_add_next() {
this.$emit('close') this.$emit('close')
webapi.queue_expression_add_next( webapi.queue_expression_add_next(
'path starts with "' + this.directory + '" order by path asc' `path starts with "${this.directory}" order by path asc`
) )
} }
} }

View File

@ -231,7 +231,7 @@ export default {
search_name: { search_name: {
get() { get() {
return 'search-' + this.$store.state.search_source return `search-${this.$store.state.search_source}`
} }
}, },

View File

@ -19,7 +19,7 @@ export default {
return 0 return 0
}, },
width_percent() { width_percent() {
return this.width + '%' return `${this.width}%`
} }
} }
} }

View File

@ -24,46 +24,26 @@ function calc_text_color(background_color) {
function createSVG(data) { function createSVG(data) {
const svg = const svg =
'<svg width="' + `<svg width="${data.width}" height="${data.height}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${data.width} ${data.height}" preserveAspectRatio="none">` +
data.width + `<defs>` +
'" height="' + `<style type="text/css">` +
data.height + ` #holder text {` +
'" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ' + ` fill: ${data.textColor};` +
data.width + ` font-family: ${data.fontFamily};` +
' ' + ` font-size: ${data.fontSize}px;` +
data.height + ` font-weight: ${data.fontWeight};` +
'" preserveAspectRatio="none">' + ` }` +
'<defs>' + ` </style>` +
'<style type="text/css">' + `</defs>` +
' #holder text {' + `<g id="holder">` +
' fill: ' + ` <rect width="100%" height="100%" fill="${data.backgroundColor}"></rect>` +
data.textColor + ` <g>` +
';' + ` <text text-anchor="middle" x="50%" y="50%" dy=".3em">${data.caption}</text>` +
' font-family: ' + ` </g>` +
data.fontFamily + `</g>` +
';' + `</svg>`
' font-size: ' +
data.fontSize +
'px;' +
' font-weight: ' +
data.fontWeight +
';' +
' }' +
' </style>' +
'</defs>' +
'<g id="holder">' +
' <rect width="100%" height="100%" fill="' +
data.backgroundColor +
'"></rect>' +
' <g>' +
' <text text-anchor="middle" x="50%" y="50%" dy=".3em">' +
data.caption +
'</text>' +
' </g>' +
'</g>' +
'</svg>'
return 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg) return `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(svg)}`
} }
function renderSVG(caption, alt_text, params) { function renderSVG(caption, alt_text, params) {

View File

@ -105,7 +105,7 @@ export default {
play() { play() {
webapi.player_play_expression( webapi.player_play_expression(
'composer is "' + this.composer.name + '" and media_kind is music', `composer is "${this.composer.name}" and media_kind is music`,
true true
) )
} }

View File

@ -130,7 +130,7 @@ export default {
computed: { computed: {
expression() { expression() {
return 'composer is "' + this.composer.name + '" and media_kind is music' return `composer is "${this.composer.name}" and media_kind is music`
}, },
selected_groupby_option_id: { selected_groupby_option_id: {
get() { get() {

View File

@ -110,9 +110,7 @@ export default {
}, },
play_expression() { play_expression() {
return ( return `path starts with "${this.current_directory}" order by path asc`
'path starts with "' + this.current_directory + '" order by path asc'
)
} }
}, },

View File

@ -430,12 +430,7 @@ export default {
if (query.query.startsWith('query:')) { if (query.query.startsWith('query:')) {
searchParams.expression = query.query.replace(/^query:/, '').trim() searchParams.expression = query.query.replace(/^query:/, '').trim()
} else { } else {
searchParams.expression = searchParams.expression = `((album includes "${query.query}" or artist includes "${query.query}") and media_kind is audiobook)`
'((album includes "' +
query.query +
'" or artist includes "' +
query.query +
'") and media_kind is audiobook)'
} }
if (query.limit) { if (query.limit) {
@ -461,12 +456,7 @@ export default {
if (query.query.startsWith('query:')) { if (query.query.startsWith('query:')) {
searchParams.expression = query.query.replace(/^query:/, '').trim() searchParams.expression = query.query.replace(/^query:/, '').trim()
} else { } else {
searchParams.expression = searchParams.expression = `((album includes "${query.query}" or artist includes "${query.query}") and media_kind is podcast)`
'((album includes "' +
query.query +
'" or artist includes "' +
query.query +
'") and media_kind is podcast)'
} }
if (query.limit) { if (query.limit) {

View File

@ -33,10 +33,7 @@ export default {
}, },
settings_update(categoryName, option) { settings_update(categoryName, option) {
return axios.put( return axios.put(`./api/settings/${categoryName}/${option.name}`, option)
'./api/settings/' + categoryName + '/' + option.name,
option
)
}, },
library_stats() { library_stats() {
@ -60,7 +57,7 @@ export default {
}, },
library_count(expression) { library_count(expression) {
return axios.get('./api/library/count?expression=' + expression) return axios.get(`./api/library/count?expression=${expression}`)
}, },
queue() { queue() {
@ -72,17 +69,15 @@ export default {
}, },
queue_remove(itemId) { queue_remove(itemId) {
return axios.delete('./api/queue/items/' + itemId) return axios.delete(`./api/queue/items/${itemId}`)
}, },
queue_move(itemId, newPosition) { queue_move(itemId, newPosition) {
return axios.put( return axios.put(`./api/queue/items/${itemId}?new_position=${newPosition}`)
'./api/queue/items/' + itemId + '?new_position=' + newPosition
)
}, },
queue_add(uri) { queue_add(uri) {
return axios.post('./api/queue/items/add?uris=' + uri).then((response) => { return axios.post(`./api/queue/items/add?uris=${uri}`).then((response) => {
store.dispatch('add_notification', { store.dispatch('add_notification', {
text: t('server.appended-tracks', { count: response.data.count }), text: t('server.appended-tracks', { count: response.data.count }),
type: 'info', type: 'info',
@ -98,7 +93,7 @@ export default {
position = store.getters.now_playing.position + 1 position = store.getters.now_playing.position + 1
} }
return axios return axios
.post('./api/queue/items/add?uris=' + uri + '&position=' + position) .post(`./api/queue/items/add?uris=${uri}&position=${position}`)
.then((response) => { .then((response) => {
store.dispatch('add_notification', { store.dispatch('add_notification', {
text: t('server.appended-tracks', { text: t('server.appended-tracks', {
@ -195,11 +190,11 @@ export default {
}, },
player_playpos(position) { player_playpos(position) {
return axios.put('./api/player/play?position=' + position) return axios.put(`./api/player/play?position=${position}`)
}, },
player_playid(itemId) { player_playid(itemId) {
return axios.put('./api/player/play?item_id=' + itemId) return axios.put(`./api/player/play?item_id=${itemId}`)
}, },
player_pause() { player_pause() {
@ -220,34 +215,34 @@ export default {
player_shuffle(newState) { player_shuffle(newState) {
const shuffle = newState ? 'true' : 'false' const shuffle = newState ? 'true' : 'false'
return axios.put('./api/player/shuffle?state=' + shuffle) return axios.put(`./api/player/shuffle?state=${shuffle}`)
}, },
player_consume(newState) { player_consume(newState) {
const consume = newState ? 'true' : 'false' const consume = newState ? 'true' : 'false'
return axios.put('./api/player/consume?state=' + consume) return axios.put(`./api/player/consume?state=${consume}`)
}, },
player_repeat(newRepeatMode) { player_repeat(newRepeatMode) {
return axios.put('./api/player/repeat?state=' + newRepeatMode) return axios.put(`./api/player/repeat?state=${newRepeatMode}`)
}, },
player_volume(volume) { player_volume(volume) {
return axios.put('./api/player/volume?volume=' + volume) return axios.put(`./api/player/volume?volume=${volume}`)
}, },
player_output_volume(outputId, outputVolume) { player_output_volume(outputId, outputVolume) {
return axios.put( return axios.put(
'./api/player/volume?volume=' + outputVolume + '&output_id=' + outputId `./api/player/volume?volume=${outputVolume}&output_id=${outputId}`
) )
}, },
player_seek_to_pos(newPosition) { player_seek_to_pos(newPosition) {
return axios.put('./api/player/seek?position_ms=' + newPosition) return axios.put(`./api/player/seek?position_ms=${newPosition}`)
}, },
player_seek(seekMs) { player_seek(seekMs) {
return axios.put('./api/player/seek?seek_ms=' + seekMs) return axios.put(`./api/player/seek?seek_ms=${seekMs}`)
}, },
outputs() { outputs() {
@ -255,11 +250,11 @@ export default {
}, },
output_update(outputId, output) { output_update(outputId, output) {
return axios.put('./api/outputs/' + outputId, output) return axios.put(`./api/outputs/${outputId}`, output)
}, },
output_toggle(outputId) { output_toggle(outputId) {
return axios.put('./api/outputs/' + outputId + '/toggle') return axios.put(`./api/outputs/${outputId}/toggle`)
}, },
library_artists(media_kind = undefined) { library_artists(media_kind = undefined) {
@ -269,11 +264,11 @@ export default {
}, },
library_artist(artistId) { library_artist(artistId) {
return axios.get('./api/library/artists/' + artistId) return axios.get(`./api/library/artists/${artistId}`)
}, },
library_artist_albums(artistId) { library_artist_albums(artistId) {
return axios.get('./api/library/artists/' + artistId + '/albums') return axios.get(`./api/library/artists/${artistId}/albums`)
}, },
library_albums(media_kind = undefined) { library_albums(media_kind = undefined) {
@ -283,17 +278,17 @@ export default {
}, },
library_album(albumId) { library_album(albumId) {
return axios.get('./api/library/albums/' + albumId) return axios.get(`./api/library/albums/${albumId}`)
}, },
library_album_tracks(albumId, filter = { limit: -1, offset: 0 }) { library_album_tracks(albumId, filter = { limit: -1, offset: 0 }) {
return axios.get('./api/library/albums/' + albumId + '/tracks', { return axios.get(`./api/library/albums/${albumId}/tracks`, {
params: filter params: filter
}) })
}, },
library_album_track_update(albumId, attributes) { library_album_track_update(albumId, attributes) {
return axios.put('./api/library/albums/' + albumId + '/tracks', undefined, { return axios.put(`./api/library/albums/${albumId}/tracks`, undefined, {
params: attributes params: attributes
}) })
}, },
@ -375,7 +370,7 @@ export default {
if (artist) { if (artist) {
const artistParams = { const artistParams = {
type: 'tracks', type: 'tracks',
expression: 'songartistid is "' + artist + '"' expression: `songartistid is "${artist}"`
} }
return axios.get('./api/search', { return axios.get('./api/search', {
params: artistParams params: artistParams
@ -397,10 +392,7 @@ export default {
library_podcast_episodes(albumId) { library_podcast_episodes(albumId) {
const episodesParams = { const episodesParams = {
type: 'tracks', type: 'tracks',
expression: expression: `media_kind is podcast and songalbumid is "${albumId}" ORDER BY date_released DESC`
'media_kind is podcast and songalbumid is "' +
albumId +
'" ORDER BY date_released DESC'
} }
return axios.get('./api/search', { return axios.get('./api/search', {
params: episodesParams params: episodesParams
@ -412,7 +404,7 @@ export default {
}, },
library_playlist_delete(playlistId) { library_playlist_delete(playlistId) {
return axios.delete('./api/library/playlists/' + playlistId, undefined) return axios.delete(`./api/library/playlists/${playlistId}`, undefined)
}, },
library_playlists() { library_playlists() {
@ -420,27 +412,27 @@ export default {
}, },
library_playlist_folder(playlistId = 0) { library_playlist_folder(playlistId = 0) {
return axios.get('./api/library/playlists/' + playlistId + '/playlists') return axios.get(`./api/library/playlists/${playlistId}/playlists`)
}, },
library_playlist(playlistId) { library_playlist(playlistId) {
return axios.get('./api/library/playlists/' + playlistId) return axios.get(`./api/library/playlists/${playlistId}`)
}, },
library_playlist_tracks(playlistId) { library_playlist_tracks(playlistId) {
return axios.get('./api/library/playlists/' + playlistId + '/tracks') return axios.get(`./api/library/playlists/${playlistId}/tracks`)
}, },
library_track(trackId) { library_track(trackId) {
return axios.get('./api/library/tracks/' + trackId) return axios.get(`./api/library/tracks/${trackId}`)
}, },
library_track_playlists(trackId) { library_track_playlists(trackId) {
return axios.get('./api/library/tracks/' + trackId + '/playlists') return axios.get(`./api/library/tracks/${trackId}/playlists`)
}, },
library_track_update(trackId, attributes = {}) { library_track_update(trackId, attributes = {}) {
return axios.put('./api/library/tracks/' + trackId, undefined, { return axios.put(`./api/library/tracks/${trackId}`, undefined, {
params: attributes params: attributes
}) })
}, },
@ -493,9 +485,9 @@ export default {
artwork_url_append_size_params(artworkUrl, maxwidth = 600, maxheight = 600) { artwork_url_append_size_params(artworkUrl, maxwidth = 600, maxheight = 600) {
if (artworkUrl && artworkUrl.startsWith('/')) { if (artworkUrl && artworkUrl.startsWith('/')) {
if (artworkUrl.includes('?')) { if (artworkUrl.includes('?')) {
return artworkUrl + '&maxwidth=' + maxwidth + '&maxheight=' + maxheight return `${artworkUrl}&maxwidth=${maxwidth}&maxheight=${maxheight}`
} }
return artworkUrl + '?maxwidth=' + maxwidth + '&maxheight=' + maxheight return `${artworkUrl}?maxwidth=${maxwidth}&maxheight=${maxheight}`
} }
return artworkUrl return artworkUrl
} }