Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
| 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 Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 16 | import { Component, OnInit, OnDestroy } from '@angular/core'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 17 | import { LionService } from './fw/util/lion.service'; |
| 18 | import { LogService } from './log.service'; |
| 19 | import { KeyService } from './fw/util/key.service'; |
| 20 | import { ThemeService } from './fw/util/theme.service'; |
| 21 | import { GlyphService } from './fw/svg/glyph.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 22 | import { PanelService } from './fw/layer/panel.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 23 | import { QuickHelpService } from './fw/layer/quickhelp.service'; |
| 24 | import { EeService } from './fw/util/ee.service'; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 25 | import { WebSocketService, WsOptions } from './fw/remote/websocket.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 26 | import { SpriteService } from './fw/svg/sprite.service'; |
| 27 | import { OnosService, View } from './onos.service'; |
| 28 | |
| 29 | // secret sauce |
| 30 | const 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 | |
| 53 | function 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 Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 63 | styleUrls: ['./onos.component.css', './onos.common.css'] |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 64 | }) |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 65 | export class OnosComponent implements OnInit, OnDestroy { |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 66 | 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 Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 83 | private ps: PanelService, |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 84 | private qhs: QuickHelpService, |
| 85 | private ee: EeService, |
Sean Condon | a00bf38 | 2018-06-23 07:54:01 +0100 | [diff] [blame^] | 86 | public wss: WebSocketService, |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 87 | 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 Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 102 | this.wss.createWebSocket(<WsOptions>{ wsport: 8181}); |
| 103 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 104 | 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 Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 113 | // TODO: Enable this this.saucy(this.ee, this.ks); |
| 114 | this.log.debug('OnosComponent initialized'); |
| 115 | } |
| 116 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 117 | 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 Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 126 | 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 | } |