From 5a26b01ffb1a5ecdbf09f82d14a71f9f1e177e57 Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 14 Apr 2022 17:15:52 -0500 Subject: [PATCH] Add LibrarySettings and update edit library modal to include settings tab --- client/components/modals/item/EditModal.vue | 4 +- .../modals/libraries/EditLibrary.vue | 171 ++++------------- .../components/modals/libraries/EditModal.vue | 181 +++++++++++++++++- .../modals/libraries/FolderChooser.vue | 23 ++- .../modals/libraries/LibrarySettings.vue | 63 ++++++ client/components/ui/MediaIconPicker.vue | 8 +- client/components/ui/TextInputWithLabel.vue | 5 +- server/Db.js | 2 +- server/Watcher.js | 6 +- server/objects/Library.js | 17 +- server/objects/settings/LibrarySettings.js | 34 ++++ .../objects/{ => settings}/ServerSettings.js | 4 +- 12 files changed, 356 insertions(+), 162 deletions(-) create mode 100644 client/components/modals/libraries/LibrarySettings.vue create mode 100644 server/objects/settings/LibrarySettings.js rename server/objects/{ => settings}/ServerSettings.js (97%) diff --git a/client/components/modals/item/EditModal.vue b/client/components/modals/item/EditModal.vue index 2840898e..094ef9bd 100644 --- a/client/components/modals/item/EditModal.vue +++ b/client/components/modals/item/EditModal.vue @@ -5,7 +5,7 @@

{{ title }}

