From 30ca0bb95f0d6bcae96daba8d4564e1f32e65191 Mon Sep 17 00:00:00 2001 From: Mark Cooper Date: Wed, 18 Aug 2021 06:50:24 -0500 Subject: [PATCH] Sorting, fix user object bug, add settings module --- client/.nuxt/components/index.js | 2 + client/.nuxt/components/plugin.js | 1 + client/.nuxt/components/readme.md | 1 + client/.nuxt/store.js | 2 + client/.nuxt/vetur/tags.json | 3 ++ client/components/app/Appbar.vue | 3 +- client/components/app/BookShelf.vue | 29 ++++++++++- client/components/app/BookShelfToolbar.vue | 33 +++++++++++++ client/components/modals/edit-tabs/Match.vue | 52 +++++++++++++++++--- client/components/ui/Tooltip.vue | 3 ++ client/package.json | 2 +- client/pages/config/index.vue | 10 +++- client/pages/index.vue | 1 + client/store/settings.js | 20 ++++++++ client/tailwind.config.js | 9 +++- docker-template.xml | 2 +- package.json | 2 +- server/StreamManager.js | 6 ++- 18 files changed, 164 insertions(+), 17 deletions(-) create mode 100644 client/components/app/BookShelfToolbar.vue create mode 100644 client/store/settings.js diff --git a/client/.nuxt/components/index.js b/client/.nuxt/components/index.js index 84236346..8d1a1122 100644 --- a/client/.nuxt/components/index.js +++ b/client/.nuxt/components/index.js @@ -3,6 +3,7 @@ import { wrapFunctional } from './utils' export { default as AudioPlayer } from '../..\\components\\AudioPlayer.vue' export { default as AppAppbar } from '../..\\components\\app\\Appbar.vue' export { default as AppBookShelf } from '../..\\components\\app\\BookShelf.vue' +export { default as AppBookShelfToolbar } from '../..\\components\\app\\BookShelfToolbar.vue' export { default as AppStreamContainer } from '../..\\components\\app\\StreamContainer.vue' export { default as AppTracksTable } from '../..\\components\\app\\TracksTable.vue' export { default as CardsBookCard } from '../..\\components\\cards\\BookCard.vue' @@ -27,6 +28,7 @@ export { default as ModalsEditTabsTracks } from '../..\\components\\modals\\edit export const LazyAudioPlayer = import('../..\\components\\AudioPlayer.vue' /* webpackChunkName: "components/audio-player" */).then(c => wrapFunctional(c.default || c)) export const LazyAppAppbar = import('../..\\components\\app\\Appbar.vue' /* webpackChunkName: "components/app-appbar" */).then(c => wrapFunctional(c.default || c)) export const LazyAppBookShelf = import('../..\\components\\app\\BookShelf.vue' /* webpackChunkName: "components/app-book-shelf" */).then(c => wrapFunctional(c.default || c)) +export const LazyAppBookShelfToolbar = import('../..\\components\\app\\BookShelfToolbar.vue' /* webpackChunkName: "components/app-book-shelf-toolbar" */).then(c => wrapFunctional(c.default || c)) export const LazyAppStreamContainer = import('../..\\components\\app\\StreamContainer.vue' /* webpackChunkName: "components/app-stream-container" */).then(c => wrapFunctional(c.default || c)) export const LazyAppTracksTable = import('../..\\components\\app\\TracksTable.vue' /* webpackChunkName: "components/app-tracks-table" */).then(c => wrapFunctional(c.default || c)) export const LazyCardsBookCard = import('../..\\components\\cards\\BookCard.vue' /* webpackChunkName: "components/cards-book-card" */).then(c => wrapFunctional(c.default || c)) diff --git a/client/.nuxt/components/plugin.js b/client/.nuxt/components/plugin.js index 978b5c83..53a12e7e 100644 --- a/client/.nuxt/components/plugin.js +++ b/client/.nuxt/components/plugin.js @@ -5,6 +5,7 @@ const components = { AudioPlayer: () => import('../..\\components\\AudioPlayer.vue' /* webpackChunkName: "components/audio-player" */).then(c => wrapFunctional(c.default || c)), AppAppbar: () => import('../..\\components\\app\\Appbar.vue' /* webpackChunkName: "components/app-appbar" */).then(c => wrapFunctional(c.default || c)), AppBookShelf: () => import('../..\\components\\app\\BookShelf.vue' /* webpackChunkName: "components/app-book-shelf" */).then(c => wrapFunctional(c.default || c)), + AppBookShelfToolbar: () => import('../..\\components\\app\\BookShelfToolbar.vue' /* webpackChunkName: "components/app-book-shelf-toolbar" */).then(c => wrapFunctional(c.default || c)), AppStreamContainer: () => import('../..\\components\\app\\StreamContainer.vue' /* webpackChunkName: "components/app-stream-container" */).then(c => wrapFunctional(c.default || c)), AppTracksTable: () => import('../..\\components\\app\\TracksTable.vue' /* webpackChunkName: "components/app-tracks-table" */).then(c => wrapFunctional(c.default || c)), CardsBookCard: () => import('../..\\components\\cards\\BookCard.vue' /* webpackChunkName: "components/cards-book-card" */).then(c => wrapFunctional(c.default || c)), diff --git a/client/.nuxt/components/readme.md b/client/.nuxt/components/readme.md index 3d00872c..2c3c4000 100644 --- a/client/.nuxt/components/readme.md +++ b/client/.nuxt/components/readme.md @@ -9,6 +9,7 @@ You can directly use them in pages and other components without the need to impo - `` | `` (components/AudioPlayer.vue) - `` | `` (components/app/Appbar.vue) - `` | `` (components/app/BookShelf.vue) +- `` | `` (components/app/BookShelfToolbar.vue) - `` | `` (components/app/StreamContainer.vue) - `` | `` (components/app/TracksTable.vue) - `` | `` (components/cards/BookCard.vue) diff --git a/client/.nuxt/store.js b/client/.nuxt/store.js index ca03d15a..367d8ba3 100644 --- a/client/.nuxt/store.js +++ b/client/.nuxt/store.js @@ -20,6 +20,7 @@ let store = {}; store.modules = store.modules || {} resolveStoreModules(require('..\\store\\audiobooks.js'), 'audiobooks.js') + resolveStoreModules(require('..\\store\\settings.js'), 'settings.js') // If the environment supports hot reloading... @@ -28,6 +29,7 @@ let store = {}; module.hot.accept([ '..\\store\\audiobooks.js', '..\\store\\index.js', + '..\\store\\settings.js', ], () => { // Update `root.modules` with the latest definitions. updateModules() diff --git a/client/.nuxt/vetur/tags.json b/client/.nuxt/vetur/tags.json index a0578d25..dfa2cd6f 100644 --- a/client/.nuxt/vetur/tags.json +++ b/client/.nuxt/vetur/tags.json @@ -8,6 +8,9 @@ "AppBookShelf": { "description": "Auto imported from components/app/BookShelf.vue" }, + "AppBookShelfToolbar": { + "description": "Auto imported from components/app/BookShelfToolbar.vue" + }, "AppStreamContainer": { "description": "Auto imported from components/app/StreamContainer.vue" }, diff --git a/client/components/app/Appbar.vue b/client/components/app/Appbar.vue index 3ba21bfb..0398d3fb 100644 --- a/client/components/app/Appbar.vue +++ b/client/components/app/Appbar.vue @@ -83,6 +83,7 @@ export default { \ No newline at end of file diff --git a/client/components/app/BookShelf.vue b/client/components/app/BookShelf.vue index bf4a0302..d2ab1b1b 100644 --- a/client/components/app/BookShelf.vue +++ b/client/components/app/BookShelf.vue @@ -35,21 +35,43 @@ export default { }, audiobooks() { return this.$store.state.audiobooks.audiobooks + }, + orderBy() { + return this.$store.state.settings.orderBy + }, + orderDesc() { + return this.$store.state.settings.orderDesc } }, methods: { + sortAudiobooks() { + var audiobooks = this.audiobooks.map((ab) => ({ ...ab })) + audiobooks.sort((a, b) => { + var bookA = a.book || {} + var bookB = b.book || {} + if (this.orderDesc) { + return bookB[this.orderBy] > bookA[this.orderBy] ? 1 : -1 + } else { + // ASCENDING A -> Z + return bookA[this.orderBy] > bookB[this.orderBy] ? 1 : -1 + } + }) + return audiobooks + }, setGroupedBooks() { var groups = [] var currentRow = 0 var currentGroup = [] - for (let i = 0; i < this.audiobooks.length; i++) { + var audiobooksSorted = this.sortAudiobooks() + console.log('AB SORTED', audiobooksSorted) + for (let i = 0; i < audiobooksSorted.length; i++) { var row = Math.floor(i / this.booksPerRow) if (row > currentRow) { groups.push([...currentGroup]) currentRow = row currentGroup = [] } - currentGroup.push(this.audiobooks[i]) + currentGroup.push(audiobooksSorted[i]) } if (currentGroup.length) { groups.push([...currentGroup]) @@ -98,6 +120,9 @@ export default { \ No newline at end of file diff --git a/client/components/modals/edit-tabs/Match.vue b/client/components/modals/edit-tabs/Match.vue index 2f66cd26..93705ce0 100644 --- a/client/components/modals/edit-tabs/Match.vue +++ b/client/components/modals/edit-tabs/Match.vue @@ -11,6 +11,9 @@

