From 391fb3aa70d37eda281f05fc1626b5de144b24c6 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Thu, 10 Nov 2022 17:17:56 +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=20BookInfoDialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Search/BookInfoDialog/BookInfoDialog.vue | 178 ++++++++++++++++-- client/quasar.js | 4 +- server/core/fb2/Fb2Parser.js | 20 +- 3 files changed, 177 insertions(+), 25 deletions(-) diff --git a/client/components/Search/BookInfoDialog/BookInfoDialog.vue b/client/components/Search/BookInfoDialog/BookInfoDialog.vue index a66c857..4cd2d94 100644 --- a/client/components/Search/BookInfoDialog/BookInfoDialog.vue +++ b/client/components/Search/BookInfoDialog/BookInfoDialog.vue @@ -9,9 +9,57 @@
-
-
- +
+ {{ bookAuthor }} +
+
+ {{ book.title }} +
+ +
+
+ +
+ {{ book.ext }} +
+
+ +
+
+ + + + +
+ +
+
+
+
+ {{ item.label }} +
+
+
+ +
+
+ {{ subItem.label }} +
+
+ {{ subItem.value }} +
+
+
+
@@ -40,13 +88,12 @@ const componentOptions = { watch: { modelValue(newValue) { this.dialogVisible = newValue; + if (newValue) + this.init(); }, dialogVisible(newValue) { this.$emit('update:modelValue', newValue); }, - bookInfo() { - this.parseBookInfo(); - } } }; class BookInfoDialog { @@ -57,28 +104,125 @@ class BookInfoDialog { }; dialogVisible = false; + selectedTab = 'fb2'; //info props coverSrc = ''; annotation = ''; - info = []; + fb2 = []; + book = {}; created() { this.commit = this.$store.commit; - this.parseBookInfo(); } mounted() { } - parseBookInfo() { - const bookInfo = this.bookInfo; - const parser = new Fb2Parser(); - + init() { //defaults this.coverSrc = ''; this.annotation = ''; - this.info = []; + this.fb2 = []; + this.book = {}; + + this.parseBookInfo(); + } + + get bookAuthor() { + if (this.book.author) { + let a = this.book.author.split(','); + return a.slice(0, 3).join(', ') + (a.length > 3 ? ' и др.' : ''); + } + + return ''; + } + + get inpx() { + const mapping = [ + {name: 'fileInfo', label: 'Информация о файле', value: [ + {name: 'folder', label: 'Папка'}, + {name: 'file', label: 'Файл'}, + {name: 'size', label: 'Размер'}, + {name: 'date', label: 'Добавлен'}, + ]}, + ]; +/* + {name: 'author', label: 'Автор(ы)'}, + {name: 'bookTitle', label: 'Название'}, + {name: 'sequenceName', label: 'Серия'}, + {name: 'sequenceNum', label: 'Номер в серии'}, + {name: 'genre', label: 'Жанр'}, + + {name: 'date', label: 'Дата'}, + {name: 'lang', label: 'Язык книги'}, + {name: 'srcLang', label: 'Язык оригинала'}, + {name: 'translator', label: 'Переводчик(и)'}, + {name: 'keywords', label: 'Ключевые слова'}, + + + {"author":"Грант Максвелл", + "genre":"det_hard", + "title":"Tower of Death", + "series":"The Shadow[a]", + "serno":53, + "file":"641310", + "size":420422, + "libid":"641310", + "del":0, + "ext":"fb2", + "date":"2021-11-04", + "insno":181, + "folder":"f.fb2-641019-643928.zip", + "lang":"en", + "librate":0, + "keywords":"Hard-Boiled, Pulp Fiction,det", +*/ + const valueToString = (value, nodePath) => {//eslint-disable-line no-unused-vars + if (typeof(value) === 'string') { + return value; + } + + return value; + }; + + let result = []; + for (const item of mapping) { + const itemOut = {name: item.name, label: item.label, value: []}; + + for (const subItem of item.value) { + const subItemOut = { + name: subItem.name, + label: subItem.label, + value: valueToString(this.book[subItem.name], `${item.name}/${subItem.name}`) + }; + if (subItemOut.value) + itemOut.value.push(subItemOut); + } + + if (itemOut.value.length) + result.push(itemOut); + } + + return result; + } + + get info() { + let result = []; + + switch (this.selectedTab) { + case 'fb2': + return this.fb2; + case 'inpx': + return this.inpx; + } + + return result; + } + + parseBookInfo() { + const bookInfo = this.bookInfo; + const parser = new Fb2Parser(); //cover if (bookInfo.cover) @@ -86,10 +230,10 @@ class BookInfoDialog { //fb2 if (bookInfo.fb2) { - this.info = parser.bookInfoList(bookInfo.fb2); + this.fb2 = parser.bookInfoList(bookInfo.fb2); const infoObj = parser.bookInfo(bookInfo.fb2); - if (infoObj) { + if (infoObj.titleInfo) { let ann = infoObj.titleInfo.annotationHtml; if (ann) { ann = ann.replace(/

/g, `

`); @@ -97,6 +241,10 @@ class BookInfoDialog { } } } + + //book + if (bookInfo.book) + this.book = bookInfo.book; } okClick() { diff --git a/client/quasar.js b/client/quasar.js index 925a20f..9acf6b1 100644 --- a/client/quasar.js +++ b/client/quasar.js @@ -17,7 +17,7 @@ import {QBtn} from 'quasar/src/components/btn'; import {QBtnToggle} from 'quasar/src/components/btn-toggle'; import {QIcon} from 'quasar/src/components/icon'; //import {QSlider} from 'quasar/src/components/slider'; -//import {QTabs, QTab} from 'quasar/src/components/tabs'; +import {QTabs, QTab} from 'quasar/src/components/tabs'; //import {QTabPanels, QTabPanel} from 'quasar/src/components/tab-panels'; //import {QSeparator} from 'quasar/src/components/separator'; //import {QList} from 'quasar/src/components/item'; @@ -52,7 +52,7 @@ const components = { QBtnToggle, QIcon, //QSlider, - //QTabs, QTab, + QTabs, QTab, //QTabPanels, QTabPanel, //QSeparator, //QList, diff --git a/server/core/fb2/Fb2Parser.js b/server/core/fb2/Fb2Parser.js index f8cdd6a..efc0b83 100644 --- a/server/core/fb2/Fb2Parser.js +++ b/server/core/fb2/Fb2Parser.js @@ -79,10 +79,10 @@ class Fb2Parser extends XmlParser { info.translator = parseAuthors('translator'); - const seqAttrs = titleInfo.attrs('sequence') || new Map(); - info.sequenceName = seqAttrs.get('name') || null; - info.sequenceNum = seqAttrs.get('number') || null; - info.sequenceLang = seqAttrs.get('xml:lang') || null; + const seqAttrs = titleInfo.attrs('sequence') || {}; + info.sequenceName = seqAttrs['name'] || null; + info.sequenceNum = seqAttrs['number'] || null; + info.sequenceLang = seqAttrs['xml:lang'] || null; result.titleInfo = info; } @@ -141,12 +141,16 @@ class Fb2Parser extends XmlParser { continue; for (const subItem of item.value) { - if (info[subItem.name] !== null) - itemOut.value.push({ + if (info[subItem.name] !== null) { + const subItemOut = { name: subItem.name, label: subItem.label, - value: valueToString(info[subItem.name]) - }); + value: valueToString(info[subItem.name], `${item.name}/${subItem.name}`) + }; + + if (subItemOut.value) + itemOut.value.push(subItemOut); + } } if (itemOut.value.length)