Skip to content

Commit

Permalink
Add input for canoncial dataset in EML editor
Browse files Browse the repository at this point in the history
- Add logic to identify the canonical dataset while parsing EML
- Update the Annotations collection with the value in the canonical dataset input changes

Issue #2542
  • Loading branch information
robyngit committed Oct 17, 2024
1 parent bea2d7b commit 4df698d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
29 changes: 29 additions & 0 deletions src/js/models/metadata/eml211/EML211.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ define([
methods: new EMLMethods(), // An EMLMethods objects
project: null, // An EMLProject object,
annotations: null, // Dataset-level annotations
canonicalDataset: null,
dataSensitivityPropertyURI:
"http://purl.dataone.org/odo/SENSO_00000005",
nodeOrder: [
Expand Down Expand Up @@ -143,6 +144,13 @@ define([
this.set("synced", true);
});

this.stopListening(this, "change:canonicalDataset");
this.listenTo(
this,
"change:canonicalDataset",
this.updateCanonicalDataset,
);

//Create a Unit collection
if (!this.units.length) this.createUnits();
},
Expand All @@ -160,6 +168,17 @@ define([
);
},

updateCanonicalDataset() {
let uri = this.get("canonicalDataset");
uri = uri?.length ? uri[0] : null;
let annotations = this.get("annotations");
if (!annotations) {
annotations = new EMLAnnotations();
this.set("annotations", annotations);
}
annotations.updateCanonicalDataset(uri);
},

/*
* Maps the lower-case EML node names (valid in HTML DOM) to the camel-cased EML node names (valid in EML).
* Used during parse() and serialize()
Expand Down Expand Up @@ -734,6 +753,16 @@ define([
}
}

// Once all the nodes have been parsed, check if any of the annotations
// make up a canonical dataset reference
const annotations = modelJSON["annotations"];
if (annotations) {
const canonicalDataset = annotations.getCanonicalURI();
if (canonicalDataset) {
modelJSON["canonicalDataset"] = canonicalDataset;
}
}

return modelJSON;
},

Expand Down
8 changes: 8 additions & 0 deletions src/js/templates/metadata/metadataOverview.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ <h5>Alternate Identifiers <i class="required-icon hidden" data-category="alterna
list any additional identifiers that can be used to locate or label the dataset here.</p>
<p class="notification" data-category="alternateIdentifier"></p>
</div>

<div class="canonical-id basic-text-container" data-category="canonicalDataset">
<h5>Canonical Dataset <i class="required-icon hidden" data-category="canonicalDataset"></i></h5>
<p class="subtle">If this dataset is essentially a duplicate of a version
stored elsewhere, provide the ID of the original dataset here. This must be a
DOI or URL</p>
<p class="notification" data-category="canonicalDataset"></p>
</div>
26 changes: 21 additions & 5 deletions src/js/views/metadata/EML211View.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ define([
);
$(overviewEl).find(".altids").append(altIdsEls);

// Canonical Identifier
const canonicalIdEl = this.createBasicTextFields(
"canonicalDataset",
"Add a new canonical identifier",
);
$(overviewEl).find(".canonical-id").append(canonicalIdEl);

//Usage
//Find the model value that matches a radio button and check it
// Note the replace() call removing newlines and replacing them with a single space
Expand Down Expand Up @@ -1909,7 +1916,7 @@ define([
.addClass("basic-text");
textRow.append(input.clone().val(value));

if (category != "title")
if (category !== "title" && category !== "canonicalDataset")
textRow.append(
this.createRemoveButton(
null,
Expand All @@ -1922,7 +1929,11 @@ define([
textContainer.append(textRow);

//At the end, append an empty input for the user to add a new one
if (i + 1 == allModelValues.length && category != "title") {
if (
i + 1 == allModelValues.length &&
category !== "title" &&
category !== "canonicalDataset"
) {
var newRow = $(
$(document.createElement("div")).addClass("basic-text-row"),
);
Expand Down Expand Up @@ -2006,7 +2017,12 @@ define([
}

//Add another blank text input
if ($(e.target).is(".new") && value != "" && category != "title") {
if (
$(e.target).is(".new") &&
value != "" &&
category != "title" &&
category !== "canonicalDataset"
) {
$(e.target).removeClass("new");
this.addBasicText(e);
}
Expand Down Expand Up @@ -2036,12 +2052,12 @@ define([
allBasicTexts = $(
".basic-text.new[data-category='" + category + "']",
);

//Only show one new row at a time
if (allBasicTexts.length == 1 && !allBasicTexts.val()) return;
else if (allBasicTexts.length > 1) return;
//We are only supporting one title right now
else if (category == "title") return;
else if (category === "title" || category === "canonicalDataset")
return;

//Add another blank text input
var newRow = $(document.createElement("div")).addClass(
Expand Down

0 comments on commit 4df698d

Please sign in to comment.