Skip to content

Commit

Permalink
Allow CrossRef as source dataset for CitationModel
Browse files Browse the repository at this point in the history
and add rendering of issue & volume for journal articles in the citation APA template

Issue #2541
  • Loading branch information
robyngit committed Oct 14, 2024
1 parent b5359d2 commit cd22959
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
57 changes: 47 additions & 10 deletions src/js/models/CitationModel.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
"use strict";

define(["jquery", "underscore", "backbone", "collections/Citations"], (
$,
_,
Backbone,
Citations,
) => {
define(["underscore", "backbone"], (_, Backbone) => {
/**
* @class CitationModel
* @classdesc A Citation Model represents a single Citation Object returned by
Expand Down Expand Up @@ -52,6 +47,8 @@ define(["jquery", "underscore", "backbone", "collections/Citations"], (
* published
* @property {number|string} volume - The volume of the journal where the
* document was published
* @property {number|string} issue - The issue of the journal where the
* document was published
* @property {number} page - The page of the journal where the document was
* published
* @property {Citations} citationMetadata - When this Citation Model refers
Expand Down Expand Up @@ -91,6 +88,7 @@ define(["jquery", "underscore", "backbone", "collections/Citations"], (
publisher: null,
journal: null,
volume: null,
issue: null,
page: null,
citationMetadata: null,
sourceModel: null,
Expand Down Expand Up @@ -118,6 +116,8 @@ define(["jquery", "underscore", "backbone", "collections/Citations"], (
pid: this.getPidFromSourceModel,
seriesId: this.getSeriesIdFromSourceModel,
originArray: this.getOriginArrayFromSourceModel,
volume: this.getVolumeFromSourceModel,
issue: this.getIssueFromSourceModel,
view_url: this.getViewUrlFromSourceModel,
};
},
Expand Down Expand Up @@ -412,10 +412,15 @@ define(["jquery", "underscore", "backbone", "collections/Citations"], (
*/
getYearFromSourceModel(sourceModel) {
try {
const year =
let year =
this.yearFromDate(sourceModel.get("pubDate")) ||
this.yearFromDate(sourceModel.get("dateUploaded")) ||
this.yearFromDate(sourceModel.get("datePublished"));
// for cross ref
const created = sourceModel.get("created");
if (!year && created) {
year = created?.["date-parts"]?.[0]?.[0];
}
return year;
} catch (error) {
console.log(
Expand Down Expand Up @@ -476,6 +481,12 @@ define(["jquery", "underscore", "backbone", "collections/Citations"], (
getJournalFromSourceModel(sourceModel) {
try {
let journal = null;
journal = sourceModel.get("journal");

// cross ref
journal = sourceModel.get("container-title")?.[0];
if (journal) return journal;

const datasource = sourceModel.get("datasource");
const mn = MetacatUI.nodeModel.getMember(datasource);
const currentMN = MetacatUI.nodeModel.get("currentMemberNode");
Expand Down Expand Up @@ -519,6 +530,8 @@ define(["jquery", "underscore", "backbone", "collections/Citations"], (
sourceModel.get("creator") ||
// If it's a science metadata model or solr results, use origin
sourceModel.get("origin") ||
// If it's a cross ref model, use author
sourceModel.get("author") ||
"";

// otherwise, this is probably a base D1 object model. Don't use
Expand Down Expand Up @@ -554,7 +567,11 @@ define(["jquery", "underscore", "backbone", "collections/Citations"], (
getPidFromSourceModel(sourceModel) {
try {
const pid =
sourceModel.get("id") || sourceModel.get("identifier") || null;
sourceModel.get("id") ||
sourceModel.get("identifier") ||
sourceModel.get("doi") ||
sourceModel.get("DOI") ||
null;
return pid;
} catch (error) {
console.log(
Expand Down Expand Up @@ -587,6 +604,26 @@ define(["jquery", "underscore", "backbone", "collections/Citations"], (
}
},

/**
* Get the volume from the sourceModel.
* @param {Backbone.Model} sourceModel - The model to get the volume from
* @returns {number|string} - The volume
* @since 0.0.0
*/
getVolumeFromSourceModel(sourceModel) {
return sourceModel.get("volume") || null;
},

/**
* Get the issue from the sourceModel.
* @param {Backbone.Model} sourceModel - The model to get the issue from
* @returns {number|string} - The issue
* @since 0.0.0
*/
getIssueFromSourceModel(sourceModel) {
return sourceModel.get("issue") || null;
},

/**
* Use the sourceModel's createViewURL() method to get the viewUrl for the
* citation. This method is built into DataONEObject models, SolrResult
Expand Down Expand Up @@ -1075,13 +1112,13 @@ define(["jquery", "underscore", "backbone", "collections/Citations"], (
/**
* Get the main identifier for the citation. This will check the model for
* the following attributes and return the first that is not empty: pid,
* seriesId, source_url.
* seriesId, source_url, doi, DOI
* @returns {string} Returns the main identifier for the citation or an
* empty string.
* @since 2.23.0
*/
getID() {
const idSources = ["pid", "seriesId", "source_url"];
const idSources = ["pid", "seriesId", "source_url", "doi", "DOI"];
for (let i = 0; i < idSources.length; i++) {
const id = this.get(idSources[i]);
if (id) return id;
Expand Down
15 changes: 11 additions & 4 deletions src/js/templates/citations/citationAPA.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@

let titleHTML = title ? `<span class="${titleClass}"${dataID}><i>${title}</i></span>. ` : '';

let journalHTML = journal ? `<span class="publisher">${journal}. </span>` : '';
let issueHTML = issue ? issue : '';
issueHTML = volume && issue ? `(${issue})` : '';

let volumeHTML = volume ? `<span class="publisher">Vol. ${volume}. </span>` : '';
let volumeIssueHTML = volume || issueHTML ? `<span class="volume">${volume}${issueHTML}</span>` : '';

let pageHTML = page ? `<span class="publisher">pp. ${page}. </span>` : '';
let pageHTML = page ? `<span class="page">${page}</span>` : '';

let journalHTML = journal || '';
journalHTML = volumeIssueHTML || pageHTML ? `${journalHTML}, ` : journalHTML;
journalHTML = volumeIssueHTML ? `${journalHTML}${volumeIssueHTML}` : journalHTML;
journalHTML = pageHTML ? `${journalHTML}, ${pageHTML}` : journalHTML;
journalHTML = journalHTML ? `<span class="publisher">${journalHTML}. </span>` : journalHTML;

let seriesIdHTML = seriesId || '';
if (seriesId) {
Expand All @@ -34,7 +41,7 @@
const idHTML = seriesIdHTML || pidHTML ? `<span class="id">${seriesIdHTML}${pidHTML}</span>` : '';

%>
<%= originHTML + pubHTML + titleHTML + journalHTML + volumeHTML + pageHTML + idHTML %>
<%= originHTML + pubHTML + titleHTML + journalHTML + idHTML %>
<%if(citationMetadata){%>
<br>
<span>Cites Data: </span>
Expand Down

0 comments on commit cd22959

Please sign in to comment.