From 9fb9f07b43d0e1f6aefe588a69ac9a06878788d1 Mon Sep 17 00:00:00 2001 From: Mirjan Hoffmann Date: Tue, 30 May 2023 11:20:03 +0200 Subject: [PATCH] Simplified input fields Ref https://gitlab.com/oersi/metadata-form/-/issues/3 --- i18n/de.json | 3 ++- i18n/en.json | 3 ++- metadata-generator.html | 28 +++++++++++++++++----------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/i18n/de.json b/i18n/de.json index 8584b10..db40b2e 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -41,6 +41,7 @@ "LABEL_STATUS_PUBLISHED": "Veröffentlicht", "LABEL_SUBJECT": "Fach", "LABEL_TITLE": "Titel", - "LABEL_URL": "URL", + "LABEL_URL": "URL der Ressource", + "LABEL_URL_PLACEHOLDER": "Direktlink zur Resource (Voreinstellung GitHub/GitLab Pages URL)", "LABEL_YAML_METADATA": "YAML Metadaten" } \ No newline at end of file diff --git a/i18n/en.json b/i18n/en.json index 45ecd32..c6d2c0b 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -41,6 +41,7 @@ "LABEL_STATUS_PUBLISHED": "Published", "LABEL_SUBJECT": "Subject", "LABEL_TITLE": "Title", - "LABEL_URL": "URL", + "LABEL_URL": "Resource URL", + "LABEL_URL_PLACEHOLDER": "Direct link to the resource (default GitHub/GitLab Pages URL)", "LABEL_YAML_METADATA": "YAML Metadata" } \ No newline at end of file diff --git a/metadata-generator.html b/metadata-generator.html index 1f5fbe7..b8ddd5e 100644 --- a/metadata-generator.html +++ b/metadata-generator.html @@ -205,10 +205,8 @@
- +
-
Pflichtfeld
@@ -612,13 +610,16 @@ const selectedSubjects = $('#inputSubjectOf').val(); const selectedResourceTypes = $('#inputResourceType').val(); const selectedEducationalLevel = $('#inputEducationalLevel').val(); + const identifier = document.getElementById("inputUrl").value; let meta = { creativeWorkStatus: document.getElementById("inputStatus").value, - id: document.getElementById("inputUrl").value, name: document.getElementById("inputTitle").value, description: document.getElementById("inputDescription").value, license: {id: document.getElementById("licenseUrl").value} } + if (identifier) { + meta.id = identifier; + } if (creators.length > 0) { meta.creator = creators } @@ -629,16 +630,16 @@ meta.inLanguage = selectedLanguages; } if (selectedSubjects.length > 0) { - meta.about = selectedSubjects.map((s) => ({id: s})) + meta.about = selectedSubjects } if (document.getElementById("inputImage").value) { meta.image = document.getElementById("inputImage").value } if (selectedResourceTypes.length > 0) { - meta.learningResourceType = selectedResourceTypes.map((t) => ({id: t})) + meta.learningResourceType = selectedResourceTypes } if (selectedEducationalLevel.length > 0) { - meta.educationalLevel = selectedEducationalLevel.map((t) => ({id: t})) + meta.educationalLevel = selectedEducationalLevel } document.getElementById("comment").value = jsyaml.dump(meta); if (navigator.clipboard) { @@ -666,21 +667,26 @@ } function importData() { try { + const idMap = (o) => (typeof o === 'string' || o instanceof String) ? o : o.id; const data = jsyaml.load(document.getElementById("importData").value); - const aboutIds = data.about ? data.about.map((o) => o.id) : []; - const learningResourceTypeIds = data.learningResourceType ? data.learningResourceType.map((o) => o.id) : []; + const aboutIds = data.about ? data.about.map(idMap) : []; + const learningResourceTypeIds = data.learningResourceType ? data.learningResourceType.map(idMap) : []; + const educationalLevelIds = data.educationalLevel ? data.educationalLevel.map(idMap) : []; document.getElementById("inputStatus").value = data.creativeWorkStatus ? data.creativeWorkStatus : "Draft"; - document.getElementById("inputUrl").value = data.id; + document.getElementById("inputUrl").value = data.id ? data.id : ""; document.getElementById("inputTitle").value = data.name; setCreators(data.creator ? data.creator : []); document.getElementById("inputTags").value = data.keywords ? data.keywords.join(", ") : ""; document.getElementById("inputDescription").value = data.description ? data.description : ""; $('#inputLanguage').val(data.inLanguage ? data.inLanguage : []).selectpicker('refresh'); $('#inputSubjectOf').val(aboutIds).selectpicker('refresh'); - setLicense((data.license && data.license.id) ? data.license.id : "") + setLicense((data.license && data.license.id) ? idMap(data.license) : "") document.getElementById("inputImage").value = data.image ? data.image : ""; $('#inputResourceType').val(learningResourceTypeIds).selectpicker('refresh'); + if (educationalLevelIds.length > 0) { + $('#inputEducationalLevel').val(educationalLevelIds).selectpicker('refresh'); + } } catch (e) { console.warn(e); alert(i18next.t("LABEL_IMPORT_ERROR_MSG"));