blob: 30d957b592ce55a61bd721c61147b683287c4d1a [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
Sean Condonf4f54a12018-10-10 23:25:46 +01002 * Copyright 2018-present Open Networking Foundation
Sean Condon83fc39f2018-04-19 18:56:13 +01003 *
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 */
16import { Injectable } from '@angular/core';
Sean Condon87b78502018-09-17 20:53:24 +010017import { HttpClient } from '@angular/common/http';
Sean Condon83fc39f2018-04-19 18:56:13 +010018import { FnService } from '../util/fn.service';
Sean Condon5ca00262018-09-06 17:55:25 +010019import { LogService } from '../log.service';
Sean Condon98b6ddb2019-12-24 08:07:40 +000020import {UrlFnService} from "../remote/urlfn.service";
Sean Condon83fc39f2018-04-19 18:56:13 +010021
Sean Condon87b78502018-09-17 20:53:24 +010022export interface UiView {
23 id: string;
24 icon: string;
25 cat: string;
26 label: string;
27}
28
Sean Condon83fc39f2018-04-19 18:56:13 +010029/**
30 * ONOS GUI -- Navigation Service
31 */
Sean Condon5ca00262018-09-06 17:55:25 +010032@Injectable({
33 providedIn: 'root',
34})
Sean Condon83fc39f2018-04-19 18:56:13 +010035export class NavService {
36 public showNav = false;
37
Sean Condon87b78502018-09-17 20:53:24 +010038 uiPlatformViews = new Array<UiView>();
39 uiNetworkViews = new Array<UiView>();
40 uiOtherViews = new Array<UiView>();
41 uiHiddenViews = new Array<UiView>();
42
Sean Condon83fc39f2018-04-19 18:56:13 +010043 constructor(
44 private _fn_: FnService,
Sean Condon87b78502018-09-17 20:53:24 +010045 private log: LogService,
Sean Condon98b6ddb2019-12-24 08:07:40 +000046 private ufs: UrlFnService,
47 private httpClient: HttpClient,
Sean Condon83fc39f2018-04-19 18:56:13 +010048 ) {
49 this.log.debug('NavService constructed');
50 }
51
52 hideNav() {
Sean Condonb2c483c2019-01-16 20:28:55 +000053 this.showNav = false;
54 this.log.debug('Hiding Nav menu');
Sean Condon83fc39f2018-04-19 18:56:13 +010055 }
56
57 toggleNav() {
58 this.showNav = !this.showNav;
59 if (this.showNav) {
60 this.log.debug('Showing Nav menu');
Sean Condon98b6ddb2019-12-24 08:07:40 +000061 this.getUiViews();
Sean Condon83fc39f2018-04-19 18:56:13 +010062 } else {
63 this.log.debug('Hiding Nav menu');
64 }
65 }
66
Sean Condon87b78502018-09-17 20:53:24 +010067 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 Condon98b6ddb2019-12-24 08:07:40 +000072 this.httpClient.get(this.ufs.rsUrl('nav/uiextensions')).subscribe((v: UiView[]) => {
Sean Condon87b78502018-09-17 20:53:24 +010073 v.forEach((uiView: UiView) => {
74 if (uiView.cat === 'PLATFORM') {
75 this.uiPlatformViews.push(uiView);
76 } else if (uiView.cat === 'NETWORK') {
Sean Condonaa4366d2018-11-02 14:29:01 +000077 if ( uiView.id !== 'topo') {
78 this.uiNetworkViews.push(uiView);
Sean Condon59d31372019-02-02 20:07:00 +000079 } else {
80 this.uiNetworkViews.push(<UiView>{
81 id: 'topo2',
82 icon: 'nav_topo',
83 cat: 'NETWORK',
84 label: uiView.label
85 });
Sean Condonaa4366d2018-11-02 14:29:01 +000086 }
Sean Condon87b78502018-09-17 20:53:24 +010087 } else if (uiView.cat === 'HIDDEN') {
88 this.uiHiddenViews.push(uiView);
89 } else {
90 this.uiOtherViews.push(uiView);
91 }
92 });
93 });
94 }
95
Sean Condon83fc39f2018-04-19 18:56:13 +010096}