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 = ` + ${legend} +

+ + +

+ `; + + 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 @@

- +

the software title

+ +

+ + +

such as ISBNs, GTIN codes, UUIDs etc.. http://schema.org/identifier
+

+ + +

+ + +

+ +

+ +
+ +

+ +

- + - + +

from SPDX licence list

@@ -86,8 +125,102 @@

+ +

+ +
+ +

+ +
+ Keywords + +

Order of keywords does not matter.

+ + +
+ + +
+
+ +
+ Software requirements + +

Order of Software requirements does not matter.

+ + +
+ + +
+
+ + + + + +
+ Additional Info +

+ + +

software funded by (e.g. specific grant)
+

+ +

+ + +

+ +

+ + +

+ +

+ + + + +

see www.repostatus.org for details
+

+ +

+ + +

+ +

+ + +

+
+
Authors @@ -115,6 +248,7 @@ onclick="removePerson('contributor');" />
+
diff --git a/style.css b/style.css --- a/style.css +++ b/style.css @@ -5,11 +5,12 @@ * See top-level LICENSE file for more information */ + .person { display: inline-block; } -#fieldsetSoftwareItself, #fieldsetDevelopmentCommunity, #fieldsetCurrentVersion { +#fieldsetSoftwareItself, #fieldsetDevelopmentCommunity, #fieldsetCurrentVersion, #fieldsetAdditionalInfo { display: inline-block; } @@ -18,10 +19,19 @@ min-width: 20em; } +#funding { + /* Funding names are long */ + min-width: 20em; +} + input[type=URL] { /* URLs are longer than the other fields */ min-width: 20em; } +.field-description { + color : rgb(100, 104, 103); + font-size: small; +} #codemetaText { width: 100%; @@ -32,3 +42,8 @@ #errorMessage { color: red; } + +input:invalid { + color: red; +} + diff --git a/utils.js b/utils.js --- a/utils.js +++ b/utils.js @@ -17,6 +17,16 @@ nbField.value = nb; } +function getNbArray(prefix) { + var nbField = document.querySelector(`#${prefix}_nb`); + return parseInt(nbField.value, 10); +} + +function setNbArray(prefix, nb) { + var nbField = document.querySelector(`#${prefix}_nb`); + nbField.value = nb; +} + function setError(msg) { document.querySelector("#errorMessage").innerHTML = msg; }