Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 { Component, OnInit } from '@angular/core'; |
| 17 | import { ViewControllerImpl } from '../viewcontroller'; |
| 18 | import { |
| 19 | FnService, |
| 20 | LogService, |
| 21 | PrefsService, |
| 22 | IconService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 23 | SvgUtilService, LionService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 24 | } from 'gui2-fw-lib'; |
| 25 | |
| 26 | /** |
| 27 | * ONOS GUI -- Topology No Connected Devices View. |
| 28 | * View that contains the 'No Connected Devices' message |
| 29 | * |
| 30 | * This component is an SVG snippet that expects to be in an SVG element with a view box of 1000x1000 |
| 31 | * |
| 32 | * It should be added to a template with a tag like <svg:g onos-nodeviceconnected /> |
| 33 | */ |
| 34 | @Component({ |
| 35 | selector: '[onos-nodeviceconnected]', |
| 36 | templateUrl: './nodeviceconnectedsvg.component.html', |
| 37 | styleUrls: ['./nodeviceconnectedsvg.component.css'] |
| 38 | }) |
| 39 | export class NoDeviceConnectedSvgComponent extends ViewControllerImpl implements OnInit { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 40 | lionFn; // Function |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 41 | |
| 42 | constructor( |
| 43 | protected fs: FnService, |
| 44 | protected log: LogService, |
| 45 | protected ps: PrefsService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 46 | protected sus: SvgUtilService, |
| 47 | private lion: LionService |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 48 | ) { |
| 49 | super(fs, log, ps); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 50 | |
| 51 | if (this.lion.ubercache.length === 0) { |
| 52 | this.lionFn = this.dummyLion; |
| 53 | this.lion.loadCbs.set('topo-nodevices', () => this.doLion()); |
| 54 | } else { |
| 55 | this.doLion(); |
| 56 | } |
| 57 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 58 | this.log.debug('NoDeviceConnectedSvgComponent constructed'); |
| 59 | } |
| 60 | |
| 61 | ngOnInit() { |
| 62 | this.log.debug('NoDeviceConnectedSvgComponent initialized'); |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * The whole SVG canvas is based on a 1000 by 1000 box |
| 67 | */ |
| 68 | centre(repositionBox: SVGRect) { |
| 69 | const scale: number = Number.parseFloat((1000 / repositionBox.width).toFixed(3)); |
| 70 | repositionBox.x -= Number.parseFloat((repositionBox.width * scale / 2).toFixed(0)); |
| 71 | repositionBox.y -= Number.parseFloat((repositionBox.height * scale / 2).toFixed(0)); |
| 72 | return this.sus.translate([repositionBox.x, repositionBox.y]) + '' + this.sus.scale(scale, scale); |
| 73 | } |
| 74 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame^] | 75 | /** |
| 76 | * Read the LION bundle for Details panel and set up the lionFn |
| 77 | */ |
| 78 | doLion() { |
| 79 | this.lionFn = this.lion.bundle('core.view.Topo'); |
| 80 | |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * A dummy implementation of the lionFn until the response is received and the LION |
| 85 | * bundle is received from the WebSocket |
| 86 | */ |
| 87 | dummyLion(key: string): string { |
| 88 | return '%' + key + '%'; |
| 89 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 90 | } |