Skip to content

Commit

Permalink
Fetch citation info for canonical datasets
Browse files Browse the repository at this point in the history
using the new CrossRef model

Issue #2541
  • Loading branch information
robyngit committed Oct 14, 2024
1 parent cd22959 commit 5c124bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/js/models/CitationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,13 @@ define(["underscore", "backbone"], (_, Backbone) => {
}
return "";
},

/** Set the model back to its defaults */
reset() {
this.clear({ silent: true });
this.set(this.defaults(), { silent: true });
this.trigger("change");
},
},
);

Expand Down
1 change: 1 addition & 0 deletions src/js/models/CrossRefModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ define(["backbone"], (Backbone) => {
const cachedResponse = this.getCachedResponse(doi);
if (cachedResponse) {
this.set(cachedResponse);
this.trigger("sync");
return;
}

Expand Down
26 changes: 17 additions & 9 deletions src/js/views/CanonicalDatasetHandlerView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
define(["backbone", "models/CitationModel"], (Backbone, CitationModel) => {
define(["backbone", "models/CitationModel", "models/CrossRefModel"], (
Backbone,
CitationModel,
CrossRefModel,
) => {
// The "Type" property of the annotation view
const ANNO_VIEW_TYPE = "AnnotationView";
// The URI for the schema.org:sameAs annotation
Expand Down Expand Up @@ -101,6 +105,7 @@ define(["backbone", "models/CitationModel"], (Backbone, CitationModel) => {
*/
initialize(options) {
this.metadataView = options?.metadataView;
this.citationModel = new CitationModel();
if (!this.metadataView) {
throw new Error(
"The CanonicalDatasetHandlerView requires a MetadataView instance.",
Expand Down Expand Up @@ -130,6 +135,7 @@ define(["backbone", "models/CitationModel"], (Backbone, CitationModel) => {
this.fieldItem?.remove();
this.infoIcon?.remove();
this.showAnnotations();
this.citationModel.reset();
},

/**
Expand Down Expand Up @@ -191,9 +197,14 @@ define(["backbone", "models/CitationModel"], (Backbone, CitationModel) => {
* this information in a CitationModel instance.
*/
getCitationInfo() {
// TODO: Get citation info from the canonical dataset
// what API can we use to get this info?
// this.citationModel = new CitationModel({});
const view = this;
this.crossRef = new CrossRefModel({
doi: this.canonicalUri,
});
this.listenToOnce(this.crossRef, "sync", () => {
view.citationModel.setSourceModel(this.crossRef);
});
this.crossRef.fetch();
},

/**
Expand Down Expand Up @@ -264,6 +275,7 @@ define(["backbone", "models/CitationModel"], (Backbone, CitationModel) => {
* current dataset.
*/
modifyCitationModal() {
const view = this;
// The CitationModalView is recreated each time it is shown.
const citationModalView = this.metadataView[CITATION_MODAL_PROP];
this.listenToOnce(citationModalView, "rendered", () => {
Expand All @@ -277,11 +289,7 @@ define(["backbone", "models/CitationModel"], (Backbone, CitationModel) => {
const headingOriginal = document.createElement("h5");
headingOriginal.textContent = CITATION_TITLE_CANONICAL;
citationModalView.citationContainer.append(headingOriginal);

const testCitationModel = new CitationModel({
// TODO: Add citation info for the canonical dataset
});
citationModalView.insertCitation(testCitationModel);
citationModalView.insertCitation(view.citationModel);
});
},

Expand Down

0 comments on commit 5c124bd

Please sign in to comment.