Commit 0c957a9e authored by Maxime Chaillet's avatar Maxime Chaillet

Merge branch 'issue41' into 'master'

Issue41

Closes #41

See merge request !40
parents df99f7b1 fb85c6f0
......@@ -54,6 +54,8 @@
</div>
<div id="main"></div>
<div id='error' ></div>
<div class="modal">
<!-- nothing to write here -->
</div>
......
......@@ -43,6 +43,8 @@
</div>
<div id="main"></div>
<div id='error' ></div>
<div class="modal">
<!-- nothing to write here -->
</div>
......
......@@ -47,6 +47,7 @@
</div>
</div>
<div id='main' ></div>
<div id='error' ></div>
<div class="modal">
<!-- nothing to write here -->
</div>
......
This diff is collapsed.
......@@ -19,107 +19,65 @@ DOIController.prototype.getData = function(doi) {
Accept : "application/vnd.datacite.datacite+json"
},
type : "GET",
timeout: 5000, // 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);
},
success : function(doiData) {
if (doiData) {
var jsonExtractor = new JsonExtractor();
jsonExtractor.extractDates(doiData);
var proposalType = jsonExtractor.getFieldFromSubject(
doiData.subject, "Proposal Type Description");
if (proposalType) {
doiData.proposalType = proposalType;
} else {
doiData.proposalType = "Not Available";
}
var proposalNumber = jsonExtractor.getFieldFromSubject(
doiData.subject, "Proposal");
if (proposalNumber) {
doiData.proposalNumber = proposalNumber;
} else {
doiData.proposalNumber = "Not Available";
}
var beamline = jsonExtractor.getFieldFromSubject(doiData.subject,
"instrument");
if (beamline) {
doiData.beamline = beamline;
} else {
doiData.beamline = "Not Available";
}
jsonExtractor.extractInvestigationId(doiData);
_this.view.setDataAccessMessage(doiData);
_this.createCitation(doiData);
// Set the URL corresponding to the beamline name.
if (doiData.date_collected) {
var experimentalDate = moment(doiData.date_collected);
doiData.beamlineUrl = _this.getBeamlineUrl(doiData.beamline,
experimentalDate);
} else {
doiData.beamlineUrl = "noLink";
}
})
.done(
function(doiData) {
if (doiData) {
var jsonExtractor = new JsonExtractor();
jsonExtractor.extractDates(doiData);
var proposalType = jsonExtractor.getFieldFromSubject(
doiData.subject, "Proposal Type Description");
doiData.proposalType = (proposalType ? proposalType
: "Not Available");
var proposalNumber = jsonExtractor.getFieldFromSubject(
doiData.subject, "Proposal");
doiData.proposalNumber = (proposalNumber ? proposalNumber
: "Not Available");
var beamline = jsonExtractor.getFieldFromSubject(
doiData.subject, "instrument");
doiData.beamline = (beamline ? beamline : "Not Available");
jsonExtractor.extractInvestigationId(doiData);
_this.view.setDataAccessMessage(doiData);
_this.createCitation(doiData);
// Set the URL corresponding to the beamline name.
if (doiData.date_collected) {
var experimentalDate = moment(doiData.date_collected);
doiData.beamlineUrl = _this.getBeamlineUrl(doiData.beamline,
experimentalDate);
} else {
doiData.beamlineUrl = "noLink";
}
// send to dust render
dust.render('esrf-landing-page', {
data : doiData
}, function(err, out) {
$("#main").html(out);
});
}
})
.fail(
function(jqXHR, textStatus, errorThrown) {
_this.view.renderError(errorThrown, _this.origin);
_this.view.setLoading(false);
});
// send to dust render
dust.render('esrf-landing-page', {
data : doiData
}, function(err, out) {
$("#main").html(out);
});
} else {
if (_this.origin === "welcome-page") {
_this.view.displayMessage('doi-not-found-page2',
"Sorry, the requested DOI was not found.", "error");
} else {
_this.view.displayMessage('doi-not-found-page',
"Sorry, the requested DOI was not found.", "main");
}
}
},
error : function(jqXHR, textStatus, errorThrown) {
if (_this.origin === "welcome-page") {
_this.view
.displayMessage(
'doi-not-found-page2',
"<h3> Not found ! </h3> <p> Sorry, there was a connexion problem with the datacite server. </p>",
"error");
} else {
_this.view
.displayMessage(
'doi-not-found-page',
"<h2> Not found ! </h2> <p> Sorry, there was a connexion problem with the datacite server. </p>",
"main");
}
_this.view.setLoading(false);
}
});
} else {
if (_this.origin === "welcome-page") {
_this.view
.displayMessage(
'doi-not-found-page2',
'<h3> Not found ! </h3> <p> The DOI <b>' +
doi +
'</b> was not found at ESRF because its prefix is not ESRF specific. Please use the DOI search engine at <a href="https://www.doi.org"> doi.org</a>. </p>',
'error');
} else {
_this.view
.displayMessage(
'doi-not-found-page',
'<h2> Not found ! </h2> <p> The DOI <b>' +
doi +
'</b> was not found at ESRF because its prefix is not ESRF specific. </br> Please use the DOI search engine at <a href="https://www.doi.org"> doi.org</a>.</p>',
'main');
}
_this.view.renderError("Bad Prefix", _this.origin);
}
};
......@@ -239,4 +197,4 @@ DOIController.prototype.createCitation = function(data) {
data.citation = citation;
}
};
\ No newline at end of file
};
......@@ -14,31 +14,68 @@ DOIView.prototype.setDOI = function(doi) {
$("#doiPanel").html(doi.toUpperCase());
};
/**
* Render the error message
*
* @param {string}
* error The error which was thrown
* @param {string}
* origin The page which caused this rendering. This directly
* influence the element id
*/
DOIView.prototype.renderError = function(error, origin) {
var template = ((origin === "welcome-page") ? "doi-not-found-page2" : "doi-not-found-page");
DOIView.prototype.displayMessage = function(template, message, id){
dust.render(
template,
{
message : message
},
function(err, out) {
$("#" + id).html(out);
var message = "";
if (error === "Bad Prefix") {
if (origin === "welcome-page") {
message = '<h3> Not found ! </h3> <p> The DOI was not found at ESRF because its prefix is not ESRF specific. Please use the DOI search engine at <a href="https://www.doi.org"> doi.org</a>. </p>';
} else {
message = '<h2> Not found ! </h2> <p> The DOI was not found at ESRF because its prefix is not ESRF specific. </br> Please use the DOI search engine at <a href="https://www.doi.org"> doi.org</a>. </p>';
}
} else if (error === "Not Found") {
if (origin === "welcome-page") {
message = "<h3> Not found ! </h3> <p> Sorry, the requested DOI was not found. </p>";
} else {
message = "<h2> Not found ! </h2> <p> Sorry, the requested DOI was not found. </p>";
}
} else if (error === "timeout") {
if (origin === "welcome-page") {
message = "<h3> Not found ! </h3> <p> Sorry, the server took too long to reply. Try again later. </p>";
} else {
message = "<h2> Not found ! </h2> <p> Sorry, the server took too long to reply. Try again later. </p>";
}
);
} else {
if (origin === "welcome-page") {
message = "<h3> Not found ! </h3> <p> Connexion problem to the server. </p>";
} else {
message = "<h2> Not found ! </h2> <p> Connexion problem to the server. </p>";
}
}
dust.render(template, {
message : message
}, function(err, out) {
$("#error").html(out);
});
};
/**
* Set the message which is displayed just above the "Access data button"
* @param {object} data The json object reference.
*
* @param {object}
* data The json object reference.
*/
DOIView.prototype.setDataAccessMessage = function(data){
DOIView.prototype.setDataAccessMessage = function(data) {
var publicationDate = moment(data.publication_year, "YYYY");
var now = moment();
if (now > publicationDate) {
data.accessMessage = "The data can be downloaded 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. It is currently only available to download if you are a member of the proposal team.";
data.accessMessage = "The data is under embargo until <b>" +
data.publication_year +
"</b> but could be released earlier. It is currently only available to download if you are a member of the proposal team.";
}
};
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