Skip to content

Commit

Permalink
#2 load indicator data from study group entity
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Oct 31, 2018
1 parent cba2c13 commit 8732dee
Show file tree
Hide file tree
Showing 9 changed files with 724 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ app/bower_components
target
.checkDependencies
test-results.xml
private/
19 changes: 19 additions & 0 deletions app/frameset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Scenario Analysis</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="bower_components/seamless/build/seamless.parent.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
window.onload = function () {
// Turns the iframe into a seamless iframe.
window.seamless(document.getElementById('scenarioanalysis'));
};
</script>

<iframe id="scenarioanalysis" src="index.html"></iframe>
</body>
</html>
2 changes: 2 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ <h3 class="panel-title ng-binding">
<script src="scripts/services/icmmPersistanceService.js"></script>
<script src="scripts/services/icmmCriteriaFunctions.js"></script>
<script src="scripts/services/icmmDecisionStrategies.js"></script>
<script src="scripts/services/drupalService.js"></script>
<script src="scripts/controllers/drupalContextProviderDirectiveController.js"></script>
<!-- endbuild -->

<!-- demo only -->
Expand Down
486 changes: 486 additions & 0 deletions app/scripts/controllers/drupalContextProviderDirectiveController.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions app/scripts/controllers/mainController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ angular.module(
'$q',
'eu.myclimateservice.csis.scenario-analysis.services.IcmmPersistanceService',
'eu.myclimateservice.csis.scenario-analysis.services.FilesPersistanceService',
'eu.myclimateservice.csis.scenario-analysis.services.drupalService',
'ngDialog',
function ($window, $scope, $resource, $http, $timeout, $q, IcmmPersistanceService, FilesPersistanceService, ngDialog) {
function ($window, $scope, $resource, $http, $timeout, $q, IcmmPersistanceService, FilesPersistanceService, drupalService, ngDialog) {
'use strict';

var parent = window.seamless.connect();
Expand All @@ -30,8 +31,9 @@ angular.module(
// Print out the data that was received.
console.log('child recieved: ' + data + event);
});

var drupal = 'http://roberto:8080';

var restApi = drupalService.restApi;


var createChartModels;
// we bind to the container object since the provider directives are nested in angular-bootstrap tabs
Expand Down Expand Up @@ -270,12 +272,12 @@ angular.module(
$window.html2canvas(document.getElementById(elementId), {logging: true, foreignObjectRendering: foreignObjectRendering}).then(canvas => {
document.body.appendChild(canvas);
var imageBlob = canvas.toDataURL().replace(/^data:image\/(png|jpg);base64,/, '');

//console.log(dataURL);
var payload = {
'_links': {
'type': {
'href': drupal + '/rest/type/file/image'
'href': restApi.host + '/rest/type/file/image'
}
},
'filename': [
Expand All @@ -298,10 +300,10 @@ angular.module(
/**
* 1) get the X-CSRF-Token
*/
$http({method: 'GET', url: drupal + '/rest/session/token'})
$http({method: 'GET', url: restApi.host + '/rest/session/token'})
.then(function tokenSuccessCallback(response) {

var uploadImage = $resource(drupal + '/entity/file',
var uploadImage = $resource(restApi.host + '/entity/file',
{
_format: 'hal_json'
}, {
Expand All @@ -325,8 +327,8 @@ angular.module(
// return the image id
return response.fid[0];
}, function uploadImageError(response) {
console.log('error uploading Image: ' + response);
$q.reject(response);
console.log('error uploading Image: ' + response.data.message);
$q.reject(response.data);
});
}, function tokenErrorCallback(response) {
console.log('error retrieving X-CSRF-Token: ' + response);
Expand All @@ -338,7 +340,7 @@ angular.module(
*/
function successCallback(response) {
console.log('image id: ' + response);

// TODO UPDATE Resource
},
function errorCallback(response) {
Expand All @@ -360,7 +362,5 @@ angular.module(
});*/
});
};

}
]
);
]);
3 changes: 2 additions & 1 deletion app/scripts/directives/fileBasedAnalysisContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ angular.module(
scope: scope,
restrict: 'E',
templateUrl: 'templates/fileContextProviderTemplate.html',
controller: 'eu.myclimateservice.csis.scenario-analysis.controllers.FileContextProviderDirectiveController'
//controller: 'eu.myclimateservice.csis.scenario-analysis.controllers.FileContextProviderDirectiveController'
controller: 'eu.myclimateservice.csis.scenario-analysis.controllers.drupalContextProviderDirectiveController'
};
}
]
Expand Down
93 changes: 93 additions & 0 deletions app/scripts/services/drupalDecisionStrategies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
angular.module(
'eu.myclimateservice.csis.scenario-analysis.services'
).factory(
'eu.myclimateservice.csis.scenario-analysis.services.DecisionStrategies',
[
'$resource',
'eu.myclimateservice.csis.scenario-analysis.services.configurationService',
function ($resource, configurationService) {
'use strict';
var decisionStrategy, transformResponse, decisionStrategyFacade, createResource;
transformResponse = function (studyJsonString) {
var study;
if (studyJsonString) {
study = JSON.parse(studyJsonString);

return JSON.parse(study.decisionStrategies);
}
return null;

};



createResource = function () {
var r;

r = $resource(configurationService.$this.drupalRestApi.host + '/' + configurationService.getDomain() + '.decisionstrategies/1', {
decisionStrategyId: '@id',
deduplicate: false,
omitNullValues: 'false'
}, {
'query': {
method: 'GET',
isArray: true,
params: {
level: '1',
omitNullValues: 'true'
},
transformResponse: transformResponse
},
'update': {
method: 'PUT',
transformRequest: function (data) {
var transformedData, study;
study = {
$self: '/CRISMA.decisionstrategies/1',
id: 1,
decisionStrategies: angular.toJson(data)
};
transformedData = JSON.stringify(study, function (k, v) {
// we have to take care of angular properties by ourselves
if (k.substring(0, 1) === '$' && !(k === '$self' || k === '$ref')) {
return undefined;
}

return v;
});
return transformedData;
}
}
});

r.getId = function () {
return Icmm.getNextId(configurationService.getIcmmApi() + '/' + configurationService.getDomain(), '.decisionstrategies');
};

return r;
};

decisionStrategy = createResource();
decisionStrategyFacade = {
'get': function () {
return decisionStrategy.get.apply(this, arguments);
},
'query': function () {
return decisionStrategy.query.apply(this, arguments);
},
'update': function () {
return decisionStrategy.update.apply(this, arguments);
},
'getId': function () {
return decisionStrategy.getId.apply(this, arguments);
}
};

configurationService.addApiListener(function () {
decisionStrategy = createResource();
});

return decisionStrategyFacade;
}
]
);
106 changes: 106 additions & 0 deletions app/scripts/services/drupalService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* ***************************************************
*
* cismet GmbH, Saarbruecken, Germany
*
* ... and it just works.
*
* ***************************************************
*/

/*global angular*/
/*jshint sub:true*/

angular.module(
'eu.myclimateservice.csis.scenario-analysis.services'
).factory('eu.myclimateservice.csis.scenario-analysis.services.drupalService',
['$http', '$resource', '$q', function ($http, $resource, $q) {
'use strict';

var $this;
$this = this;

// <editor-fold defaultstate="open" desc="=== drupalRestApi ===========================">
$this.drupalRestApi = {};
$this.drupalRestApi.host = ''; //http://roberto:8080';
$this.drupalRestApi.token = undefined;
// </editor-fold>

$this.drupalRestApi.initToken = function () {
return $http({method: 'GET', url: $this.drupalRestApi.host + '/rest/session/token'})
.then(function tokenSuccessCallback(response) {
$this.drupalRestApi.token = response.data;
console.log('X-CSRF-Token recieved from API: ' + $this.drupalRestApi.token);
return response.data;
}, function tokenErrorCallback(response) {
$this.drupalRestApi.token = undefined;
console.log('error retrieving X-CSRF-Token: ' + response);
$q.reject(undefined);
});
};

/**
* return a promise!
*/
$this.drupalRestApi.getToken = function () {
if (!$this.drupalRestApi.token || $this.drupalRestApi.token === null || $this.drupalRestApi.token === undefined) {
return $this.drupalRestApi.initToken();
} else {
$q.when($this.drupalRestApi.token);
}
};

$this.drupalRestApi.getStudy = function (studyId) {

return $this.drupalRestApi.getToken().then(function tokenSuccessCallback(token) {
var studyResource = $resource($this.drupalRestApi.host + '/study/:studyId',
{
studyId: '@studyId',
_format: 'hal_json'

}, {
get: {
method: 'GET',
isArray: false,
headers: {
'Content-Type': 'application/hal+json',
'X-CSRF-Token': token
}
}
});

var studyInstance = studyResource.get({studyId: studyId});
return studyInstance.$promise;

}, function tokenErrorCallback(response) {
return $q.reject(response);
});
};

// init the token
//$this.drupalRestApi.initToken();

$this.drupalStudyHelper = {};
$this.drupalStudyHelper.getIndicatorArray = function (study) {
if (!study || study === null || study === undefined ||
!study.field_indicators || study.field_indicators === null || study.field_indicators === undefined) {
return [];
} else {
var studyIndicators = [];
for(var i = 0; i < study.field_indicators.length; i++) {
// this is madness: parse into object and later stringify again
// so that it can be used by the akward ICMM library (won't touch this thing!)
var studyIndicator = JSON.parse(study.field_indicators[i].value);
studyIndicators.push(studyIndicator);
}
return studyIndicators;
}

};

return {
restApi: $this.drupalRestApi,
studyHelper: $this.drupalStudyHelper
};
}
]);
2 changes: 2 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ basePath: '',
'target/dist/scripts/services/icmmPersistanceService.js',
'target/dist/scripts/services/icmmCriteriaFunctions.js',
'target/dist/scripts/services/icmmDecisionStrategies.js',
'target/dist/scripts/services/drupalService.js',
'target/dist/scripts/services/drupalContextProviderDirectiveController.js',
'target/dist/bower_components/angular-mocks/angular-mocks.js',
'app/templates/criteriaEmphasesTemplate.html',
'app/templates/criteriaFunctionManagerTemplate.html',
Expand Down

0 comments on commit 8732dee

Please sign in to comment.