Commit fbcf9f9f authored by Maxime Chaillet's avatar Maxime Chaillet
Browse files

reshape doiController. Write tests on getBeamlineUrl(). It fixes icat/doi-landing-page#55

parent 14e1ad71
// Karma configuration
// Generated on Thu Oct 11 2018 23:09:22 GMT+0200 (CEST)
module.exports = function(config) {
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
......@@ -15,10 +15,18 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
'src/jsonextractor.js',
'src/beamlineurl.js',
'src/constants.js',
'src/doicontroller.js',
'src/doiview.js',
'src/experimentalreportcontroller.js',
'src/event.js',
'src/jsonextractor.js',
'tests/jsonExtractor.test.js',
'bower_components/lodash/lodash.js'
'tests/doiController.test.js',
'bower_components/lodash/lodash.js',
'bower_components/moment/moment.js'
],
......@@ -30,7 +38,7 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'tests/jsonExtractor.test.js': [ 'browserify' ]
'tests/jsonExtractor.test.js': ['browserify']
},
......@@ -59,7 +67,7 @@ module.exports = function(config) {
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox', 'Chrome' ],
browsers: ['Firefox', 'Chrome'],
// Continuous Integration mode
......
This diff is collapsed.
......@@ -3,5 +3,5 @@
(function(dust){dust.register("doinotfound2_tpl",body_0);function body_0(chk,ctx){return chk.f(ctx.get(["message"], false),ctx,"h",["s"]);}body_0.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("experimentalreport_tpl",body_0);function body_0(chk,ctx){return chk.w("<div class=\"card-header text-center\"><label>Experimental report </label></div><div class=\"card-body padding10\">").x(ctx.get(["data"], false),ctx,{"else":body_1,"block":body_2},{});}body_0.__dustBody=!0;function body_1(chk,ctx){return chk.w("<p class=\"card-text\"> There is currently no experimental report. </p></div>");}body_1.__dustBody=!0;function body_2(chk,ctx){return chk.h("eq",ctx,{"block":body_3},{"key":ctx.getPath(false, ["data","length"]),"value":1},"h").h("gt",ctx,{"block":body_4},{"key":ctx.getPath(false, ["data","length"]),"value":1},"h").w(" ");}body_2.__dustBody=!0;function body_3(chk,ctx){return chk.w("<p class=\"card-text\"> <b> One </b> report has been found for this proposal. </p></div><div class=\"card-body\"> <button type=\"button\" class=\"btn btn-primary btn-lg btn-block\" onclick=\"javascript:(function(){ var expRep = new ExperimentalReportController(); expRep.openFileInNewTab('").f(ctx.getPath(false, ["data","0"]),ctx,"h").w("'); })()\" > <span class=\"fa fa-download whiteFont\"></span> ").f(ctx.getPath(false, ["data","0"]),ctx,"h").w(" </button></div>");}body_3.__dustBody=!0;function body_4(chk,ctx){return chk.w("<p class=\"card-text\"> In total, <b> ").f(ctx.getPath(false, ["data","length"]),ctx,"h").w(" </b> reports have been found for this proposal: </p></div> <div class=\"card-body\"><div class=\"scroll-box\">").s(ctx.get(["data"], false),ctx,{"block":body_5},{}).w("</div> </div>");}body_4.__dustBody=!0;function body_5(chk,ctx){return chk.w(" ").h("sep",ctx,{"block":body_6},{},"h").h("last",ctx,{"block":body_7},{},"h");}body_5.__dustBody=!0;function body_6(chk,ctx){return chk.w("<div class=\"row\"> <div class=\"col-1\"> </div><div class=\"col-10 padding-bottom-10\"><button type=\"button\" class=\"btn btn-primary btn-lg btn-block\" onclick=\"javascript:(function(){ var expRep = new ExperimentalReportController(); expRep.openFileInNewTab('").f(ctx.getPath(true, []),ctx,"h").w("'); })()\" > <span class=\"fa fa-download whiteFont\"></span> <span class=\"whitefont\"> ").f(ctx.getPath(true, []),ctx,"h").w("</span> </button></div><div class=\"col-1\"> </div> </div>");}body_6.__dustBody=!0;function body_7(chk,ctx){return chk.w("<div class=\"row\"> <div class=\"col-1\"> </div><div class=\"col-10\"><button type=\"button\" class=\"btn btn-primary btn-lg btn-block\" onclick=\"javascript:(function(){ var expRep = new ExperimentalReportController(); expRep.openFileInNewTab('").f(ctx.getPath(true, []),ctx,"h").w("'); })()\" > <span class=\"fa fa-download whiteFont\"></span> <span class=\"whitefont\"> ").f(ctx.getPath(true, []),ctx,"h").w("</span> </button></div><div class=\"col-1\"> </div> </div>");}body_7.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("landingpage_tpl",body_0);function body_0(chk,ctx){return chk.w("<div class=\"container-fluid\"><div class=\"row padding-top-15\"><div class=\"col-12 col-md-9\"><div class=\"row\"><div class=\"col-12\"><div id=\"badges\"> </div> </div></div><div class=\"row\"><div class=\"col-12 fontSize-20 text-center text-uppercase font-weight-bold py-3\">").f(ctx.getPath(false, ["data","title"]),ctx,"h").w("</div></div><div class=\"row\"><div class=\"col-12\"><div class=\"myBorder-left\"><div><cite>").s(ctx.getPath(false, ["data","creator"]),ctx,{"block":body_1},{}).w("</cite></div></div></div></div><div class=\"padding-top-15\"></div></div><div class=\"col-12 col-md-3\"><div class=\"card\"><div class=\"card-body\"><div class=\"card-text\"><label> DOI </label><div class=\"padding-left-15\"> <span class=\"doiBadge borderRadius-5 font-1p4rem\"> <a id=\"doiLink\" href=").f(ctx.getPath(false, ["data","dataciteLink"]),ctx,"h").w("> ").f(ctx.getPath(false, ["data","doi"]),ctx,"h").w(" </a></span> </div><label class=\"padding-top-5\"> Licence (for files) </label><div class=\"padding-left-15\"><p> <a href=\"https://creativecommons.org/licenses/by/4.0/\"> Creative Commons Attribution 4.0 </a> </p></div> </div></div></div></div></div><hr> <div id=\"metadata\"> </div><hr><div class=\"row\"><div class=\"col-12\"> <div class=\"card\" id=\"expReport\"><div class=\"card-header text-center\"><label>Experimental report </label></div></div></div></div><br><div class=\"row\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header text-center\"><label>Experimental data </label></div><div class=\"card-body padding10\"><p class=\"card-text\" >").f(ctx.getPath(false, ["data","accessMessage"]),ctx,"h",["s"]).w("</p></div><div class=\"card-body\"><div class=\"row\"><div class=\"col-1\"> </div><div class=\"col-10\"><form action=\"https://icat.esrf.fr/#/browse/facility/ESRF/proposal/").f(ctx.getPath(false, ["data","proposalName"]),ctx,"h").w("/investigation/").f(ctx.getPath(false, ["data","investigationId"]),ctx,"h").w("/dataset\" target=\"_blank\"><button type=\"submit\" class=\"btn btn-primary btn-lg btn-block\"> Access data </button></form></div><div class=\"col-1\"> </div></div></div></div> </div></div><hr><div class=\"row\"><div class=\"col-12\"><div class=\"myBorder-left\"><label class=\"greyGradientToRight padding-left-10 padding-right-20\"> Citation </label><div class=\"padding-left-25\"><p> Below is the recommended format for citing this work in a research publication.</p><div class=\"padding-left-25\"><cite> ").f(ctx.getPath(false, ["data","citation"]),ctx,"h",["s"]).w(" </cite></div></div></div> </div></div></div>");}body_0.__dustBody=!0;function body_1(chk,ctx){return chk.h("sep",ctx,{"block":body_2},{},"h").h("last",ctx,{"block":body_5},{},"h");}body_1.__dustBody=!0;function body_2(chk,ctx){return chk.x(ctx.getPath(true, ["givenName"]),ctx,{"else":body_3,"block":body_4},{});}body_2.__dustBody=!0;function body_3(chk,ctx){return chk.w(" ").f(ctx.getPath(true, ["name"]),ctx,"h").w(" ; ");}body_3.__dustBody=!0;function body_4(chk,ctx){return chk.w(" ").f(ctx.getPath(true, ["givenName"]),ctx,"h").w(" ").f(ctx.getPath(true, ["familyName"]),ctx,"h").w(" ; ");}body_4.__dustBody=!0;function body_5(chk,ctx){return chk.x(ctx.getPath(true, ["givenName"]),ctx,{"else":body_6,"block":body_7},{});}body_5.__dustBody=!0;function body_6(chk,ctx){return chk.w(" ").f(ctx.getPath(true, ["name"]),ctx,"h").w(". ");}body_6.__dustBody=!0;function body_7(chk,ctx){return chk.w(" ").f(ctx.getPath(true, ["givenName"]),ctx,"h").w(" ").f(ctx.getPath(true, ["familyName"]),ctx,"h").w(". ");}body_7.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("metadata_tpl",body_0);function body_0(chk,ctx){return chk.h("eq",ctx,{"block":body_1},{"key":ctx.getPath(false, ["data","resourceType"]),"value":ctx.getPath(false, ["data","ES_RESOURCE_TYPE"])},"h").h("eq",ctx,{"block":body_17},{"key":ctx.getPath(false, ["data","resourceType"]),"value":ctx.getPath(false, ["data","DC_RESOURCE_TYPE"])},"h").w(" ");}body_0.__dustBody=!0;function body_1(chk,ctx){return chk.w("<div class=\"row\">").x(ctx.getPath(false, ["data","mergedProposalBeamlines"]),ctx,{"block":body_2},{}).w("</div><hr> <div class=\"row\"><div class=\"col-12\">").h("abstract",ctx,{"block":body_16},{"abstract":ctx.getPath(false, ["data","abstract"])},"h").w("</div></div>");}body_1.__dustBody=!0;function body_2(chk,ctx){return chk.x(ctx.getPath(false, ["data","mergedProposalBeamlines","0"]),ctx,{"block":body_3},{});}body_2.__dustBody=!0;function body_3(chk,ctx){return chk.w("<div class=\"col\"><div class=\"myBorder-left\"><label> Proposal </label>").x(ctx.getPath(false, ["data","mergedProposalBeamlines","0","proposal"]),ctx,{"else":body_4,"block":body_5},{}).w("</div></div><div class=\"col\"><div class=\"myBorder-left\"><label> Publication year </label>").x(ctx.getPath(false, ["data","mintingYear"]),ctx,{"else":body_6,"block":body_7},{}).w("</div></div><div class=\"col\"><div class=\"myBorder-left\"><label> Beamline </label> ").x(ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamline"]),ctx,{"else":body_8,"block":body_9},{}).w("</div></div><div class=\"col\"><div class=\"myBorder-left\"><label> Session date </label>").x(ctx.getPath(false, ["data","sessionDate"]),ctx,{"else":body_12,"block":body_13},{}).w("</div></div> <div class=\"col-4\"><div class=\"myBorder-left\"><label>Category </label>").x(ctx.getPath(false, ["data","proposalType"]),ctx,{"else":body_14,"block":body_15},{}).w("</div></div> ");}body_3.__dustBody=!0;function body_4(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_4.__dustBody=!0;function body_5(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","mergedProposalBeamlines","0","proposal"]),ctx,"h").w("</div>");}body_5.__dustBody=!0;function body_6(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_6.__dustBody=!0;function body_7(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","mintingYear"]),ctx,"h").w("</div>");}body_7.__dustBody=!0;function body_8(chk,ctx){return chk.w("<div class=\"padding-left-15\">Not available</div>");}body_8.__dustBody=!0;function body_9(chk,ctx){return chk.h("eq",ctx,{"else":body_10,"block":body_11},{"key":ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamlineUrl"]),"value":"noLink"},"h");}body_9.__dustBody=!0;function body_10(chk,ctx){return chk.w("<div class=\"padding-left-15\"><a href=\"").f(ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamlineUrl"]),ctx,"h").w("\" target=\"_blank\"> ").f(ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamline"]),ctx,"h").w(" </a></div>");}body_10.__dustBody=!0;function body_11(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamline"]),ctx,"h").w("</div>");}body_11.__dustBody=!0;function body_12(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_12.__dustBody=!0;function body_13(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","sessionDate"]),ctx,"h").w("</div>");}body_13.__dustBody=!0;function body_14(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_14.__dustBody=!0;function body_15(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","proposalType"]),ctx,"h").w("</div>");}body_15.__dustBody=!0;function body_16(chk,ctx){return chk.w(" ");}body_16.__dustBody=!0;function body_17(chk,ctx){return chk.w("<div class=\"container-fluid\"><div class=\"row\"><div class=\"col-md-12 col-xl-8\">").h("abstract",ctx,{"block":body_18},{"abstract":ctx.getPath(false, ["data","abstract"])},"h").w("</br></div><div class=\"col-sm-6 col-xl-2\"><div class=\"myBorder-left\">").h("proposalBeamlineTable",ctx,{"block":body_19},{"mergedProposalBeamlines":ctx.getPath(false, ["data","mergedProposalBeamlines"])},"h").w("</div></div><div class=\"col-sm-6 col-xl-2\"><div class=\"myBorder-left\"><label> Publication year </label>").x(ctx.getPath(false, ["data","mintingYear"]),ctx,{"else":body_20,"block":body_21},{}).w("</div></div></div></div>");}body_17.__dustBody=!0;function body_18(chk,ctx){return chk.w(" ");}body_18.__dustBody=!0;function body_19(chk,ctx){return chk.w(" ");}body_19.__dustBody=!0;function body_20(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_20.__dustBody=!0;function body_21(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","mintingYear"]),ctx,"h").w("</div>");}body_21.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("metadata_tpl",body_0);function body_0(chk,ctx){return chk.h("eq",ctx,{"block":body_1},{"key":ctx.getPath(false, ["data","resourceType"]),"value":ctx.getPath(false, ["constants","ES_RESOURCE_TYPE"])},"h").h("eq",ctx,{"block":body_17},{"key":ctx.getPath(false, ["data","resourceType"]),"value":ctx.getPath(false, ["constants","DC_RESOURCE_TYPE"])},"h").w(" ");}body_0.__dustBody=!0;function body_1(chk,ctx){return chk.w("<div class=\"row\">").x(ctx.getPath(false, ["data","mergedProposalBeamlines"]),ctx,{"block":body_2},{}).w("</div><hr> <div class=\"row\"><div class=\"col-12\">").h("abstract",ctx,{"block":body_16},{"abstract":ctx.getPath(false, ["data","abstract"])},"h").w("</div></div>");}body_1.__dustBody=!0;function body_2(chk,ctx){return chk.x(ctx.getPath(false, ["data","mergedProposalBeamlines","0"]),ctx,{"block":body_3},{});}body_2.__dustBody=!0;function body_3(chk,ctx){return chk.w("<div class=\"col\"><div class=\"myBorder-left\"><label> Proposal </label>").x(ctx.getPath(false, ["data","mergedProposalBeamlines","0","proposal"]),ctx,{"else":body_4,"block":body_5},{}).w("</div></div><div class=\"col\"><div class=\"myBorder-left\"><label> Publication year </label>").x(ctx.getPath(false, ["data","mintingYear"]),ctx,{"else":body_6,"block":body_7},{}).w("</div></div><div class=\"col\"><div class=\"myBorder-left\"><label> Beamline </label> ").x(ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamline"]),ctx,{"else":body_8,"block":body_9},{}).w("</div></div><div class=\"col\"><div class=\"myBorder-left\"><label> Session date </label>").x(ctx.getPath(false, ["data","sessionDate"]),ctx,{"else":body_12,"block":body_13},{}).w("</div></div> <div class=\"col-4\"><div class=\"myBorder-left\"><label>Category </label>").x(ctx.getPath(false, ["data","proposalType"]),ctx,{"else":body_14,"block":body_15},{}).w("</div></div> ");}body_3.__dustBody=!0;function body_4(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_4.__dustBody=!0;function body_5(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","mergedProposalBeamlines","0","proposal"]),ctx,"h").w("</div>");}body_5.__dustBody=!0;function body_6(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_6.__dustBody=!0;function body_7(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","mintingYear"]),ctx,"h").w("</div>");}body_7.__dustBody=!0;function body_8(chk,ctx){return chk.w("<div class=\"padding-left-15\">Not available</div>");}body_8.__dustBody=!0;function body_9(chk,ctx){return chk.h("eq",ctx,{"else":body_10,"block":body_11},{"key":ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamlineUrl"]),"value":"noLink"},"h");}body_9.__dustBody=!0;function body_10(chk,ctx){return chk.w("<div class=\"padding-left-15\"><a href=\"").f(ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamlineUrl"]),ctx,"h").w("\" target=\"_blank\"> ").f(ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamline"]),ctx,"h").w(" </a></div>");}body_10.__dustBody=!0;function body_11(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","mergedProposalBeamlines","0","beamline"]),ctx,"h").w("</div>");}body_11.__dustBody=!0;function body_12(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_12.__dustBody=!0;function body_13(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","sessionDate"]),ctx,"h").w("</div>");}body_13.__dustBody=!0;function body_14(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_14.__dustBody=!0;function body_15(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","proposalType"]),ctx,"h").w("</div>");}body_15.__dustBody=!0;function body_16(chk,ctx){return chk.w(" ");}body_16.__dustBody=!0;function body_17(chk,ctx){return chk.w("<div class=\"container-fluid\"><div class=\"row\"><div class=\"col-md-12 col-xl-8\">").h("abstract",ctx,{"block":body_18},{"abstract":ctx.getPath(false, ["data","abstract"])},"h").w("</br></div><div class=\"col-sm-6 col-xl-2\"><div class=\"myBorder-left\">").h("proposalBeamlineTable",ctx,{"block":body_19},{"mergedProposalBeamlines":ctx.getPath(false, ["data","mergedProposalBeamlines"])},"h").w("</div></div><div class=\"col-sm-6 col-xl-2\"><div class=\"myBorder-left\"><label> Publication year </label>").x(ctx.getPath(false, ["data","mintingYear"]),ctx,{"else":body_20,"block":body_21},{}).w("</div></div></div></div>");}body_17.__dustBody=!0;function body_18(chk,ctx){return chk.w(" ");}body_18.__dustBody=!0;function body_19(chk,ctx){return chk.w(" ");}body_19.__dustBody=!0;function body_20(chk,ctx){return chk.w("<div class=\"padding-left-15\"> Not available</div>");}body_20.__dustBody=!0;function body_21(chk,ctx){return chk.w("<div class=\"padding-left-15\">").f(ctx.getPath(false, ["data","mintingYear"]),ctx,"h").w("</div>");}body_21.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("welcome_tpl",body_0);function body_0(chk,ctx){return chk.w(" <div class=\"container-fluid\"><div class=\"row\"><div class=\"col-12 flexCentered whiteFont\" style=\"color:#132577; font-size: 6.4rem; height: 200px; margin-top: 10px; margin-bottom: 10px;\">ESRF DOI Portal</div></div></div><div class=\"container-fluid\"><div class=\"row\"><div class=\"col-12 col-md-4\"><div class=\"padding10\"><div class=\"card-header text-center\"><h1 class=\"font-3p2rem\">About the portal</h1></div><div class=\"card-body padding10\">This page centralizes the <a href=\"http://www.esrf.eu/home/UsersAndScience/UserGuide/esrf-data-policy/doi.html\" target=\"_blank\"> DOI</a> services offered by the ESRF to access data stored at the facility as part of its data policy. Data referred to by ESRF DOIs are accessed via the ESRF data catalogue <a href=\"https://icat.esrf.fr\" target=\"_blank\"> icat.esrf.fr</a>.<p> In case you require a DOI for a subset of data please send an email with the following high level metadata - \"proposal\", \"title\", \"authors\", \"abstract\", \"datasets\" to datapolicy@esrf.fr </p></div></div></div><div class=\"col-12 col-md-4\"><div class=\"padding10\"><div class=\"card-header text-center \"><h1 class=\"font-3p2rem\">DOI resolver</h1></div><div class=\"card-body padding10\"><p>The search engine below only searches DOIs which have been minted at the ESRF. </br> Use <a href=\"https://doi.org\">doi.org </a> search engine for other DOIs.</p><div class=\"row\"><div class=\"col-xl-9 padding-right-0\"><p> <input id=\"doiSearchBox\" class=\"form-control\" placeholder=\"10.15151/ESRF-ES-90632078\" type=\"text\" required/> </p><div class=\"text-danger\" id=\"error\"> </div> </div><div class=\"col padding-left-0\"> <input class=\"btn btn-primary\" type=\"submit\" value=\"Search\" onclick=\"searchDOI()\" /> </div></div><div class=\"row\"><div class=\"col\"><p> <a href=\"https://search.datacite.org/works?query=10.15151\"> List all ESRF DOIs </a> </p></div></div></div> </div></div><div class=\"col-12 col-md-4\"><div class=\"padding10\"><div class=\"card-header text-center\"><h1 class=\"font-3p2rem\">About DOI </h1></div><div class=\"card-body padding10\">The Digital Object Identifier (<a href=\"http://www.esrf.eu/home/UsersAndScience/UserGuide/esrf-data-policy/doi.html\">DOI</a>) is a code composed of digits and characters. It identifies data in a unique and permanent way thereby allowing data to be referenced worldwide. The DOI has two parts, namely the DOI prefix and the DOI suffix separated by a slash (\"/\"). The ESRF prefix is 10.15151 followed by a slash and the ESRF suffix. Currently the following suffix(es) are defined:</p><pre>ESRF-ES - for a session at the ESRF </pre>Refer to the <a href=\"http://www.esrf.eu/home/UsersAndScience/UserGuide/esrf-data-policy/doi/doi---concepts.html\">DOI concepts</a> page to find out what a session is.</div></div></div></div></div>");}body_0.__dustBody=!0;return body_0}(dust));
\ No newline at end of file
......@@ -2,5 +2,3 @@ var CONSTANTS = {
ES_RESOURCE_TYPE : "experimental session resource type",
DC_RESOURCE_TYPE : "dataset collection resource type"
};
\ No newline at end of file
//module.exports = CONSTANTS;
function DoiData() {
function DoiData(title, doi, dataciteLink, publisher, creator, publication_year) {
this.title = title;
this.doi = doi;
this.dataciteLink = dataciteLink;
this.publisher = publisher;
this.creator = creator;
this.publiclyAccessibleYear = publication_year;
}
/**
* Get the accessibility status
* @param {string} resourceType the resource type for this DOI
......
function DOIController(view) {
var _this = this;
// doiServer = the server which provides doi details from a given doi name.
//this.doiServer = "https://data.datacite.org/";
this.doiServer = "https://api.test.datacite.org/";
this.doiServer = "https://data.datacite.org/";
// 10.5072 is the test esrf doi prefix;
......@@ -50,9 +49,8 @@ DOIController.prototype.getData = function (doi) {
timeout: 15000, // triggers timeout when request pends longer than
// 5000ms
url: this.doiServer + doi,
beforeSend: function (xhr) {
beforeSend: function () {
_this.view.setLoading("Retrieving data from Server");
xhr.setRequestHeader("Authorization", "Basic " + btoa("DATACITE.ESRF" + ":" + "datacyte1")); // to be removed as well as the parameter
},
complete: function () {
_this.view.setLoading(false);
......@@ -65,56 +63,37 @@ DOIController.prototype.getData = function (doi) {
if (!_this.isValidDOIData(data)) {
_this.view.renderError("Not Found", _this.origin);
} else {
var doiData = new DoiData();
doiData.title = data.title;
doiData.doi = data.doi.toUpperCase();
doiData.dataciteLink = _this.doiServer + doi;
doiData.publisher = data.publisher;
doiData.creator = data.creator;
// Extract data and fill doiData with it
var doiData = new DoiData(data.title, data.doi.toUpperCase(), _this.doiServer + doi, data.publisher, data.creator, data.publication_year);
var jsonExtractor = new JsonExtractor();
doiData.abstract = jsonExtractor.getAbstract(data);
doiData.investigationId = jsonExtractor.extractInvestigationId(data);
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.proposalNames = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
console.log(doiData.proposalNames);
_this.experimentalReportController.requestFilenameList(doiData.proposalName);
doiData.resourceType = jsonExtractor.getResourceType(data);
doiData.resourceTypeGeneral = jsonExtractor.getResourceTypeGeneral(data);
doiData.sessionDate = jsonExtractor.getSessionDate(data);
doiData.beamlines = jsonExtractor.getFieldFromSubject(data.subject, "Instrument");
var proposalNames = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
var beamlines = jsonExtractor.getFieldFromSubject(data.subject, "Instrument");
doiData.investigationId = jsonExtractor.extractInvestigationId(data);
doiData.resourceType = jsonExtractor.getResourceType(data);
_this.experimentalReportController.requestFilenameList(proposalNames[0]);
doiData.accessibility = doiData.getAccessibilityStatus(doiData.resourceType, doiData.sessionDate, doiData.publiclyAccessibleYear);
doiData.accessMessage = _this.view.setDataAccessMessage(doiData);
doiData.citation = _this.createCitation(data);
doiData.resourceTypeGeneral = jsonExtractor.getResourceTypeGeneral(data);
// constants passed for tests in the templates
doiData.DC_RESOURCE_TYPE = CONSTANTS.DC_RESOURCE_TYPE;
doiData.ES_RESOURCE_TYPE = CONSTANTS.ES_RESOURCE_TYPE;
// Set the URL corresponding to the beamline name.
if (doiData.resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
if (data.date_collected) {
var experimentalDate = moment(data.date_collected);
doiData.beamlineUrls = _this.getBeamlineUrl(doiData.beamlines, experimentalDate);
}
doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, data.date_collected, doiData.resourceType);
}
if (doiData.resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
if (data.publication_year) {
var publicationDate = moment(data.publication_year, "YYYY");
doiData.beamlineUrls = _this.getBeamlineUrl(doiData.beamlines, publicationDate);
}
doiData.beamlineUrls = _this.getBeamlineUrl(beamlines, data.publication_year, doiData.resourceType);
}
doiData.mergedProposalBeamlines = jsonExtractor.getMergedProposalAndBeamline(doiData.proposalNames, doiData.beamlines, doiData.beamlineUrls);
// Create a table containing unique tuples [proposal, beamline, beamlineUrl]
doiData.mergedProposalBeamlines = jsonExtractor.getMergedProposalAndBeamline(proposalNames, beamlines, doiData.beamlineUrls);
// send to dust render
_this.view.renderDOIData(doiData);
}
}
......@@ -169,16 +148,25 @@ DOIController.prototype.setOrigin = function (origin) {
};
/**
* Get the corresponding url for a given beamline name
* @param {array} beamlines The beamline name
* @param {momentJS} date The date the experiment was performed.
* @return {array} an array containing urls of the beamLine(s).
*/
DOIController.prototype.getBeamlineUrl = function (beamlines, date) {
* Get the corresponding url for a given beamline name
* @param {array} beamlines The beamlines
* @param {momentJS} date The date the experiment was performed.
* @param {String} resourceType the data resource type
* @return {array} an array containing urls of the beamLine(s).
*/
DOIController.prototype.getBeamlineUrl = function (beamlines, date, resourceType) {
var result = [];
beamlines.forEach(function (beamline) {
for (var i = 0; i < BEAMLINEURL.length; i++) {
if (date) {
if (resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
date = moment(date);
}
if (resourceType === CONSTANTS.DC_RESOURCE_TYPE) {
date = moment(date, "YYYY");
}
var foundUrl = "";
for (var i = 0; i < BEAMLINEURL.length; i++) {
var startDate = moment(BEAMLINEURL[i].startDate);
var endDate = moment(BEAMLINEURL[i].endDate);
if (BEAMLINEURL[i].name.toLowerCase() === beamline.toLowerCase() && date >= startDate && date <= endDate) {
......@@ -187,10 +175,14 @@ DOIController.prototype.getBeamlineUrl = function (beamlines, date) {
}
}
if (foundUrl === "") {
result.push("no link");
result.push("noLink");
} else {
result.push(foundUrl);
}
} else {
result.push("noLink");
}
});
return result;
};
......
......@@ -154,7 +154,8 @@ DOIView.prototype.renderMetadata = function (data) {
if (data) {
var _this = this;
dust.render('metadata_tpl', {
data: data
data: data,
constants : CONSTANTS
}, function (err, out) {
$('#' + _this.metadataDivId).html(out);
});
......
......@@ -8,17 +8,13 @@ function ExperimentalReportController() {
/**
* Request the experimental report filename list for the given proposal
*
* @param {string}
* proposal The proposal
*
* @param {string} proposal The proposal
*/
ExperimentalReportController.prototype.requestFilenameList = function(proposal) {
var _this = this;
if (proposal) {
// extract the proposal LetterCode (before the hyphen) and the digits (after
// the hyphen)
aroundHyphenRegExp = new RegExp(/^(.*)-(.*)/);
// extract the proposal LetterCode (before the hyphen) and the digits (after the hyphen)
var aroundHyphenRegExp = new RegExp(/^(.*)-(.*)/);
var beforeHyphen = aroundHyphenRegExp.exec(proposal)[1];
var afterHyphen = aroundHyphenRegExp.exec(proposal)[2];
......
{! Presentation of the metadata for the DOI which are from sessions !}
{@eq key=data.resourceType value=data.ES_RESOURCE_TYPE}
{@eq key=data.resourceType value=constants.ES_RESOURCE_TYPE}
<div class="row">
{?data.mergedProposalBeamlines}
{?data.mergedProposalBeamlines[0]}
......@@ -78,7 +78,7 @@
{! Presentation of the metadata for the DOI which are from dataset collections !}
{@eq key=data.resourceType value=data.DC_RESOURCE_TYPE}
{@eq key=data.resourceType value=constants.DC_RESOURCE_TYPE}
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-xl-8">
......
describe("Tests on doi controller", () => {
describe("getBeamlineUrl()", () => {
it("return beamlineurl for a 'ES' doi", () => {
let actualBeamlines = ['ID11'];
let actualDate = "2018-03-07"
let actualResourceType = CONSTANTS.ES_RESOURCE_TYPE;
let expectedBeamlineUrls = ["http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11"];
myDoiController = new DOIController(null);
expect(myDoiController.getBeamlineUrl(actualBeamlines, actualDate, actualResourceType)).toEqual(expectedBeamlineUrls);
})
it("return beamlineurl for a 'ES' doi without date", () => {
let actualBeamlines = ['ID11'];
let actualDate = null;
let actualResourceType = CONSTANTS.ES_RESOURCE_TYPE;
let expectedBeamlineUrls = ["noLink"];
myDoiController = new DOIController(null);
expect(myDoiController.getBeamlineUrl(actualBeamlines, actualDate, actualResourceType)).toEqual(expectedBeamlineUrls);
})
it("return beamlineurl for a 'ES' doi which beamline does not exists", () => {
let actualBeamlines = ['ID11', 'ID100'];
let actualDate = "2018-03-07";
let actualResourceType = CONSTANTS.ES_RESOURCE_TYPE;
let expectedBeamlineUrls = ["http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11", "noLink"];
myDoiController = new DOIController(null);
expect(myDoiController.getBeamlineUrl(actualBeamlines, actualDate, actualResourceType)).toEqual(expectedBeamlineUrls);
})
it("return beamlineurl for a 'ES' doi which beamline which exists but it does not exist at the provided date ", () => {
let actualBeamlines = ['ID11', 'ID100'];
let actualDate = "1900-01-01"; //ESRF was not built at this time
let actualResourceType = CONSTANTS.ES_RESOURCE_TYPE;
let expectedBeamlineUrls = ["noLink", "noLink"];
myDoiController = new DOIController(null);
expect(myDoiController.getBeamlineUrl(actualBeamlines, actualDate, actualResourceType)).toEqual(expectedBeamlineUrls);
})
it("return beamlineurl for a 'DC' doi", () => {
let actualBeamlines = ['ID11', 'ID21'];
let actualDate = "2018-03-07"
let actualResourceType = CONSTANTS.DC_RESOURCE_TYPE;
let expectedBeamlineUrls = ["http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11", "http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21"];
myDoiController = new DOIController(null);
expect(myDoiController.getBeamlineUrl(actualBeamlines, actualDate, actualResourceType)).toEqual(expectedBeamlineUrls);
})
it("return beamlineurl for a 'DC' doi without date", () => {
let actualBeamlines = ['ID11', 'ID21'];
let actualDate = null
let actualResourceType = CONSTANTS.DC_RESOURCE_TYPE;
let expectedBeamlineUrls = ["noLink", "noLink"];
myDoiController = new DOIController(null);
expect(myDoiController.getBeamlineUrl(actualBeamlines, actualDate, actualResourceType)).toEqual(expectedBeamlineUrls);
})
it("return beamlineurl for a 'DC' doi which beamline does not exists", () => {
let actualBeamlines = ['ID11', 'ID100'];
let actualDate = "2018-03-07";
let actualResourceType = CONSTANTS.DC_RESOURCE_TYPE;
let expectedBeamlineUrls = ["http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11", "noLink"];
myDoiController = new DOIController(null);
expect(myDoiController.getBeamlineUrl(actualBeamlines, actualDate, actualResourceType)).toEqual(expectedBeamlineUrls);
})
it("return beamlineurl for a 'DC' doi which beamline which exists but it does not exist at the provided date ", () => {
let actualBeamlines = ['ID11', 'ID100'];
let actualDate = "1900-01-01"; //ESRF was not built at this time
let actualResourceType = CONSTANTS.DC_RESOURCE_TYPE;
let expectedBeamlineUrls = ["noLink", "noLink"];
myDoiController = new DOIController(null);
expect(myDoiController.getBeamlineUrl(actualBeamlines, actualDate, actualResourceType)).toEqual(expectedBeamlineUrls);
})
})
})
\ No newline at end of file
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