Commit 097ff806 authored by Alejandro De Maria Antolinos's avatar Alejandro De Maria Antolinos

Merge branch 'issue_62' into 'master'

Issue 62

Closes #62

See merge request !70
parents d243d56c a9df75cf
Pipeline #7527 passed with stages
in 16 seconds
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,6 +2,7 @@ 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.icatPlusServer = "https://icatplus.esrf.fr/doi/";
// 10.5072 is the test esrf doi prefix;
// 10.15151 is the production esrf doi prefix;
......@@ -27,13 +28,6 @@ function DOIController(view) {
* executed. Reloading the page is treated by .fail as it should be.
*/
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;
};
......@@ -62,12 +56,7 @@ DOIController.prototype.render = function (doi, data) {
doiData.abstract = jsonExtractor.getAbstract(data);
doiData.investigationId = jsonExtractor.getInvestigationId(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");
......@@ -115,29 +104,51 @@ DOIController.prototype.getData = function (doi) {
}
if (this.hasAcceptedPrefix(doi)) {
$.ajax({
headers: {
Accept: "application/vnd.datacite.datacite+json"
},
type: "GET",
timeout: 15000, // triggers timeout when request pends longer than
// 5000ms
url: this.doiServer + doi,
beforeSend: function () {
_this.view.setLoading("Retrieving data from Server");
},
complete: function () {
_this.view.setLoading(false);
}
})
$.ajax({
headers: {
Accept: "application/vnd.datacite.datacite+json"
},
type: "GET",
timeout: 15000, // triggers timeout when request pends longer than
// 5000ms
url: "sdfdsf" + this.doiServer + doi,
beforeSend: function () {
_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);
}).fail(function (jqXHR, textStatus, errorThrown) {
/** Try with icat server **/
$.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 {
......
......@@ -52,8 +52,7 @@ DOIView.prototype.renderExperimentalReportData = function (data) {
};
DOIView.prototype.renderDOIData = function (doiData) {
var _this = this;
console.log(doiData);
var _this = this;
dust.render('landingpage_tpl', {
data: doiData,
constants : CONSTANTS
......
......@@ -6,36 +6,64 @@ function ExperimentalReportController() {
this.onError = new Event(this);
}
ExperimentalReportController.prototype.normalizeProposalName = function (proposalName) {
var aroundHyphenRegExp;
try {
// extract the proposal LetterCode (before the hyphen) and the digits (after the hyphen)
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+$/ */
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
* @param {string} proposal The proposal
* @param {string} proposal The proposal code
*/
ExperimentalReportController.prototype.requestFilenameList = function(proposal) {
ExperimentalReportController.prototype.requestFilenameList = function (proposal) {
var _this = this;
if (proposal) {
// 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];
if (beforeHyphen && afterHyphen) {
var data = this.normalizeProposalName(proposal);
if (data) {
$.ajax({
type : "GET",
timeout : this.timeout,
url : this.server,
data : {
categoryCode : beforeHyphen,
categoryCounter : afterHyphen
},
dataType : "json",
success : function(data) {
type: "GET",
timeout: this.timeout,
url: this.server,
data: data,
dataType: "json",
success: function (data) {
_this.onSuccess.notify(data);
},
error : function(message) {
error: function (message) {
_this.onError.notify(message);
}
});
}
else{
_this.onError.notify("Proposal could not be normalized: " + proposal);
}
} else {
_this.onError.notify("Proposal is null");
}
......@@ -45,7 +73,7 @@ ExperimentalReportController.prototype.requestFilenameList = function(proposal)
* Opens the file in a new tab if it exists. Display an alert message if it
* fails loading the file
*/
ExperimentalReportController.prototype.openFileInNewTab = function(filename) {
ExperimentalReportController.prototype.openFileInNewTab = function (filename) {
if (filename) {
try {
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