blob: 6638a95fc1f16c2ec5eb66cd509c4b98983f6a5f [file] [log] [blame]
Matteo Scandoloda19dff2016-02-08 16:55:44 -08001(function () {
2 'use strict';
Matteo Scandolo4b3d8722016-02-24 11:22:48 -08003 angular.module('xos.diagnostic')
Matteo Scandolo16763e92016-02-24 15:40:22 -08004 .directive('diagnosticContainer', function(){
Matteo Scandoloda19dff2016-02-08 16:55:44 -08005 return {
6 restrict: 'E',
7 templateUrl: 'templates/diagnostic.tpl.html',
8 controllerAs: 'vm',
Matteo Scandolo16763e92016-02-24 15:40:22 -08009 controller: function(ChartData, Subscribers, ServiceRelation, $rootScope, $log){
10
Matteo Scandolo17dc11d2016-02-22 09:16:46 -080011 this.loader = true;
12 this.error = false;
Matteo Scandoloba2d63d2016-02-17 13:54:11 -080013 Subscribers.query().$promise
Matteo Scandoloda19dff2016-02-08 16:55:44 -080014 .then((subscribers) => {
15 this.subscribers = subscribers;
Matteo Scandolo657d1322016-02-16 17:43:00 -080016 return ServiceRelation.get();
Matteo Scandoloda19dff2016-02-08 16:55:44 -080017 })
18 .then((serviceChain) => {
19 this.serviceChain = serviceChain;
Matteo Scandolo17dc11d2016-02-22 09:16:46 -080020 })
21 .catch(e => {
22 throw new Error(e);
23 this.error = e;
24 })
25 .finally(() => {
26 this.loader = false;
Matteo Scandoloda19dff2016-02-08 16:55:44 -080027 });
Matteo Scandolocc8fa152016-02-22 09:57:55 -080028
29 $rootScope.$on('subscriber.selected', (evt, subscriber) => {
30 ServiceRelation.getBySubscriber(subscriber)
31 .then((serviceChain) => {
32 this.serviceChain = serviceChain;
Matteo Scandolo0344ef32016-02-22 16:53:22 -080033 ChartData.currentServiceChain = serviceChain;
Matteo Scandolodffc1382016-02-22 14:53:44 -080034 return Subscribers.getWithDevices({id: subscriber.id}).$promise;
35 })
36 .then((subscriber) => {
37 this.selectedSubscriber = subscriber;
Matteo Scandolo0344ef32016-02-22 16:53:22 -080038 ChartData.currentSubscriber = subscriber;
Matteo Scandolocc8fa152016-02-22 09:57:55 -080039 });
40 });
Matteo Scandoloda19dff2016-02-08 16:55:44 -080041 }
42 }
43 });
Matteo Scandolo16763e92016-02-24 15:40:22 -080044})();