From cd831d88cc822e4292bf6d9d97f46f38f52455fa Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 5 Apr 2020 14:45:37 -0400 Subject: Update schema to include additional fields --- ext/bg/data/dictionary-index-schema.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ext') diff --git a/ext/bg/data/dictionary-index-schema.json b/ext/bg/data/dictionary-index-schema.json index 9311f14c..09cff711 100644 --- a/ext/bg/data/dictionary-index-schema.json +++ b/ext/bg/data/dictionary-index-schema.json @@ -30,6 +30,22 @@ "description": "Alias for format.", "enum": [1, 2, 3] }, + "author": { + "type": "string", + "description": "Creator of the dictionary." + }, + "url": { + "type": "string", + "description": "URL for the source of the dictionary." + }, + "description": { + "type": "string", + "description": "Description of the dictionary data." + }, + "attribution": { + "type": "string", + "description": "Attribution information for the dictionary data." + }, "tagMeta": { "type": "object", "description": "Tag information for terms and kanji. This object is obsolete and individual tag files should be used instead.", -- cgit v1.2.3 From 1b97629cd8014d7523a12ae857305e65a6d06672 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 5 Apr 2020 14:45:54 -0400 Subject: Store new dictionary data --- ext/bg/js/dictionary-importer.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'ext') diff --git a/ext/bg/js/dictionary-importer.js b/ext/bg/js/dictionary-importer.js index 589e7656..f9e173ea 100644 --- a/ext/bg/js/dictionary-importer.js +++ b/ext/bg/js/dictionary-importer.js @@ -150,13 +150,7 @@ class DictionaryImporter { } // Add dictionary - const summary = { - title: dictionaryTitle, - revision: index.revision, - sequenced: index.sequenced, - version, - prefixWildcardsSupported - }; + const summary = this._createSummary(dictionaryTitle, version, index, {prefixWildcardsSupported}); database.bulkAdd('dictionaries', [summary], 0, 1); @@ -199,6 +193,25 @@ class DictionaryImporter { return {result: summary, errors}; } + _createSummary(dictionaryTitle, version, index, details) { + const summary = { + title: dictionaryTitle, + revision: index.revision, + sequenced: index.sequenced, + version + }; + + const {author, url, description, attribution} = index; + if (typeof author === 'string') { summary.author = author; } + if (typeof url === 'string') { summary.url = url; } + if (typeof description === 'string') { summary.description = description; } + if (typeof attribution === 'string') { summary.attribution = attribution; } + + Object.assign(summary, details); + + return summary; + } + async _getSchema(fileName) { let schemaPromise = this._schemas.get(fileName); if (typeof schemaPromise !== 'undefined') { -- cgit v1.2.3 From dd9d50bfc194aa4c3d8e99188cfac0214476f868 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 5 Apr 2020 14:46:21 -0400 Subject: Update settings page to display additional information --- ext/bg/css/settings.css | 37 ++++++++++++++++++++++++++++ ext/bg/js/settings/dictionaries.js | 50 ++++++++++++++++++++++++++++++++++++++ ext/bg/settings.html | 4 +++ 3 files changed, 91 insertions(+) (limited to 'ext') diff --git a/ext/bg/css/settings.css b/ext/bg/css/settings.css index d686e8f8..6344bd38 100644 --- a/ext/bg/css/settings.css +++ b/ext/bg/css/settings.css @@ -235,6 +235,43 @@ html:root[data-operating-system=openbsd] [data-hide-for-operating-system~=openbs display: none; } +.dict-details-container { + margin: 0.5em 0; +} + +.dict-details-toggle-link { + cursor: pointer; +} + +.dict-details { + margin-left: 1em; +} + +.dict-details-table { + display: table; + width: 100% +} + +.dict-details-entry { + display: table-row; +} + +.dict-details-entry+.dict-details-entry>* { + padding-top: 0.25em; +} + +.dict-details-entry-label { + display: table-cell; + font-weight: bold; + white-space: nowrap; + padding-right: 0.5em; +} + +.dict-details-entry-info { + display: table-cell; + white-space: pre-line; +} + @media screen and (max-width: 740px) { .col-xs-6 { diff --git a/ext/bg/js/settings/dictionaries.js b/ext/bg/js/settings/dictionaries.js index 5e59cc3d..b9e4fe82 100644 --- a/ext/bg/js/settings/dictionaries.js +++ b/ext/bg/js/settings/dictionaries.js @@ -199,11 +199,16 @@ class SettingsDictionaryEntryUI { this.allowSecondarySearchesCheckbox = this.content.querySelector('.dict-allow-secondary-searches'); this.priorityInput = this.content.querySelector('.dict-priority'); this.deleteButton = this.content.querySelector('.dict-delete-button'); + this.detailsToggleLink = this.content.querySelector('.dict-details-toggle-link'); + this.detailsContainer = this.content.querySelector('.dict-details'); + this.detailsTable = this.content.querySelector('.dict-details-table'); if (this.dictionaryInfo.version < 3) { this.content.querySelector('.dict-outdated').hidden = false; } + this.setupDetails(dictionaryInfo); + this.content.querySelector('.dict-title').textContent = this.dictionaryInfo.title; this.content.querySelector('.dict-revision').textContent = `rev.${this.dictionaryInfo.revision}`; this.content.querySelector('.dict-prefix-wildcard-searches-supported').checked = !!this.dictionaryInfo.prefixWildcardsSupported; @@ -214,6 +219,45 @@ class SettingsDictionaryEntryUI { this.eventListeners.addEventListener(this.allowSecondarySearchesCheckbox, 'change', this.onAllowSecondarySearchesChanged.bind(this), false); this.eventListeners.addEventListener(this.priorityInput, 'change', this.onPriorityChanged.bind(this), false); this.eventListeners.addEventListener(this.deleteButton, 'click', this.onDeleteButtonClicked.bind(this), false); + this.eventListeners.addEventListener(this.detailsToggleLink, 'click', this.onDetailsToggleLinkClicked.bind(this), false); + } + + setupDetails(dictionaryInfo) { + const targets = [ + ['Author', 'author'], + ['URL', 'url'], + ['Description', 'description'], + ['Attribution', 'attribution'] + ]; + + let count = 0; + for (const [label, key] of targets) { + const info = dictionaryInfo[key]; + if (typeof info !== 'string') { continue; } + + const n1 = document.createElement('div'); + n1.className = 'dict-details-entry'; + n1.dataset.type = key; + + const n2 = document.createElement('span'); + n2.className = 'dict-details-entry-label'; + n2.textContent = `${label}:`; + n1.appendChild(n2); + + const n3 = document.createElement('span'); + n3.className = 'dict-details-entry-info'; + n3.textContent = info; + n1.appendChild(n3); + + this.detailsTable.appendChild(n1); + + ++count; + } + + if (count === 0) { + this.detailsContainer.hidden = true; + this.detailsToggleLink.hidden = true; + } } cleanup() { @@ -318,6 +362,12 @@ class SettingsDictionaryEntryUI { document.querySelector('#dict-remove-modal-dict-name').textContent = title; $(n).modal('show'); } + + onDetailsToggleLinkClicked(e) { + e.preventDefault(); + + this.detailsContainer.hidden = !this.detailsContainer.hidden; + } } class SettingsDictionaryExtraUI { diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 237162c7..1297a9cc 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -674,6 +674,10 @@ +
+ Details... + +
-- cgit v1.2.3