summaryrefslogtreecommitdiff
path: root/ext/js/language/dictionary-importer.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-07 11:12:58 -0400
committerGitHub <noreply@github.com>2021-09-07 11:12:58 -0400
commitac12b5093906e3a09724f96fee0c1a5141e52d3b (patch)
treeb7362890ecfd176e3de1e0f6501332eada450bba /ext/js/language/dictionary-importer.js
parentc91831a81722345ef7b4d20bd87c855903a7bca7 (diff)
Dictionary import count details (#1935)
* Store count information when importing a dictionary * Add importDate * Update property ordering * Update tests * Update importDate
Diffstat (limited to 'ext/js/language/dictionary-importer.js')
-rw-r--r--ext/js/language/dictionary-importer.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/ext/js/language/dictionary-importer.js b/ext/js/language/dictionary-importer.js
index 5629e197..4144de66 100644
--- a/ext/js/language/dictionary-importer.js
+++ b/ext/js/language/dictionary-importer.js
@@ -128,7 +128,15 @@ class DictionaryImporter {
// Add dictionary descriptor
this._progressNextStep(termList.length + termMetaList.length + kanjiList.length + kanjiMetaList.length + tagList.length + media.length);
- const summary = this._createSummary(dictionaryTitle, version, index, {prefixWildcardsSupported});
+ const counts = {
+ terms: {total: termList.length},
+ termMeta: this._getMetaCounts(termMetaList),
+ kanji: {total: kanjiList.length},
+ kanjiMeta: this._getMetaCounts(kanjiMetaList),
+ tagMeta: {total: tagList.length},
+ media: {total: media.length}
+ };
+ const summary = this._createSummary(dictionaryTitle, version, index, {prefixWildcardsSupported, counts});
dictionaryDatabase.bulkAdd('dictionaries', [summary], 0, 1);
// Add data
@@ -189,7 +197,8 @@ class DictionaryImporter {
title: dictionaryTitle,
revision: index.revision,
sequenced: index.sequenced,
- version
+ version,
+ importDate: Date.now()
};
const {author, url, description, attribution} = index;
@@ -556,4 +565,19 @@ class DictionaryImporter {
}
return results;
}
+
+ _getMetaCounts(metaList) {
+ const countsMap = new Map();
+ for (const {mode} of metaList) {
+ let count = countsMap.get(mode);
+ count = typeof count !== 'undefined' ? count + 1 : 1;
+ countsMap.set(mode, count);
+ }
+ const counts = {total: metaList.length};
+ for (const [key, value] of countsMap.entries()) {
+ if (Object.prototype.hasOwnProperty.call(counts, key)) { continue; }
+ counts[key] = value;
+ }
+ return counts;
+ }
}