blob: dc8430aba15e1dce3b26d216b2ee5611b1201c6f [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolofcdbed32016-02-08 16:55:44 -080019(function () {
20 'use strict';
Matteo Scandolo04564952016-02-24 11:22:48 -080021 angular.module('xos.diagnostic')
Matteo Scandolo70ac2162016-02-24 15:40:22 -080022 .directive('diagnosticContainer', function(){
Matteo Scandolofcdbed32016-02-08 16:55:44 -080023 return {
24 restrict: 'E',
25 templateUrl: 'templates/diagnostic.tpl.html',
26 controllerAs: 'vm',
Matteo Scandoloe64dcc02016-08-02 11:53:22 -070027 controller: function(ChartData, Subscribers, SubscribersWithDevice, ServiceRelation, $rootScope){
Matteo Scandolo70ac2162016-02-24 15:40:22 -080028
Matteo Scandolo07246ca2016-02-22 09:16:46 -080029 this.loader = true;
30 this.error = false;
Matteo Scandolo3a176a22016-03-07 16:42:03 -080031
32 const loadGlobalScope = () => {
33 Subscribers.query().$promise
34 .then((subscribers) => {
35 this.subscribers = subscribers;
36 return ServiceRelation.get();
37 })
38 .then((serviceChain) => {
39 this.serviceChain = serviceChain;
40 // debug helper
41 // loadSubscriber(this.subscribers[0]);
42 })
43 .catch(e => {
44 throw new Error(e);
45 this.error = e;
46 })
47 .finally(() => {
48 this.loader = false;
49 });
50 };
51
52 loadGlobalScope();
53
54 this.reloadGlobalScope = () => {
55 this.selectedSubscriber = null;
56 loadGlobalScope();
57 }
Matteo Scandolo388795a2016-02-22 09:57:55 -080058
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080059 const loadSubscriber = (subscriber) => {
Matteo Scandolo388795a2016-02-22 09:57:55 -080060 ServiceRelation.getBySubscriber(subscriber)
61 .then((serviceChain) => {
62 this.serviceChain = serviceChain;
Matteo Scandolo012dddb2016-02-22 16:53:22 -080063 ChartData.currentServiceChain = serviceChain;
Matteo Scandoloe64dcc02016-08-02 11:53:22 -070064 return SubscribersWithDevice.get({id: subscriber.id}).$promise;
Matteo Scandolo45fba732016-02-22 14:53:44 -080065 })
66 .then((subscriber) => {
67 this.selectedSubscriber = subscriber;
Matteo Scandolo012dddb2016-02-22 16:53:22 -080068 ChartData.currentSubscriber = subscriber;
Matteo Scandolo388795a2016-02-22 09:57:55 -080069 });
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080070 };
71
72 $rootScope.$on('subscriber.selected', (evt, subscriber) => {
73 loadSubscriber(subscriber);
Matteo Scandolo388795a2016-02-22 09:57:55 -080074 });
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080075
Matteo Scandolofcdbed32016-02-08 16:55:44 -080076 }
77 }
78 });
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080079})();