Skip to content

Commit

Permalink
Merge branch 'feature/019-non-existent-events' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Jan 27, 2020
2 parents cc0636e + 24697e0 commit f3551c0
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 26 deletions.
6 changes: 6 additions & 0 deletions app/scripts/connectors/nodeConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -564,7 +570,8 @@ angular.module(

loadIndicatorObjects(worldstates);
}, function (error) {
console.error(error.message, error);
showIndicatorFileLoadingError(error);
console.error(error);
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions app/scripts/controllers/mainController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 31 additions & 12 deletions app/scripts/services/drupalService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
});
};
Expand All @@ -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);
}
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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. <div id="inlcudeInReport">
$window.html2canvas(document.getElementById(elementId), {logging: true, foreignObjectRendering: foreignObjectRendering}).then(canvas => {
$window.html2canvas(document.getElementById(elementId), {logging: true, foreignObjectRendering: foreignObjectRendering}).then(function(canvas) {
canvas.toBlob(function uploadImage(imageBlob) {
// function is invoked on button press, so we can safely assume that the token promise was resolved.
// TODO: add some error checking before going live
Expand Down Expand Up @@ -515,7 +534,7 @@ angular.module(
},
data: glStepTemplate
}
).then(function successCallback(glStepResponse) {
).then(function successCallback() {
console.log('report image ' + reportImageResponse.data.id + ' successfully assigned to GL Step ' + $this.drupalRestApi.studyInfo.step_uuid);
}, function errorCallback(glStepErrorResponse) {
console.log('error updating GL Step ' + $this.drupalRestApi.studyInfo.step_uuid + ': ' + glStepErrorResponse);
Expand Down
2 changes: 1 addition & 1 deletion app/templates/drupalContextProviderTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h4 class="panel-title">
ng-click="indicatorFileCollapsed = !indicatorFileCollapsed">
<i ng-if="!indicatorFileCollapsed" class="glyphicon glyphicon-chevron-up"></i>
<i ng-if="indicatorFileCollapsed" class="glyphicon glyphicon-chevron-down"></i>
Indicator files
Indicators
</a>
<span style="font-size: 14px"
class="pull-right glyphicon glyphicon-plus-sign btn-file ">
Expand Down
1 change: 0 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ basePath: '',
'target/dist/bower_components/bootstrap/dist/js/bootstrap.js',
'target/dist/bower_components/angular/angular.js',
'target/dist/bower_components/angular-resource/angular-resource.js',
'target/dist/bower_components/angular-cookies/angular-cookies.min.js',
'target/dist/bower_components/ng-table/ng-table.js',
'target/dist/bower_components/angular-bootstrap/ui-bootstrap.js',
'target/dist/bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
Expand Down

0 comments on commit f3551c0

Please sign in to comment.