blob: 76865402eee1f1523dcd280904062aa5424648c6 [file] [log] [blame]
Simon Huntc2202d52014-12-16 13:30:15 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Simon Huntc2202d52014-12-16 13:30:15 -08003 *
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 Huntdc6362a2014-12-18 19:55:23 -080018 ONOS GUI -- Masthead Module
Simon Huntc2202d52014-12-16 13:30:15 -080019 */
20(function () {
21 'use strict';
22
Simon Hunta11b4eb2015-01-28 16:20:50 -080023 // configuration
Simon Huntd42e5d12016-05-25 16:46:52 -070024 var mastHeight = 48,
Simon Hunt3be29942016-06-28 10:44:51 -070025 padMobile = 16,
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070026 dialogOpts = {
Simon Hunt5c3ed732017-07-20 19:03:28 +000027 edge: 'left'
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070028 };
29
Simon Hunt0981f762017-07-10 18:34:15 -070030 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 Hunt3be29942016-06-28 10:44:51 -070040 angular.module('onosMast', ['onosNav'])
41 .controller('MastCtrl',
Simon Hunt0981f762017-07-10 18:34:15 -070042 ['$log', '$scope', '$location', '$window', 'WebSocketService',
43 'NavService', 'DialogService', 'LionService',
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070044
Simon Hunt0981f762017-07-10 18:34:15 -070045 function ($log, $scope, $location, $window, wss, ns, ds, _ls_) {
Simon Hunt86388b12015-01-09 14:23:26 -080046 var self = this;
47
Simon Hunt0981f762017-07-10 18:34:15 -070048 ls = _ls_;
49
50 $scope.lion = getLion;
51
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070052 function triggerRefresh(action) {
Simon Hunt0981f762017-07-10 18:34:15 -070053 var uicomp = action === 'add' ? getLion('uicomp_added')
54 : getLion('uicomp_removed'),
55 okupd = getLion('ui_ok_to_update');
Simon Hunt3be29942016-06-28 10:44:51 -070056
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070057 function createConfirmationText() {
Simon Hunt0981f762017-07-10 18:34:15 -070058 var content = ds.createDiv();
59 content.append('p').text(uicomp + ' ' + okupd);
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070060 return content;
61 }
62
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070063 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 Hunt3be29942016-06-28 10:44:51 -070072 // 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 Hunt0981f762017-07-10 18:34:15 -070078 .setTitle(getLion('confirm_refresh_title'))
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070079 .addContent(createConfirmationText())
80 .addOk(dOk)
81 .addCancel(dCancel)
82 .bindKeys();
83 }
84
85 wss.bindHandlers({
Simon Hunt5c3ed732017-07-20 19:03:28 +000086 'guiAdded': function () { triggerRefresh('add') },
87 'guiRemoved': function () { triggerRefresh('rem') }
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070088 });
89
Simon Hunt86388b12015-01-09 14:23:26 -080090 // delegate to NavService
91 self.toggleNav = function () {
92 ns.toggleNav();
93 };
94
Simon Hunt1169c952017-06-05 11:20:11 -070095 // onosUser is a global set via the index.html generated source
Simon Hunt0981f762017-07-10 18:34:15 -070096 $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 = '';
chengfan386620e2016-11-09 17:02:40 +0800107
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 Burrows530cf462016-04-12 16:04:37 +0100114
Simon Huntdc6362a2014-12-18 19:55:23 -0800115 $log.log('MastCtrl has been created');
Simon Hunta11b4eb2015-01-28 16:20:50 -0800116 }])
117
118 // also define a service to allow lookup of mast height.
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700119 .factory('MastService', ['FnService', function (fs) {
Simon Hunta11b4eb2015-01-28 16:20:50 -0800120 return {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700121 mastHeight: function () {
122 return fs.isMobile() ? mastHeight + padMobile : mastHeight;
Simon Hunt5c3ed732017-07-20 19:03:28 +0000123 }
124 }
Simon Huntc2202d52014-12-16 13:30:15 -0800125 }]);
126
127}());