Commit 23c2094d authored by Alejandro De Maria Antolinos's avatar Alejandro De Maria Antolinos
Browse files
parent d243d56c
...@@ -2,6 +2,7 @@ function DOIController(view) { ...@@ -2,6 +2,7 @@ function DOIController(view) {
var _this = this; var _this = this;
// doiServer = the server which provides doi details from a given doi name. // doiServer = the server which provides doi details from a given doi name.
this.doiServer = "https://data.datacite.org/"; this.doiServer = "https://data.datacite.org/";
this.icatPlusServer = "https://icatplus.esrf.fr/doi/";
// 10.5072 is the test esrf doi prefix; // 10.5072 is the test esrf doi prefix;
// 10.15151 is the production esrf doi prefix; // 10.15151 is the production esrf doi prefix;
...@@ -27,13 +28,6 @@ function DOIController(view) { ...@@ -27,13 +28,6 @@ function DOIController(view) {
* executed. Reloading the page is treated by .fail as it should be. * executed. Reloading the page is treated by .fail as it should be.
*/ */
DOIController.prototype.isValidDOIData = function (doiData) { DOIController.prototype.isValidDOIData = function (doiData) {
// console.log(doiData)
// if (_.keysIn(doiData).length > 3) {
// return _.find(_.keysIn(doiData), function (value) {
// return value === "title";
// }).length > 0;
// }
// return false;
return true; return true;
}; };
...@@ -62,12 +56,7 @@ DOIController.prototype.render = function (doi, data) { ...@@ -62,12 +56,7 @@ DOIController.prototype.render = function (doi, data) {
doiData.abstract = jsonExtractor.getAbstract(data); doiData.abstract = jsonExtractor.getAbstract(data);
doiData.investigationId = jsonExtractor.getInvestigationId(data); doiData.investigationId = jsonExtractor.getInvestigationId(data);
doiData.resourceType = jsonExtractor.getResourceType(data); doiData.resourceType = jsonExtractor.getResourceType(data);
// doiData.mintingYear = jsonExtractor.getMintingYear(data);
//console.log("minting year = " + doiData.mintingYear);
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subjects, "Proposal Type Description"); doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subjects, "Proposal Type Description");
...@@ -115,29 +104,51 @@ DOIController.prototype.getData = function (doi) { ...@@ -115,29 +104,51 @@ DOIController.prototype.getData = function (doi) {
} }
if (this.hasAcceptedPrefix(doi)) { if (this.hasAcceptedPrefix(doi)) {
$.ajax({ $.ajax({
headers: { headers: {
Accept: "application/vnd.datacite.datacite+json" Accept: "application/vnd.datacite.datacite+json"
}, },
type: "GET", type: "GET",
timeout: 15000, // triggers timeout when request pends longer than timeout: 15000, // triggers timeout when request pends longer than
// 5000ms // 5000ms
url: this.doiServer + doi, url: "sdfdsf" + this.doiServer + doi,
beforeSend: function () { beforeSend: function () {
_this.view.setLoading("Retrieving data from Server"); _this.view.setLoading("Retrieving data from Server");
}, },
complete: function () { complete: function () {
_this.view.setLoading(false); _this.view.setLoading(false);
} }
}) })
.done(function (data) { .done(function (data) {
if (data) { if (data) {
_this.render(doi, data); _this.render(doi, data);
} }
}).fail(function (jqXHR, textStatus, errorThrown) { }).fail(function (jqXHR, textStatus, errorThrown) {
_this.view.renderError(jqXHR, errorThrown, _this.origin); /** Try with icat server **/
_this.view.setLoading(false); $.ajax({
type: "GET",
timeout: 15000, // triggers timeout when request pends longer than
// 5000ms
url: _this.icatPlusServer + doi + "/json-datacite",
beforeSend: function () {
try{
$("logo").fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut();
}
catch(e){}
_this.view.setLoading("Retrieving data from Server");
},
complete: function () {
_this.view.setLoading(false);
}
})
.done(function (data) {
if (data) {
_this.render(doi, data);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
_this.view.renderError(jqXHR, errorThrown, _this.origin);
_this.view.setLoading(false);
});
}); });
} else { } else {
......
...@@ -52,8 +52,7 @@ DOIView.prototype.renderExperimentalReportData = function (data) { ...@@ -52,8 +52,7 @@ DOIView.prototype.renderExperimentalReportData = function (data) {
}; };
DOIView.prototype.renderDOIData = function (doiData) { DOIView.prototype.renderDOIData = function (doiData) {
var _this = this; var _this = this;
console.log(doiData);
dust.render('landingpage_tpl', { dust.render('landingpage_tpl', {
data: doiData, data: doiData,
constants : CONSTANTS constants : CONSTANTS
......
...@@ -6,36 +6,63 @@ function ExperimentalReportController() { ...@@ -6,36 +6,63 @@ function ExperimentalReportController() {
this.onError = new Event(this); this.onError = new Event(this);
} }
ExperimentalReportController.prototype.normalizeProposalName = function (proposalName) {
try {
// extract the proposal LetterCode (before the hyphen) and the digits (after the hyphen)
var aroundHyphenRegExp = new RegExp(/^(.*)-(.*)/);
return {
categoryCode: aroundHyphenRegExp.exec(proposalName)[1],
categoryCounter: aroundHyphenRegExp.exec(proposalName)[2]
};
} catch (e) {
/** It is most likely that symbol '-' is not present in the proposal name then we use /\d+$/ */
var aroundHyphenRegExp = new RegExp( /\d+$/);
/** This will get all numbers at the end of the string
* Example: input=mx3030 then output[0]=3030
*/
try{
return {
categoryCode: proposalName.substring(0, proposalName.length - aroundHyphenRegExp.exec(proposalName)[0].length),
categoryCounter: aroundHyphenRegExp.exec(proposalName)[0]
};
}
catch(e){
console.log(e);
return null;
}
}
};
/** /**
* Request the experimental report filename list for the given proposal * Request the experimental report filename list for the given proposal
* @param {string} proposal The proposal * @param {string} proposal The proposal code
*/ */
ExperimentalReportController.prototype.requestFilenameList = function(proposal) { ExperimentalReportController.prototype.requestFilenameList = function (proposal) {
var _this = this; var _this = this;
if (proposal) { if (proposal) {
// extract the proposal LetterCode (before the hyphen) and the digits (after the hyphen) var data = this.normalizeProposalName(proposal);
var aroundHyphenRegExp = new RegExp(/^(.*)-(.*)/); if (data) {
var beforeHyphen = aroundHyphenRegExp.exec(proposal)[1];
var afterHyphen = aroundHyphenRegExp.exec(proposal)[2];
if (beforeHyphen && afterHyphen) {
$.ajax({ $.ajax({
type : "GET", type: "GET",
timeout : this.timeout, timeout: this.timeout,
url : this.server, url: this.server,
data : { data: data,
categoryCode : beforeHyphen, dataType: "json",
categoryCounter : afterHyphen success: function (data) {
},
dataType : "json",
success : function(data) {
_this.onSuccess.notify(data); _this.onSuccess.notify(data);
}, },
error : function(message) { error: function (message) {
_this.onError.notify(message); _this.onError.notify(message);
} }
}); });
} }
else{
_this.onError.notify("Proposal could not be normalized: " + proposal);
}
} else { } else {
_this.onError.notify("Proposal is null"); _this.onError.notify("Proposal is null");
} }
...@@ -45,7 +72,7 @@ ExperimentalReportController.prototype.requestFilenameList = function(proposal) ...@@ -45,7 +72,7 @@ ExperimentalReportController.prototype.requestFilenameList = function(proposal)
* Opens the file in a new tab if it exists. Display an alert message if it * Opens the file in a new tab if it exists. Display an alert message if it
* fails loading the file * fails loading the file
*/ */
ExperimentalReportController.prototype.openFileInNewTab = function(filename) { ExperimentalReportController.prototype.openFileInNewTab = function (filename) {
if (filename) { if (filename) {
try { try {
window.open('ftp://www.esrf.eu/pub/UserReports/' + filename, '_blank'); window.open('ftp://www.esrf.eu/pub/UserReports/' + filename, '_blank');
......
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