blob: a245fad67860bf5b9b44153c2669cbc41be316d4 [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +01001/*
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 */
16import { Component, OnInit } from '@angular/core';
17import { ViewControllerImpl } from '../viewcontroller';
18import {
19 FnService,
20 LogService,
21 PrefsService,
22 IconService,
Sean Condon91481822019-01-01 13:56:14 +000023 SvgUtilService, LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010024} 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})
39export class NoDeviceConnectedSvgComponent extends ViewControllerImpl implements OnInit {
Sean Condon91481822019-01-01 13:56:14 +000040 lionFn; // Function
Sean Condonf4f54a12018-10-10 23:25:46 +010041
42 constructor(
43 protected fs: FnService,
44 protected log: LogService,
45 protected ps: PrefsService,
Sean Condon91481822019-01-01 13:56:14 +000046 protected sus: SvgUtilService,
47 private lion: LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010048 ) {
49 super(fs, log, ps);
Sean Condon91481822019-01-01 13:56:14 +000050
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 Condonf4f54a12018-10-10 23:25:46 +010058 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 Condon91481822019-01-01 13:56:14 +000075 /**
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 Condonf4f54a12018-10-10 23:25:46 +010090}