Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | import { Injectable } from '@angular/core'; |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 17 | import { HttpClient } from '@angular/common/http'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 18 | import { FnService } from '../util/fn.service'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 19 | import { LogService } from '../log.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 20 | |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 21 | export interface UiView { |
| 22 | id: string; |
| 23 | icon: string; |
| 24 | cat: string; |
| 25 | label: string; |
| 26 | } |
| 27 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 28 | /** |
| 29 | * ONOS GUI -- Navigation Service |
| 30 | */ |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 31 | @Injectable({ |
| 32 | providedIn: 'root', |
| 33 | }) |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 34 | export class NavService { |
| 35 | public showNav = false; |
| 36 | |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 37 | uiPlatformViews = new Array<UiView>(); |
| 38 | uiNetworkViews = new Array<UiView>(); |
| 39 | uiOtherViews = new Array<UiView>(); |
| 40 | uiHiddenViews = new Array<UiView>(); |
| 41 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 42 | constructor( |
| 43 | private _fn_: FnService, |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 44 | private log: LogService, |
| 45 | private httpClient: HttpClient |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 46 | ) { |
| 47 | this.log.debug('NavService constructed'); |
| 48 | } |
| 49 | |
| 50 | hideNav() { |
| 51 | this.showNav = !this.showNav; |
| 52 | if (!this.showNav) { |
| 53 | this.log.debug('Hiding Nav menu'); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | toggleNav() { |
| 58 | this.showNav = !this.showNav; |
| 59 | if (this.showNav) { |
| 60 | this.log.debug('Showing Nav menu'); |
| 61 | } else { |
| 62 | this.log.debug('Hiding Nav menu'); |
| 63 | } |
| 64 | } |
| 65 | |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 66 | getUiViews() { |
| 67 | this.uiPlatformViews = new Array<UiView>(); |
| 68 | this.uiNetworkViews = new Array<UiView>(); |
| 69 | this.uiOtherViews = new Array<UiView>(); |
| 70 | this.uiHiddenViews = new Array<UiView>(); |
| 71 | this.httpClient.get('rs/nav/uiextensions').subscribe((v: UiView[]) => { |
| 72 | v.forEach((uiView: UiView) => { |
| 73 | if (uiView.cat === 'PLATFORM') { |
| 74 | this.uiPlatformViews.push(uiView); |
| 75 | } else if (uiView.cat === 'NETWORK') { |
| 76 | this.uiNetworkViews.push(uiView); |
| 77 | } else if (uiView.cat === 'HIDDEN') { |
| 78 | this.uiHiddenViews.push(uiView); |
| 79 | } else { |
| 80 | this.uiOtherViews.push(uiView); |
| 81 | } |
| 82 | }); |
| 83 | }); |
| 84 | } |
| 85 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 86 | } |