Simplified input fields

Ref https://gitlab.com/oersi/metadata-form/-/issues/3
This commit is contained in:
Mirjan Hoffmann 2023-05-30 11:20:03 +02:00
parent c6e7593fee
commit 9fb9f07b43
3 changed files with 21 additions and 13 deletions

View file

@ -41,6 +41,7 @@
"LABEL_STATUS_PUBLISHED": "Veröffentlicht", "LABEL_STATUS_PUBLISHED": "Veröffentlicht",
"LABEL_SUBJECT": "Fach", "LABEL_SUBJECT": "Fach",
"LABEL_TITLE": "Titel", "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" "LABEL_YAML_METADATA": "YAML Metadaten"
} }

View file

@ -41,6 +41,7 @@
"LABEL_STATUS_PUBLISHED": "Published", "LABEL_STATUS_PUBLISHED": "Published",
"LABEL_SUBJECT": "Subject", "LABEL_SUBJECT": "Subject",
"LABEL_TITLE": "Title", "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" "LABEL_YAML_METADATA": "YAML Metadata"
} }

View file

@ -205,10 +205,8 @@
<div class="form-group row"> <div class="form-group row">
<label for="inputUrl" class="col-sm-2 col-form-label" data-i18n="LABEL_URL">URL</label> <label for="inputUrl" class="col-sm-2 col-form-label" data-i18n="LABEL_URL">URL</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="url" class="form-control" id="inputUrl" placeholder="URL" <input type="url" class="form-control" id="inputUrl" placeholder="URL" data-i18n-placeholder="LABEL_URL_PLACEHOLDER" value="">
data-i18n-placeholder="LABEL_URL" value="" required>
<div class="valid-feedback"></div> <div class="valid-feedback"></div>
<div class="invalid-feedback" data-i18n="LABEL_MANDATORY_FIELD">Pflichtfeld</div>
</div> </div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
@ -612,13 +610,16 @@
const selectedSubjects = $('#inputSubjectOf').val(); const selectedSubjects = $('#inputSubjectOf').val();
const selectedResourceTypes = $('#inputResourceType').val(); const selectedResourceTypes = $('#inputResourceType').val();
const selectedEducationalLevel = $('#inputEducationalLevel').val(); const selectedEducationalLevel = $('#inputEducationalLevel').val();
const identifier = document.getElementById("inputUrl").value;
let meta = { let meta = {
creativeWorkStatus: document.getElementById("inputStatus").value, creativeWorkStatus: document.getElementById("inputStatus").value,
id: document.getElementById("inputUrl").value,
name: document.getElementById("inputTitle").value, name: document.getElementById("inputTitle").value,
description: document.getElementById("inputDescription").value, description: document.getElementById("inputDescription").value,
license: {id: document.getElementById("licenseUrl").value} license: {id: document.getElementById("licenseUrl").value}
} }
if (identifier) {
meta.id = identifier;
}
if (creators.length > 0) { if (creators.length > 0) {
meta.creator = creators meta.creator = creators
} }
@ -629,16 +630,16 @@
meta.inLanguage = selectedLanguages; meta.inLanguage = selectedLanguages;
} }
if (selectedSubjects.length > 0) { if (selectedSubjects.length > 0) {
meta.about = selectedSubjects.map((s) => ({id: s})) meta.about = selectedSubjects
} }
if (document.getElementById("inputImage").value) { if (document.getElementById("inputImage").value) {
meta.image = document.getElementById("inputImage").value meta.image = document.getElementById("inputImage").value
} }
if (selectedResourceTypes.length > 0) { if (selectedResourceTypes.length > 0) {
meta.learningResourceType = selectedResourceTypes.map((t) => ({id: t})) meta.learningResourceType = selectedResourceTypes
} }
if (selectedEducationalLevel.length > 0) { if (selectedEducationalLevel.length > 0) {
meta.educationalLevel = selectedEducationalLevel.map((t) => ({id: t})) meta.educationalLevel = selectedEducationalLevel
} }
document.getElementById("comment").value = jsyaml.dump(meta); document.getElementById("comment").value = jsyaml.dump(meta);
if (navigator.clipboard) { if (navigator.clipboard) {
@ -666,21 +667,26 @@
} }
function importData() { function importData() {
try { try {
const idMap = (o) => (typeof o === 'string' || o instanceof String) ? o : o.id;
const data = jsyaml.load(document.getElementById("importData").value); const data = jsyaml.load(document.getElementById("importData").value);
const aboutIds = data.about ? data.about.map((o) => o.id) : []; const aboutIds = data.about ? data.about.map(idMap) : [];
const learningResourceTypeIds = data.learningResourceType ? data.learningResourceType.map((o) => o.id) : []; 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("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; document.getElementById("inputTitle").value = data.name;
setCreators(data.creator ? data.creator : []); setCreators(data.creator ? data.creator : []);
document.getElementById("inputTags").value = data.keywords ? data.keywords.join(", ") : ""; document.getElementById("inputTags").value = data.keywords ? data.keywords.join(", ") : "";
document.getElementById("inputDescription").value = data.description ? data.description : ""; document.getElementById("inputDescription").value = data.description ? data.description : "";
$('#inputLanguage').val(data.inLanguage ? data.inLanguage : []).selectpicker('refresh'); $('#inputLanguage').val(data.inLanguage ? data.inLanguage : []).selectpicker('refresh');
$('#inputSubjectOf').val(aboutIds).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 : ""; document.getElementById("inputImage").value = data.image ? data.image : "";
$('#inputResourceType').val(learningResourceTypeIds).selectpicker('refresh'); $('#inputResourceType').val(learningResourceTypeIds).selectpicker('refresh');
if (educationalLevelIds.length > 0) {
$('#inputEducationalLevel').val(educationalLevelIds).selectpicker('refresh');
}
} catch (e) { } catch (e) {
console.warn(e); console.warn(e);
alert(i18next.t("LABEL_IMPORT_ERROR_MSG")); alert(i18next.t("LABEL_IMPORT_ERROR_MSG"));