From f2be3bc95ebc44b9d18c96bb2bfdcdbda14460df Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 10 Mar 2022 19:13:19 -0600 Subject: [PATCH] Add multi select dropdown with query from server --- .../components/modals/edit-tabs/Details.vue | 7 +- .../components/ui/MultiSelectQueryInput.vue | 252 ++++++++++++++++++ server/ApiController.js | 37 ++- server/Server.js | 4 +- 4 files changed, 275 insertions(+), 25 deletions(-) create mode 100644 client/components/ui/MultiSelectQueryInput.vue diff --git a/client/components/modals/edit-tabs/Details.vue b/client/components/modals/edit-tabs/Details.vue index 0613c35a..abf8c6a0 100644 --- a/client/components/modals/edit-tabs/Details.vue +++ b/client/components/modals/edit-tabs/Details.vue @@ -14,7 +14,8 @@
-

Authors placeholder

+ +
@@ -115,6 +116,7 @@ export default { genres: [] }, newTags: [], + authorNames: [], resettingProgress: false, isScrollable: false, savingMetadata: false, @@ -278,7 +280,7 @@ export default { this.details.title = this.mediaMetadata.title this.details.subtitle = this.mediaMetadata.subtitle this.details.description = this.mediaMetadata.description - this.details.authors = this.mediaMetadata.authors + this.details.authors = this.mediaMetadata.authors || [] this.details.narrator = this.mediaMetadata.narrator this.details.genres = this.mediaMetadata.genres || [] this.details.series = this.mediaMetadata.series @@ -289,6 +291,7 @@ export default { this.details.asin = this.mediaMetadata.asin || null this.newTags = this.media.tags || [] + this.authorNames = this.details.authors.map((au) => au.name) }, removeItem() { if (confirm(`Are you sure you want to remove this item?\n\n*Does not delete your files, only removes the item from audiobookshelf`)) { diff --git a/client/components/ui/MultiSelectQueryInput.vue b/client/components/ui/MultiSelectQueryInput.vue new file mode 100644 index 00000000..403ad3ad --- /dev/null +++ b/client/components/ui/MultiSelectQueryInput.vue @@ -0,0 +1,252 @@ + + + + + \ No newline at end of file diff --git a/server/ApiController.js b/server/ApiController.js index 9ee97346..f8b14ce2 100644 --- a/server/ApiController.js +++ b/server/ApiController.js @@ -22,12 +22,11 @@ const PodcastFinder = require('./finders/PodcastFinder') const FileSystemController = require('./controllers/FileSystemController') class ApiController { - constructor(db, auth, scanner, streamManager, rssFeeds, downloadManager, coverController, backupManager, watcher, cacheManager, emitter, clientEmitter) { + constructor(db, auth, scanner, streamManager, downloadManager, coverController, backupManager, watcher, cacheManager, emitter, clientEmitter) { this.db = db this.auth = auth this.scanner = scanner this.streamManager = streamManager - this.rssFeeds = rssFeeds this.downloadManager = downloadManager this.backupManager = backupManager this.coverController = coverController @@ -145,6 +144,7 @@ class ApiController { this.router.get('/search/covers', this.findCovers.bind(this)) this.router.get('/search/books', this.findBooks.bind(this)) this.router.get('/search/podcast', this.findPodcasts.bind(this)) + this.router.get('/search/authors', this.findAuthor.bind(this)) // // File System Routes @@ -155,7 +155,7 @@ class ApiController { // Others // this.router.get('/authors', this.getAuthors.bind(this)) - this.router.get('/authors/search', this.searchAuthor.bind(this)) + this.router.get('/authors/search', this.searchAuthors.bind(this)) this.router.get('/authors/:id', this.getAuthor.bind(this)) this.router.post('/authors', this.createAuthor.bind(this)) this.router.patch('/authors/:id', this.updateAuthor.bind(this)) @@ -165,8 +165,6 @@ class ApiController { this.router.post('/authorize', this.authorize.bind(this)) - this.router.post('/feed', this.openRssFeed.bind(this)) - this.router.get('/download/:id', this.download.bind(this)) this.router.post('/syncUserAudiobookData', this.syncUserAudiobookData.bind(this)) @@ -201,6 +199,12 @@ class ApiController { res.json(results) } + async findAuthor(req, res) { + var query = req.query.q + var author = await this.authorFinder.findAuthorByName(query) + res.json(author) + } + authorize(req, res) { if (!req.user) { Logger.error('Invalid user in authorize') @@ -209,20 +213,19 @@ class ApiController { res.json({ user: req.user }) } - async openRssFeed(req, res) { - var audiobookId = req.body.audiobookId - var audiobook = this.db.audiobooks.find(ab => ab.id === audiobookId) - if (!audiobook) return res.sendStatus(404) - var feed = await this.rssFeeds.openFeed(audiobook) - console.log('Feed open', feed) - res.json(feed) - } - async getAuthors(req, res) { var authors = this.db.authors.filter(p => p.isAuthor) res.json(authors) } + searchAuthors(req, res) { + var query = req.query.q || '' + var limit = req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 100 + var authors = this.db.authors.filter(au => au.name.toLowerCase().includes(query.toLowerCase())) + authors = authors.slice(0, limit) + res.json(authors) + } + async getAuthor(req, res) { var author = this.db.authors.find(p => p.id === req.params.id) if (!author) { @@ -231,12 +234,6 @@ class ApiController { res.json(author.toJSON()) } - async searchAuthor(req, res) { - var query = req.query.q - var author = await this.authorFinder.findAuthorByName(query) - res.json(author) - } - async createAuthor(req, res) { var author = await this.authorFinder.createAuthor(req.body) if (!author) { diff --git a/server/Server.js b/server/Server.js index bfc48297..d151454c 100644 --- a/server/Server.js +++ b/server/Server.js @@ -25,7 +25,6 @@ const LogManager = require('./LogManager') const ApiController = require('./ApiController') const HlsController = require('./HlsController') const StreamManager = require('./StreamManager') -const RssFeeds = require('./RssFeeds') const DownloadManager = require('./DownloadManager') const CoverController = require('./CoverController') const CacheManager = require('./CacheManager') @@ -62,9 +61,8 @@ class Server { this.scanner = new Scanner(this.db, this.coverController, this.emitter.bind(this)) this.streamManager = new StreamManager(this.db, this.emitter.bind(this), this.clientEmitter.bind(this)) - this.rssFeeds = new RssFeeds(this.Port, this.db) this.downloadManager = new DownloadManager(this.db, this.Uid, this.Gid) - this.apiController = new ApiController(this.db, this.auth, this.scanner, this.streamManager, this.rssFeeds, this.downloadManager, this.coverController, this.backupManager, this.watcher, this.cacheManager, this.emitter.bind(this), this.clientEmitter.bind(this)) + this.apiController = new ApiController(this.db, this.auth, this.scanner, this.streamManager, this.downloadManager, this.coverController, this.backupManager, this.watcher, this.cacheManager, this.emitter.bind(this), this.clientEmitter.bind(this)) this.hlsController = new HlsController(this.db, this.auth, this.streamManager, this.emitter.bind(this), this.streamManager.StreamsPath) Logger.logManager = this.logManager