Loading...

+
+

No Results

+
@@ -23,7 +25,11 @@ export default { data() { return {} }, - computed: {}, + computed: { + streamAudiobook() { + return this.$store.state.streamAudiobook + } + }, methods: { scan() { this.$root.socket.emit('scan') diff --git a/client/pages/index.vue b/client/pages/index.vue index 32bf76e9..2051a0c4 100644 --- a/client/pages/index.vue +++ b/client/pages/index.vue @@ -1,5 +1,6 @@ diff --git a/client/store/settings.js b/client/store/settings.js new file mode 100644 index 00000000..72ce11ca --- /dev/null +++ b/client/store/settings.js @@ -0,0 +1,20 @@ + +export const state = () => ({ + orderBy: 'title', + orderDesc: false +}) + +export const getters = { + +} + +export const actions = { + +} + +export const mutations = { + setSettings(state, settings) { + state.orderBy = settings.orderBy + state.orderDesc = settings.orderDesc + } +} \ No newline at end of file diff --git a/client/tailwind.config.js b/client/tailwind.config.js index a5ec2ca8..b9a0634b 100644 --- a/client/tailwind.config.js +++ b/client/tailwind.config.js @@ -1,13 +1,18 @@ const defaultTheme = require('tailwindcss/defaultTheme') module.exports = { - purge: {}, + purge: { + options: { + safelist: [ + 'bg-success' + ] + } + }, darkMode: false, theme: { extend: { colors: { bg: '#373838', - yellowgreen: 'yellowgreen', primary: '#262626', accent: '#1ad691', error: '#FF5252', diff --git a/docker-template.xml b/docker-template.xml index 9ffeafd2..1b264ed9 100644 --- a/docker-template.xml +++ b/docker-template.xml @@ -8,7 +8,7 @@ sh false https://hub.docker.com/r/advplyr/audiobookshelf/ - + https://github.com/advplyr/audiobookshelf Audiobook manager and player MediaApp:Books MediaServer:Books Status:Beta< http://[IP]:[PORT:80] diff --git a/package.json b/package.json index 3f5e309b..ea083a13 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf", - "version": "0.9.1", + "version": "0.9.3", "description": "", "main": "index.js", "scripts": { diff --git a/server/StreamManager.js b/server/StreamManager.js index bde3664e..d020d039 100644 --- a/server/StreamManager.js +++ b/server/StreamManager.js @@ -115,8 +115,12 @@ class StreamManager { Logger.error('No User for client', client) return } + if (!client.user.updateAudiobookProgress) { + Logger.error('Invalid User for client', client) + return + } client.user.updateAudiobookProgress(client.stream) - this.db.updateEntity('user', client.user.toJSON()) + this.db.updateEntity('user', client.user) } } module.exports = StreamManager \ No newline at end of file