diff --git a/components/Dictionary.vue b/components/Dictionary.vue
index 7631d409..e885c992 100644
--- a/components/Dictionary.vue
+++ b/components/Dictionary.vue
@@ -74,6 +74,15 @@
+
+
+
sources.referenced:
+
+
@@ -375,4 +384,8 @@
}
}
}
+
+ .div-three-columns {
+ width: 300%;
+ }
diff --git a/components/NounSubmitForm.vue b/components/NounSubmitForm.vue
index 42fcda01..8824323f 100644
--- a/components/NounSubmitForm.vue
+++ b/components/NounSubmitForm.vue
@@ -68,6 +68,10 @@
+
+
+
+
nouns.editing
@@ -128,6 +132,7 @@
mascPl: this.config.nouns.pluralsRequired ? [''] : [],
femPl: this.config.nouns.pluralsRequired ? [''] : [],
neutrPl: this.config.nouns.pluralsRequired ? [''] : [],
+ sources: [],
base: null,
},
submitting: false,
@@ -151,6 +156,7 @@
mascPl: this.config.nouns.pluralsRequired ? [''] : [],
femPl: this.config.nouns.pluralsRequired ? [''] : [],
neutrPl: this.config.nouns.pluralsRequired ? [''] : [],
+ sources: [],
base: null,
};
this.templateVisible = false;
@@ -164,6 +170,7 @@
mascPl: word.mascPl,
femPl: word.femPl,
neutrPl: word.neutrPl,
+ sources: word.sources,
base: word.id,
}
this.afterSubmit = false;
diff --git a/locale/de/translations.suml b/locale/de/translations.suml
index 3e1478ea..2be16054 100644
--- a/locale/de/translations.suml
+++ b/locale/de/translations.suml
@@ -97,6 +97,7 @@ sources:
key: 'Key' # TODO
keyInfo: 'Identifier for linking sources between language versions and linking with the dictionary' # TODO
otherVersions: 'In other languages' # TODO
+ referenced: 'Examples of use' # TODO
nouns:
header: 'Wörterbuch'
diff --git a/locale/en/translations.suml b/locale/en/translations.suml
index bb157312..c5552374 100644
--- a/locale/en/translations.suml
+++ b/locale/en/translations.suml
@@ -97,6 +97,7 @@ sources:
key: 'Key'
keyInfo: 'Identifier for linking sources between language versions and linking with the dictionary'
otherVersions: 'In other languages'
+ referenced: 'Examples of use'
nouns:
diff --git a/locale/es/translations.suml b/locale/es/translations.suml
index a3782f79..6f51d9fc 100644
--- a/locale/es/translations.suml
+++ b/locale/es/translations.suml
@@ -97,6 +97,7 @@ sources:
key: 'Key' # TODO
keyInfo: 'Identifier for linking sources between language versions and linking with the dictionary' # TODO
otherVersions: 'In other languages' # TODO
+ referenced: 'Examples of use' # TODO
nouns:
header: 'Diccionario'
diff --git a/locale/pl/translations.suml b/locale/pl/translations.suml
index 99527d19..a60e69a4 100644
--- a/locale/pl/translations.suml
+++ b/locale/pl/translations.suml
@@ -196,6 +196,7 @@ sources:
key: 'Klucz'
keyInfo: 'Identyfikator do łączenia tekstów między wersjami językowymi i łączenia ze słownikiem'
otherVersions: 'W innych językach'
+ referenced: 'Przykłady użycia'
nouns:
header: 'Słowniki'
diff --git a/locale/zh/translations.suml b/locale/zh/translations.suml
index 9e3b1c98..99b4c040 100644
--- a/locale/zh/translations.suml
+++ b/locale/zh/translations.suml
@@ -95,6 +95,7 @@ sources:
key: 'Key' # TODO
keyInfo: 'Identifier for linking sources between language versions and linking with the dictionary' # TODO
otherVersions: 'In other languages' # TODO
+ referenced: 'Examples of use' # TODO
nouns:
header: '字典'
diff --git a/migrations/018-noun-source.sql b/migrations/018-noun-source.sql
new file mode 100644
index 00000000..3ef35915
--- /dev/null
+++ b/migrations/018-noun-source.sql
@@ -0,0 +1,5 @@
+-- Up
+
+ALTER TABLE nouns ADD COLUMN sources TEXT NULL DEFAULT NULL;
+
+-- Down
diff --git a/server/routes/nouns.js b/server/routes/nouns.js
index 16104c56..fc70470b 100644
--- a/server/routes/nouns.js
+++ b/server/routes/nouns.js
@@ -3,7 +3,7 @@ import SQL from 'sql-template-strings';
import {ulid} from "ulid";
import {createCanvas, loadImage, registerFont} from "canvas";
import {loadSuml} from "../loader";
-import {isTroll} from "../../src/helpers";
+import {buildDict, isTroll} from "../../src/helpers";
const translations = loadSuml('translations');
@@ -23,22 +23,45 @@ const approve = async (db, id) => {
`);
}
+const addVersions = async (req, nouns) => {
+ const keys = new Set();
+ nouns.filter(s => !!s && s.sources)
+ .forEach(s => s.sources.split(',').forEach(k => keys.add(`'` + k + `'`)));
+
+ const sources = await req.db.all(SQL`
+ SELECT s.*, u.username AS submitter FROM sources s
+ LEFT JOIN users u ON s.submitter_id = u.id
+ WHERE s.locale == ${req.config.locale}
+ AND s.deleted = 0
+ AND s.approved >= ${req.isGranted('sources') ? 0 : 1}
+ AND s.key IN (`.append([...keys].join(',')).append(SQL`)
+ `));
+
+ const sourcesMap = {};
+ sources.forEach(s => sourcesMap[s.key] = s)
+
+ return nouns.map(n => {
+ n.sourcesData = (n.sources ? n.sources.split(',') : []).map(s => sourcesMap[s]);
+ return n;
+ });
+};
+
const router = Router();
router.get('/nouns', async (req, res) => {
- return res.json(await req.db.all(SQL`
+ return res.json(await addVersions(req, await req.db.all(SQL`
SELECT n.*, u.username AS author FROM nouns n
LEFT JOIN users u ON n.author_id = u.id
WHERE n.locale = ${req.config.locale}
AND n.deleted = 0
AND n.approved >= ${req.isGranted('nouns') ? 0 : 1}
ORDER BY n.approved, n.masc
- `));
+ `)));
});
router.get('/nouns/search/:term', async (req, res) => {
const term = '%' + req.params.term + '%';
- return res.json(await req.db.all(SQL`
+ return res.json(await addVersions(req, await req.db.all(SQL`
SELECT n.*, u.username AS author FROM nouns n
LEFT JOIN users u ON n.author_id = u.id
WHERE n.locale = ${req.config.locale}
@@ -46,7 +69,7 @@ router.get('/nouns/search/:term', async (req, res) => {
AND n.deleted = 0
AND (n.masc like ${term} OR n.fem like ${term} OR n.neutr like ${term} OR n.mascPl like ${term} OR n.femPl like ${term} OR n.neutrPl like ${term})
ORDER BY n.approved, n.masc
- `));
+ `)));
});
router.post('/nouns/submit', async (req, res) => {
@@ -56,11 +79,12 @@ router.post('/nouns/submit', async (req, res) => {
const id = ulid();
await req.db.get(SQL`
- INSERT INTO nouns (id, masc, fem, neutr, mascPl, femPl, neutrPl, approved, base_id, locale, author_id)
+ INSERT INTO nouns (id, masc, fem, neutr, mascPl, femPl, neutrPl, sources, approved, base_id, locale, author_id)
VALUES (
${id},
${req.body.masc.join('|')}, ${req.body.fem.join('|')}, ${req.body.neutr.join('|')},
${req.body.mascPl.join('|')}, ${req.body.femPl.join('|')}, ${req.body.neutrPl.join('|')},
+ ${req.body.sources || null},
0, ${req.body.base}, ${req.config.locale}, ${req.user ? req.user.id : null}
)
`);
diff --git a/src/classes.js b/src/classes.js
index c590d443..b2877a64 100644
--- a/src/classes.js
+++ b/src/classes.js
@@ -554,7 +554,7 @@ export class PronounLibrary {
}
export class Noun {
- constructor({id, masc, fem, neutr, mascPl, femPl, neutrPl, approved = true, base_id = null, author = null}) {
+ constructor({id, masc, fem, neutr, mascPl, femPl, neutrPl, sources = null, sourcesData = [], approved = true, base_id = null, author = null}) {
this.id = id;
this.masc = masc.split('|');
this.fem = fem.split('|');
@@ -562,6 +562,8 @@ export class Noun {
this.mascPl = mascPl ? mascPl.split('|') : [];
this.femPl = femPl ? femPl.split('|') : [];
this.neutrPl = neutrPl ? neutrPl.split('|') : [];
+ this.sources = sources ? sources.split(',') : [];
+ this.sourcesData = sourcesData.map(s => new Source(s));
this.approved = !!approved;
this.base = base_id;
this.author = author;
|