diff --git a/app/scripts/connectors/nodeConnector.js b/app/scripts/connectors/nodeConnector.js index 89192e2..e39a7a0 100644 --- a/app/scripts/connectors/nodeConnector.js +++ b/app/scripts/connectors/nodeConnector.js @@ -23,6 +23,12 @@ window.Drupal.behaviors.myBehavior = { } else { console.error('no global csisHelpers object found, probably not connected to Drupal!'); } + + // ugly workaround for https://github.com/clarity-h2020/csis-helpers-module/issues/9#issuecomment-539436236 + //var baseTag = document.createElement('base'); + //var prependURL = 'https://csis.myclimateservice.eu/apps/scenario-analysis/app/'; + //baseTag.href = prependURL ; + //$('#scenario-analysis').contents().find('head').append(baseTag); var connectCount = 0; // for some unknown the reason angular directive controler of the embedded child iframe diff --git a/app/scripts/controllers/drupalContextProviderDirectiveController.js b/app/scripts/controllers/drupalContextProviderDirectiveController.js index adf39b0..a69994a 100644 --- a/app/scripts/controllers/drupalContextProviderDirectiveController.js +++ b/app/scripts/controllers/drupalContextProviderDirectiveController.js @@ -215,7 +215,6 @@ angular.module( try { /* - * * accept two differnt kind of files. * 1. A plain icc data object. * In that case we apply a standard name to this object @@ -228,7 +227,7 @@ angular.module( origLoadedIndicators = indicatorObject.iccdata; worldstateDummy.iccdata = { // this is a total mess: serialise the deserialized icc data again - // so that it can be deserilaized by icmm helper library + // so that it can be deserialized by icmm helper library actualaccessinfo: JSON.stringify(worldstateDummy.iccdata) }; } else { @@ -283,7 +282,11 @@ angular.module( if (!containsIndicator) { msg = 'Could not load indicator file ' + worldstateDummy.name + '. It contains no indicator data for ' + indicator; console.error(msg, worldstateDummy); - showIndicatorFileLoadingError(msg); + /** + * Silently ignore. It's not a bug - it's a feature! ;-) + * See https://github.com/clarity-h2020/scenario-analysis/issues/19 + */ + // showIndicatorFileLoadingError(msg); return; } } @@ -304,8 +307,8 @@ angular.module( } // an excellent example on technical debt and accidental complexity: - // instead of adressing the root cause of the problem, we - // introduce additional inadequateness and ambiguity + // instead of adressing the root cause of the problem, sb + // introduced additional inadequateness and ambiguity Icmm.convertToCorrectIccDataFormat(worldstateDummy); if ($scope.worldstates) { @@ -320,7 +323,10 @@ angular.module( // when indicator objects are added we want them to be selected by default $scope.selectedWorldstates.splice(0, $scope.selectedWorldstates.length); $scope.worldstates.forEach(function (object, index) { - $scope.toggleSelection(index); + // but not more than 5 indicators! + if(index < 5) { + $scope.toggleSelection(index); + } }); //$scope.$apply(); @@ -564,7 +570,8 @@ angular.module( loadIndicatorObjects(worldstates); }, function (error) { - console.error(error.message, error); + showIndicatorFileLoadingError(error); + console.error(error); }); }; diff --git a/app/scripts/controllers/fileContextProviderDirectiveController.js b/app/scripts/controllers/fileContextProviderDirectiveController.js index bfe31d1..ca8e589 100644 --- a/app/scripts/controllers/fileContextProviderDirectiveController.js +++ b/app/scripts/controllers/fileContextProviderDirectiveController.js @@ -219,7 +219,11 @@ angular.module( if (!containsIndicator) { msg = 'Could not load indicator file ' + file.name + '. It contains no indicator data for ' + indicator; console.error(msg); - showIndicatorFileLoadingError(msg); + /** + * Silently ignore. It's not a bug - it's a feature! ;-) + * See https://github.com/clarity-h2020/scenario-analysis/issues/19 + */ + // showIndicatorFileLoadingError(msg); return; } } @@ -254,7 +258,10 @@ angular.module( // when indicator objects are added we want them to be selected by default $scope.selectedWorldstates.splice(0, $scope.selectedWorldstates.length); $scope.worldstates.forEach(function (object, index) { - $scope.toggleSelection(index); + // but not more than 5 indicators! + if(index < 5) { + $scope.toggleSelection(index); + } }); $scope.$apply(); diff --git a/app/scripts/controllers/mainController.js b/app/scripts/controllers/mainController.js index 772182b..81c5909 100644 --- a/app/scripts/controllers/mainController.js +++ b/app/scripts/controllers/mainController.js @@ -24,9 +24,6 @@ angular.module( function ($window, $scope, $resource, $http, $timeout, $q, IcmmPersistanceService, FilesPersistanceService, drupalService, ngDialog) { 'use strict'; - var restApi = drupalService.restApi; - - var createChartModels; // we bind to the container object since the provider directives are nested in angular-bootstrap tabs // tabs create a own scope and thus override every "simple" property. using an container object the binding diff --git a/app/scripts/services/drupalService.js b/app/scripts/services/drupalService.js index 4efc602..38f14c1 100644 --- a/app/scripts/services/drupalService.js +++ b/app/scripts/services/drupalService.js @@ -131,7 +131,10 @@ angular.module( $this.drupalRestApi.initEmikatCredentials = function () { return $http({method: 'GET', url: $this.drupalRestApi.host + '/jsonapi/'}).then(function success(apiResponse) { - if (apiResponse !== null && apiResponse.data !== null && apiResponse.data.meta.links.me !== null && + // FIXME: this will throw an exception, if no user is logged in. -> meta.links is null + // TypeError: Cannot read property 'links' of undefined + if (apiResponse !== null && apiResponse.data !== null && apiResponse.data.meta && apiResponse.data.meta.links && + apiResponse.data.meta.links.me !== null && apiResponse.data.meta.links.me.meta !== null && apiResponse.data.meta.links.me.meta.id !== null) { // FIXME: Ugly workaround for https://github.com/clarity-h2020/docker-drupal/issues/57 apiResponse.data.meta.links.me.href = $this.drupalRestApi.host + '/jsonapi/user/user/' + apiResponse.data.meta.links.me.meta.id; @@ -153,12 +156,12 @@ angular.module( }); } else { - console.log('error retrieving meta.links.me: null from ' + apiResponse.data.meta.links.me.href); - $q.reject(apiResponse); + console.error('error retrieving meta.links.me: null from ' + $this.drupalRestApi.host + '/jsonapi/', apiResponse); + return $q.reject('error retrieving meta.links.me: null from ' + $this.drupalRestApi.host + '/jsonapi/'); } }, function error(apiErrorResponse) { $this.emikatRestApi.emikatCredentials = undefined; - console.log('error retrieving meta.links.me from ' + apiErrorResponse.data.meta.links.me.href + ': ' + apiErrorResponse); + console.error('error retrieving meta.links.me from ' + $this.drupalRestApi.host + '/jsonapi/', apiErrorResponse); $q.reject(apiErrorResponse); }); }; @@ -170,6 +173,7 @@ angular.module( if (!$this.drupalRestApi.emikatCredentials || $this.drupalRestApi.emikatCredentials === null || $this.drupalRestApi.emikatCredentials === undefined) { return $this.drupalRestApi.initEmikatCredentials(); } else { + // Calling $q.when takes a promise or any other type, if it is not a promise then it will wrap it in a promise and call resolve. $q.when($this.drupalRestApi.emikatCredentials); } }; @@ -246,7 +250,7 @@ angular.module( }, function credentialsErrorCallback(response) { console.error(response); - return $q.reject(response); + return $q.reject('You are not logged-in in CSIS and EMIKAT, respectively.'); }); } else { console.debug('emikat credentials already avilable, loading Impact Scenario Data for scenario ' + scenarioId + ' and view ' + viewId); @@ -302,7 +306,12 @@ angular.module( * @param {type} icon * @returns {Array} */ - $this.emikatHelper.transformImpactScenario = function (scenarioData, damageClasses, aggregate = false, icon = 'flower_injured_16.png') { + $this.emikatHelper.transformImpactScenario = function (scenarioData, damageClasses, aggregate, icon) { + // Yes, NetBeans will yell at function(aggregate = false, icon = 'flower_injured_16.png') + // See https://stackoverflow.com/questions/45562266/expected-but-found-in-warning-in-netbeans-for-js-function-with-default-param + aggregate = (typeof aggregate !== 'undefined') ? aggregate : false; + icon = (typeof icon !== 'undefined') ? icon : 'flower_injured_16.png'; + damageClasses = null; aggregate = false; @@ -335,9 +344,14 @@ angular.module( TIME_PERIODS[column[criteriaMap['TIME_PERIOD']]] + ')'; + /** + * Don't make functions within a loop. + */ + /* jshint ignore:start */ var worldstate = worldstates.find(function (ws) { return ws.name === scenarioName; }); + /* jshint ignore:end */ if (!worldstate || worldstate === null) { worldstate = {}; @@ -431,8 +445,8 @@ angular.module( * @param {type} imageName * @returns {unresolved} */ - var createReportImageFileResource = function (token, imageName = 'scenario-analysis.png') { - + var createReportImageFileResource = function (token, imageName) { + imageName = (typeof imageName !== 'undefined') ? imageName : 'scenario-analysis.png'; return $resource($this.drupalRestApi.host + '/jsonapi/node/report_image/field_image', { //_format: 'hal_json' @@ -460,11 +474,16 @@ angular.module( * @param {type} foreignObjectRendering * @returns {undefined} */ - $this.screenshotHelper.uploadScreenshot = function (elementId, title = elementId, imageName = elementId + '.png', comment = title, foreignObjectRendering = false) { - + $this.screenshotHelper.uploadScreenshot = function (elementId, title, comment, foreignObjectRendering) { + // ARGH. See https://stackoverflow.com/questions/45562266/expected-but-found-in-warning-in-netbeans-for-js-function-with-default-param + title = (typeof title !== 'undefined') ? title : elementId; + imageName = (typeof imageName !== 'undefined') ? imageName : elementId + '.png'; + comment = (typeof comment !== 'undefined') ? comment : title; + foreignObjectRendering = (typeof foreignObjectRendering !== 'undefined') ? foreignObjectRendering : false; + // STEP #1: // html2canvas screenshot function: take snapshot of HTML element $elementId (e.g.