From 54b390b851914d58a2b8fea5393bf03939680c8d Mon Sep 17 00:00:00 2001 From: tankchintan Date: Thu, 21 Jul 2011 20:31:36 +0000 Subject: [PATCH] 1. Fix for issue http://issues.library.cornell.edu/browse/NIHVIVO-3019 2. Also changed the text in different cases for the error. Code reviewed by Chin Hua. --- .../css/visualization/mapofscience/layout.css | 5 + .../mapofscience/ErrorDisplayWidget.js | 100 ++++++++++++++++++ .../mapofscience/InitializeMap.js | 7 ++ .../mapofscience/VisModeControllers.js | 6 +- .../mapOfScience/mapOfScienceSetup.ftl | 3 + .../mapOfScience/mapOfScienceStandalone.ftl | 8 +- ...pOfScienceVisualizationRequestHandler.java | 44 +++----- 7 files changed, 137 insertions(+), 36 deletions(-) create mode 100644 productMods/js/visualization/mapofscience/ErrorDisplayWidget.js diff --git a/productMods/css/visualization/mapofscience/layout.css b/productMods/css/visualization/mapofscience/layout.css index 1cf098fa..787468f4 100644 --- a/productMods/css/visualization/mapofscience/layout.css +++ b/productMods/css/visualization/mapofscience/layout.css @@ -232,4 +232,9 @@ a.map-of-science-links { #noPublications-span a { color: #84a655; font-size:16px; +} + +ul.error-list li { + font-size: 0.81em; + list-style: disc inside none; } \ No newline at end of file diff --git a/productMods/js/visualization/mapofscience/ErrorDisplayWidget.js b/productMods/js/visualization/mapofscience/ErrorDisplayWidget.js new file mode 100644 index 00000000..1959505e --- /dev/null +++ b/productMods/js/visualization/mapofscience/ErrorDisplayWidget.js @@ -0,0 +1,100 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +var ErrorDisplayWidget = Class.extend({ + + container: '', + body: '', + bodyID: 'error-body', + messagePlaceholderID: 'variable-error-text', + + init: function(opts) { + + this.container = $("#" + opts.containerID); + this.body = this.container.find("#" + this.bodyID); + }, + + isErrorConditionTriggered: function(responseData) { + + if (responseData.error) { + return true; + } + + if (responseData[0].pubsMapped === 0) { + return true; + } + + return false; + }, + + show: function(errorForType, responseData) { + + var isZeroPublicationsCase = responseData.error ? true : false; + var newErrorMessage = ""; + + /* + * This means that the organization or person has zero publications. + * */ + if (isZeroPublicationsCase) { + + newErrorMessage += "No publications in the system have been attributed to this " + errorForType.toLowerCase() + "."; + + } else { + /* + * This means that the organization or person has publications but none of them are mapped. + * Change the default text. + * */ + newErrorMessage += this._getUnScienceLocatedErrorMessage(errorForType, responseData[0]); + } + + /* + * Now replace the error message with the newly created one. + * */ + this.body.find("#" + this.messagePlaceholderID).html(newErrorMessage); + + this.container.show(); + }, + + _getUnScienceLocatedErrorMessage: function(errorForType, responseData) { + + var totalPublications = responseData.pubsWithNoJournals + responseData.pubsWithInvalidJournals; + var newErrorMessage = ""; + + if (totalPublications > 1) { + newErrorMessage = "None of the " + totalPublications + " publications attributed to this " + + errorForType.toLowerCase() + " have been 'science-located'."; + + } else { + newErrorMessage = "The publication attributed to this " + + errorForType.toLowerCase() + " has not been 'science-located'."; + } + + + newErrorMessage += ""; + + return newErrorMessage; + }, + + hide: function() { + this.container.hide(); + } + +}); \ No newline at end of file diff --git a/productMods/js/visualization/mapofscience/InitializeMap.js b/productMods/js/visualization/mapofscience/InitializeMap.js index 48e7f7dd..3c2b4c46 100644 --- a/productMods/js/visualization/mapofscience/InitializeMap.js +++ b/productMods/js/visualization/mapofscience/InitializeMap.js @@ -6,6 +6,8 @@ var currentVisMode; var currentController; var visModeControllers = {}; var responseContainerID = "map-of-science-response"; +var ERROR_DISPLAY_WIDGET = ''; + var loadingScreenTimeout; /* @@ -84,6 +86,11 @@ function helper() { /* Using .load instead of .ready due to issue with IE and Google Maps API */ $(window).load(function() { + + ERROR_DISPLAY_WIDGET = new ErrorDisplayWidget({ + containerID: 'error-container' + }); + setupLoadingScreen(); initMap(); initVisModeController(); diff --git a/productMods/js/visualization/mapofscience/VisModeControllers.js b/productMods/js/visualization/mapofscience/VisModeControllers.js index 2d9ab836..c9721348 100644 --- a/productMods/js/visualization/mapofscience/VisModeControllers.js +++ b/productMods/js/visualization/mapofscience/VisModeControllers.js @@ -74,11 +74,11 @@ var EntityVisModeController = Class.extend({ $("#" + responseContainerID).unblock(); - if (data.error) { + if (ERROR_DISPLAY_WIDGET.isErrorConditionTriggered(data)) { $("#map-of-science-response").hide(); - $("#error-container").show(); + ERROR_DISPLAY_WIDGET.show(ENTITY_TYPE, data); return; - } + } data = data[0]; diff --git a/productMods/templates/freemarker/visualization/mapOfScience/mapOfScienceSetup.ftl b/productMods/templates/freemarker/visualization/mapOfScience/mapOfScienceSetup.ftl index fa132aad..8034fbc4 100644 --- a/productMods/templates/freemarker/visualization/mapOfScience/mapOfScienceSetup.ftl +++ b/productMods/templates/freemarker/visualization/mapOfScience/mapOfScienceSetup.ftl @@ -45,6 +45,8 @@ var disciplineLabelImageUrlPrefix = mapOfScienceImageFolderPrefix + "labels/"; var entityLabel = '${entityLabel}'; +var ENTITY_TYPE = '${entityType}'; + var loadingImageLink = contextPath + "/images/visualization/ajax-loader-indicator.gif"; var refreshPageImageLink = contextPath + "/images/visualization/refresh-green.png"; @@ -62,6 +64,7 @@ ${scripts.add('', '', '', + '', '', '', '', diff --git a/productMods/templates/freemarker/visualization/mapOfScience/mapOfScienceStandalone.ftl b/productMods/templates/freemarker/visualization/mapOfScience/mapOfScienceStandalone.ftl index c341d260..870d8991 100644 --- a/productMods/templates/freemarker/visualization/mapOfScience/mapOfScienceStandalone.ftl +++ b/productMods/templates/freemarker/visualization/mapOfScience/mapOfScienceStandalone.ftl @@ -142,13 +142,11 @@ concern.

${entityLabel}

- -

Map of Science Visualization

+

Map of Science Visualization

-

This organization has neither sub-organizations nor people with publications in the system. - Please visit the full ${entityLabel} profile page for a more complete overview.

+

No publications in the system have been attributed to this organization.


+ Please visit the ${entityLabel} profile page for a complete overview.

-
${headScripts.add('')} \ No newline at end of file diff --git a/src/edu/cornell/mannlib/vitro/webapp/visualization/mapofscience/MapOfScienceVisualizationRequestHandler.java b/src/edu/cornell/mannlib/vitro/webapp/visualization/mapofscience/MapOfScienceVisualizationRequestHandler.java index f9f4e15e..a1173957 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/visualization/mapofscience/MapOfScienceVisualizationRequestHandler.java +++ b/src/edu/cornell/mannlib/vitro/webapp/visualization/mapofscience/MapOfScienceVisualizationRequestHandler.java @@ -82,11 +82,6 @@ public class MapOfScienceVisualizationRequestHandler implements } -// System.out.println("current models in the system are"); -// for (Map.Entry entry : ConstructedModelTracker.getAllModels().entrySet()) { -// System.out.println(entry.getKey() + " -> " + entry.getValue().size()); -// } -// return prepareStandaloneMarkupResponse(vitroRequest, entityURI); } @@ -160,23 +155,7 @@ public class MapOfScienceVisualizationRequestHandler implements organizationEntity = OrganizationUtilityFunctions.mergeEntityIfShareSameURI( organizationEntity, organizationWithAssociatedPeople); - } /*else { - - - // This is for just people. - Set test = new HashSet(); - - test.add(new SubEntity(subjectEntityURI)); - - documentURIForAssociatedPeopleTOVO = SelectOnModelUtilities - .getPublicationsWithJournalForAssociatedPeople(dataset, test); - - organizationEntity = OrganizationUtilityFunctions.mergeEntityIfShareSameURI( - organizationEntity, - organizationWithAssociatedPeople); - - - }*/ + } if (allDocumentURIToVOs.isEmpty() && documentURIForAssociatedPeopleTOVO.isEmpty()) { @@ -347,19 +326,28 @@ public class MapOfScienceVisualizationRequestHandler implements } private TemplateResponseValues prepareStandaloneMarkupResponse(VitroRequest vreq, - String entityURI) { + String entityURI) + throws MalformedQueryParametersException { String standaloneTemplate = "mapOfScienceStandalone.ftl"; - String organizationLabel = OrganizationUtilityFunctions - .getEntityLabelFromDAO(vreq, - entityURI); + String entityLabel = UtilityFunctions.getIndividualLabelFromDAO( + vreq, + entityURI); Map body = new HashMap(); - body.put("title", organizationLabel + " - Map of Science Visualization"); + body.put("title", entityLabel + " - Map of Science Visualization"); body.put("entityURI", entityURI); body.put("entityLocalName", UtilityFunctions.getIndividualLocalName(entityURI, vreq)); - body.put("entityLabel", organizationLabel); + body.put("entityLabel", entityLabel); + + if (UtilityFunctions.isEntityAPerson(vreq, entityURI)) { + body.put("entityType", "PERSON"); + + } else { + body.put("entityType", "ORGANIZATION"); + } + body.put("vivoDefaultNamespace", vreq.getWebappDaoFactory().getDefaultNamespace()); return new TemplateResponseValues(standaloneTemplate, body);