diff --git a/codemeta_generation.js b/codemeta_generation.js --- a/codemeta_generation.js +++ b/codemeta_generation.js @@ -17,6 +17,7 @@ } function getIfSet(query) { + console.log(query) return emptyToUndefined(document.querySelector(query).value); } @@ -36,6 +37,24 @@ 'issueTracker', 'name', 'version', + 'identifier', + 'description', + 'applicationCategory', + //keywords TODO:keywords array + 'releaseNotes', + 'funding', + 'runtimePlatform', + //softwareRequiremnts, + 'operatingSystem', + 'developmentStatus', + //relatedLink + 'programmingLanguage', + 'isPartOf', + //'referencePublication' + // "@type": "ScholarlyArticle", + // "idendifier": "https://doi.org/xx.xxxx/xxxx.xxxx.xxxx", + // "name": "title of publication" + ]; // Names of codemeta properties with a matching HTML field name, @@ -44,6 +63,11 @@ 'givenName', 'familyName', 'email', + 'affiliation' +]; + +const directKeywordCodemetaFields = [ + 'keyword' ]; function generatePerson(idPrefix) { @@ -69,6 +93,25 @@ return persons; } +function generateArray(idPrefix,prefix) { + console.log(idPrefix) + console.log(prefix) + return getIfSet(`#${idPrefix}_${prefix}`); +} + +function generateArrays(prefix) { + console.log(prefix) + var array = []; + var nbArray = getNbArray(prefix); + console.log(nbArray) + + for (let ArrayId = 1; ArrayId <= nbArray; ArrayId++) { + array.push(generateArray(`${prefix}_${ArrayId}`,prefix)); + } + + return array; +} + function generateCodemeta() { var inputForm = document.querySelector('#inputForm'); var codemetaText, errorHTML; @@ -89,6 +132,8 @@ doc = Object.assign(doc, { "author": generatePersons('author'), "contributor": generatePersons('contributor'), + "keyword" : generateArrays('keyword'), + "software_requirements" : generateArrays('software_requirements'), }); codemetaText = JSON.stringify(doc, null, 4); diff --git a/dynamic_form.js b/dynamic_form.js --- a/dynamic_form.js +++ b/dynamic_form.js @@ -7,6 +7,7 @@ "use strict"; +/////////////////BEGIN-PERSONS function createPersonFieldset(personPrefix, legend) { // Creates a fieldset containing inputs for informations about a person var fieldset = document.createElement("fieldset") @@ -35,6 +36,11 @@
++ + +
`; return fieldset; @@ -84,6 +90,71 @@ removePerson(prefix) } } +/////////////////END-PERSONS + +/////////////////BEGIN-ARRAYS +function createArrayFieldset(prefix, legend, postfix) { + // Creates a fieldset containing inputs for informations about an array field + var fieldset = document.createElement(`fieldset_${prefix}`) + fieldset.classList.add(prefix); + fieldset.id = prefix; + + fieldset.innerHTML = ` + ++ + +
+ `; + + return fieldset; +} + +function addArrayWithId(container, prefix, legend, id) { + var fieldset = createArrayFieldset(`${prefix}_${id}`, `${legend} #${id}`,`${prefix}`); + + container.appendChild(fieldset); +} + +function addArray(prefix, legend) { + var container = document.querySelector(`#${prefix}_container`); + var ArrayId = getNbArray(prefix) + 1; + addArrayWithId(container, prefix, legend, ArrayId); + + setNbArray(prefix, ArrayId); + + return ArrayId; +} + +function removeArray(prefix) { + var ArrayId = getNbArray(prefix); + + document.querySelector(`#${prefix}_${ArrayId}`).remove(); + + setNbPersons(prefix, ArrayId-1); +} + +// Initialize a group of keywords on page load. +// Useful if the page is reloaded. +function initArrays(prefix, legend) { + var nbArray = getNbArray(prefix); + var ArrayContainer = document.querySelector(`#${prefix}_container`) + + for (let ArrayId = 1; ArrayId <= nbArray; ArrayId++) { + addKeywordWithId(ArrayContainer, prefix, legend, ArrayId); + } +} + +function removeArray(prefix) { + var nbArray = getNbArray(prefix); + var ArrayContainer = document.querySelector(`#${prefix}_container`) + + for (let ArrayId = 1; ArrayId <= nbArray; ArrayId++) { + removeArray(prefix) + } +} +/////////////////END-KEYWORDS function resetForm() { removePersons('author'); @@ -112,4 +183,6 @@ initPersons('author', 'Author'); initPersons('contributor', 'Contributor'); + initArrays('keyword', 'Keyword'); + initArrays('software_requirements', 'Software Requirements'); } diff --git a/fields_data.js b/fields_data.js --- a/fields_data.js +++ b/fields_data.js @@ -10,6 +10,7 @@ var SPDX_LICENSES = null; var SPDX_LICENSE_IDS = null; + function initSpdx() { var xhr = new XMLHttpRequest(); xhr.open('GET', './data/spdx/licenses.json', true); diff --git a/index.html b/index.html --- a/index.html +++ b/index.html @@ -26,10 +26,48 @@- +
+ + +
+ + +
+ +
+
+
+
+
- + + +
+
+
+
+