Skip to content
Snippets Groups Projects
Commit 31f2f3c9 authored by Mathis Neumann's avatar Mathis Neumann
Browse files

update the graph whenever the changelog changes

parent ba3dbf34
No related branches found
No related tags found
No related merge requests found
import Ember from 'ember';
const observables = [
'nodes',
'nodeGroups',
'serviceInstances',
'communicationInstances'
];
export default Ember.Controller.extend({
graphingService: Ember.inject.service(),
init() {
this.debug('initializing controller');
},
// gets automatically updated when any of the instances changes (updated from changelog stream)
graphModel: Ember.computed(`model.instances.{${observables.join(',')}}.[]`, function() {
const systemId = this.get('model.systemId');
const instances = this.get('model.instances');
/*
* Since we use findAll to not load ALL instances but only for a specific system,
* Ember would cache any instances by any system in the store,
* this might lead to unexpected behavior after navigating to multiple systems/deployments.
* Solution: filter out invalid
*/
const filteredInstances = {};
Object.keys(instances).map((key) => {
filteredInstances[key] = instances[key].filterBy('systemId', systemId);
});
this.debug('creating graph', filteredInstances);
return this.get('graphingService').createGraph(filteredInstances); // TODO: update instead of complete recalculation?
}),
});
\ No newline at end of file
......@@ -2,7 +2,6 @@ import Ember from 'ember';
export default Ember.Route.extend({
session: Ember.inject.service(), // loads services/session.js
graphingService: Ember.inject.service(),
changelogStream: Ember.inject.service(),
model(params) {
const systemId = params.systemId;
......@@ -10,22 +9,31 @@ export default Ember.Route.extend({
const changelogStream = this.get('changelogStream'); // lazy loaded, requires session id
changelogStream.connect(systemId);
const graphingService = this.get('graphingService');
const createGraph = graphingService.createGraph.bind(graphingService);
/*
* note that findAll returns an Observable Array which automatically
* update whenever new records are pushed into the store.
* The controller can observe this.
* Also note that since we changed the behavior of findAll() to use the systemId
* Ember will probably also update for other systems. These are filtered in the controller
*/
const load = (type) => this.store.findAll(type);
this.set('loading', true);
return Ember.RSVP.hash({
nodes: this.store.findAll('node'),
nodeGroups: this.store.findAll('nodegroup'),
services: this.store.findAll('service'),
serviceInstances: this.store.findAll('serviceinstance'),
communications: this.store.findAll('communication'),
communicationInstances: this.store.findAll('communicationinstance')
}).then(createGraph).then((graph) => {
this.set('loading', false);
return graph;
nodes: load('node'),
nodeGroups: load('nodegroup'),
services: load('service'),
serviceInstances: load('serviceinstance'),
communications: load('communication'),
communicationInstances: load('communicationinstance')
}).then((models) => {
this.debug('loaded models', models);
return {
systemId: systemId,
instances: models
};
});
},
actions: {
loadDetails(rawEntity) {
this.debug('loadDetails action', rawEntity);
......@@ -42,7 +50,7 @@ export default Ember.Route.extend({
});
this.transitionTo(url);
},
willTransition() {
willTransition() { // FIXME: do not disconnect for subpages!
this.get('changelogStream').disconnect();
}
}
......
{{#architecture-viewer graph=model}}
{{#architecture-viewer graph=graphModel}}
{{!-- show entity details in sidebar if subroute (details) is used --}}
{{outlet}}
{{/architecture-viewer}}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment