blob: fddfe7f40bbc0db4ba42f472322d8f859d7fa92b [file] [log] [blame]
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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
17/*
18 ONOS GUI -- Layer -- Veil Service
19
20 Provides a mechanism to display an overlaying div with information.
21 Used mainly for web socket connection interruption.
22 */
23(function () {
24 'use strict';
25
26 // injected references
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070027 var $log, $route, fs, ks, gs;
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080028
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070029 var veil;
30
31 function init() {
32 var wSize = fs.windowSize(),
33 ww = wSize.width,
34 wh = wSize.height,
35 shrink = wh * 0.3,
36 birdDim = wh - shrink,
37 birdCenter = (ww - birdDim) / 2,
38 svg;
39
40 veil = d3.select('#veil');
41
42 svg = veil.select('svg').attr({
43 width: ww,
44 height: wh
45 }).style('opacity', 0.2);
46
47 gs.addGlyph(svg, 'bird', birdDim, false, [birdCenter, shrink/2]);
48 }
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080049
Simon Hunt36fc15c2015-02-12 17:02:58 -080050 // msg should be an array of strings
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080051 function show(msg) {
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070052 var msgs = fs.isA(msg) || [msg],
53 pdiv = veil.select('.msg');
Bri Prebilic Cole5e940e22015-02-06 11:34:08 -080054 pdiv.selectAll('p').remove();
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080055
Simon Hunt36fc15c2015-02-12 17:02:58 -080056 msgs.forEach(function (line) {
Bri Prebilic Cole5e940e22015-02-06 11:34:08 -080057 pdiv.append('p').text(line);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080058 });
59
60 veil.style('display', 'block');
Simon Hunt36fc15c2015-02-12 17:02:58 -080061 ks.enableKeys(false);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080062 }
63
64 function hide() {
65 veil.style('display', 'none');
Simon Hunt36fc15c2015-02-12 17:02:58 -080066 ks.enableKeys(true);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080067 }
68
Simon Huntbc76fb12015-02-26 18:09:54 -080069 // function that only invokes the veil if the caller is the current view
Simon Hunt4deb0e82015-06-10 16:18:25 -070070 // TODO: review - is this deprecated ?
Simon Huntbc76fb12015-02-26 18:09:54 -080071 function lostServer(ctrlName, msg) {
72 if ($route.current.$$route.controller === ctrlName) {
73 $log.debug('VEIL-service: ', ctrlName);
74 show(msg)
75 } else {
76 $log.debug('VEIL-service: IGNORING ', ctrlName);
77 }
78 }
79
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080080 angular.module('onosLayer')
Simon Hunt36fc15c2015-02-12 17:02:58 -080081 .factory('VeilService',
Thomas Vachuska0af26912016-03-21 21:37:30 -070082 ['$log', '$route', 'FnService', 'KeyService', 'GlyphService', 'WebSocketService',
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080083
Thomas Vachuska0af26912016-03-21 21:37:30 -070084 function (_$log_, _$route_, _fs_, _ks_, _gs_, wss) {
Simon Hunt36fc15c2015-02-12 17:02:58 -080085 $log = _$log_;
Simon Huntbc76fb12015-02-26 18:09:54 -080086 $route = _$route_;
Simon Hunt36fc15c2015-02-12 17:02:58 -080087 fs = _fs_;
88 ks = _ks_;
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070089 gs = _gs_;
Simon Hunt36fc15c2015-02-12 17:02:58 -080090
Thomas Vachuska0af26912016-03-21 21:37:30 -070091 var self = {
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070092 init: init,
Simon Hunt36fc15c2015-02-12 17:02:58 -080093 show: show,
Simon Huntbc76fb12015-02-26 18:09:54 -080094 hide: hide,
95 lostServer: lostServer
Simon Hunt36fc15c2015-02-12 17:02:58 -080096 };
Thomas Vachuska0af26912016-03-21 21:37:30 -070097 wss._setVeilDelegate(self);
98 return self;
Simon Hunt36fc15c2015-02-12 17:02:58 -080099 }]);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -0800100
101}());