diff --git a/www/dev.html b/www/dev.html index 9e3d543f0ee44331da904845eae572be5b87f1be..714070b833c8e02f43c5a5001b3c2721b25319ce 100644 --- a/www/dev.html +++ b/www/dev.html @@ -1,90 +1,96 @@ - - - ESRF - DOI - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + ESRF - DOI + - - - - - - - -
-
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
-
- -
+
+ +
-
-
+
+
-
-
- - + + + + \ No newline at end of file diff --git a/www/index.html b/www/index.html index cc21a98f0c1dc5d81e09e377aa95c0284fc78efd..6e0117a44ccc0089c0a32788ec8f7edf2bf9a9b4 100644 --- a/www/index.html +++ b/www/index.html @@ -1,75 +1,83 @@ - - - - - ESRF - DOI - - - - - - - - - - - - -
-
-
+ + + + + ESRF - DOI + + + + + + + + + + + + + +
+
+
+ +
-
- - -
+
+ + +
-
-
-
-
- -
-
+
+
+
+
+ + - - +
+ + + + \ No newline at end of file diff --git a/www/src/doicontroller.js b/www/src/doicontroller.js index 45849f00fb8f6ab58d96c45de3f5163f238281c2..ad42f3a74ef9be906b9b149774a9679296a10bc4 100644 --- a/www/src/doicontroller.js +++ b/www/src/doicontroller.js @@ -56,7 +56,7 @@ DOIController.prototype.render = function (doi, data) { doiData.abstract = jsonExtractor.getAbstract(data); doiData.investigationId = jsonExtractor.getInvestigationId(data); doiData.resourceType = jsonExtractor.getResourceType(data); - + doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subjects, "Proposal Type Description"); @@ -88,6 +88,7 @@ DOIController.prototype.render = function (doi, data) { _this.view.renderDOIData(doiData); } }; + DOIController.prototype.getData = function (doi) { var _this = this; @@ -104,64 +105,93 @@ 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: 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) { - /** Try with icat server **/ - $.ajax({ + }).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", + url: _this.icatPlusServer + doi + "/json-datacite", beforeSend: function () { - try{ - $("logo").fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut(); + try { + $("logo").fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut(); } - catch(e){} + 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); - }); + .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); + }); + }); + this.getDataForGoogleSearch(doi); } else { _this.view.renderError("Bad Prefix", _this.origin); } }; +/** + * Get the DOI metadata in the ld+Json format as requested by google search engine for datasets. + * @param {string} doi in the format prefix/suffix + */ +DOIController.prototype.getDataForGoogleSearch = function (doi) { + var _this = this; + if (doi) { + $.ajax({ + headers: { + Accept: "application/vnd.schemaorg.ld+json" + }, + type: "GET", + timeout: 15000, + url: 'https://data.datacite.org/' + doi, + dataType: 'text', // don't convert JSON to Javascript object + success: function (data) { + if (data) { + _this.view.addDOIMetadataToHead(data); + } + console.log("[GOOGLE SEARCH INDEXING] - No metadata recieved from datacite.") + }, + error: function (error) { + console.log("[GOOGLE SEARCH INDEXING] - Failed getting metadata from datacite.") + console.log(error.responseJSON); + } + }) + } +} + /** * Checks whether the requested doi prefix is an esrf prefix - * * @param{string} doi The DOI number * @return true if the prefix is an esrf prefix, false otherwise - * */ DOIController.prototype.hasAcceptedPrefix = function (doi) { var prefix = doi.split('/')[0]; diff --git a/www/src/doiview.js b/www/src/doiview.js index 3de3d8bf4449a0a0ea1212714cee18d54200fe97..bc8fac92d25d0493b7e02e285fcca74d30abe9d8 100644 --- a/www/src/doiview.js +++ b/www/src/doiview.js @@ -20,8 +20,7 @@ DOIView.prototype.setLoading = function (message) { }; /** -* Set the doi prefix/suffix text in the top banner of the doi landing page. This is done before the template is rendered. -* +* Set the doi prefix/suffix text in the top banner of the doi landing page. This is done before the template is rendered. */ DOIView.prototype.setDOIInTopBanner = function (doiCode) { $("#doiValue").text("DOI > " + doiCode.toUpperCase()); @@ -29,9 +28,7 @@ DOIView.prototype.setDOIInTopBanner = function (doiCode) { /** * Render experimental Report data - * - * @param {array} - * data The filename list to be displayed + * @param {array} data The filename list to be displayed */ DOIView.prototype.renderExperimentalReportData = function (data) { if (data) { @@ -52,10 +49,10 @@ DOIView.prototype.renderExperimentalReportData = function (data) { }; DOIView.prototype.renderDOIData = function (doiData) { - var _this = this; + var _this = this; dust.render('landingpage_tpl', { data: doiData, - constants : CONSTANTS + constants: CONSTANTS }, function (err, out) { $('#' + _this.mainPanelId).html(out); _this.isDOIAlreadyRendered = true; @@ -76,11 +73,8 @@ DOIView.prototype.renderDOIData = function (doiData) { /** * 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 + * @param {string} errorThrown The error which was thrown + * @param {string} origin The page which caused this rendering. This directly influences the element id */ DOIView.prototype.renderError = function (jqXHR, errorThrown, origin) { var template = ((origin === "welcome-page") ? "doinotfound2_tpl" : "doinotfound_tpl"); @@ -142,7 +136,7 @@ DOIView.prototype.renderBadges = function (data) { dust.render('badges_tpl', { data: data, - constants : CONSTANTS + constants: CONSTANTS }, function (err, out) { $('#' + _this.badgePanelId).html(out); }); @@ -157,21 +151,17 @@ DOIView.prototype.renderMetadata = function (data) { var _this = this; dust.render('metadata_tpl', { data: data, - constants : CONSTANTS + constants: CONSTANTS }, function (err, out) { $('#' + _this.metadataDivId).html(out); }); } }; - /** * Set the message which is displayed just above the "Access data button" in experimental data box. - * - * @param {object} - * data The json object reference. - * @return {string} - * the message to display + * @param {object} doiData json object reference. + * @return {string} message to display */ DOIView.prototype.setDataAccessMessage = function (doiData) { if (doiData.accessibility === "Open access") { @@ -182,3 +172,14 @@ DOIView.prototype.setDataAccessMessage = function (doiData) { } }; + +/** + * Add JSON LD metadata to the head of the page such that google search engine can index this page. + * @param {string} data doi metadata in Json+LD format as provided by datacite. + */ +DOIView.prototype.addDOIMetadataToHead = function (data) { + $('