-
+
@@ -252,7 +252,7 @@ export default { } - \ No newline at end of file diff --git a/client/components/modals/libraries/FolderChooser.vue b/client/components/modals/libraries/FolderChooser.vue index d41d16e9..a54cdfe6 100644 --- a/client/components/modals/libraries/FolderChooser.vue +++ b/client/components/modals/libraries/FolderChooser.vue @@ -1,10 +1,14 @@ @@ -161,4 +161,9 @@ export default { .dir-item.dir-used { background-color: rgba(255, 25, 0, 0.1); } +.folder-container { + max-height: calc(100% - 130px); + height: calc(100% - 130px); + min-height: calc(100% - 130px); +} \ No newline at end of file diff --git a/client/components/modals/libraries/LibrarySettings.vue b/client/components/modals/libraries/LibrarySettings.vue new file mode 100644 index 00000000..c27f4838 --- /dev/null +++ b/client/components/modals/libraries/LibrarySettings.vue @@ -0,0 +1,63 @@ + + + \ No newline at end of file diff --git a/client/components/ui/MediaIconPicker.vue b/client/components/ui/MediaIconPicker.vue index 50280904..efb0b9a0 100644 --- a/client/components/ui/MediaIconPicker.vue +++ b/client/components/ui/MediaIconPicker.vue @@ -40,8 +40,8 @@ export default { showMenu: false, types: [ { - id: 'default', - name: 'Default' + id: 'database', + name: 'Database' }, { id: 'audiobook', @@ -65,7 +65,7 @@ export default { computed: { selected: { get() { - return this.value || 'default' + return this.value || 'database' }, set(val) { this.$emit('input', val) @@ -75,7 +75,7 @@ export default { return this.types.find((t) => t.id === this.selected) }, selectedName() { - return this.selectedItem ? this.selectedItem.name : 'Default' + return this.selectedItem ? this.selectedItem.name : 'Database' } }, methods: { diff --git a/client/components/ui/TextInputWithLabel.vue b/client/components/ui/TextInputWithLabel.vue index f5cbd1e4..0dab6109 100644 --- a/client/components/ui/TextInputWithLabel.vue +++ b/client/components/ui/TextInputWithLabel.vue @@ -3,7 +3,7 @@

{{ label }}{{ note }}

- +
@@ -38,6 +38,9 @@ export default { if (this.$refs.input && this.$refs.input.blur) { this.$refs.input.blur() } + }, + inputBlurred() { + this.$emit('blur') } }, mounted() {} diff --git a/server/Db.js b/server/Db.js index 62e1bb0f..e3700d7e 100644 --- a/server/Db.js +++ b/server/Db.js @@ -9,7 +9,7 @@ const UserCollection = require('./objects/UserCollection') const Library = require('./objects/Library') const Author = require('./objects/entities/Author') const Series = require('./objects/entities/Series') -const ServerSettings = require('./objects/ServerSettings') +const ServerSettings = require('./objects/settings/ServerSettings') const PlaybackSession = require('./objects/PlaybackSession') class Db { diff --git a/server/Watcher.js b/server/Watcher.js index aa3c68f6..ea9e46e0 100644 --- a/server/Watcher.js +++ b/server/Watcher.js @@ -69,19 +69,19 @@ class FolderWatcher extends EventEmitter { initWatcher(libraries) { libraries.forEach((lib) => { - if (!lib.disableWatcher) { + if (!lib.settings.disableWatcher) { this.buildLibraryWatcher(lib) } }) } addLibrary(library) { - if (this.disabled || library.disableWatcher) return + if (this.disabled || library.settings.disableWatcher) return this.buildLibraryWatcher(library) } updateLibrary(library) { - if (this.disabled || library.disableWatcher) return + if (this.disabled || library.settings.disableWatcher) return var libwatcher = this.libraryWatchers.find(lib => lib.id === library.id) if (libwatcher) { libwatcher.name = library.name diff --git a/server/objects/Library.js b/server/objects/Library.js index 1219d8f0..aef80702 100644 --- a/server/objects/Library.js +++ b/server/objects/Library.js @@ -1,4 +1,5 @@ const Folder = require('./Folder') +const LibrarySettings = require('./settings/LibrarySettings') const { getId } = require('../utils/index') class Library { @@ -10,9 +11,9 @@ class Library { this.icon = 'database' // database, podcast, book, audiobook, comic this.mediaType = 'book' // book, podcast this.provider = 'google' - this.disableWatcher = false this.lastScan = 0 + this.settings = null this.createdAt = null this.lastUpdate = null @@ -34,7 +35,11 @@ class Library { this.icon = library.icon || 'database' this.mediaType = library.mediaType this.provider = library.provider || 'google' - this.disableWatcher = !!library.disableWatcher + + this.settings = new LibrarySettings(library.settings) + if (library.settings === undefined) { // LibrarySettings added in v2, migrate settings + this.settings.disableWatcher = !!library.disableWatcher + } this.createdAt = library.createdAt this.lastUpdate = library.lastUpdate @@ -62,7 +67,7 @@ class Library { icon: this.icon, mediaType: this.mediaType, provider: this.provider, - disableWatcher: this.disableWatcher, + settings: this.settings.toJSON(), createdAt: this.createdAt, lastUpdate: this.lastUpdate } @@ -89,7 +94,7 @@ class Library { this.icon = data.icon || 'database' this.mediaType = data.mediaType || 'book' this.provider = data.provider || 'google' - this.disableWatcher = !!data.disableWatcher + this.settings = new LibrarySettings(data.settings) this.createdAt = Date.now() this.lastUpdate = Date.now() } @@ -105,10 +110,10 @@ class Library { } }) - if (payload.disableWatcher !== this.disableWatcher) { - this.disableWatcher = !!payload.disableWatcher + if (payload.settings && this.settings.update(payload.settings)) { hasUpdates = true } + if (!isNaN(payload.displayOrder) && payload.displayOrder !== this.displayOrder) { this.displayOrder = Number(payload.displayOrder) hasUpdates = true diff --git a/server/objects/settings/LibrarySettings.js b/server/objects/settings/LibrarySettings.js new file mode 100644 index 00000000..853962ad --- /dev/null +++ b/server/objects/settings/LibrarySettings.js @@ -0,0 +1,34 @@ +const { BookCoverAspectRatio } = require('../../utils/constants') +const Logger = require('../../Logger') + +class LibrarySettings { + constructor(settings) { + this.disableWatcher = false + + if (settings) { + this.construct(settings) + } + } + + construct(settings) { + this.disableWatcher = !!settings.disableWatcher + } + + toJSON() { + return { + disableWatcher: this.disableWatcher + } + } + + update(payload) { + var hasUpdates = false + for (const key in payload) { + if (this[key] !== payload[key]) { + this[key] = payload[key] + hasUpdates = true + } + } + return hasUpdates + } +} +module.exports = LibrarySettings \ No newline at end of file diff --git a/server/objects/ServerSettings.js b/server/objects/settings/ServerSettings.js similarity index 97% rename from server/objects/ServerSettings.js rename to server/objects/settings/ServerSettings.js index 43e777e7..86cb33fb 100644 --- a/server/objects/ServerSettings.js +++ b/server/objects/settings/ServerSettings.js @@ -1,5 +1,5 @@ -const { BookCoverAspectRatio, BookshelfView } = require('../utils/constants') -const Logger = require('../Logger') +const { BookCoverAspectRatio, BookshelfView } = require('../../utils/constants') +const Logger = require('../../Logger') class ServerSettings { constructor(settings) {