blob: c2680b7fac43aae265c5fae18a82fa5031801bce [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
2 * Copyright 2014-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 */
Sean Condon2bd11b72018-06-15 08:00:48 +010016import { Component, OnInit, OnDestroy } from '@angular/core';
Sean Condon83fc39f2018-04-19 18:56:13 +010017import { LionService } from './fw/util/lion.service';
18import { LogService } from './log.service';
19import { KeyService } from './fw/util/key.service';
20import { ThemeService } from './fw/util/theme.service';
21import { GlyphService } from './fw/svg/glyph.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010022import { PanelService } from './fw/layer/panel.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010023import { QuickHelpService } from './fw/layer/quickhelp.service';
24import { EeService } from './fw/util/ee.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010025import { WebSocketService, WsOptions } from './fw/remote/websocket.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010026import { SpriteService } from './fw/svg/sprite.service';
27import { OnosService, View } from './onos.service';
28
29// secret sauce
30const sauce: string[] = [
31 '6:69857666',
32 '9:826970',
33 '22:8069828667',
34 '6:698570688669887967',
35 '7:6971806889847186',
36 '22:8369867682',
37 '13:736583',
38 '7:667186698384',
39 '1:857780888778876787',
40 '20:70717066',
41 '24:886774868469',
42 '17:7487696973687580739078',
43 '14:70777086',
44 '17:7287687967',
45 '11:65678869706783687184',
46 '1:80777778',
47 '9:72696982',
48 '7:857165828967',
49 '11:8867696882678869759071'
50 // Add more sauce...
51];
52
53function cap(s: string): string {
54 return s ? s[0].toUpperCase() + s.slice(1) : s;
55}
56
57/**
58 * The main ONOS Component - the root of the whole user interface
59 */
60@Component({
61 selector: 'onos-root',
62 templateUrl: './onos.component.html',
Sean Condonfd6d11b2018-06-02 20:29:49 +010063 styleUrls: ['./onos.component.css', './onos.common.css']
Sean Condon83fc39f2018-04-19 18:56:13 +010064})
Sean Condon2bd11b72018-06-15 08:00:48 +010065export class OnosComponent implements OnInit, OnDestroy {
Sean Condon83fc39f2018-04-19 18:56:13 +010066 public title = 'onos';
67
68 // view ID to help page url map.. injected via the servlet
69 viewMap: View[] = [
70 // {INJECTED-VIEW-DATA-START}
71 // {INJECTED-VIEW-DATA-END}
72 ];
73
74 defaultView = 'topo';
75 // TODO Move this to OnosModule - warning servlet will have to be updated too
76 viewDependencies: string[] = [];
77
78 constructor (
79 private lion: LionService,
80 private ks: KeyService,
81 private ts: ThemeService,
82 private gs: GlyphService,
Sean Condon83fc39f2018-04-19 18:56:13 +010083 private ps: PanelService,
Sean Condon83fc39f2018-04-19 18:56:13 +010084 private qhs: QuickHelpService,
85 private ee: EeService,
Sean Condona00bf382018-06-23 07:54:01 +010086 public wss: WebSocketService,
Sean Condon83fc39f2018-04-19 18:56:13 +010087 private ss: SpriteService,
88 private log: LogService,
89 private onos: OnosService
90 ) {
91
92// This is not like onos.js of AngularJS 1.x In this new structure modules are
93// imported instead in the OnosModule. view dependencies should be there too
94// const moduleDependencies = coreDependencies.concat(this.viewDependencies);
95
96 // Testing of debugging
97 log.debug('OnosComponent: testing logger.debug()');
98 log.info('OnosComponent: testing logger.info()');
99 log.warn('OnosComponent: testing logger.warn()');
100 log.error('OnosComponent: testing logger.error()');
101
Sean Condonfd6d11b2018-06-02 20:29:49 +0100102 this.wss.createWebSocket(<WsOptions>{ wsport: 8181});
103
Sean Condon83fc39f2018-04-19 18:56:13 +0100104 log.debug('OnosComponent constructed');
105 }
106
107 ngOnInit() {
108 this.viewMap.forEach(view =>
109 this.viewDependencies.push('ov' + cap(view.id)));
110
111 this.onos.viewMap = this.viewMap;
112
Sean Condon83fc39f2018-04-19 18:56:13 +0100113 // TODO: Enable this this.saucy(this.ee, this.ks);
114 this.log.debug('OnosComponent initialized');
115 }
116
Sean Condon2bd11b72018-06-15 08:00:48 +0100117 ngOnDestroy() {
118 if (this.wss.isConnected()) {
119 this.log.debug('Stopping Web Socket connection');
120 this.wss.closeWebSocket();
121 }
122
123 this.log.debug('OnosComponent destroyed');
124 }
125
Sean Condon83fc39f2018-04-19 18:56:13 +0100126 saucy(ee, ks) {
127 const map = ee.genMap(sauce);
128 Object.keys(map).forEach(function (k) {
129 ks.addSeq(k, map[k]);
130 });
131 }
132}