OPDS: добавлен раздел "Жанры", в поиск добавлен раздел "Поиск книг в жанре" (#9)
This commit is contained in:
@@ -66,7 +66,7 @@ class AuthorPage extends BasePage {
|
|||||||
author: req.query.author || '',
|
author: req.query.author || '',
|
||||||
series: req.query.series || '',
|
series: req.query.series || '',
|
||||||
genre: req.query.genre || '',
|
genre: req.query.genre || '',
|
||||||
del: 0,
|
del: '0',
|
||||||
|
|
||||||
all: req.query.all || '',
|
all: req.query.all || '',
|
||||||
depth: 0,
|
depth: 0,
|
||||||
@@ -86,7 +86,7 @@ class AuthorPage extends BasePage {
|
|||||||
|
|
||||||
if (bookList.books) {
|
if (bookList.books) {
|
||||||
let books = bookList.books;
|
let books = bookList.books;
|
||||||
const booksAll = this.filterBooks(books, {del: 0});
|
const booksAll = this.filterBooks(books);
|
||||||
const filtered = (query.all ? booksAll : this.filterBooks(books, query));
|
const filtered = (query.all ? booksAll : this.filterBooks(books, query));
|
||||||
const sorted = this.sortSeriesBooks(filtered);
|
const sorted = this.sortSeriesBooks(filtered);
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class BasePage {
|
|||||||
this.webWorker = new WebWorker(config);
|
this.webWorker = new WebWorker(config);
|
||||||
this.rootTag = 'feed';
|
this.rootTag = 'feed';
|
||||||
this.opdsRoot = config.opdsRoot;
|
this.opdsRoot = config.opdsRoot;
|
||||||
|
|
||||||
|
this.showDeleted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
makeEntry(entry = {}) {
|
makeEntry(entry = {}) {
|
||||||
@@ -213,7 +215,7 @@ class BasePage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//скопировано из BaseList.js, часть функционала не используется
|
//скопировано из BaseList.js, часть функционала не используется
|
||||||
filterBooks(books, query) {
|
filterBooks(books, query = {}) {
|
||||||
const s = query;
|
const s = query;
|
||||||
|
|
||||||
const splitAuthor = (author) => {
|
const splitAuthor = (author) => {
|
||||||
|
|||||||
@@ -13,13 +13,17 @@ class GenrePage extends BasePage {
|
|||||||
const result = {};
|
const result = {};
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
from: req.query.from || '',
|
from: req.query.from || 'search',
|
||||||
|
term: req.query.term || '*',
|
||||||
section: req.query.section || '',
|
section: req.query.section || '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let searchQuery = '';
|
||||||
|
if (query.from == 'search')
|
||||||
|
searchQuery = `&type=title&term=${encodeURIComponent(query.term)}`;
|
||||||
|
|
||||||
const entry = [];
|
const entry = [];
|
||||||
if (query.from) {
|
if (query.from) {
|
||||||
|
|
||||||
if (query.section) {
|
if (query.section) {
|
||||||
//выбираем подразделы
|
//выбираем подразделы
|
||||||
const {genreSection} = await this.getGenres();
|
const {genreSection} = await this.getGenres();
|
||||||
@@ -34,7 +38,7 @@ class GenrePage extends BasePage {
|
|||||||
this.makeEntry({
|
this.makeEntry({
|
||||||
id: ++id,
|
id: ++id,
|
||||||
title: g.name,
|
title: g.name,
|
||||||
link: this.navLink({href: `/${encodeURIComponent(query.from)}?genre=${encodeURIComponent(g.value)}`}),
|
link: this.navLink({href: `/${encodeURIComponent(query.from)}?genre=${encodeURIComponent(g.value)}${searchQuery}`}),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -43,7 +47,7 @@ class GenrePage extends BasePage {
|
|||||||
this.makeEntry({
|
this.makeEntry({
|
||||||
id: 'whole_section',
|
id: 'whole_section',
|
||||||
title: '[Весь раздел]',
|
title: '[Весь раздел]',
|
||||||
link: this.navLink({href: `/${encodeURIComponent(query.from)}?genre=${encodeURIComponent(all.join(','))}`}),
|
link: this.navLink({href: `/${encodeURIComponent(query.from)}?genre=${encodeURIComponent(all.join(','))}${searchQuery}`}),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -56,7 +60,7 @@ class GenrePage extends BasePage {
|
|||||||
this.makeEntry({
|
this.makeEntry({
|
||||||
id: ++id,
|
id: ++id,
|
||||||
title: section.name,
|
title: section.name,
|
||||||
link: this.navLink({href: `/genre?from=${encodeURIComponent(query.from)}§ion=${encodeURIComponent(section.name)}`}),
|
link: this.navLink({href: `/genre?from=${encodeURIComponent(query.from)}§ion=${encodeURIComponent(section.name)}${searchQuery}`}),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const BasePage = require('./BasePage');
|
|||||||
const AuthorPage = require('./AuthorPage');
|
const AuthorPage = require('./AuthorPage');
|
||||||
const SeriesPage = require('./SeriesPage');
|
const SeriesPage = require('./SeriesPage');
|
||||||
const TitlePage = require('./TitlePage');
|
const TitlePage = require('./TitlePage');
|
||||||
|
const GenrePage = require('./GenrePage');
|
||||||
|
|
||||||
class RootPage extends BasePage {
|
class RootPage extends BasePage {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
@@ -13,6 +14,7 @@ class RootPage extends BasePage {
|
|||||||
this.authorPage = new AuthorPage(config);
|
this.authorPage = new AuthorPage(config);
|
||||||
this.seriesPage = new SeriesPage(config);
|
this.seriesPage = new SeriesPage(config);
|
||||||
this.titlePage = new TitlePage(config);
|
this.titlePage = new TitlePage(config);
|
||||||
|
this.genrePage = new GenrePage(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
async body(req) {
|
async body(req) {
|
||||||
@@ -30,6 +32,7 @@ class RootPage extends BasePage {
|
|||||||
this.authorPage.myEntry(),
|
this.authorPage.myEntry(),
|
||||||
this.seriesPage.myEntry(),
|
this.seriesPage.myEntry(),
|
||||||
this.titlePage.myEntry(),
|
this.titlePage.myEntry(),
|
||||||
|
this.genrePage.myEntry(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return this.makeBody(result, req);
|
return this.makeBody(result, req);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class SearchPage extends BasePage {
|
|||||||
const query = {
|
const query = {
|
||||||
type: req.query.type || '',
|
type: req.query.type || '',
|
||||||
term: req.query.term || '',
|
term: req.query.term || '',
|
||||||
|
genre: req.query.genre || '',
|
||||||
page: parseInt(req.query.page, 10) || 1,
|
page: parseInt(req.query.page, 10) || 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ class SearchPage extends BasePage {
|
|||||||
|
|
||||||
const limit = 100;
|
const limit = 100;
|
||||||
const offset = (page - 1)*limit;
|
const offset = (page - 1)*limit;
|
||||||
const queryRes = await this.webWorker.search(from, {[from]: query.term, del: 0, offset, limit});
|
const queryRes = await this.webWorker.search(from, {[from]: query.term, genre: query.genre, del: '0', offset, limit});
|
||||||
|
|
||||||
const found = queryRes.found;
|
const found = queryRes.found;
|
||||||
|
|
||||||
@@ -98,6 +99,15 @@ class SearchPage extends BasePage {
|
|||||||
'*TEXT': `Искать по названиям книг`,
|
'*TEXT': `Искать по названиям книг`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
this.makeEntry({
|
||||||
|
id: 'search_genre',
|
||||||
|
title: 'Поиск книг в жанре',
|
||||||
|
link: this.navLink({href: `/genre?from=search&term=${encodeURIComponent(query.term)}`}),
|
||||||
|
content: {
|
||||||
|
'*ATTRS': {type: 'text'},
|
||||||
|
'*TEXT': `Искать по названиям книг в выбранном жанре`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
this.makeEntry({
|
this.makeEntry({
|
||||||
id: 'search_help',
|
id: 'search_help',
|
||||||
title: '[Памятка по поиску]',
|
title: '[Памятка по поиску]',
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class SeriesPage extends BasePage {
|
|||||||
const query = {
|
const query = {
|
||||||
series: req.query.series || '',
|
series: req.query.series || '',
|
||||||
genre: req.query.genre || '',
|
genre: req.query.genre || '',
|
||||||
del: 0,
|
del: '0',
|
||||||
|
|
||||||
all: req.query.all || '',
|
all: req.query.all || '',
|
||||||
depth: 0,
|
depth: 0,
|
||||||
@@ -46,7 +46,7 @@ class SeriesPage extends BasePage {
|
|||||||
|
|
||||||
if (bookList.books) {
|
if (bookList.books) {
|
||||||
let books = bookList.books;
|
let books = bookList.books;
|
||||||
const booksAll = this.filterBooks(books, {del: 0});
|
const booksAll = this.filterBooks(books);
|
||||||
const filtered = (query.all ? booksAll : this.filterBooks(books, query));
|
const filtered = (query.all ? booksAll : this.filterBooks(books, query));
|
||||||
const sorted = this.sortSeriesBooks(filtered);
|
const sorted = this.sortSeriesBooks(filtered);
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class TitlePage extends BasePage {
|
|||||||
const query = {
|
const query = {
|
||||||
title: req.query.title || '',
|
title: req.query.title || '',
|
||||||
genre: req.query.genre || '',
|
genre: req.query.genre || '',
|
||||||
del: 0,
|
del: '0',
|
||||||
|
|
||||||
depth: 0,
|
depth: 0,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user