From 8cd378cc21973de9ce0e229e8ddb0ec3e7f34e57 Mon Sep 17 00:00:00 2001 From: Maxime Chaillet Date: Thu, 21 Feb 2019 10:22:21 +0100 Subject: [PATCH] clean and minify the code. IT fixes icat/doi-landing-page#66 --- www/dev.html | 164 +++++++++++++++++++-------------------- www/min/doi.min.js | 2 +- www/src/doicontroller.js | 1 - 3 files changed, 80 insertions(+), 87 deletions(-) diff --git a/www/dev.html b/www/dev.html index 714070b..9e3d543 100644 --- a/www/dev.html +++ b/www/dev.html @@ -1,96 +1,90 @@ + + + ESRF - DOI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - ESRF - DOI - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
+ + + + + + + +
+
+
-
- -
+
+ +
-
-
+
+
-
-
- - + + + diff --git a/www/min/doi.min.js b/www/min/doi.min.js index 20d199d..e83aee3 100644 --- a/www/min/doi.min.js +++ b/www/min/doi.min.js @@ -1 +1 @@ -function Author(){}function Citation(e){this.isBuildable=function(){if(e&&e.creators&&0!==e.creators.length&&e.title&&e.publisher&&e.doi){if(e.resourceType===CONSTANTS.ES_RESOURCE_TYPE&&e.sessionDate)return!0;if(e.resourceType===CONSTANTS.DC_RESOURCE_TYPE&&e.publiclyAccessibleYear)return!0}return!1}()}function DOIController(e){var t=this;this.doiServer="https://data.datacite.org/",this.icatPlusServer="https://icatplus.esrf.fr/doi/",this.acceptedPrefix=["10.5072","10.15151"],this.view=e,this.experimentalReportController=new ExperimentalReportController,this.experimentalReportController.onSuccess.attach(function(e,r){t.view.renderExperimentalReportData(r)}),this.experimentalReportController.onError.attach(function(e,r){console.log("Error when retrieving fileList from SMIS."),t.view.renderErrorForExperimentalReport()})}function DoiData(e,t,r,i,n){this.doi=e,this.dataciteLink=t,this.publisher=r,this.creator=i,this.publiclyAccessibleYear=n}function DOIView(){this.mainPanelId="main",this.reportPanelId="expReport",this.badgePanelId="badges",this.metadataDivId="metadata",this.reportExperimentFileNames=null,this.failedRecievingExpReport=!1,this.isDOIAlreadyRendered=!1,this.onDOIRendered=new Event(this)}function Event(e){this._sender=e,this._listeners=[]}function ExperimentalReportController(){this.server="https://wwws.esrf.fr/misapps/SMISServer/rest/reports/fileNames",this.timeout=5e3,this.onSuccess=new Event(this),this.onError=new Event(this)}function JsonExtractor(){}function proposalBeamlineTable(e,t,r,i){var n=i.mergedProposalBeamlines;if(e.write(''),e.write(""),e.write(""),e.write(''),e.write(''),e.write(""),e.write(""),e.write(""),n){for(var a=0;a"),e.write(""),"noLink"===l?e.write(""):e.write('"),e.write("")}else e.write(""),chunck.write(""),chunck.write(""),e.write("");return e.write(""),e.write("
ProposalsBeamlines
"+o+""+s+" '+s+"
unknown unknown
"),e.render(r.block,t)}}function abstract(e,t,r,i){var n=i.abstract;return e.write('
'),e.write(""),e.write('
'),n?e.write(n):e.write("There is no abstract for this session."),e.write("
"),e.write("
"),e.render(r.block,t)}Author.prototype.setFirstName=function(e){this.firstName=e},Author.prototype.setFamilyName=function(e){this.familyName=e},Author.prototype.setSingleName=function(e){this.singleName=e},Author.prototype.getRawFamilyName=function(){if(this.familyName)return this.familyName;if(this.singleName){var e=new RegExp(/(\S+)/g),t=this.singleName.match(e);if(2===t.length)return this.familyName=t[1],this.familyName;var r=new RegExp(/\s([^a-z]+$)/).exec(this.singleName);return r&&(this.familyName=r[1]),this.familyName}},Author.prototype.getRawFirstName=function(){if(this.firstName)return this.firstName;if(this.singleName){var e=new RegExp(/(\S+)/g),t=this.singleName.match(e);if(2===t.length)return this.firstName=t[0],this.firstName;var r=new RegExp(/^(.[^A-Z]+)+\b/).exec(this.singleName);return r&&(this.firstName=r[0]),r}},Author.prototype.getTitleCaseFamilyName=function(){if(this.familyName){allLowerCase=this.familyName.toLowerCase();var e=new RegExp(/^./);return allLowerCase.replace(e,function(e){return e.toUpperCase()})}return console.log("family name is undefined"),null},Author.prototype.getFirstNameInitials=function(){var e=new RegExp(/(\S+)/g);return this.firstName?this.firstName.replace(e,function(e){return e.charAt(0)+"."}):(console.log("first name is undefined"),null)};var BEAMLINEURL=[{name:"BM05",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/XNP/BM05"},{name:"BM29",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/MX/About_our_beamlines/BM29"},{name:"CM01",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/MX/About_our_beamlines/CM01.html"},{name:"ID01",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID01"},{name:"ID06",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/MEx/id06-large-volume-press.html"},{name:"ID11",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11"},{name:"ID16A",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/XNP/ID16A"},{name:"ID16B",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/XNP/ID16B"},{name:"ID17",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/CBS/ID17"},{name:"ID19",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/home/UsersAndScience/Experiments/StructMaterials/ID19.html"},{name:"ID21",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21"},{name:"ID22",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/id22"},{name:"ID23-1",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/MX/About_our_beamlines/ID23-1"},{name:"ID23-2",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/MX/About_our_beamlines/ID23-2"},{name:"ID29",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/Beamlines/content/content/id29.html"},{name:"ID30A1",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/MASSIF1"},{name:"ID30A3",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/MX/About_our_beamlines/id30a-3--massif-3.html"},{name:"ID30B",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/id30b"},{name:"ID32",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/ID32"}];Citation.prototype.getAuthorsForCitation=function(e){if(this.isBuildable){var t=_.transform(e,function(e,t,r,i){i instanceof Array||(t=i);var n=null;if(t.givenName?((n=new Author).setFamilyName(t.familyName),n.setFirstName(t.givenName),e.push(n.getTitleCaseFamilyName()+" "+n.getFirstNameInitials())):((n=new Author).setSingleName(t.name),n.getRawFamilyName()&&n.getRawFirstName()?e.push(n.getTitleCaseFamilyName()+" "+n.getFirstNameInitials()):e.push(t.name)),!(i instanceof Array))return!1},[]);return _.join(t,", ")}return console.log("[CITATION GENERATION] Author list for the citation could not be generated."),""},Citation.prototype.getDOIRegistrationYear=function(e){return e.resourceType===CONSTANTS.ES_RESOURCE_TYPE?moment(e.sessionDate).year():e.resourceType===CONSTANTS.DC_RESOURCE_TYPE?e.publiclyAccessibleYear:(console.log("[CITATION GENERATION] Could not get the year to generate the citation."),"")};var CONSTANTS={ES_RESOURCE_TYPE:"experimental session resource type",DC_RESOURCE_TYPE:"dataset collection resource type"};DOIController.prototype.isValidDOIData=function(e){return!0},DOIController.prototype.render=function(e,t){if(this.isValidDOIData(t)){var r=new DoiData,i=new JsonExtractor;r.title=i.getTitle(t),r.doi=i.getDOI(t),r.dataciteLink=this.doiServer+e,r.publisher=i.getPublisher(t),r.creators=i.getCreators(t),r.publiclyAccessibleYear=i.getPubliclyAccessibleYear(t),r.abstract=i.getAbstract(t),r.investigationId=i.getInvestigationId(t),r.resourceType=i.getResourceType(t),r.proposalType=i.getFieldFromSubject(t.subjects,"Proposal Type Description"),r.resourceTypeGeneral=i.getResourceTypeGeneral(t),r.sessionDate=i.getSessionDate(t);var n=i.getFieldFromSubject(t.subjects,"Proposal"),a=i.getFieldFromSubject(t.subjects,"Instrument");this.experimentalReportController.requestFilenameList(n[0]),r.accessibility=r.getAccessibilityStatus(r.resourceType,r.sessionDate,r.publiclyAccessibleYear),r.accessMessage=this.view.setDataAccessMessage(r),r.citation=this.createCitation(r),r.resourceType===CONSTANTS.ES_RESOURCE_TYPE&&(r.beamlineUrls=this.getBeamlineUrl(a,r.sessionDate,r.resourceType),r.mintingYear=moment(r.sessionDate).year()),r.resourceType===CONSTANTS.DC_RESOURCE_TYPE&&(r.beamlineUrls=this.getBeamlineUrl(a,r.publiclyAccessibleYear,r.resourceType),r.mintingYear=r.publiclyAccessibleYear),r.mergedProposalBeamlines=i.getMergedProposalAndBeamline(n,a,r.beamlineUrls),this.view.renderDOIData(r)}else this.view.renderError("Not Found",this.origin)},DOIController.prototype.getData=function(e){var t=this;this.view.setDOIInTopBanner(e),"10.15151/ESRF-DC-142893590"!=e.toUpperCase()?"10.15151/ESRF-DC-142915526"!=e.toUpperCase()?this.hasAcceptedPrefix(e)?($.ajax({headers:{Accept:"application/vnd.datacite.datacite+json"},type:"GET",timeout:15e3,url:this.doiServer+e,beforeSend:function(){t.view.setLoading("Retrieving data from Server")},complete:function(){t.view.setLoading(!1)}}).done(function(r){r&&t.render(e,r)}).fail(function(r,i,n){$.ajax({type:"GET",timeout:15e3,url:t.icatPlusServer+e+"/json-datacite",beforeSend:function(){try{$("logo").fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut()}catch(e){}t.view.setLoading("Retrieving data from Server")},complete:function(){t.view.setLoading(!1)}}).done(function(r){r&&t.render(e,r)}).fail(function(e,r,i){t.view.renderError(e,i,t.origin),t.view.setLoading(!1)})}),this.getDataForGoogleSearch(e)):t.view.renderError("Bad Prefix",t.origin):this.render(e,ESRF_DC_142915526):this.render(e,ESRF_DC_142893590)},DOIController.prototype.getDataForGoogleSearch=function(e){var t=this;e&&$.ajax({headers:{Accept:"application/vnd.schemaorg.ld+json"},type:"GET",timeout:15e3,url:"https://data.datacite.org/"+e,dataType:"text",success:function(e){e?(console.log(e),e.name?(e.documentation||(e.documentation=e.name),t.view.addDOIMetadataToHead(e)):console.log("[GOOGLE SEARCH INDEXING] - The data required by Google is missing the 'name' field. This is required by Google for indexing.")):console.log("[GOOGLE SEARCH INDEXING] - No metadata recieved from datacite.")},error:function(e){console.log("[GOOGLE SEARCH INDEXING] - Failed getting metadata from datacite."),console.log(e.responseJSON)}})},DOIController.prototype.hasAcceptedPrefix=function(e){var t=e.split("/")[0];return-1!=_.findIndex(this.acceptedPrefix,function(e){return t==e})},DOIController.prototype.displayMainContent=function(e){"welcome-page"===this.origin&&dust.render("welcome_tpl",{},function(e,t){$("#main").html(t)}),"index"===this.origin&&this.getData(e)},DOIController.prototype.setOrigin=function(e){this.origin=e},DOIController.prototype.getBeamlineUrl=function(e,t,r){var i=[];return e.forEach(function(e){if(t){r===CONSTANTS.ES_RESOURCE_TYPE&&(t=moment(t)),r===CONSTANTS.DC_RESOURCE_TYPE&&(t=moment(t,"YYYY"));for(var n="",a=0;a=o&&t<=s){n=BEAMLINEURL[a].url;break}}""===n?i.push("noLink"):i.push(n)}else i.push("noLink")}),i},DOIController.prototype.createCitation=function(e){var t=new Citation(e);if(t.isBuildable){return t.getAuthorsForCitation(e.creators)+" ("+t.getDOIRegistrationYear(e)+"). "+e.title+". "+e.publisher+" (ESRF). doi:"+e.doi.toUpperCase()+""}return"The citation could not be generated."},DoiData.prototype.getAccessibilityStatus=function(e,t,r){if(e)if(e===CONSTANTS.ES_RESOURCE_TYPE){if(r&&t){var i=moment(r,"YYYY"),n=moment();if(n>i)return"Open access";if(n<=i)return"Restricted access"}}else if(e===CONSTANTS.DC_RESOURCE_TYPE)return"Open access";return console.log("Failed to determine whether the accessibility of the DOI."),"Accessibility status could not be determined"},DOIView.prototype.setLoading=function(e){0!=e?$("body").addClass("loading"):$("body").removeClass("loading")},DOIView.prototype.setDOIInTopBanner=function(e){$("#doiValue").text("DOI > "+e.toUpperCase())},DOIView.prototype.renderExperimentalReportData=function(e){if(e){var t=this;this.isDOIAlreadyRendered?dust.render("experimentalreport_tpl",{data:e},function(e,r){$("#"+t.reportPanelId).html(r)}):this.reportExperimentFileNames=e}},DOIView.prototype.renderDOIData=function(e){var t=this;dust.render("landingpage_tpl",{data:e,constants:CONSTANTS},function(r,i){$("#"+t.mainPanelId).html(i),t.isDOIAlreadyRendered=!0,t.renderBadges(e),t.renderMetadata(e),t.failedRecievingExpReport?t.renderErrorForExperimentalReport():t.reportExperimentFileNames&&t.renderExperimentalReportData(t.reportExperimentFileNames)})},DOIView.prototype.renderError=function(e,t,r){var i="welcome-page"===r?"doinotfound2_tpl":"doinotfound_tpl",n="";n="Bad Prefix"===t?"welcome-page"===r?'

Not found !

The DOI was not found at ESRF because its prefix is not ESRF specific. Please use the DOI search engine at doi.org.

':'

Not found !

The DOI was not found at ESRF because its prefix is not ESRF specific.
Please use the DOI search engine at doi.org.

':"Not Found"===t?"welcome-page"===r?"

Not found !

Sorry, the requested DOI was not found.

":"

Not found !

Sorry, the requested DOI was not found.

":"timeout"===t?"welcome-page"===r?"

Not found !

Sorry, the server took too long to reply. Try again later.

":"

Not found !

Sorry, the server took too long to reply. Try again later.

":""===t&&"The resource you are looking for doesn't exist."===e.responseText?"welcome-page"===r?"

Not found !

It may take up to 24 hours for a newly generated DOI to become available. Please try again later.

":"

Not found !

It may take up to 24 hours for a newly generated DOI to become available. Please try again later.

":"welcome-page"===r?"

Not found !

Connexion problem to the datacite server. Please try again later.

":"

Not found !

Connexion problem to the datacite server. Please try again later.

",dust.render(i,{message:n},function(e,t){$("#error").html(t)})},DOIView.prototype.renderErrorForExperimentalReport=function(){this.failedRecievingExpReport=!0;$("#"+this.reportPanelId).html('

The filename list is not available.

')},DOIView.prototype.renderBadges=function(e){if(e){var t=this;dust.render("badges_tpl",{data:e,constants:CONSTANTS},function(e,r){$("#"+t.badgePanelId).html(r)})}},DOIView.prototype.renderMetadata=function(e){if(e){var t=this;e.sessionDate=moment(e.sessionDate).format("YYYY-M-D"),dust.render("metadata_tpl",{data:e,constants:CONSTANTS},function(e,r){$("#"+t.metadataDivId).html(r)})}},DOIView.prototype.setDataAccessMessage=function(e){return"Open access"===e.accessibility?"The data can be accessed by clicking on the link below":"Restricted access"===e.accessibility?"The data are under embargo until "+e.publiclyAccessibleYear+" but could be released earlier. Currently, they are only accessible to proposal team members.":void 0},DOIView.prototype.addDOIMetadataToHead=function(e){$("