Рефакторинг
This commit is contained in:
@@ -462,7 +462,7 @@ class AuthorList extends BaseList {
|
|||||||
let result;
|
let result;
|
||||||
|
|
||||||
if (this.abCacheEnabled) {
|
if (this.abCacheEnabled) {
|
||||||
const key = `${authorId}-${this.list.inpxHash}`;
|
const key = `author-${authorId}-${this.list.inpxHash}`;
|
||||||
const data = await authorBooksStorage.getData(key);
|
const data = await authorBooksStorage.getData(key);
|
||||||
if (data) {
|
if (data) {
|
||||||
result = JSON.parse(data);
|
result = JSON.parse(data);
|
||||||
@@ -811,7 +811,9 @@ class AuthorList extends BaseList {
|
|||||||
|
|
||||||
async refresh() {
|
async refresh() {
|
||||||
//параметры запроса
|
//параметры запроса
|
||||||
const newQuery = _.cloneDeep(this.search);
|
let newQuery = _.cloneDeep(this.search);
|
||||||
|
newQuery = newQuery.setDefaults(newQuery);
|
||||||
|
delete newQuery.setDefaults;
|
||||||
newQuery.offset = (newQuery.page - 1)*newQuery.limit;
|
newQuery.offset = (newQuery.page - 1)*newQuery.limit;
|
||||||
|
|
||||||
if (_.isEqual(newQuery, this.prevQuery))
|
if (_.isEqual(newQuery, this.prevQuery))
|
||||||
@@ -824,7 +826,7 @@ class AuthorList extends BaseList {
|
|||||||
const author = this.cachedAuthors[authorSearch];
|
const author = this.cachedAuthors[authorSearch];
|
||||||
|
|
||||||
if (author) {
|
if (author) {
|
||||||
const key = `${author.id}-${this.list.inpxHash}`;
|
const key = `author-${author.id}-${this.list.inpxHash}`;
|
||||||
let data = await authorBooksStorage.getData(key);
|
let data = await authorBooksStorage.getData(key);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|||||||
@@ -97,13 +97,6 @@
|
|||||||
</q-tooltip>
|
</q-tooltip>
|
||||||
</q-input>
|
</q-input>
|
||||||
|
|
||||||
<!--div class="q-mx-xs" />
|
|
||||||
<DivBtn class="text-white q-mt-xs bg-grey-13" :size="30" :icon-size="24" icon="la la-broom" round @click="setDefaults">
|
|
||||||
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
|
|
||||||
Сбросить поиск
|
|
||||||
</q-tooltip>
|
|
||||||
</DivBtn-->
|
|
||||||
|
|
||||||
<div class="q-mx-xs" />
|
<div class="q-mx-xs" />
|
||||||
<div class="row items-center q-mt-xs">
|
<div class="row items-center q-mt-xs">
|
||||||
<div v-show="list.queryFound > 0">
|
<div v-show="list.queryFound > 0">
|
||||||
@@ -296,13 +289,17 @@ class Search {
|
|||||||
|
|
||||||
//search fields
|
//search fields
|
||||||
search = {
|
search = {
|
||||||
author: '',
|
setDefaults(search) {
|
||||||
series: '',
|
return Object.assign({}, search, {
|
||||||
title: '',
|
author: search.author || '',
|
||||||
genre: '',
|
series: search.series || '',
|
||||||
lang: '',
|
title: search.title || '',
|
||||||
page: 1,
|
genre: search.genre || '',
|
||||||
limit: 50,
|
lang: search.lang || '',
|
||||||
|
page: search.page || 1,
|
||||||
|
limit: search.limit || 50,
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
//settings
|
//settings
|
||||||
@@ -346,6 +343,9 @@ class Search {
|
|||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
this.api = this.$root.api;
|
this.api = this.$root.api;
|
||||||
|
|
||||||
|
this.search = this.search.setDefaults(this.search);
|
||||||
|
this.search.lang = this.langDefault;
|
||||||
|
|
||||||
this.loadSettings();
|
this.loadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +367,6 @@ class Search {
|
|||||||
if (!this.$root.isMobileDevice)
|
if (!this.$root.isMobileDevice)
|
||||||
this.$refs.authorInput.focus();
|
this.$refs.authorInput.focus();
|
||||||
|
|
||||||
this.setDefaults();
|
|
||||||
this.updateListFromRoute(this.$route);
|
this.updateListFromRoute(this.$route);
|
||||||
this.updateSearchFromRouteQuery(this.$route);
|
this.updateSearchFromRouteQuery(this.$route);
|
||||||
|
|
||||||
@@ -699,16 +698,6 @@ class Search {
|
|||||||
this.commit('setSettings', {[name]: _.cloneDeep(newValue)});
|
this.commit('setSettings', {[name]: _.cloneDeep(newValue)});
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaults() {
|
|
||||||
this.search = Object.assign({}, this.search, {
|
|
||||||
author: '',
|
|
||||||
series: '',
|
|
||||||
title: '',
|
|
||||||
genre: '',
|
|
||||||
lang: this.langDefault,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
highlightPageScroller(query) {
|
highlightPageScroller(query) {
|
||||||
const q = _.cloneDeep(query);
|
const q = _.cloneDeep(query);
|
||||||
delete q.limit;
|
delete q.limit;
|
||||||
@@ -728,31 +717,39 @@ class Search {
|
|||||||
updateSearchFromRouteQuery(to) {
|
updateSearchFromRouteQuery(to) {
|
||||||
if (this.list.liberamaReady)
|
if (this.list.liberamaReady)
|
||||||
this.sendCurrentUrl();
|
this.sendCurrentUrl();
|
||||||
|
|
||||||
if (this.routeUpdating)
|
if (this.routeUpdating)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const query = to.query;
|
const query = to.query;
|
||||||
|
|
||||||
this.search = Object.assign({}, this.search, {
|
this.search = this.search.setDefaults(
|
||||||
author: query.author || '',
|
Object.assign({}, this.search, {
|
||||||
series: query.series || '',
|
author: query.author,
|
||||||
title: query.title || '',
|
series: query.series,
|
||||||
genre: query.genre || '',
|
title: query.title,
|
||||||
lang: (typeof(query.lang) == 'string' ? query.lang : this.langDefault),
|
genre: query.genre,
|
||||||
page: parseInt(query.page, 10) || 1,
|
lang: (typeof(query.lang) == 'string' ? query.lang : this.langDefault),
|
||||||
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 > 1000)
|
if (this.search.limit > 1000)
|
||||||
this.search.limit = 1000;
|
this.search.limit = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRouteQueryFromSearch() {
|
updateRouteQueryFromSearch() {
|
||||||
|
if (!this.ready)
|
||||||
|
return;
|
||||||
|
|
||||||
this.routeUpdating = true;
|
this.routeUpdating = true;
|
||||||
try {
|
try {
|
||||||
const oldQuery = this.$route.query;
|
const oldQuery = this.$route.query;
|
||||||
const query = _.pickBy(this.search);
|
const cloned = _.cloneDeep(this.search);
|
||||||
|
delete cloned.setDefaults;
|
||||||
|
|
||||||
|
const query = _.pickBy(cloned);
|
||||||
|
|
||||||
if (this.search.lang == this.langDefault) {
|
if (this.search.lang == this.langDefault) {
|
||||||
delete query.lang;
|
delete query.lang;
|
||||||
|
|||||||
Reference in New Issue
Block a user