diff --git a/app/controllers/deployments/single.js b/app/controllers/deployments/single.js new file mode 100644 index 0000000000000000000000000000000000000000..cd0b8dc87d7042f302fb68d7167095f6da77a98e --- /dev/null +++ b/app/controllers/deployments/single.js @@ -0,0 +1,34 @@ +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 diff --git a/app/routes/deployments/single.js b/app/routes/deployments/single.js index 344ef5b113dfb49f35b9c2ae854795c82845ffb0..341da11767fe97b0ce8ee234c9fd7dd4afa220e1 100644 --- a/app/routes/deployments/single.js +++ b/app/routes/deployments/single.js @@ -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(); } } diff --git a/app/templates/deployments/single.hbs b/app/templates/deployments/single.hbs index 46f98c443ab171dbc00c1d8f65c7a9f81244d394..369bd73de964b292b1d53e533ab09b9f7aa742d6 100644 --- a/app/templates/deployments/single.hbs +++ b/app/templates/deployments/single.hbs @@ -1,4 +1,4 @@ -{{#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