-
- {{ row.title }} {{ row.src.del }}
+
+
+ {{ book.title }} {{ book.src.del }}
@@ -159,6 +159,9 @@ const componentOptions = {
config() {
this.makeTitle();
},
+ settings() {
+ this.loadSettings();
+ },
author() {
this.refresh();
},
@@ -178,21 +181,17 @@ const componentOptions = {
this.refresh();
},
limit(newValue) {
- const newSettings = _.cloneDeep(this.settings);
- newSettings.limit = newValue;
- this.commit('setSettings', newSettings);
+ this.setSetting('limit', newValue);
this.updatePageCount();
this.refresh();
},
+ showDeleted(newValue) {
+ this.setSetting('showDeleted', newValue);
+ },
totalFound() {
this.updatePageCount();
},
- expanded(newValue) {
- const newSettings = _.cloneDeep(this.settings);
- newSettings.expanded = _.cloneDeep(newValue);
- this.commit('setSettings', newSettings);
- },
},
};
class Search {
@@ -201,10 +200,9 @@ class Search {
projectName = '';
loadingMessage = '';
- getBooksMessage = '';
+ loadingMessage2 = '';
page = 1;
pageCount = 1;
- expanded = [];
//input field consts
inputMaxLength = 1000;
@@ -216,7 +214,11 @@ class Search {
title = '';
genre = '';
lang = '';
- limit = 50;
+ limit = 50;//settings
+
+ //settings
+ expanded = [];
+ showDeleted = false;
//stuff
queryFound = -1;
@@ -257,6 +259,7 @@ class Search {
this.limit = settings.limit;
this.expanded = _.cloneDeep(settings.expanded);
+ this.showDeleted = settings.showDeleted;
}
get config() {
@@ -351,6 +354,12 @@ class Search {
return this.expanded.indexOf(item.author) >= 0;
}
+ setSetting(name, newValue) {
+ const newSettings = _.cloneDeep(this.settings);
+ newSettings[name] = _.cloneDeep(newValue);
+ this.commit('setSettings', newSettings);
+ }
+
expandAuthor(item) {
const expanded = _.cloneDeep(this.expanded);
const author = item.author;
@@ -364,17 +373,34 @@ class Search {
expanded.shift();
}
- this.expanded = expanded;
+ this.setSetting('expanded', expanded);
this.ignoreScroll();
} else {
const i = expanded.indexOf(author);
if (i >= 0) {
expanded.splice(i, 1);
- this.expanded = expanded;
+ this.setSetting('expanded', expanded);
}
}
}
+ getBookCount(item) {
+ let result = '';
+ if (item.bookCount === undefined)
+ return result;
+
+ if (this.showDeleted) {
+ result = item.bookCount + item.bookDelCount;
+ } else {
+ result = item.bookCount;
+ }
+
+ if (item.books && item.books.length < result)
+ result = `${item.books.length}/${result}`;
+
+ return `(${result})`;
+ }
+
async loadBooks(author, authorId) {
try {
const result = await this.api.getBookList(authorId);
@@ -403,7 +429,7 @@ class Search {
(async() => {
await utils.sleep(500);
if (this.getBooksFlag > 0)
- this.getBooksMessage = 'Загрузка списка книг...';
+ this.loadingMessage2 = 'Загрузка списка книг...';
})();
}
@@ -413,22 +439,16 @@ class Search {
filtered.sort((a, b) => a.title.localeCompare(b.title));
- const rows = [];
+ const books = [];
for (const book of filtered) {
- rows.push({key: book.id, title: book.title, src: book});
+ books.push({key: book.id, title: book.title, src: book});
}
- const books = {
- totalCount: loadedBooks.length,
- filteredCount: filtered.length,
- rows,
- };
-
item.books = books;
} finally {
this.getBooksFlag--;
if (this.getBooksFlag == 0)
- this.getBooksMessage = '';
+ this.loadingMessage2 = '';
}
}
@@ -445,6 +465,8 @@ class Search {
num,
author: rec.author,
name: rec.author.replace(/,/g, ', '),
+ bookCount: rec.bookCount,
+ bookDelCount: rec.bookDelCount,
book: false,
});
num++;
diff --git a/client/store/root.js b/client/store/root.js
index 367252a..8ebf55f 100644
--- a/client/store/root.js
+++ b/client/store/root.js
@@ -4,6 +4,7 @@ const state = {
settings: {
limit: 50,
expanded: [],
+ showDeleted: false,
},
};
diff --git a/server/core/DbCreator.js b/server/core/DbCreator.js
index 51cf613..457be2b 100644
--- a/server/core/DbCreator.js
+++ b/server/core/DbCreator.js
@@ -82,7 +82,7 @@ class DbCreator {
const authorTmpId = authorMap.get(value);
authorRec = authorArr[authorTmpId];
} else {
- authorRec = {tmpId: authorArr.length, author: a, value, bookId: []};
+ authorRec = {tmpId: authorArr.length, author: a, value, bookCount: 0, bookDelCount: 0, bookId: []};
authorArr.push(authorRec);
authorMap.set(value, authorRec.tmpId);
@@ -94,6 +94,13 @@ class DbCreator {
if (a[0].toUpperCase() === a[0])
authorRec.author = a;
+ //счетчики
+ if (!rec.del) {
+ authorRec.bookCount++;
+ } else {
+ authorRec.bookDelCount++;
+ }
+
//ссылки на книги
authorRec.bookId.push(id);
}
diff --git a/server/core/DbSearcher.js b/server/core/DbSearcher.js
index 289768d..e2a90a1 100644
--- a/server/core/DbSearcher.js
+++ b/server/core/DbSearcher.js
@@ -252,7 +252,7 @@ class DbSearcher {
//выборка найденных авторов
let result = await db.select({
table: 'author',
- map: `(r) => ({id: r.id, author: r.author})`,
+ map: `(r) => ({id: r.id, author: r.author, bookCount: r.bookCount, bookDelCount: r.bookDelCount})`,
where: `@@id(${db.esc(authorIds.slice(offset, offset + limit))})`
});