Matteo Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
Matteo Scandolo | 0456495 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 3 | angular.module('xos.diagnostic') |
Matteo Scandolo | 70ac216 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 4 | .directive('diagnosticContainer', function(){ |
Matteo Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 5 | return { |
| 6 | restrict: 'E', |
| 7 | templateUrl: 'templates/diagnostic.tpl.html', |
| 8 | controllerAs: 'vm', |
Matteo Scandolo | 70ac216 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 9 | controller: function(ChartData, Subscribers, ServiceRelation, $rootScope, $log){ |
| 10 | |
Matteo Scandolo | 07246ca | 2016-02-22 09:16:46 -0800 | [diff] [blame] | 11 | this.loader = true; |
| 12 | this.error = false; |
Matteo Scandolo | 3a176a2 | 2016-03-07 16:42:03 -0800 | [diff] [blame] | 13 | |
| 14 | const loadGlobalScope = () => { |
| 15 | Subscribers.query().$promise |
| 16 | .then((subscribers) => { |
| 17 | this.subscribers = subscribers; |
| 18 | return ServiceRelation.get(); |
| 19 | }) |
| 20 | .then((serviceChain) => { |
| 21 | this.serviceChain = serviceChain; |
| 22 | // debug helper |
| 23 | // loadSubscriber(this.subscribers[0]); |
| 24 | }) |
| 25 | .catch(e => { |
| 26 | throw new Error(e); |
| 27 | this.error = e; |
| 28 | }) |
| 29 | .finally(() => { |
| 30 | this.loader = false; |
| 31 | }); |
| 32 | }; |
| 33 | |
| 34 | loadGlobalScope(); |
| 35 | |
| 36 | this.reloadGlobalScope = () => { |
| 37 | this.selectedSubscriber = null; |
| 38 | loadGlobalScope(); |
| 39 | } |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 40 | |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 41 | const loadSubscriber = (subscriber) => { |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 42 | ServiceRelation.getBySubscriber(subscriber) |
| 43 | .then((serviceChain) => { |
| 44 | this.serviceChain = serviceChain; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 45 | ChartData.currentServiceChain = serviceChain; |
Matteo Scandolo | 45fba73 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 46 | return Subscribers.getWithDevices({id: subscriber.id}).$promise; |
| 47 | }) |
| 48 | .then((subscriber) => { |
| 49 | this.selectedSubscriber = subscriber; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 50 | ChartData.currentSubscriber = subscriber; |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 51 | }); |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | $rootScope.$on('subscriber.selected', (evt, subscriber) => { |
| 55 | loadSubscriber(subscriber); |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 56 | }); |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 57 | |
Matteo Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | }); |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 61 | })(); |