Commit 5a43330c authored by Maxime Chaillet's avatar Maxime Chaillet

Merge branch 'issue50' into 'master'

Issue50

Closes #50

See merge request !54
parents 1e3755c0 c4d92ee8
Pipeline #3093 passed with stages
in 1 minute and 14 seconds
......@@ -12,6 +12,7 @@
<script src="src/beamlineurl.js"></script>
<script src="src/citation.js"></script>
<script src="src/doicontroller.js"></script>
<script src="src/doiData.js"></script>
<script src="src/doiview.js"></script>
<script src="src/event.js"></script>
<script src="src/experimentalreportcontroller.js"></script>
......
This diff is collapsed.
This diff is collapsed.
function DoiData() {
}
/**
* Get the accessibility status
*
* */
DoiData.prototype.getAccessibilityStatus = function( sessionDate, publiclyAccessibleYear ) {
if ( publiclyAccessibleYear && sessionDate ) {
var publiclyAvailableDate = moment( publiclyAccessibleYear, "YYYY" );
var now = moment();
if ( now > publiclyAvailableDate ) {
return "Open access";
} else if ( now <= publiclyAvailableDate ) {
return "Under embargo";
}
}
console.log( "Failed to determine whether the accessibility of the DOI." );
return "Accessibility status could not be determined";
};
......@@ -57,32 +57,40 @@ DOIController.prototype.getData = function(doi) {
}
})
.done(function(doiData) {
if (doiData) {
.done(function(data) {
if (data) {
// Test abnormal length of the json object
if (!_this.isValidDOIData(doiData)) {
if (!_this.isValidDOIData(data)) {
_this.view.renderError("Not Found", _this.origin);
} else {
var doiData = new DoiData();
doiData.title = data.title;
doiData.publisher = data.publisher;
doiData.creator = data.creator;
var jsonExtractor = new JsonExtractor();
doiData.mintingYear = jsonExtractor.getMintingYear(doiData);
doiData.sessionDate = jsonExtractor.getSessionDate(doiData);
doiData.mintingYear = jsonExtractor.getMintingYear(data);
doiData.sessionDate = jsonExtractor.getSessionDate(data);
doiData.publiclyAccessibleYear = data.publication_year;
doiData.proposalType = jsonExtractor.getFieldFromSubject(doiData.subject, "Proposal Type Description");
doiData.proposalNumber = jsonExtractor.getFieldFromSubject(doiData.subject, "Proposal");
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description");
doiData.proposalNumber = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
_this.experimentalReportController.requestFilenameList(doiData.proposalNumber);
doiData.beamline = jsonExtractor.getFieldFromSubject(doiData.subject, "instrument");
doiData.beamline = jsonExtractor.getFieldFromSubject(data.subject, "instrument");
jsonExtractor.extractInvestigationId(doiData);
_this.view.setDataAccessMessage(doiData);
_this.createCitation(doiData);
doiData.investigationId = jsonExtractor.extractInvestigationId(data);
doiData.accessibility = doiData.getAccessibilityStatus(doiData.sessionDate, doiData.publiclyAccessibleYear);
doiData.accessMessage = _this.view.setDataAccessMessage(doiData);
doiData.citation = _this.createCitation(data);
doiData.resourceTypeGeneral = jsonExtractor.getResourceTypeGeneral(data);
doiData.resourceType = jsonExtractor.getResourceType(data);
// Set the URL corresponding to the beamline name.
if (doiData.date_collected) {
var experimentalDate = moment(doiData.date_collected);
if (data.date_collected) {
var experimentalDate = moment(data.date_collected);
doiData.beamlineUrl = _this.getBeamlineUrl(doiData.beamline, experimentalDate);
} else {
doiData.beamlineUrl = "noLink";
......@@ -170,6 +178,8 @@ DOIController.prototype.getBeamlineUrl = function(beamline, date) {
*
* @param {string}
* data: the data object, it is a reference
* @return {string}
* citation : the citation to be displayed
*/
DOIController.prototype.createCitation = function(data) {
// Authors sent in json can be in several format. The following call find
......@@ -177,16 +187,13 @@ DOIController.prototype.createCitation = function(data) {
var citation = new Citation(data);
if (!citation.isBuildable) {
data.citation = "The citation could not be generated.";
return "The citation could not be generated.";
} else {
var authorInCitation = citation.getAuthorsForCitation(data.creator);
var doiRegistrationYear = moment(data.date_registered).year();
var fullCitation = authorInCitation + ' (' + doiRegistrationYear + '). ' + data.title + '. ' + data.publisher + ' (ESRF). ' +
" <a href='https://doi.esrf.fr/" + data.doi + "'> doi:" + data.doi.toUpperCase() + "</a>";
data.citation = fullCitation;
return fullCitation;
}
};
......@@ -2,6 +2,7 @@ function DOIView() {
this.mainPanelId = "main";
this.reportPanelId = "expReport";
this.badgePanelId = "badges";
this.reportExperimentFileNames = null;
this.failedRecievingExpReport = false;
......@@ -24,23 +25,23 @@ DOIView.prototype.setLoading = function( message ) {
DOIView.prototype.setDOI = function( doiCode ) {
// $( "#doiPanel" ).text( doiCode.toUpperCase() );
$( "#doiPanel" ).html(
"<div class='col'> </div> " +
"<div class='col-auto mr-3 borderRadius-5 whiteBackground' style='padding:10px;'>" +
"<span class='doiBadge borderRadius-5 fontSize-20'> <a href=''>" +
doiCode.toUpperCase() +
"</a> </span> </div>");
"<div class='col'> </div> " +
"<div class='col-auto mr-3 borderRadius-5 whiteBackground' style='padding:10px;'>" +
"<span class='doiBadge borderRadius-5 fontSize-20'> <a id='doiLink' href=''>" +
doiCode.toUpperCase() +
"</a> </span> </div>" );
};
/**
* Set the doi http link in the doi landing page. It is the http adress at datacite server which will redirect to the DOI landing page.
* Set the doi http link in the doi landing page. It is the http address at datacite server which will redirect to the DOI landing page.
*
*/
DOIView.prototype.setDOILink = function( doiLink ) {
$( "#doiPanel" ).attr("href", doiLink.toUpperCase() );
$( "#doiLink" ).attr( "href", doiLink.toUpperCase() );
};
/**
* Render experimental Report data *
* Render experimental Report data
*
* @param {array}
* data The filename list to be displayed
......@@ -63,16 +64,17 @@ DOIView.prototype.renderExperimentalReportData = function( data ) {
}
};
DOIView.prototype.renderDOIData = function( doiData, target ) {
DOIView.prototype.renderDOIData = function( doiData ) {
var _this = this;
dust.render( 'landingpage_tpl', {
data: doiData
}, function( err, out ) {
$( '#' + _this.mainPanelId ).html( out );
_this.isDOIAlreadyRendered = true;
_this.renderBadges( doiData );
/**
* If there are experimental reports already retrieved then reder them after
* the rendering of the DOI *
* If there are experimental reports already retrieved then render them after
* the rendering of the DOI
*/
if ( _this.failedRecievingExpReport ) {
_this.renderErrorForExperimentalReport();
......@@ -134,20 +136,39 @@ DOIView.prototype.renderErrorForExperimentalReport = function() {
$( '#' + this.reportPanelId ).html( out );
};
/**
* Render the badge template in the corresponding div
*
* */
DOIView.prototype.renderBadges = function( data ) {
if ( data ) {
var _this = this;
dust.render( 'badges_tpl', {
data: data
}, function( err, out ) {
$( '#' + _this.badgePanelId ).html( out );
} );
}
};
/**
* Set the message which is displayed just above the "Access data button"
* Set the message which is displayed just above the "Access data button" in experimental data box.
*
* @param {object}
* data The json object reference.
* @return {string}
* the message to display
*/
DOIView.prototype.setDataAccessMessage = function( data ) {
var publicationDate = moment( data.publication_year, "YYYY" );
var now = moment();
if ( now > publicationDate ) {
data.accessMessage = "The data can be accessed by clicking on the link below";
} else {
data.accessMessage = "The data is under embargo until <b>" + data.publication_year + "</b> but could be released earlier. </p> " +
DOIView.prototype.setDataAccessMessage = function( doiData ) {
if ( doiData.accessibility === "Open access" ) {
return "The data can be accessed by clicking on the link below";
} else if ( doiData.accessibility === "Under embargo" ) {
return "The data is under embargo until <b>" + doiData.publiclyAccessibleYear + "</b> but could be released earlier. </p> " +
" <p> Currently, it is only accessible to proposal team members. </p>";
}
......
function JsonExtractor(json) {
function JsonExtractor( json ) {
}
/**
* Extract investigationId from the data.doi field as received from the json
* response. Add the corresponding fields in the data object
* response.
*
* @param {string}
* data The data object reference which is sent to the dustjs
* template
* data The data object provided by datacite
* @return {string}
* investigationId The investigationID requested for accessing data in ICAT.
*/
JsonExtractor.prototype.extractInvestigationId = function(data) {
var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);
data.investigationId = regExp.exec(data.doi)[1];
JsonExtractor.prototype.extractInvestigationId = function( data ) {
var regExp = RegExp( /\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/ );
return regExp.exec( data.doi )[1];
};
/**
* Extract field value (beamline, proposal number and proposal type) from the
* data json object. Returns nullif the field is not found.
* data json object. Returns null if the field is not found.
*
* @param {array}
* subject The array containing objects of interest template
* @param {string}
* field The text field which is searched
*/
JsonExtractor.prototype.getFieldFromSubject = function(subject, field) {
if (subject) {
if (subject[0]) {
for (var i = 0; i < subject[0].length; i++) {
if (subject[0][i].subject_scheme === field) {
return subject[0][i].text;
JsonExtractor.prototype.getFieldFromSubject = function( subject, field ) {
if ( subject ) {
if ( subject[0] ) {
for ( var i = 0; i < subject[0].length; i++ ) {
if ( subject[0][i].subject_scheme === field ) {
return subject[0][i].text;
}
}
}
}
}
}
return null;
return null;
};
/**
* Get minting year from the data object.
*
* @param {object}
* data The data object reference which is sent to the dustjs
* template
* @return {string} The minting year. Null if it does not exist.
* data The data object provided by datacite template
* @return {string}
* The minting year. Null if it does not exist.
*/
JsonExtractor.prototype.getMintingYear = function(data) {
if (data) {
if (data.date_registered && data.date_registered != null) {
return moment(data.date_registered).year();
JsonExtractor.prototype.getMintingYear = function( data ) {
if ( data ) {
if ( data.date_registered && data.date_registered != null ) {
return moment( data.date_registered ).year();
}
}
}
return null;
return null;
};
/**
* Get session date from the data object.
*
* @param {object}
* data The data object reference which is sent to the dustjs
* template
* @return {string} The formatted (YYY-M-D) session date. Null if it does not
* exist.
* data The data object provided by datacite
* @return {string}
* The formatted (YYY-M-D) session date. Null if it does not exist.
*/
JsonExtractor.prototype.getSessionDate = function(data) {
if (data) {
if (data.date_collected && data.date_collected != null) {
return moment(data.date_collected).format('YYYY-M-D');
JsonExtractor.prototype.getSessionDate = function( data ) {
if ( data ) {
if ( data.date_collected && data.date_collected != null ) {
return moment( data.date_collected ).format( 'YYYY-M-D' );
}
}
return null;
};
/**
* Get the resource type general
* @param {object}
* data The data object provided by datacite
* @return {string}
* The resource tyoe general. Null if it does not exist.
* */
JsonExtractor.prototype.getResourceTypeGeneral = function( data ) {
if ( data && data.resource_type_general ) {
return data.resource_type_general;
}
return null;
};
/**
* Get the resource type
* @param {object}
* data The data object provided by datacite
* @return {string}
* The resource tyoe. Null if it does not exist.
* */
JsonExtractor.prototype.getResourceType = function( data ) {
if ( data && data.resource_type ) {
return data.resource_type;
}
}
return null;
return null;
};
{@eq key=data.resourceTypeGeneral value="Dataset"}
{@eq key=data.resourceType value="Experiment Session"}
<div class="col-auto">
<span class="badge badge-secondary" style="font-size:14px;"> Dataset(s) / session </span>
</div>
{/eq}
{/eq}
{@eq key=data.accessibility value="Open access"}
<div class="col-auto">
<span class="badge badge-success" style="font-size:14px;"> Open access </span>
</div>
{/eq}
{@eq key=data.accessibility value="Under embargo"}
<div class="col-auto">
<span class="badge badge-warning" style="font-size:14px;"> Under embargo </span>
</div>
{/eq}
\ No newline at end of file
<div class="container-fluid">
<br />
<div class="row padding-top-15">
<div class="col-8">
<div class="row">
<div class="col-12 fontSize-20 text-center text-uppercase font-weight-bold">{data.title}</div>
<div class="col-12 fontSize-20 text-center text-uppercase font-weight-bold py-3">{data.title}</div>
</div>
<hr>
......@@ -135,6 +134,10 @@
</div>
<div class="col-4">
<div id="badges" class="row py-4"> </div>
<br>
<div class="row">
<div class="col-12">
<div class="card">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment