blob: 356583d7b904537ce485928416403a51a507b25f [file] [log] [blame]
Matteo Scandolofcdbed32016-02-08 16:55:44 -08001(function () {
2 'use strict';
3
Matteo Scandolo04564952016-02-24 11:22:48 -08004 angular.module('xos.diagnostic')
Matteo Scandolofcdbed32016-02-08 16:55:44 -08005 .directive('diagnostic', function(){
6 return {
7 restrict: 'E',
8 templateUrl: 'templates/diagnostic.tpl.html',
9 controllerAs: 'vm',
Matteo Scandolo012dddb2016-02-22 16:53:22 -080010 controller: function(ChartData, Subscribers, ServiceRelation, $rootScope){
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 Scandolo07246ca2016-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 Scandolofcdbed32016-02-08 16:55:44 -080027 });
Matteo Scandolo388795a2016-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 Scandolo012dddb2016-02-22 16:53:22 -080033 ChartData.currentServiceChain = serviceChain;
Matteo Scandolo45fba732016-02-22 14:53:44 -080034 return Subscribers.getWithDevices({id: subscriber.id}).$promise;
35 })
36 .then((subscriber) => {
37 this.selectedSubscriber = subscriber;
Matteo Scandolo012dddb2016-02-22 16:53:22 -080038 ChartData.currentSubscriber = subscriber;
Matteo Scandolo388795a2016-02-22 09:57:55 -080039 });
40 });
Matteo Scandolofcdbed32016-02-08 16:55:44 -080041 }
42 }
43 });
44})();