Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 19 | (function () { |
| 20 | 'use strict'; |
Matteo Scandolo | 0456495 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 21 | angular.module('xos.diagnostic') |
Matteo Scandolo | 70ac216 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 22 | .directive('diagnosticContainer', function(){ |
Matteo Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 23 | return { |
| 24 | restrict: 'E', |
| 25 | templateUrl: 'templates/diagnostic.tpl.html', |
| 26 | controllerAs: 'vm', |
Matteo Scandolo | e64dcc0 | 2016-08-02 11:53:22 -0700 | [diff] [blame] | 27 | controller: function(ChartData, Subscribers, SubscribersWithDevice, ServiceRelation, $rootScope){ |
Matteo Scandolo | 70ac216 | 2016-02-24 15:40:22 -0800 | [diff] [blame] | 28 | |
Matteo Scandolo | 07246ca | 2016-02-22 09:16:46 -0800 | [diff] [blame] | 29 | this.loader = true; |
| 30 | this.error = false; |
Matteo Scandolo | 3a176a2 | 2016-03-07 16:42:03 -0800 | [diff] [blame] | 31 | |
| 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 Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 58 | |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 59 | const loadSubscriber = (subscriber) => { |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 60 | ServiceRelation.getBySubscriber(subscriber) |
| 61 | .then((serviceChain) => { |
| 62 | this.serviceChain = serviceChain; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 63 | ChartData.currentServiceChain = serviceChain; |
Matteo Scandolo | e64dcc0 | 2016-08-02 11:53:22 -0700 | [diff] [blame] | 64 | return SubscribersWithDevice.get({id: subscriber.id}).$promise; |
Matteo Scandolo | 45fba73 | 2016-02-22 14:53:44 -0800 | [diff] [blame] | 65 | }) |
| 66 | .then((subscriber) => { |
| 67 | this.selectedSubscriber = subscriber; |
Matteo Scandolo | 012dddb | 2016-02-22 16:53:22 -0800 | [diff] [blame] | 68 | ChartData.currentSubscriber = subscriber; |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 69 | }); |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | $rootScope.$on('subscriber.selected', (evt, subscriber) => { |
| 73 | loadSubscriber(subscriber); |
Matteo Scandolo | 388795a | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 74 | }); |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 75 | |
Matteo Scandolo | fcdbed3 | 2016-02-08 16:55:44 -0800 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | }); |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 79 | })(); |