Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 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 Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 27 | var $log, $route, fs, ks, gs; |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 28 | |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 29 | 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 Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 49 | |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 50 | // msg should be an array of strings |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 51 | function show(msg) { |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 52 | var msgs = fs.isA(msg) || [msg], |
| 53 | pdiv = veil.select('.msg'); |
Bri Prebilic Cole | 5e940e2 | 2015-02-06 11:34:08 -0800 | [diff] [blame] | 54 | pdiv.selectAll('p').remove(); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 55 | |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 56 | msgs.forEach(function (line) { |
Bri Prebilic Cole | 5e940e2 | 2015-02-06 11:34:08 -0800 | [diff] [blame] | 57 | pdiv.append('p').text(line); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 58 | }); |
| 59 | |
| 60 | veil.style('display', 'block'); |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 61 | ks.enableKeys(false); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | function hide() { |
| 65 | veil.style('display', 'none'); |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 66 | ks.enableKeys(true); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 69 | // function that only invokes the veil if the caller is the current view |
Simon Hunt | 4deb0e8 | 2015-06-10 16:18:25 -0700 | [diff] [blame] | 70 | // TODO: review - is this deprecated ? |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 71 | 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 Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 80 | angular.module('onosLayer') |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 81 | .factory('VeilService', |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 82 | ['$log', '$route', 'FnService', 'KeyService', 'GlyphService', 'WebSocketService', |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 83 | |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 84 | function (_$log_, _$route_, _fs_, _ks_, _gs_, wss) { |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 85 | $log = _$log_; |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 86 | $route = _$route_; |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 87 | fs = _fs_; |
| 88 | ks = _ks_; |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 89 | gs = _gs_; |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 90 | |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 91 | var self = { |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 92 | init: init, |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 93 | show: show, |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 94 | hide: hide, |
| 95 | lostServer: lostServer |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 96 | }; |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 97 | wss._setVeilDelegate(self); |
| 98 | return self; |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 99 | }]); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 100 | |
| 101 | }()); |