blob: 6638a95fc1f16c2ec5eb66cd509c4b98983f6a5f [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 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 });
Matteo Scandolo70ac2162016-02-24 15:40:22 -080044})();