github.com/outbrain/consul@v1.4.5/ui-v2/app/routes/dc/nodes/show.js (about) 1 import Route from '@ember/routing/route'; 2 import { inject as service } from '@ember/service'; 3 import { hash } from 'rsvp'; 4 import { get, set } from '@ember/object'; 5 6 import distance from 'consul-ui/utils/distance'; 7 import tomographyFactory from 'consul-ui/utils/tomography'; 8 import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions'; 9 10 const tomography = tomographyFactory(distance); 11 12 export default Route.extend(WithBlockingActions, { 13 repo: service('repository/node'), 14 sessionRepo: service('repository/session'), 15 queryParams: { 16 s: { 17 as: 'filter', 18 replace: true, 19 }, 20 }, 21 model: function(params) { 22 const dc = this.modelFor('dc').dc.Name; 23 const repo = get(this, 'repo'); 24 const sessionRepo = get(this, 'sessionRepo'); 25 return hash({ 26 item: repo.findBySlug(params.name, dc), 27 }).then(function(model) { 28 // TODO: Consider loading this after initial page load 29 const coordinates = get(model.item, 'Coordinates'); 30 return hash({ 31 ...model, 32 ...{ 33 tomography: 34 get(coordinates, 'length') > 1 35 ? tomography(params.name, coordinates.map(item => get(item, 'data'))) 36 : null, 37 items: get(model.item, 'Services'), 38 sessions: sessionRepo.findByNode(get(model.item, 'Node'), dc), 39 }, 40 }); 41 }); 42 }, 43 setupController: function(controller, model) { 44 this._super(...arguments); 45 controller.setProperties(model); 46 }, 47 actions: { 48 invalidateSession: function(item) { 49 const dc = this.modelFor('dc').dc.Name; 50 const controller = this.controller; 51 const repo = get(this, 'sessionRepo'); 52 return get(this, 'feedback').execute(() => { 53 const node = get(item, 'Node'); 54 return repo.remove(item).then(() => { 55 return repo.findByNode(node, dc).then(function(sessions) { 56 set(controller, 'sessions', sessions); 57 }); 58 }); 59 }, 'delete'); 60 }, 61 }, 62 });