Search.vue 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. <template>
  2. <div class="root column fit" style="position: relative">
  3. <div ref="scroller" class="col fit column no-wrap" style="overflow: auto; position: relative" @scroll="onScroll">
  4. <div ref="toolPanel" class="tool-panel q-pb-xs column bg-cyan-2" style="position: sticky; top: 0; z-index: 10;">
  5. <div class="header q-mx-md q-mb-xs q-mt-sm row items-center">
  6. <a :href="newSearchLink" style="height: 33px; width: 34px">
  7. <img src="./assets/logo.png" />
  8. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  9. Новый поиск
  10. </q-tooltip>
  11. </a>
  12. <q-btn-toggle
  13. v-model="selectedList"
  14. class="q-ml-sm"
  15. toggle-color="primary"
  16. :options="listOptions"
  17. push
  18. no-caps
  19. rounded
  20. />
  21. <div class="row items-center q-ml-sm" style="font-size: 150%;">
  22. <div class="q-mr-xs">
  23. Коллекция
  24. </div>
  25. <div class="clickable" @click.stop.prevent="showCollectionInfo">
  26. {{ collection }}
  27. </div>
  28. </div>
  29. <div class="col"></div>
  30. <DivBtn class="q-ml-md text-white bg-secondary" :size="30" :icon-size="24" icon="la la-question" round @click.stop.prevent="showSearchHelp">
  31. <template #tooltip>
  32. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  33. Памятка
  34. </q-tooltip>
  35. </template>
  36. </DivBtn>
  37. <DivBtn class="q-ml-sm text-white bg-secondary" :size="30" :icon-size="24" :imt="1" icon="la la-cog" round @click.stop.prevent="settingsDialogVisible = true">
  38. <template #tooltip>
  39. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  40. Настройки
  41. </q-tooltip>
  42. </template>
  43. </DivBtn>
  44. <DivBtn v-if="!config.freeAccess" class="q-ml-sm text-white bg-secondary" :size="30" :icon-size="24" :imt="1" icon="la la-sign-out-alt" round @click.stop.prevent="logout">
  45. <template #tooltip>
  46. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  47. Выход
  48. </q-tooltip>
  49. </template>
  50. </DivBtn>
  51. </div>
  52. <div class="row q-mx-md q-mb-xs items-center">
  53. <DivBtn
  54. class="text-grey-5 bg-yellow-1 q-mt-xs" :size="34" :icon-size="24" round
  55. :icon="(extendedParams ? 'la la-angle-double-up' : 'la la-angle-double-down')"
  56. @click.stop.prevent="extendedParams = !extendedParams"
  57. >
  58. <template #tooltip>
  59. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  60. {{ `${(extendedParams ? 'Скрыть' : 'Показать')} дополнительные критерии поиска` }}
  61. </q-tooltip>
  62. </template>
  63. </DivBtn>
  64. <div class="q-mx-xs" />
  65. <q-input
  66. ref="authorInput" v-model="search.author" :maxlength="5000" :debounce="inputDebounce"
  67. class="q-mt-xs" :bg-color="inputBgColor('author')" style="width: 200px;" label="Автор" stack-label outlined dense clearable
  68. >
  69. <q-tooltip v-if="search.author" :delay="500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  70. {{ search.author }}
  71. </q-tooltip>
  72. </q-input>
  73. <div class="q-mx-xs" />
  74. <q-input
  75. v-model="search.series" :maxlength="inputMaxLength" :debounce="inputDebounce"
  76. class="q-mt-xs" :bg-color="inputBgColor('series')" style="width: 200px;" label="Серия" stack-label outlined dense clearable
  77. >
  78. <q-tooltip v-if="search.series" :delay="500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  79. {{ search.series }}
  80. </q-tooltip>
  81. </q-input>
  82. <div class="q-mx-xs" />
  83. <q-input
  84. v-model="search.title" :maxlength="inputMaxLength" :debounce="inputDebounce"
  85. class="q-mt-xs" :bg-color="inputBgColor('title')" style="width: 200px;" label="Название" stack-label outlined dense clearable
  86. >
  87. <q-tooltip v-if="search.title" :delay="500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  88. {{ search.title }}
  89. </q-tooltip>
  90. </q-input>
  91. <div class="q-mx-xs" />
  92. <q-input
  93. v-model="search.lang" :maxlength="inputMaxLength" :debounce="inputDebounce"
  94. class="q-mt-xs" :bg-color="inputBgColor()" input-style="cursor: pointer" style="width: 90px;" label="Язык" stack-label outlined dense clearable readonly
  95. @click.stop.prevent="selectLang"
  96. >
  97. <template v-if="search.lang" #append>
  98. <q-icon name="la la-times-circle" class="q-field__focusable-action" @click.stop.prevent="search.lang = ''" />
  99. </template>
  100. <q-tooltip v-if="search.lang && showTooltips" :delay="500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  101. {{ search.lang }}
  102. </q-tooltip>
  103. </q-input>
  104. <div class="q-mx-xs" />
  105. <DivBtn
  106. class="text-grey-8 bg-yellow-1 q-mt-xs" :size="34" :icon-size="24" round
  107. icon="la la-level-up-alt"
  108. @click.stop.prevent="cloneSearch"
  109. >
  110. <template #tooltip>
  111. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  112. Клонировать поиск
  113. </q-tooltip>
  114. </template>
  115. </DivBtn>
  116. </div>
  117. <div v-show="extendedParams" class="row q-mx-md q-mb-xs items-center">
  118. <div style="width: 34px" />
  119. <div class="q-mx-xs" />
  120. <q-input
  121. v-model="genreNames" :maxlength="inputMaxLength" :debounce="inputDebounce"
  122. class="q-mt-xs" :bg-color="inputBgColor()" input-style="cursor: pointer" style="width: 200px;" label="Жанр" stack-label outlined dense clearable readonly
  123. @click.stop.prevent="selectGenre"
  124. >
  125. <template v-if="genreNames" #append>
  126. <q-icon name="la la-times-circle" class="q-field__focusable-action" @click.stop.prevent="search.genre = ''" />
  127. </template>
  128. <q-tooltip v-if="genreNames && showTooltips" :delay="500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  129. {{ genreNames }}
  130. </q-tooltip>
  131. </q-input>
  132. <div class="q-mx-xs" />
  133. <q-select
  134. v-model="searchDate"
  135. class="q-mt-xs"
  136. :options="searchDateOptions"
  137. dropdown-icon="la la-angle-down la-sm"
  138. :bg-color="inputBgColor()"
  139. style="width: 200px;"
  140. label="Дата поступления" stack-label
  141. outlined dense emit-value map-options clearable
  142. >
  143. <template #selected-item="scope">
  144. <div v-if="scope.opt.value == 'manual'">
  145. <div v-html="formatSearchDate" />
  146. </div>
  147. <div v-else>
  148. {{ scope.opt.label }}
  149. </div>
  150. </template>
  151. <template #option="scope">
  152. <q-item v-bind="scope.itemProps" @click.stop.prevent="dateSelectItemClick(scope.opt.value)">
  153. <q-item-section>
  154. <q-item-label>
  155. {{ scope.opt.label }}
  156. </q-item-label>
  157. </q-item-section>
  158. </q-item>
  159. </template>
  160. </q-select>
  161. <div class="q-mx-xs" />
  162. <q-input
  163. v-model="librateNames" :maxlength="inputMaxLength" :debounce="inputDebounce"
  164. class="q-mt-xs" :bg-color="inputBgColor()" input-style="cursor: pointer" style="width: 90px;" label="Оценка" stack-label outlined dense clearable readonly
  165. @click.stop.prevent="selectLibRate"
  166. >
  167. <template v-if="librateNames" #append>
  168. <q-icon name="la la-times-circle" class="q-field__focusable-action" @click.stop.prevent="search.librate = ''" />
  169. </template>
  170. <q-tooltip v-if="librateNames && showTooltips" :delay="500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  171. {{ librateNames }}
  172. </q-tooltip>
  173. </q-input>
  174. </div>
  175. <div v-show="!extendedParams && extendedParamsMessage" class="row q-mx-md items-center clickable" @click.stop.prevent="extendedParams = true">
  176. +{{ extendedParamsMessage }}
  177. </div>
  178. </div>
  179. <div class="row items-center q-ml-lg q-mt-sm">
  180. <div style="width: 400px; height: 50px">
  181. <PageScroller v-show="pageCount > 1" ref="pageScroller1" v-model="search.page" :page-count="pageCount" />
  182. </div>
  183. <div v-show="list.totalFound > 0" class="text-bold" style="font-size: 120%; padding-bottom: 2px">
  184. {{ foundCountMessage }}
  185. </div>
  186. </div>
  187. <!-- Формирование списка ------------------------------------------------------------------------>
  188. <div v-if="selectedListComponent">
  189. <div class="separator" />
  190. <component :is="selectedListComponent" ref="list" :list="list" :search="search" :genre-map="genreMap" @list-event="listEvent" />
  191. <div class="separator" />
  192. </div>
  193. <!-- Формирование списка конец ------------------------------------------------------------------>
  194. <div class="row q-ml-lg q-mb-sm">
  195. <PageScroller v-show="pageCount > 1" v-model="search.page" :page-count="pageCount" />
  196. </div>
  197. <div class="row justify-center">
  198. <div class="q-mb-lg q-px-sm q-py-xs bg-cyan-2 clickable2" style="border: 1px solid #aaaaaa; border-radius: 6px; white-space: nowrap;" @click.stop.prevent="openReleasePage">
  199. {{ projectName }}
  200. </div>
  201. </div>
  202. </div>
  203. <SettingsDialog v-model="settingsDialogVisible" />
  204. <SelectGenreDialog v-model="selectGenreDialogVisible" v-model:genre="search.genre" :genre-tree="genreTree" />
  205. <SelectLangDialog v-model="selectLangDialogVisible" v-model:lang="search.lang" :lang-list="langList" :lang-default="langDefault" />
  206. <SelectLibRateDialog v-model="selectLibRateDialogVisible" v-model:librate="search.librate" />
  207. <SelectDateDialog v-model="selectDateDialogVisible" v-model:date="search.date" />
  208. <BookInfoDialog v-model="bookInfoDialogVisible" :book-info="bookInfo" />
  209. </div>
  210. </template>
  211. <script>
  212. //-----------------------------------------------------------------------------
  213. import vueComponent from '../vueComponent.js';
  214. import AuthorList from './AuthorList/AuthorList.vue';
  215. import SeriesList from './SeriesList/SeriesList.vue';
  216. import TitleList from './TitleList/TitleList.vue';
  217. import PageScroller from './PageScroller/PageScroller.vue';
  218. import SettingsDialog from './SettingsDialog/SettingsDialog.vue';
  219. import SelectGenreDialog from './SelectGenreDialog/SelectGenreDialog.vue';
  220. import SelectLangDialog from './SelectLangDialog/SelectLangDialog.vue';
  221. import SelectLibRateDialog from './SelectLibRateDialog/SelectLibRateDialog.vue';
  222. import SelectDateDialog from './SelectDateDialog/SelectDateDialog.vue';
  223. import BookInfoDialog from './BookInfoDialog/BookInfoDialog.vue';
  224. import authorBooksStorage from './authorBooksStorage';
  225. import DivBtn from '../share/DivBtn.vue';
  226. import Dialog from '../share/Dialog.vue';
  227. import * as utils from '../../share/utils';
  228. import diffUtils from '../../share/diffUtils';
  229. import _ from 'lodash';
  230. const route2component = {
  231. 'author': {component: 'AuthorList', label: 'Авторы'},
  232. 'series': {component: 'SeriesList', label: 'Серии'},
  233. 'title': {component: 'TitleList', label: 'Книги'},
  234. };
  235. const componentOptions = {
  236. components: {
  237. AuthorList,
  238. SeriesList,
  239. TitleList,
  240. PageScroller,
  241. SettingsDialog,
  242. SelectGenreDialog,
  243. SelectLangDialog,
  244. SelectLibRateDialog,
  245. SelectDateDialog,
  246. BookInfoDialog,
  247. Dialog,
  248. DivBtn
  249. },
  250. watch: {
  251. config(newValue) {
  252. this.makeProjectName();
  253. if (newValue.dbConfig)
  254. this.list.inpxHash = newValue.dbConfig.inpxHash;
  255. },
  256. settings() {
  257. this.loadSettings();
  258. },
  259. search: {
  260. handler(newValue) {
  261. this.limit = newValue.limit;
  262. if (this.pageCount > 1)
  263. this.prevPage = this.search.page;
  264. this.makeTitle();
  265. this.updateRouteQueryFromSearch();
  266. this.updateSearchDate(true);
  267. },
  268. deep: true,
  269. },
  270. extendedParams(newValue) {
  271. this.setSetting('extendedParams', newValue);
  272. },
  273. limit(newValue) {
  274. this.setSetting('limit', newValue);
  275. this.updatePageCount();
  276. },
  277. $route(to) {
  278. this.updateListFromRoute(to);
  279. this.updateSearchFromRouteQuery(to);
  280. },
  281. langDefault() {
  282. this.updateSearchFromRouteQuery(this.$route);
  283. },
  284. list: {
  285. handler(newValue) {
  286. this.updateGenreTreeIfNeeded();
  287. if (this.prevList.totalFound != newValue.totalFound) {
  288. this.updatePageCount();
  289. if (this.$refs.list)
  290. this.foundCountMessage = this.$refs.list.foundCountMessage;
  291. else
  292. this.foundCountMessage = '';
  293. }
  294. this.prevList = _.cloneDeep(newValue);
  295. },
  296. deep: true,
  297. },
  298. selectedList(newValue) {
  299. if (this.selectedListComponent) {
  300. this.pageCount = 1;
  301. this.list.totalFound = 0;
  302. }
  303. this.selectedListComponent = (route2component[newValue] ? route2component[newValue].component : null);
  304. if (this.getListRoute() != newValue) {
  305. this.updateRouteQueryFromSearch();
  306. }
  307. },
  308. searchDate() {
  309. this.updateSearchDate(false);
  310. },
  311. },
  312. };
  313. class Search {
  314. _options = componentOptions;
  315. ready = false;
  316. selectedList = '';
  317. selectedListComponent = '';
  318. collection = '';
  319. projectName = '';
  320. foundCountMessage = '';
  321. settingsDialogVisible = false;
  322. selectGenreDialogVisible = false;
  323. selectLangDialogVisible = false;
  324. selectLibRateDialogVisible = false;
  325. selectDateDialogVisible = false;
  326. bookInfoDialogVisible = false;
  327. pageCount = 1;
  328. //input field consts
  329. inputMaxLength = 1000;
  330. inputDebounce = 200;
  331. //search fields
  332. search = {
  333. setDefaults(search) {
  334. return Object.assign({}, search, {
  335. author: search.author || '',
  336. series: search.series || '',
  337. title: search.title || '',
  338. genre: search.genre || '',
  339. lang: search.lang || '',
  340. date: search.date || '',
  341. librate: search.librate || '',
  342. page: search.page || 1,
  343. limit: search.limit || 50,
  344. });
  345. },
  346. };
  347. searchDate = '';
  348. prevManualDate = '';
  349. //settings
  350. abCacheEnabled = true;
  351. langDefault = '';
  352. limit = 20;
  353. extendedParams = false;
  354. //stuff
  355. prevList = {};
  356. list = {
  357. queryFound: -1,
  358. totalFound: -1,
  359. inpxHash: '',
  360. liberamaReady: false,
  361. };
  362. genreTree = [];
  363. genreMap = new Map();
  364. langList = [];
  365. genreTreeInpxHash = '';
  366. showTooltips = true;
  367. bookInfo = {};
  368. searchDateOptions = [
  369. {label: 'сегодня', value: 'today'},
  370. {label: 'за 3 дня', value: '3days'},
  371. {label: 'за неделю', value: 'week'},
  372. {label: 'за 2 недели', value: '2weeks'},
  373. {label: 'за месяц', value: 'month'},
  374. {label: 'за 2 месяца', value: '2months'},
  375. {label: 'за 3 месяца', value: '3months'},
  376. {label: 'выбрать даты', value: 'manual'},
  377. ];
  378. created() {
  379. this.commit = this.$store.commit;
  380. this.api = this.$root.api;
  381. this.search = this.search.setDefaults(this.search);
  382. this.search.lang = this.langDefault;
  383. this.loadSettings();
  384. }
  385. mounted() {
  386. (async() => {
  387. //для встраивания в liberama
  388. window.addEventListener('message', (event) => {
  389. if (!_.isObject(event.data) || event.data.from != 'ExternalLibs')
  390. return;
  391. //console.log(event);
  392. this.recvMessage(event.data);
  393. });
  394. //локальный кеш
  395. await authorBooksStorage.init();
  396. if (!this.$root.isMobileDevice)
  397. this.$refs.authorInput.focus();
  398. this.updateListFromRoute(this.$route);
  399. this.updateSearchFromRouteQuery(this.$route);
  400. this.sendMessage({type: 'mes', data: 'hello-from-inpx-web'});
  401. this.ready = true;
  402. })();
  403. }
  404. loadSettings() {
  405. const settings = this.settings;
  406. this.search.limit = settings.limit;
  407. this.extendedParams = settings.extendedParams;
  408. this.expanded = _.cloneDeep(settings.expanded);
  409. this.expandedSeries = _.cloneDeep(settings.expandedSeries);
  410. this.abCacheEnabled = settings.abCacheEnabled;
  411. this.langDefault = settings.langDefault;
  412. }
  413. recvMessage(d) {
  414. if (d.type == 'mes') {
  415. switch(d.data) {
  416. case 'ready':
  417. this.list.liberamaReady = true;
  418. this.sendMessage({type: 'mes', data: 'ready'});
  419. this.sendCurrentUrl();
  420. break;
  421. }
  422. }
  423. }
  424. sendMessage(d) {
  425. window.parent.postMessage(Object.assign({}, {from: 'inpx-web'}, d), '*');
  426. }
  427. sendCurrentUrl() {
  428. this.sendMessage({type: 'urlChange', data: window.location.href});
  429. }
  430. get config() {
  431. return this.$store.state.config;
  432. }
  433. get settings() {
  434. return this.$store.state.settings;
  435. }
  436. get genreNames() {
  437. let result = [];
  438. const genre = this.search.genre.split(',');
  439. for (const g of genre) {
  440. const name = this.genreMap.get(g);
  441. if (name)
  442. result.push(name);
  443. }
  444. return result.join(', ');
  445. }
  446. get librateNames() {
  447. let result = [];
  448. const rates = this.search.librate.split(',');
  449. for (const r of rates) {
  450. result.push(r == '0' ? 'Без оценки' : r);
  451. }
  452. return result.join(', ');
  453. }
  454. get listOptions() {
  455. const result = [];
  456. for (const [route, rec] of Object.entries(route2component))
  457. result.push({label: rec.label, value: route});
  458. return result;
  459. }
  460. get extendedParamsMessage() {
  461. const s = this.search;
  462. const result = [];
  463. result.push(s.genre ? 'Жанр' : '');
  464. result.push(s.date ? 'Дата поступления' : '');
  465. result.push(s.librate ? 'Оценка' : '');
  466. return result.filter(s => s).join(', ');
  467. }
  468. inputBgColor(inp) {
  469. if (inp === this.selectedList)
  470. return 'white';
  471. else
  472. return 'yellow-1';
  473. }
  474. async updateListFromRoute(to) {
  475. const newPath = to.path;
  476. let newList = this.getListRoute(newPath);
  477. newList = (newList ? newList : 'author');
  478. if (this.selectedList != newList)
  479. this.selectedList = newList;
  480. }
  481. getListRoute(newPath) {
  482. newPath = (newPath ? newPath : this.$route.path);
  483. const m = newPath.match(/^\/([^/]*).*$/i);
  484. return (m ? m[1] : newPath);
  485. }
  486. openReleasePage() {
  487. window.open('https://github.com/bookpauk/inpx-web/releases', '_blank');
  488. }
  489. makeProjectName() {
  490. const collection = this.config.dbConfig.inpxInfo.collection.split('\n');
  491. this.collection = collection[0].trim();
  492. this.projectName = `${this.config.name} v${this.config.webAppVersion}`;
  493. this.makeTitle();
  494. }
  495. makeTitle() {
  496. if (!this.collection)
  497. return;
  498. let result = `Коллекция ${this.collection}`;
  499. const search = this.search;
  500. const specSym = new Set(['*', '#']);
  501. const correctValue = (v) => {
  502. if (v) {
  503. if (v[0] === '=')
  504. v = v.substring(1);
  505. else if (!specSym.has(v[0]))
  506. v = '^' + v;
  507. }
  508. return v || '';
  509. };
  510. if (search.author || search.series || search.title) {
  511. const as = (search.author ? search.author.split(',') : []);
  512. const author = (as.length ? as[0] : '') + (as.length > 1 ? ' и др.' : '');
  513. const a = correctValue(author);
  514. let s = correctValue(search.series);
  515. s = (s ? `(Серия: ${s})` : '');
  516. let t = correctValue(search.title);
  517. t = (t ? `"${t}"` : '');
  518. result = [s, t].filter(v => v).join(' ');
  519. result = [a, result].filter(v => v).join(' ');
  520. }
  521. this.$root.setAppTitle(result);
  522. if (this.list.liberamaReady)
  523. this.sendMessage({type: 'titleChange', data: result});
  524. }
  525. showSearchHelp() {
  526. let info = '';
  527. info += `<div style="min-width: 250px" />`;
  528. info += `
  529. <p>
  530. Для раздела <b>Авторы</b>, работу поискового движка можно описать простой фразой: найти авторов по указанным критериям.
  531. По тем же критериям среди найденных авторов фильтруются книги, сортируются и группируются по сериям.
  532. <br><br>
  533. По умолчанию поисковое значение трактуется как "начинается с". Например значение автора "Пушкин"
  534. трактуется как: найти авторов, имя которых начинается с "Пушкин". Поиск всегда ведется без
  535. учета регистра - значения "Ельцин" и "ельцин" равнозначны.
  536. <br><br>
  537. В поисковых полях "Автор", "Серия", "Название" также доступны следующие префиксы:
  538. <ul>
  539. <li>
  540. "=" поиск по точному совпадению. Например, если задать "=Пушкин Александр Сергеевич" в поле автора,
  541. то будет найден в точности этот автор
  542. </li>
  543. <br>
  544. <li>
  545. "*" поиск подстроки в строке. Например, для "*Александр" в поле автора, будут найдены
  546. все авторы, имя которых содержит "Александр"
  547. </li>
  548. <br>
  549. <li>
  550. "#" поиск подстроки в строке, но только для тех значений, которые не начинаются ни с одной буквы русского или латинского алфавита.
  551. Например, значение "#поворот" в поле автора означает: найти всех авторов, имя которых начинается не с русской или латинской буквы и содержит слово "поворот".
  552. Указание простого "#" в поиске по названию означает: найти всех авторов, названия книг которых начинаются не с русской или латинской буквы
  553. </li>
  554. <br>
  555. <li>
  556. "?" поиск пустых значений или тех, что начинаются с этого символа. Например, "?" в поле серии означает: найти всех авторов, у которых есть книги без серий
  557. или название серии начинается с "?".
  558. Значение "?" в поле названия означает: найти всех авторов, книги которых без названия или начинаются с "?"
  559. </li>
  560. </ul>
  561. <br>
  562. Специльное имя автора "?" служит для поиска и группировки книг без автора.
  563. <br><br>
  564. Для разделов <b>Серии</b>, <b>Книги</b> все аналогично разделу <b>Авторы</b>.
  565. </p>
  566. `;
  567. this.$root.stdDialog.alert(info, 'Памятка', {iconName: 'la la-info-circle'});
  568. }
  569. showCollectionInfo() {
  570. /*
  571. "dbConfig": {
  572. "inpxInfo": {
  573. "collection": "Flibusta Offline 2 August 2022\r\nflibusta_all_local_2022-08-02\r\n65537\r\nFlibusta. A local collection. Total: 636591 books\r\nhttp://flibusta.is/",
  574. },
  575. "stats": {
  576. "recsLoaded": 687063,
  577. "authorCount": 153364,
  578. "authorCountAll": 177034,
  579. "bookCount": 576018,
  580. "bookCountAll": 687063,
  581. "bookDelCount": 111045,
  582. "noAuthorBookCount": 4347,
  583. "titleCount": 512671,
  584. "seriesCount": 54472,
  585. "genreCount": 238,
  586. "langCount": 102
  587. },
  588. */
  589. let info = '';
  590. const inpxInfo = this.config.dbConfig.inpxInfo;
  591. const stat = this.config.dbConfig.stats;
  592. const keyStyle = 'style="display: inline-block; text-align: right; margin-right: 5px; min-width: 200px"';
  593. info += `<div style="min-width: 250px" />`;
  594. info += `
  595. <div><div ${keyStyle}>Всего файлов книг:</div><span>${stat.filesCountAll}</span></div>
  596. <div><div ${keyStyle}>Из них актуальных:</div><span>${stat.filesCount}</span></div>
  597. <div><div ${keyStyle}>Помеченных как удаленные:</div><span>${stat.filesDelCount}</span></div>
  598. <br>
  599. <div><div ${keyStyle}>Обработано ссылок на файлы:</div><span>${stat.bookCountAll}</span></div>
  600. <div><div ${keyStyle}>Из них актуальных:</div><span>${stat.bookCount}</span></div>
  601. <div><div ${keyStyle}>Помеченных как удаленные:</div><span>${stat.bookDelCount}</span></div>
  602. <div><div ${keyStyle}>Актуальных без автора:</div><span>${stat.noAuthorBookCount}</span></div>
  603. <br>
  604. <div><div ${keyStyle}>Всего имен авторов:</div><span>${stat.authorCountAll}</span></div>
  605. <div><div ${keyStyle}>Уникальных имен без соавторов:</div><span>${stat.authorCount}</span></div>
  606. <div><div ${keyStyle}>С соавторами:</div><span>${stat.authorCountAll- stat.authorCount}</span></div>
  607. <br>
  608. <div><div ${keyStyle}>Уникальных названий книг:</div><span>${stat.titleCount}</span></div>
  609. <div><div ${keyStyle}>Уникальных названий серий:</div><span>${stat.seriesCount}</span></div>
  610. <div><div ${keyStyle}>Найдено жанров:</div><span>${stat.genreCount}</span></div>
  611. <div><div ${keyStyle}>Найдено языков:</div><span>${stat.langCount}</span></div>
  612. <br>
  613. <div><div ${keyStyle}>Версия поисковой БД:</div><span>${this.config.dbVersion}</span></div>
  614. `;
  615. info += `
  616. <div><hr/>
  617. <b>collection.info:</b>
  618. <pre>${inpxInfo.collection}</pre>
  619. </div>
  620. `;
  621. this.$root.stdDialog.alert(info, 'Статистика по коллекции', {iconName: 'la la-info-circle'});
  622. }
  623. get newSearchLink() {
  624. return window.location.origin;
  625. }
  626. async hideTooltip() {
  627. //Firefox bugfix: при всплывающем диалоге скрываем подсказку
  628. this.showTooltips = false;
  629. await utils.sleep(1000);
  630. this.showTooltips = true;
  631. }
  632. selectGenre() {
  633. this.hideTooltip();
  634. this.selectGenreDialogVisible = true;
  635. }
  636. selectLang() {
  637. this.hideTooltip();
  638. this.selectLangDialogVisible = true;
  639. }
  640. selectLibRate() {
  641. this.hideTooltip();
  642. this.selectLibRateDialogVisible = true;
  643. }
  644. onScroll() {
  645. const curScrollTop = this.$refs.scroller.scrollTop;
  646. if (this.ignoreScrolling) {
  647. this.lastScrollTop = curScrollTop;
  648. if (this.$refs.toolPanel.offsetTop > curScrollTop)
  649. this.$refs.toolPanel.style.top = `${curScrollTop}px`;
  650. return;
  651. }
  652. if (!this.lastScrollTop)
  653. this.lastScrollTop = 0;
  654. if (!this.lastScrollTop2)
  655. this.lastScrollTop2 = 0;
  656. if (curScrollTop - this.lastScrollTop > 0) {
  657. this.$refs.toolPanel.style.position = 'relative';
  658. if (this.lastScrollTop2 <= curScrollTop - this.$refs.toolPanel.clientHeight)
  659. this.lastScrollTop2 = 0;
  660. this.$refs.toolPanel.style.top = `${this.lastScrollTop2}px`;
  661. } else {
  662. this.$refs.toolPanel.style.position = 'sticky';
  663. this.$refs.toolPanel.style.top = 0;
  664. this.lastScrollTop2 = curScrollTop;
  665. }
  666. this.lastScrollTop = curScrollTop;
  667. }
  668. async ignoreScroll(ms = 300) {
  669. this.ignoreScrolling = true;
  670. await utils.sleep(ms);
  671. await this.$nextTick();
  672. await this.$nextTick();
  673. await this.$nextTick();
  674. this.ignoreScrolling = false;
  675. }
  676. scrollToTop() {
  677. this.$refs.scroller.scrollTop = 0;
  678. this.lastScrollTop = 0;
  679. }
  680. updatePageCount() {
  681. if (this.list.totalFound < 0)
  682. return;
  683. const prevPageCount = this.pageCount;
  684. this.pageCount = Math.ceil(this.list.totalFound/this.limit);
  685. this.pageCount = (this.pageCount < 1 ? 1 : this.pageCount);
  686. if (this.prevPage && prevPageCount == 1 && this.pageCount > 1 && this.prevPage <= this.pageCount) {
  687. this.search.page = this.prevPage;
  688. }
  689. if (this.search.page > this.pageCount)
  690. this.search.page = 1;
  691. }
  692. listEvent(event) {
  693. switch (event.action) {
  694. case 'ignoreScroll':
  695. this.ignoreScroll();
  696. break;
  697. case 'highlightPageScroller':
  698. this.highlightPageScroller(event.query);
  699. break;
  700. case 'scrollToTop':
  701. this.scrollToTop();
  702. break;
  703. case 'submitUrl':
  704. this.sendMessage({type: 'submitUrl', data: event.data});
  705. break;
  706. case 'bookInfo':
  707. this.bookInfo = event.data;
  708. this.bookInfoDialogVisible = true;
  709. break;
  710. }
  711. }
  712. setSetting(name, newValue) {
  713. this.commit('setSettings', {[name]: _.cloneDeep(newValue)});
  714. }
  715. highlightPageScroller(query) {
  716. const q = _.cloneDeep(query);
  717. delete q.limit;
  718. delete q.offset;
  719. delete q.page;
  720. try {
  721. if (this.search.page < 2 || !this._prevQuery || _.isEqual(this._prevQuery, q))
  722. return;
  723. this.$refs.pageScroller1.highlightScroller();
  724. } finally {
  725. this._prevQuery = q;
  726. }
  727. }
  728. updateSearchFromRouteQuery(to) {
  729. if (this.list.liberamaReady)
  730. this.sendCurrentUrl();
  731. if (this.routeUpdating)
  732. return;
  733. const query = to.query;
  734. this.search = this.search.setDefaults(
  735. Object.assign({}, this.search, {
  736. author: query.author,
  737. series: query.series,
  738. title: query.title,
  739. genre: query.genre,
  740. lang: (typeof(query.lang) == 'string' ? query.lang : this.langDefault),
  741. date: query.date,
  742. librate: query.librate,
  743. page: parseInt(query.page, 10),
  744. limit: parseInt(query.limit, 10) || this.search.limit,
  745. })
  746. );
  747. if (this.search.limit > 1000)
  748. this.search.limit = 1000;
  749. }
  750. updateRouteQueryFromSearch() {
  751. if (!this.ready)
  752. return;
  753. this.routeUpdating = true;
  754. try {
  755. const oldQuery = this.$route.query;
  756. const cloned = _.cloneDeep(this.search);
  757. delete cloned.setDefaults;
  758. const query = _.pickBy(cloned);
  759. if (this.search.lang == this.langDefault) {
  760. delete query.lang;
  761. } else {
  762. query.lang = this.search.lang;
  763. }
  764. const diff = diffUtils.getObjDiff(oldQuery, query);
  765. if (!diffUtils.isEmptyObjDiff(diff)) {
  766. this.$router.replace({path: this.selectedList, query});
  767. }
  768. } finally {
  769. (async() => {
  770. await utils.sleep(100);
  771. this.routeUpdating = false;
  772. })();
  773. }
  774. }
  775. async updateGenreTreeIfNeeded() {
  776. if (this.genreTreeUpdating)
  777. return;
  778. this.genreTreeUpdating = true;
  779. try {
  780. if (this.genreTreeInpxHash !== this.list.inpxHash) {
  781. let result;
  782. if (this.abCacheEnabled) {
  783. const key = `genre-tree-${this.list.inpxHash}`;
  784. const data = await authorBooksStorage.getData(key);
  785. if (data) {
  786. result = JSON.parse(data);
  787. } else {
  788. result = await this.api.getGenreTree();
  789. await authorBooksStorage.setData(key, JSON.stringify(result));
  790. }
  791. } else {
  792. result = await this.api.getGenreTree();
  793. }
  794. this.genreTree = result.genreTree;
  795. this.genreMap = new Map();
  796. for (const section of this.genreTree) {
  797. for (const g of section.value)
  798. this.genreMap.set(g.value, g.name);
  799. }
  800. this.langList = result.langList;
  801. this.genreTreeInpxHash = result.inpxHash;
  802. }
  803. } catch (e) {
  804. this.$root.stdDialog.alert(e.message, 'Ошибка');
  805. } finally {
  806. this.genreTreeUpdating = false;
  807. }
  808. }
  809. updateSearchDate(toLocal) {
  810. if (toLocal) {
  811. let local = this.search.date || '';
  812. if (utils.isManualDate(local) || !local)
  813. this.prevManualDate = local;
  814. if (utils.isManualDate(local))
  815. local = 'manual';
  816. this.searchDate = local;
  817. } else {
  818. if (this.searchDate != 'manual')
  819. this.search.date = this.searchDate || '';
  820. }
  821. }
  822. get formatSearchDate() {
  823. const result = [];
  824. const date = this.search.date;
  825. if (utils.isManualDate(date)) {
  826. const [from, to] = date.split(',')
  827. if (from)
  828. result.push(`<div style="display: inline-block; width: 15px; text-align: right;">с</div> ${utils.sqlDateFormat(from)}`);
  829. if (to)
  830. result.push(`<div style="display: inline-block; width: 15px; text-align: right;">по</div> ${utils.sqlDateFormat(to)}`);
  831. }
  832. return result.join('<br>');
  833. }
  834. dateSelectItemClick(itemValue) {
  835. if (itemValue == 'manual') {
  836. if (!utils.isManualDate(this.search.date)) {
  837. this.search.date = this.prevManualDate;
  838. if (!this.search.date)
  839. this.searchDate = '';
  840. }
  841. this.selectDateDialogVisible = true
  842. }
  843. }
  844. cloneSearch() {
  845. window.open(window.location.href, '_blank');
  846. }
  847. async logout() {
  848. await this.api.logout();
  849. }
  850. }
  851. export default vueComponent(Search);
  852. //-----------------------------------------------------------------------------
  853. </script>
  854. <style scoped>
  855. .root {
  856. }
  857. .tool-panel {
  858. border-bottom: 1px solid #bbb;
  859. }
  860. .header {
  861. min-height: 30px;
  862. }
  863. .clickable {
  864. color: blue;
  865. cursor: pointer;
  866. }
  867. .clickable2 {
  868. cursor: pointer;
  869. }
  870. .separator {
  871. border-bottom: 2px solid #ddd;
  872. margin: 5px 0 5px 0;
  873. }
  874. </style>