Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2014-present Open Networking Foundation |
Simon Hunt | c2202d5 | 2014-12-16 13:30: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 | /* |
Simon Hunt | dc6362a | 2014-12-18 19:55:23 -0800 | [diff] [blame] | 18 | ONOS GUI -- Masthead Module |
Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 19 | */ |
| 20 | (function () { |
| 21 | 'use strict'; |
| 22 | |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 23 | // configuration |
Simon Hunt | d42e5d1 | 2016-05-25 16:46:52 -0700 | [diff] [blame] | 24 | var mastHeight = 48, |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 25 | padMobile = 16, |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 26 | dialogOpts = { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 27 | edge: 'left' |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Simon Hunt | 0981f76 | 2017-07-10 18:34:15 -0700 | [diff] [blame] | 30 | var ls; |
| 31 | |
| 32 | // In the case of Masthead, we cannot cache the lion bundle, because we |
| 33 | // call too early (before the lion data is uploaded from the server). |
| 34 | // So we'll dig into the lion service for each request... |
| 35 | function getLion(x) { |
| 36 | var lion = ls.bundle('core.fw.Mast'); |
| 37 | return lion(x); |
| 38 | } |
| 39 | |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 40 | angular.module('onosMast', ['onosNav']) |
| 41 | .controller('MastCtrl', |
Simon Hunt | 0981f76 | 2017-07-10 18:34:15 -0700 | [diff] [blame] | 42 | ['$log', '$scope', '$location', '$window', 'WebSocketService', |
| 43 | 'NavService', 'DialogService', 'LionService', |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 44 | |
Simon Hunt | 0981f76 | 2017-07-10 18:34:15 -0700 | [diff] [blame] | 45 | function ($log, $scope, $location, $window, wss, ns, ds, _ls_) { |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 46 | var self = this; |
| 47 | |
Simon Hunt | 0981f76 | 2017-07-10 18:34:15 -0700 | [diff] [blame] | 48 | ls = _ls_; |
| 49 | |
| 50 | $scope.lion = getLion; |
| 51 | |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 52 | function triggerRefresh(action) { |
Simon Hunt | 0981f76 | 2017-07-10 18:34:15 -0700 | [diff] [blame] | 53 | var uicomp = action === 'add' ? getLion('uicomp_added') |
| 54 | : getLion('uicomp_removed'), |
| 55 | okupd = getLion('ui_ok_to_update'); |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 56 | |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 57 | function createConfirmationText() { |
Simon Hunt | 0981f76 | 2017-07-10 18:34:15 -0700 | [diff] [blame] | 58 | var content = ds.createDiv(); |
| 59 | content.append('p').text(uicomp + ' ' + okupd); |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 60 | return content; |
| 61 | } |
| 62 | |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 63 | function dOk() { |
| 64 | $log.debug('Refreshing GUI'); |
| 65 | $window.location.reload(); |
| 66 | } |
| 67 | |
| 68 | function dCancel() { |
| 69 | $log.debug('Canceling GUI refresh'); |
| 70 | } |
| 71 | |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 72 | // NOTE: We use app-dialog (CSS) since we will most likely |
| 73 | // invoke this when we (de)activate apps. |
| 74 | // However we have added this to the masthead, because |
| 75 | // apps could be injected externally (via the onos-app |
| 76 | // command) and we might be looking at some other view. |
| 77 | ds.openDialog('app-dialog', dialogOpts) |
Simon Hunt | 0981f76 | 2017-07-10 18:34:15 -0700 | [diff] [blame] | 78 | .setTitle(getLion('confirm_refresh_title')) |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 79 | .addContent(createConfirmationText()) |
| 80 | .addOk(dOk) |
| 81 | .addCancel(dCancel) |
| 82 | .bindKeys(); |
| 83 | } |
| 84 | |
| 85 | wss.bindHandlers({ |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 86 | 'guiAdded': function () { triggerRefresh('add') }, |
| 87 | 'guiRemoved': function () { triggerRefresh('rem') } |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 88 | }); |
| 89 | |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 90 | // delegate to NavService |
| 91 | self.toggleNav = function () { |
| 92 | ns.toggleNav(); |
| 93 | }; |
| 94 | |
Simon Hunt | 1169c95 | 2017-06-05 11:20:11 -0700 | [diff] [blame] | 95 | // onosUser is a global set via the index.html generated source |
Simon Hunt | 0981f76 | 2017-07-10 18:34:15 -0700 | [diff] [blame] | 96 | $scope.username = function () { |
| 97 | return onosUser || getLion('unknown_user'); |
| 98 | }; |
| 99 | |
| 100 | // The problem with the following is that the localization bundle |
| 101 | // hasn't been uploaded from the server at this point, so we get |
| 102 | // a lookup miss => '%tt_help%' |
| 103 | // $scope.helpTip = getLion('tt_help'); |
| 104 | // We would need to figure out how to inject the text later. |
| 105 | // For now, we'll just leave the tooltip blank. |
| 106 | $scope.helpTip = ''; |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 107 | |
| 108 | $scope.directTo = function () { |
| 109 | var curId = $location.path().replace('/', ''), |
| 110 | viewMap = $scope.onos['viewMap'], |
| 111 | helpUrl = viewMap[curId]; |
| 112 | $window.open(helpUrl); |
| 113 | }; |
Steven Burrows | 530cf46 | 2016-04-12 16:04:37 +0100 | [diff] [blame] | 114 | |
Simon Hunt | dc6362a | 2014-12-18 19:55:23 -0800 | [diff] [blame] | 115 | $log.log('MastCtrl has been created'); |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 116 | }]) |
| 117 | |
| 118 | // also define a service to allow lookup of mast height. |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 119 | .factory('MastService', ['FnService', function (fs) { |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 120 | return { |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 121 | mastHeight: function () { |
| 122 | return fs.isMobile() ? mastHeight + padMobile : mastHeight; |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 125 | }]); |
| 126 | |
| 127 | }()); |