Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 1 | /* |
| 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 Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 27 | var $log, $route, fs, ks; |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 28 | |
Bri Prebilic Cole | 5e940e2 | 2015-02-06 11:34:08 -0800 | [diff] [blame] | 29 | var veil, pdiv, svg; |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 30 | |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 31 | // msg should be an array of strings |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 32 | function show(msg) { |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 33 | var msgs = fs.isA(msg) || [msg]; |
Bri Prebilic Cole | 5e940e2 | 2015-02-06 11:34:08 -0800 | [diff] [blame] | 34 | pdiv.selectAll('p').remove(); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 35 | |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 36 | msgs.forEach(function (line) { |
Bri Prebilic Cole | 5e940e2 | 2015-02-06 11:34:08 -0800 | [diff] [blame] | 37 | pdiv.append('p').text(line); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 38 | }); |
| 39 | |
| 40 | veil.style('display', 'block'); |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 41 | ks.enableKeys(false); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | function hide() { |
| 45 | veil.style('display', 'none'); |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 46 | ks.enableKeys(true); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 49 | // 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 Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 59 | angular.module('onosLayer') |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 60 | .factory('VeilService', |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 61 | ['$log', '$route', 'FnService', 'KeyService', 'GlyphService', |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 62 | |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 63 | function (_$log_, _$route_, _fs_, _ks_, gs) { |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 64 | $log = _$log_; |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 65 | $route = _$route_; |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 66 | fs = _fs_; |
| 67 | ks = _ks_; |
Bri Prebilic Cole | 5e940e2 | 2015-02-06 11:34:08 -0800 | [diff] [blame] | 68 | |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 69 | 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 Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 76 | |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 77 | veil = d3.select('#veil'); |
| 78 | pdiv = veil.append('div').classed('msg', true); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 79 | |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 80 | svg = veil.append('svg').attr({ |
| 81 | width: ww, |
| 82 | height: wh, |
| 83 | viewBox: vbox |
| 84 | }).style('opacity', 0.2); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 85 | |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 86 | gs.addGlyph(svg, 'bird', birdDim, false, [birdCenter, shrink/2]); |
| 87 | |
| 88 | return { |
| 89 | show: show, |
Simon Hunt | bc76fb1 | 2015-02-26 18:09:54 -0800 | [diff] [blame] | 90 | hide: hide, |
| 91 | lostServer: lostServer |
Simon Hunt | 36fc15c | 2015-02-12 17:02:58 -0800 | [diff] [blame] | 92 | }; |
| 93 | }]); |
Bri Prebilic Cole | 47bb780 | 2015-02-05 17:25:15 -0800 | [diff] [blame] | 94 | |
| 95 | }()); |