blob: 7d97fdb685fd6871a743841b7d3207b4490440f8 [file] [log] [blame]
Matteo Scandolofcdbed32016-02-08 16:55:44 -08001(function () {
2 'use strict';
Matteo Scandolo04564952016-02-24 11:22:48 -08003 angular.module('xos.diagnostic')
Matteo Scandolo70ac2162016-02-24 15:40:22 -08004 .directive('diagnosticContainer', function(){
Matteo Scandolofcdbed32016-02-08 16:55:44 -08005 return {
6 restrict: 'E',
7 templateUrl: 'templates/diagnostic.tpl.html',
8 controllerAs: 'vm',
Matteo Scandolo70ac2162016-02-24 15:40:22 -08009 controller: function(ChartData, Subscribers, ServiceRelation, $rootScope, $log){
10
Matteo Scandolo07246ca2016-02-22 09:16:46 -080011 this.loader = true;
12 this.error = false;
Matteo Scandolo3a176a22016-03-07 16:42:03 -080013
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 Scandolo388795a2016-02-22 09:57:55 -080040
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080041 const loadSubscriber = (subscriber) => {
Matteo Scandolo388795a2016-02-22 09:57:55 -080042 ServiceRelation.getBySubscriber(subscriber)
43 .then((serviceChain) => {
44 this.serviceChain = serviceChain;
Matteo Scandolo012dddb2016-02-22 16:53:22 -080045 ChartData.currentServiceChain = serviceChain;
Matteo Scandolo45fba732016-02-22 14:53:44 -080046 return Subscribers.getWithDevices({id: subscriber.id}).$promise;
47 })
48 .then((subscriber) => {
49 this.selectedSubscriber = subscriber;
Matteo Scandolo012dddb2016-02-22 16:53:22 -080050 ChartData.currentSubscriber = subscriber;
Matteo Scandolo388795a2016-02-22 09:57:55 -080051 });
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080052 };
53
54 $rootScope.$on('subscriber.selected', (evt, subscriber) => {
55 loadSubscriber(subscriber);
Matteo Scandolo388795a2016-02-22 09:57:55 -080056 });
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080057
Matteo Scandolofcdbed32016-02-08 16:55:44 -080058 }
59 }
60 });
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080061})();