Matteo Scandolo | da19dff | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
Matteo Scandolo | 4b3d872 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 3 | angular.module('xos.diagnostic') |
Matteo Scandolo | 16763e9 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 4 | .directive('diagnosticContainer', function(){ |
Matteo Scandolo | da19dff | 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 | 16763e9 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 9 | controller: function(ChartData, Subscribers, ServiceRelation, $rootScope, $log){ |
| 10 | |
Matteo Scandolo | 17dc11d | 2016-02-22 09:16:46 -0800 | [diff] [blame] | 11 | this.loader = true; |
| 12 | this.error = false; |
Matteo Scandolo | ba2d63d | 2016-02-17 13:54:11 -0800 | [diff] [blame] | 13 | Subscribers.query().$promise |
Matteo Scandolo | da19dff | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 14 | .then((subscribers) => { |
| 15 | this.subscribers = subscribers; |
Matteo Scandolo | 657d132 | 2016-02-16 17:43:00 -0800 | [diff] [blame] | 16 | return ServiceRelation.get(); |
Matteo Scandolo | da19dff | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 17 | }) |
| 18 | .then((serviceChain) => { |
| 19 | this.serviceChain = serviceChain; |
Matteo Scandolo | 17dc11d | 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 | da19dff | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 27 | }); |
Matteo Scandolo | cc8fa15 | 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 | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 33 | ChartData.currentServiceChain = serviceChain; |
Matteo Scandolo | dffc138 | 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 | 0344ef3 | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 38 | ChartData.currentSubscriber = subscriber; |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 39 | }); |
| 40 | }); |
Matteo Scandolo | da19dff | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | }); |
Matteo Scandolo | 16763e9 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 44 | })(); |