blob: 419dd7c09c4d46506662747339d0192bed12e8dc [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 Scandolo51031482016-02-17 13:54:11 -080013 Subscribers.query().$promise
Matteo Scandolofcdbed32016-02-08 16:55:44 -080014 .then((subscribers) => {
15 this.subscribers = subscribers;
Matteo Scandolo77d8fa02016-02-16 17:43:00 -080016 return ServiceRelation.get();
Matteo Scandolofcdbed32016-02-08 16:55:44 -080017 })
18 .then((serviceChain) => {
19 this.serviceChain = serviceChain;
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080020 // debug helper
21 loadSubscriber(this.subscribers[0]);
Matteo Scandolo07246ca2016-02-22 09:16:46 -080022 })
23 .catch(e => {
24 throw new Error(e);
25 this.error = e;
26 })
27 .finally(() => {
28 this.loader = false;
Matteo Scandolofcdbed32016-02-08 16:55:44 -080029 });
Matteo Scandolo388795a2016-02-22 09:57:55 -080030
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080031 const loadSubscriber = (subscriber) => {
Matteo Scandolo388795a2016-02-22 09:57:55 -080032 ServiceRelation.getBySubscriber(subscriber)
33 .then((serviceChain) => {
34 this.serviceChain = serviceChain;
Matteo Scandolo012dddb2016-02-22 16:53:22 -080035 ChartData.currentServiceChain = serviceChain;
Matteo Scandolo45fba732016-02-22 14:53:44 -080036 return Subscribers.getWithDevices({id: subscriber.id}).$promise;
37 })
38 .then((subscriber) => {
39 this.selectedSubscriber = subscriber;
Matteo Scandolo012dddb2016-02-22 16:53:22 -080040 ChartData.currentSubscriber = subscriber;
Matteo Scandolo388795a2016-02-22 09:57:55 -080041 });
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080042 };
43
44 $rootScope.$on('subscriber.selected', (evt, subscriber) => {
45 loadSubscriber(subscriber);
Matteo Scandolo388795a2016-02-22 09:57:55 -080046 });
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080047
Matteo Scandolofcdbed32016-02-08 16:55:44 -080048 }
49 }
50 });
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080051})();