Commit 58a814ff authored by Maxime Chaillet's avatar Maxime Chaillet

implement accessibility and content badge. It fixes #50.

parent 63c4aae7
......@@ -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";
};
......@@ -63,7 +63,7 @@ DOIController.prototype.getData = function(doi) {
if (!_this.isValidDOIData(data)) {
_this.view.renderError("Not Found", _this.origin);
} else {
var doiData = {};
var doiData = new DoiData();
doiData.title = data.title;
doiData.publisher = data.publisher;
doiData.creator = data.creator;
......@@ -71,6 +71,7 @@ DOIController.prototype.getData = function(doi) {
var jsonExtractor = new JsonExtractor();
doiData.mintingYear = jsonExtractor.getMintingYear(data);
doiData.sessionDate = jsonExtractor.getSessionDate(data);
doiData.publiclyAccessibleYear = data.publication_year;
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description");
doiData.proposalNumber = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
......@@ -82,6 +83,9 @@ DOIController.prototype.getData = function(doi) {
doiData.investigationId = jsonExtractor.extractInvestigationId(data);
doiData.accessMessage = _this.view.setDataAccessMessage(data);
doiData.citation = _this.createCitation(data);
doiData.resourceTypeGeneral = jsonExtractor.getResourceTypeGeneral(data);
doiData.resourceType = jsonExtractor.getResourceType(data);
doiData.accessibility = doiData.getAccessibilityStatus(doiData.sessionDate, doiData.publiclyAccessibleYear);
// Set the URL corresponding to the beamline name.
if (data.date_collected) {
......
......@@ -2,6 +2,7 @@ function DOIView() {
this.mainPanelId = "main";
this.reportPanelId = "expReport";
this.badgePanelId = "badges";
this.reportExperimentFileNames = null;
this.failedRecievingExpReport = false;
......@@ -24,11 +25,11 @@ 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 id='doiLink' 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>" );
};
/**
......@@ -36,7 +37,7 @@ DOIView.prototype.setDOI = function( doiCode ) {
*
*/
DOIView.prototype.setDOILink = function( doiLink ) {
$( "#doiLink" ).attr("href", doiLink.toUpperCase() );
$( "#doiLink" ).attr( "href", doiLink.toUpperCase() );
};
/**
......@@ -63,14 +64,14 @@ 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 render them after
* the rendering of the DOI
......@@ -135,6 +136,26 @@ 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" in experimental data box.
*
......
......@@ -6,8 +6,7 @@ function JsonExtractor( json ) {
* 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.
*/
......@@ -42,9 +41,9 @@ JsonExtractor.prototype.getFieldFromSubject = function( subject, field ) {
* 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 ) {
......@@ -59,10 +58,9 @@ JsonExtractor.prototype.getMintingYear = function( data ) {
* 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 ) {
......@@ -72,3 +70,32 @@ JsonExtractor.prototype.getSessionDate = function( data ) {
}
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;
};
<div class="col-12">
<div>
<span class="badge badge-success" style="font-size:14px;"> open Access </span>
{@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>
</div>
\ No newline at end of file
{/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,7 +134,7 @@
</div>
<div class="col-4">
<div id="badge" class="row"> </div>
<div id="badges" class="row py-4"> </div>
<br>
......
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