Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 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 | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 20 | import {UrlFnService} from "../remote/urlfn.service"; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 21 | |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 22 | export interface UiView { |
| 23 | id: string; |
| 24 | icon: string; |
| 25 | cat: string; |
| 26 | label: string; |
| 27 | } |
| 28 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 29 | /** |
| 30 | * ONOS GUI -- Navigation Service |
| 31 | */ |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 32 | @Injectable({ |
| 33 | providedIn: 'root', |
| 34 | }) |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 35 | export class NavService { |
| 36 | public showNav = false; |
| 37 | |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 38 | uiPlatformViews = new Array<UiView>(); |
| 39 | uiNetworkViews = new Array<UiView>(); |
| 40 | uiOtherViews = new Array<UiView>(); |
| 41 | uiHiddenViews = new Array<UiView>(); |
| 42 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 43 | constructor( |
| 44 | private _fn_: FnService, |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 45 | private log: LogService, |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 46 | private ufs: UrlFnService, |
| 47 | private httpClient: HttpClient, |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 48 | ) { |
| 49 | this.log.debug('NavService constructed'); |
| 50 | } |
| 51 | |
| 52 | hideNav() { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 53 | this.showNav = false; |
| 54 | this.log.debug('Hiding Nav menu'); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | toggleNav() { |
| 58 | this.showNav = !this.showNav; |
| 59 | if (this.showNav) { |
| 60 | this.log.debug('Showing Nav menu'); |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 61 | this.getUiViews(); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 62 | } else { |
| 63 | this.log.debug('Hiding Nav menu'); |
| 64 | } |
| 65 | } |
| 66 | |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 67 | getUiViews() { |
| 68 | this.uiPlatformViews = new Array<UiView>(); |
| 69 | this.uiNetworkViews = new Array<UiView>(); |
| 70 | this.uiOtherViews = new Array<UiView>(); |
| 71 | this.uiHiddenViews = new Array<UiView>(); |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 72 | this.httpClient.get(this.ufs.rsUrl('nav/uiextensions')).subscribe((v: UiView[]) => { |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 73 | v.forEach((uiView: UiView) => { |
| 74 | if (uiView.cat === 'PLATFORM') { |
| 75 | this.uiPlatformViews.push(uiView); |
| 76 | } else if (uiView.cat === 'NETWORK') { |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 77 | if ( uiView.id !== 'topo') { |
| 78 | this.uiNetworkViews.push(uiView); |
Sean Condon | 59d3137 | 2019-02-02 20:07:00 +0000 | [diff] [blame] | 79 | } else { |
| 80 | this.uiNetworkViews.push(<UiView>{ |
| 81 | id: 'topo2', |
| 82 | icon: 'nav_topo', |
| 83 | cat: 'NETWORK', |
| 84 | label: uiView.label |
| 85 | }); |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 86 | } |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 87 | } else if (uiView.cat === 'HIDDEN') { |
| 88 | this.uiHiddenViews.push(uiView); |
| 89 | } else { |
| 90 | this.uiOtherViews.push(uiView); |
| 91 | } |
| 92 | }); |
| 93 | }); |
| 94 | } |
| 95 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 96 | } |