blob: 91de19e17c8901ae5af755da399237d4dcb756e5 [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
Simon Huntbc76fb12015-02-26 18:09:54 -080027 var $log, $route, fs, ks;
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080028
Bri Prebilic Cole5e940e22015-02-06 11:34:08 -080029 var veil, pdiv, svg;
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080030
Simon Hunt36fc15c2015-02-12 17:02:58 -080031 // msg should be an array of strings
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080032 function show(msg) {
Simon Hunt36fc15c2015-02-12 17:02:58 -080033 var msgs = fs.isA(msg) || [msg];
Bri Prebilic Cole5e940e22015-02-06 11:34:08 -080034 pdiv.selectAll('p').remove();
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080035
Simon Hunt36fc15c2015-02-12 17:02:58 -080036 msgs.forEach(function (line) {
Bri Prebilic Cole5e940e22015-02-06 11:34:08 -080037 pdiv.append('p').text(line);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080038 });
39
40 veil.style('display', 'block');
Simon Hunt36fc15c2015-02-12 17:02:58 -080041 ks.enableKeys(false);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080042 }
43
44 function hide() {
45 veil.style('display', 'none');
Simon Hunt36fc15c2015-02-12 17:02:58 -080046 ks.enableKeys(true);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080047 }
48
Simon Huntbc76fb12015-02-26 18:09:54 -080049 // function that only invokes the veil if the caller is the current view
50 function lostServer(ctrlName, msg) {
51 if ($route.current.$$route.controller === ctrlName) {
52 $log.debug('VEIL-service: ', ctrlName);
53 show(msg)
54 } else {
55 $log.debug('VEIL-service: IGNORING ', ctrlName);
56 }
57 }
58
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080059 angular.module('onosLayer')
Simon Hunt36fc15c2015-02-12 17:02:58 -080060 .factory('VeilService',
Simon Huntbc76fb12015-02-26 18:09:54 -080061 ['$log', '$route', 'FnService', 'KeyService', 'GlyphService',
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080062
Simon Huntbc76fb12015-02-26 18:09:54 -080063 function (_$log_, _$route_, _fs_, _ks_, gs) {
Simon Hunt36fc15c2015-02-12 17:02:58 -080064 $log = _$log_;
Simon Huntbc76fb12015-02-26 18:09:54 -080065 $route = _$route_;
Simon Hunt36fc15c2015-02-12 17:02:58 -080066 fs = _fs_;
67 ks = _ks_;
Bri Prebilic Cole5e940e22015-02-06 11:34:08 -080068
Simon Hunt36fc15c2015-02-12 17:02:58 -080069 var wSize = fs.windowSize(),
70 ww = wSize.width,
71 wh = wSize.height,
72 vbox = '0 0 ' + ww + ' ' + wh,
73 shrink = wh * 0.3,
74 birdDim = wh - shrink,
75 birdCenter = (ww - birdDim) / 2;
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080076
Simon Hunt36fc15c2015-02-12 17:02:58 -080077 veil = d3.select('#veil');
78 pdiv = veil.append('div').classed('msg', true);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080079
Simon Hunt36fc15c2015-02-12 17:02:58 -080080 svg = veil.append('svg').attr({
81 width: ww,
82 height: wh,
83 viewBox: vbox
84 }).style('opacity', 0.2);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080085
Simon Hunt36fc15c2015-02-12 17:02:58 -080086 gs.addGlyph(svg, 'bird', birdDim, false, [birdCenter, shrink/2]);
87
88 return {
89 show: show,
Simon Huntbc76fb12015-02-26 18:09:54 -080090 hide: hide,
91 lostServer: lostServer
Simon Hunt36fc15c2015-02-12 17:02:58 -080092 };
93 }]);
Bri Prebilic Cole47bb7802015-02-05 17:25:15 -080094
95}());