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 | 5103148 | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 13 | Subscribers.query().$promise |
Matteo Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 14 | .then((subscribers) => { |
| 15 | this.subscribers = subscribers; |
Matteo Scandolo | 77d8fa0 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 16 | return ServiceRelation.get(); |
Matteo Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 17 | }) |
| 18 | .then((serviceChain) => { |
| 19 | this.serviceChain = serviceChain; |
Matteo Scandolo | 07246ca | 2016-02-22 09:16:46 -0800 | [diff] [blame] | 20 | }) |
| 21 | .catch(e => { |
| 22 | throw new Error(e); |
| 23 | this.error = e; |
| 24 | }) |
| 25 | .finally(() => { |
| 26 | this.loader = false; |
Matteo Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 27 | }); |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 28 | |
| 29 | $rootScope.$on('subscriber.selected', (evt, subscriber) => { |
| 30 | ServiceRelation.getBySubscriber(subscriber) |
| 31 | .then((serviceChain) => { |
| 32 | this.serviceChain = serviceChain; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 33 | ChartData.currentServiceChain = serviceChain; |
Matteo Scandolo | 45fba73 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 34 | return Subscribers.getWithDevices({id: subscriber.id}).$promise; |
| 35 | }) |
| 36 | .then((subscriber) => { |
| 37 | this.selectedSubscriber = subscriber; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 38 | ChartData.currentSubscriber = subscriber; |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 39 | }); |
| 40 | }); |
Matteo Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | }); |
Matteo Scandolo | 70ac216 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 44 | })(); |