From 85007f3e9194a28f18db5d99321b55599a9ed732 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 7 Dec 2022 15:36:54 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20=D1=80=D0=B0=D1=81=D1=88=D0=B8=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=BC=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Search/BaseList.js | 26 +-- client/components/Search/Search.vue | 151 ++++++++++-------- .../SelectExtSearchDialog.vue | 35 ++-- server/core/DbSearcher.js | 9 +- 4 files changed, 122 insertions(+), 99 deletions(-) diff --git a/client/components/Search/BaseList.js b/client/components/Search/BaseList.js index 265d6e3..376968a 100644 --- a/client/components/Search/BaseList.js +++ b/client/components/Search/BaseList.js @@ -21,13 +21,16 @@ const componentOptions = { this.loadSettings(); }, search: { - handler(newValue) { - this.limit = newValue.limit; - - if (this.pageCount > 1) - this.prevPage = this.search.page; - - this.refresh(); + handler() { + if (!this.isExtendedSearch) + this.refresh(); + }, + deep: true, + }, + extSearch: { + handler() { + if (this.isExtendedSearch) + this.refresh(); }, deep: true, }, @@ -519,9 +522,8 @@ export default class BaseList { getQuery() { const search = (this.isExtendedSearch ? this.extSearch : this.search); - let newQuery = _.cloneDeep(search); - newQuery = newQuery.setDefaults(newQuery); - delete newQuery.setDefaults; + const newQuery = {}; + search.setDefaults(newQuery, search); //дата if (newQuery.date) { @@ -532,8 +534,8 @@ export default class BaseList { newQuery.offset = (newQuery.page - 1)*newQuery.limit; //del - if (!this.showDeleted) - newQuery.del = 0; + if (!newQuery.del && !this.showDeleted) + newQuery.del = '0'; return newQuery; } diff --git a/client/components/Search/Search.vue b/client/components/Search/Search.vue index 31c6b5f..5536f28 100644 --- a/client/components/Search/Search.vue +++ b/client/components/Search/Search.vue @@ -339,6 +339,13 @@ const componentOptions = { }, deep: true, }, + extSearch: { + handler() { + this.makeTitle(); + this.updateRouteQueryFromSearch(); + }, + deep: true, + }, extendedParams(newValue) { this.setSetting('extendedParams', newValue); }, @@ -415,31 +422,8 @@ class Search { inputDebounce = 200; //search fields - search = { - setDefaults(search) { - return Object.assign({}, search, { - author: search.author || '', - series: search.series || '', - title: search.title || '', - genre: search.genre || '', - lang: search.lang || '', - date: search.date || '', - librate: search.librate || '', - - page: search.page || 1, - limit: search.limit || 50, - }); - }, - }; - - extSearch = { - setDefaults(search) { - return Object.assign({}, search, { - page: search.page || 1, - limit: search.limit || 50, - }); - }, - }; + search = {}; + extSearch = {}; searchDate = ''; prevManualDate = ''; @@ -478,13 +462,22 @@ class Search { {label: 'выбрать даты', value: 'manual'}, ]; + generateDefaults(obj, fields) { + obj.setDefaults = (self, value = {}) => { + for (const f of fields) + self[f] = value[f] || ''; + + self.page = value.page || 1; + self.limit = value.limit || 50; + }; + } + created() { this.commit = this.$store.commit; this.api = this.$root.api; - this.search = this.search.setDefaults(this.search); - this.extSearch = this.extSearch.setDefaults(this.extSearch); - this.search.lang = this.langDefault; + this.generateDefaults(this.search, ['author', 'series', 'title', 'genre', 'lang', 'date', 'librate']); + this.search.setDefaults(this.search); this.loadSettings(); } @@ -493,6 +486,10 @@ class Search { (async() => { await this.api.updateConfig(); + this.generateDefaults(this.extSearch, this.recStruct.map(f => f.field)); + this.extSearch.setDefaults(this.extSearch); + this.search.lang = this.langDefault; + //для встраивания в liberama window.addEventListener('message', (event) => { if (!_.isObject(event.data) || event.data.from != 'ExternalLibs') @@ -510,11 +507,11 @@ class Search { this.$refs.authorInput.focus(); this.updateListFromRoute(this.$route); - this.updateSearchFromRouteQuery(this.$route); - - this.sendMessage({type: 'mes', data: 'hello-from-inpx-web'}); this.ready = true; + + this.sendMessage({type: 'mes', data: 'hello-from-inpx-web'}); + this.updateSearchFromRouteQuery(this.$route); })(); } @@ -554,6 +551,13 @@ class Search { return this.$store.state.config; } + get recStruct() { + if (this.config.dbConfig && this.config.dbConfig.inpxInfo.recStruct) + return this.config.dbConfig.inpxInfo.recStruct; + else + return []; + } + get settings() { return this.$store.state.settings; } @@ -610,7 +614,12 @@ class Search { } get extSearchNames() { - return ''; + let result = []; + for (const f of this.recStruct) { + if (this.extSearch[f.field]) + result.push(`${f.field}=${this.extSearch[f.field]}`); + } + return result.join(', '); } inputBgColor(inp) { @@ -820,6 +829,8 @@ class Search { } clearExtSearch() { + const self = this.extSearch; + self.setDefaults(self, {page: self.page, limit: self.limit}); } onScroll() { @@ -925,6 +936,8 @@ class Search { } updateSearchFromRouteQuery(to) { + if (!this.ready) + return; if (this.list.liberamaReady) this.sendCurrentUrl(); @@ -933,35 +946,34 @@ class Search { const query = to.query; - if (!this.isExtendedSearch) { - this.search = this.search.setDefaults( - Object.assign({}, this.search, { - author: query.author, - series: query.series, - title: query.title, - genre: query.genre, - lang: (typeof(query.lang) == 'string' ? query.lang : this.langDefault), - date: query.date, - librate: query.librate, + this.search.setDefaults(this.search, { + author: query.author, + series: query.series, + title: query.title, + genre: query.genre, + lang: (typeof(query.lang) == 'string' ? query.lang : this.langDefault), + date: query.date, + librate: query.librate, - page: parseInt(query.page, 10), - limit: parseInt(query.limit, 10) || this.search.limit, - }) - ); + page: parseInt(query.page, 10), + limit: parseInt(query.limit, 10) || this.search.limit, + }); - if (this.search.limit > maxLimit) - this.search.limit = maxLimit; - } else { - this.extSearch = this.extSearch.setDefaults( - Object.assign({}, this.extSearch, { - page: parseInt(query.page, 10), - limit: parseInt(query.limit, 10) || this.search.limit, - }) - ); + if (this.search.limit > maxLimit) + this.search.limit = maxLimit; - if (this.extSearch.limit > maxLimit) - this.extSearch.limit = maxLimit; + const queryExtSearch = { + page: this.search.page, + limit: this.search.limit, + }; + + for (const f of this.recStruct) { + const field = `ex_${f.field}`; + if (query[field]) + queryExtSearch[f.field] = query[field]; } + + this.extSearch.setDefaults(this.extSearch, queryExtSearch); } updateRouteQueryFromSearch() { @@ -973,22 +985,21 @@ class Search { const oldQuery = this.$route.query; let query = {}; - if (!this.isExtendedSearch) { - const cloned = _.cloneDeep(this.search); + const cloned = {}; + this.search.setDefaults(cloned, this.search); - delete cloned.setDefaults; + query = _.pickBy(cloned); - query = _.pickBy(cloned); - - if (this.search.lang == this.langDefault) { - delete query.lang; - } else { - query.lang = this.search.lang; - } + if (this.search.lang == this.langDefault) { + delete query.lang; } else { - const cloned = _.cloneDeep(this.extSearch); - delete cloned.setDefaults; - query = _.pickBy(cloned); + query.lang = this.search.lang; + } + + for (const f of this.recStruct) { + const field = `ex_${f.field}`; + if (this.extSearch[f.field]) + query[field] = this.extSearch[f.field]; } const diff = diffUtils.getObjDiff(oldQuery, query); diff --git a/client/components/Search/SelectExtSearchDialog/SelectExtSearchDialog.vue b/client/components/Search/SelectExtSearchDialog/SelectExtSearchDialog.vue index fe00906..8f62229 100644 --- a/client/components/Search/SelectExtSearchDialog/SelectExtSearchDialog.vue +++ b/client/components/Search/SelectExtSearchDialog/SelectExtSearchDialog.vue @@ -8,13 +8,13 @@ -
+
@@ -31,9 +31,6 @@ Применить - - Закрыть - @@ -43,6 +40,7 @@ import vueComponent from '../../vueComponent.js'; import Dialog from '../../share/Dialog.vue'; +import _ from 'lodash'; const componentOptions = { components: { @@ -55,8 +53,11 @@ const componentOptions = { dialogVisible(newValue) { this.$emit('update:modelValue', newValue); }, - extSearch(newValue) { - this.search = newValue; + extSearch: { + handler(newValue) { + this.search = _.cloneDeep(newValue); + }, + deep: true, }, search: { handler() { @@ -98,7 +99,16 @@ class SelectExtSearchDialog { validate() { const validNumValue = (n) => { - return false; + const validChars = new Set('0123456789.'.split('')); + for (const c of n.split('')) + if (!validChars.has(c)) + return false; + + const v = n.split('..'); + if ( isNaN(parseInt(v[0] || '0', 10)) || isNaN(parseInt(v[1] || '0', 10)) ) + return false; + + return true; }; let error = []; @@ -115,13 +125,12 @@ class SelectExtSearchDialog { this.error = error.join('
'); } - okClick() { - this.dialogVisible = false; - } - apply() { this.validate(); - this.dialogVisible = false; + if (!this.error) { + this.$emit('update:extSearch', _.cloneDeep(this.search)); + this.dialogVisible = false; + } } } diff --git a/server/core/DbSearcher.js b/server/core/DbSearcher.js index c706331..4e7b940 100644 --- a/server/core/DbSearcher.js +++ b/server/core/DbSearcher.js @@ -213,12 +213,13 @@ class DbSearcher { } //удаленные - if (query.del !== undefined) { - const key = `book-ids-del-${query.del}`; + if (query.del) { + const del = parseInt(query.del, 10) || 0; + const key = `book-ids-del-${del}`; let ids = await this.getCached(key); if (ids === null) { - ids = await tableBookIds('del', `@indexLR('value', ${db.esc(query.del)}, ${db.esc(query.del)})`); + ids = await tableBookIds('del', `@indexLR('value', ${db.esc(del)}, ${db.esc(del)})`); await this.putCached(key, ids); } @@ -559,7 +560,7 @@ class DbSearcher { //return !bookValue || (bookValue !== emptyFieldValue && !enru.has(bookValue[0]) && bookValue.indexOf(searchValue) >= 0); return 'true'; } else { - return `(row.${bookField}.localeCompare(${db.esc(searchValue)}) >= 0 && row.${bookField}.localeCompare(${db.esc(searchValue)} + maxUtf8Char) <= 0)`; + return `(row.${bookField}.localeCompare(${db.esc(searchValue)}) >= 0 && row.${bookField}.localeCompare(${db.esc(searchValue)} + ${db.esc(maxUtf8Char)}) <= 0)`; } };