[web] Lint source code

This commit is contained in:
Alain Nussbaumer 2023-11-24 15:48:29 +01:00
parent 5c7ec031b5
commit 095d60af00
13 changed files with 88 additions and 95 deletions

View File

@ -67,9 +67,8 @@ export default {
return 'folder'
} else if (playlist.type === 'rss') {
return 'rss'
} else {
return 'music-box-multiple'
}
return 'music-box-multiple'
}
}
}

View File

@ -160,7 +160,7 @@ export default {
* Distinguish scroll event triggered by a user or programmatically
* Programmatically triggered event are ignored
*/
if (!e.screenX || e.screenX == 0 || !e.screenY || e.screenY == 0) return
if (!e.screenX || e.screenX == 0 || !e.screenY || e.screenY == 0) return
this.autoScroll = false
if (this.scrollTimer) clearTimeout(this.scrollTimer)
let t = this

View File

@ -64,9 +64,8 @@ export default {
return 'cast'
} else if (this.output.type === 'fifo') {
return 'pipe'
} else {
return 'server'
}
return 'server'
}
},

View File

@ -7,11 +7,11 @@ export const filters = {
durationInHours(value_ms) {
const seconds = Math.floor(value_ms / 1000)
if (seconds > 3600) {
return Duration.fromObject({ seconds: seconds })
return Duration.fromObject({ seconds })
.shiftTo('hours', 'minutes', 'seconds')
.toFormat('hh:mm:ss')
}
return Duration.fromObject({ seconds: seconds })
return Duration.fromObject({ seconds })
.shiftTo('minutes', 'seconds')
.toFormat('mm:ss')
},
@ -19,18 +19,15 @@ export const filters = {
durationInDays(value_ms) {
const minutes = Math.floor(value_ms / 60000)
if (minutes > 1440) {
// 60 * 24
return Duration.fromObject({ minutes: minutes })
return Duration.fromObject({ minutes })
.shiftTo('days', 'hours', 'minutes')
.toHuman()
} else if (minutes > 60) {
return Duration.fromObject({ minutes: minutes })
return Duration.fromObject({ minutes })
.shiftTo('hours', 'minutes')
.toHuman()
}
return Duration.fromObject({ minutes: minutes })
.shiftTo('minutes')
.toHuman()
return Duration.fromObject({ minutes }).shiftTo('minutes').toHuman()
},
date(value) {

View File

@ -26,9 +26,8 @@ export function byName(field, keepSortOrder = false, defaultValue = '_') {
return value.toUpperCase()
} else if (value.match(/\p{Number}/gu)) {
return '#'
} else {
return '⌘'
}
return '⌘'
}
}
}
@ -137,9 +136,11 @@ export class GroupByList {
}
[Symbol.iterator]() {
// Use a new index for each iterator. This makes multiple
// iterations over the iterable safe for non-trivial cases,
// such as use of break or nested looping over the same iterable.
/*
* Use a new index for each iterator. This makes multiple
* iterations over the iterable safe for non-trivial cases,
* such as use of break or nested looping over the same iterable.
*/
let groupIndex = -1
let itemIndex = -1
@ -148,16 +149,18 @@ export class GroupByList {
if (this.isEmpty()) {
return { done: true }
} else if (groupIndex >= this.indexList.length) {
// We reached the end of all groups and items
//
// This should never happen, as the we already
// return "done" after we reached the last item
// of the last group
/*
* End of all groups and items reached
* This should never happen, as the we already
* return "done" after we reached the last item
* of the last group
*/
return { done: true }
} else if (groupIndex < 0) {
// We start iterating
//
// Return the first group title as the next item
/*
* Start iterating
* Return the first group title as the next item
*/
++groupIndex
itemIndex = 0
@ -179,9 +182,10 @@ export class GroupByList {
let currentGroupItems = this.itemsByGroup[currentGroupKey]
if (itemIndex < currentGroupItems.length) {
// We are in a group with items left
//
// Return the current item and increment the item index
/*
* Within a group with remaining items
* Return the current item and increment the item index
*/
const currentItem = this.itemsByGroup[currentGroupKey][itemIndex++]
return {
value: {
@ -192,30 +196,29 @@ export class GroupByList {
},
done: false
}
} else {
// We reached the end of the current groups item list
//
// Move to the next group and return the group key/title
// as the next item
++groupIndex
itemIndex = 0
}
/*
* End of the current groups item list reached
* Move to the next group and return the group key/title
* as the next item
*/
++groupIndex
itemIndex = 0
if (groupIndex < this.indexList.length) {
currentGroupKey = this.indexList[groupIndex]
return {
value: {
groupKey: currentGroupKey,
itemId: currentGroupKey,
isItem: false,
item: {}
},
done: false
}
} else {
// No group left, we are done iterating
return { done: true }
if (groupIndex < this.indexList.length) {
currentGroupKey = this.indexList[groupIndex]
return {
value: {
groupKey: currentGroupKey,
itemId: currentGroupKey,
isItem: false,
item: {}
},
done: false
}
}
// No group left, we are done iterating
return { done: true }
}
}
}

View File

@ -54,7 +54,7 @@ function renderSVG(caption, alt_text, params) {
height: params.height,
textColor: text_color,
backgroundColor: background_color,
caption: caption,
caption,
fontFamily: params.font_family,
fontSize: params.font_size,
fontWeight: params.font_weight

View File

@ -81,7 +81,7 @@ import webapi from '@/webapi'
const PAGE_SIZE = 50
const dataObject = {
load: function (to) {
load(to) {
const spotifyApi = new SpotifyWebApi()
spotifyApi.setAccessToken(store.state.spotify.webapi_token)
return Promise.all([

View File

@ -60,9 +60,7 @@ const dataObject = {
vm.playlists = new GroupByList(response.data.playlists)
vm.tracks = new GroupByList(response.data.tracks)
} else {
vm.dirs = vm.$store.state.config.directories.map((dir) => {
return { path: dir }
})
vm.dirs = vm.$store.state.config.directories.map((dir) => ({ path: dir }))
vm.playlists = new GroupByList()
vm.tracks = new GroupByList()
}

View File

@ -27,7 +27,7 @@ const dataObject = {
type: 'album',
expression:
'media_kind is music having track_count > 3 order by time_added desc',
limit: limit
limit
})
},

View File

@ -156,7 +156,7 @@ export default {
)
// Filters out null tracks and adds a position to the playable tracks
data.items.forEach((item) => {
const track = item.track
const { track } = item
if (track) {
if (track.is_playable) {
track.position = ++position

View File

@ -298,7 +298,7 @@ export const router = createRouter({
scrollBehavior(to, from, savedPosition) {
const wait_ms = 0
if (savedPosition) {
// We have saved scroll position (browser back/forward navigation), use this position
// Use the saved scroll position (browser back/forward navigation)
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(savedPosition)
@ -307,10 +307,12 @@ export const router = createRouter({
}
if (to.path === from.path && to.hash) {
// We are staying on the same page and are jumping to an anchor (e. g. index nav)
// We don't have a transition, so don't add a timeout!
/*
* Staying on the same page and jumping to an anchor (e. g. index nav)
* As there is no transition, there is no timeout added
*/
const top = to.meta.has_tabs ? TOP_WITH_TABS : TOP_WITHOUT_TABS
return { el: to.hash, top: top, behavior: 'smooth' }
return { el: to.hash, top, behavior: 'smooth' }
}
if (to.hash) {
@ -323,12 +325,14 @@ export const router = createRouter({
}
if (to.meta.has_index) {
// We are navigating to a page with index nav, that should be hidden automatically
// Depending on wether we have a tab navigation, add an offset to the "top" anchor
/*
* Navigate to a page with index nav that should be hidden automatically
* If a tab navigation exists, an offset to the "top" anchor is added
*/
return new Promise((resolve, reject) => {
const top = to.meta.has_tabs ? TOP_WITH_TABS : TOP_WITHOUT_TABS
setTimeout(() => {
resolve({ el: '#top', top: top })
resolve({ el: '#top', top })
}, wait_ms)
})
}

View File

@ -79,9 +79,7 @@ export default createStore({
lyrics_pane: (state) => state.lyrics.pane,
now_playing: (state) => {
const item = state.queue.items.find(function (item) {
return item.id === state.player.item_id
})
const item = state.queue.items.find((e) => e.id === state.player.item_id)
return item === undefined ? {} : item
},
@ -142,11 +140,8 @@ export default createStore({
return false
},
settings_category: (state) => (categoryName) => {
return state.settings.categories.find(
(elem) => elem.name === categoryName
)
},
settings_category: (state) => (categoryName) =>
state.settings.categories.find((e) => e.name === categoryName),
settings_option: (state) => (categoryName, optionName) => {
const category = state.settings.categories.find(
@ -168,11 +163,11 @@ export default createStore({
},
[types.UPDATE_SETTINGS_OPTION](state, option) {
const settingCategory = state.settings.categories.find(
(elem) => elem.name === option.category
)
const settingOption = settingCategory.options.find(
(elem) => elem.name === option.name
)
(e) => e.name === option.category
),
settingOption = settingCategory.options.find(
(e) => e.name === option.name
)
settingOption.value = option.value
},
[types.UPDATE_LIBRARY_STATS](state, libraryStats) {

View File

@ -5,10 +5,8 @@ import i18n from '@/i18n'
const { t } = i18n.global
axios.interceptors.response.use(
function (response) {
return response
},
function (error) {
(response) => response,
(error) => {
if (error.request.status && error.request.responseURL) {
store.dispatch('add_notification', {
text: t('server.request-failed', {
@ -45,7 +43,7 @@ export default {
if (scanKind) {
params.scan_kind = scanKind
}
return axios.put('./api/update', undefined, { params: params })
return axios.put('./api/update', undefined, { params })
},
library_rescan(scanKind) {
@ -53,7 +51,7 @@ export default {
if (scanKind) {
params.scan_kind = scanKind
}
return axios.put('./api/rescan', undefined, { params: params })
return axios.put('./api/rescan', undefined, { params })
},
library_count(expression) {
@ -148,10 +146,10 @@ export default {
queue_save_playlist(name) {
return axios
.post('./api/queue/save', undefined, { params: { name: name } })
.post('./api/queue/save', undefined, { params: { name } })
.then((response) => {
store.dispatch('add_notification', {
text: t('server.queue-saved', { name: name }),
text: t('server.queue-saved', { name }),
type: 'info',
timeout: 2000
})
@ -259,7 +257,7 @@ export default {
library_artists(media_kind = undefined) {
return axios.get('./api/library/artists', {
params: { media_kind: media_kind }
params: { media_kind }
})
},
@ -273,7 +271,7 @@ export default {
library_albums(media_kind = undefined) {
return axios.get('./api/library/albums', {
params: { media_kind: media_kind }
params: { media_kind }
})
},
@ -295,13 +293,13 @@ export default {
library_genres(media_kind = undefined) {
return axios.get('./api/library/genres', {
params: { media_kind: media_kind }
params: { media_kind }
})
},
library_genre(genre, media_kind = undefined) {
return axios.get(`./api/library/genres/${encodeURIComponent(genre)}`, {
params: { media_kind: media_kind }
params: { media_kind }
})
},
@ -332,13 +330,13 @@ export default {
expression: 'data_kind is url and song_length = 0'
}
return axios.get('./api/search', {
params: params
params
})
},
library_composers(media_kind = undefined) {
return axios.get('./api/library/composers', {
params: { media_kind: media_kind }
params: { media_kind }
})
},
@ -352,7 +350,7 @@ export default {
expression: `composer is "${composer}" and media_kind is music`
}
return axios.get('./api/search', {
params: params
params
})
},
@ -362,7 +360,7 @@ export default {
expression: `composer is "${composer}" and media_kind is music`
}
return axios.get('./api/search', {
params: params
params
})
},
@ -400,7 +398,7 @@ export default {
},
library_add(url) {
return axios.post('./api/library/add', undefined, { params: { url: url } })
return axios.post('./api/library/add', undefined, { params: { url } })
},
library_playlist_delete(playlistId) {
@ -438,7 +436,7 @@ export default {
},
library_files(directory = undefined) {
const filesParams = { directory: directory }
const filesParams = { directory }
return axios.get('./api/library/files', {
params: filesParams
})