forked from crismaproject/worldstate-analysis-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2 load indicator data from study group entity
- Loading branch information
1 parent
cba2c13
commit 8732dee
Showing
9 changed files
with
724 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ app/bower_components | |
target | ||
.checkDependencies | ||
test-results.xml | ||
private/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
486 changes: 486 additions & 0 deletions
486
app/scripts/controllers/drupalContextProviderDirectiveController.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
] | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters