blob: 6483703212e370d92a326e28ed12c869db702c1e [file] [log] [blame]
Simon Huntc2202d52014-12-16 13:30:15 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
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 = {
27 edge: 'left'
Simon Hunt3be29942016-06-28 10:44:51 -070028 },
29 msg = {
30 add: { adj: 'New', op: 'added'},
31 rem: { adj: 'Some', op: 'removed'}
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070032 };
33
Simon Hunt3be29942016-06-28 10:44:51 -070034 angular.module('onosMast', ['onosNav'])
35 .controller('MastCtrl',
chengfan386620e2016-11-09 17:02:40 +080036 ['$log', '$scope', '$location', '$window', 'WebSocketService', 'NavService',
Simon Hunt3be29942016-06-28 10:44:51 -070037 'DialogService',
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070038
chengfan386620e2016-11-09 17:02:40 +080039 function ($log, $scope, $location, $window, wss, ns, ds) {
Simon Hunt86388b12015-01-09 14:23:26 -080040 var self = this;
41
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070042 function triggerRefresh(action) {
Simon Hunt3be29942016-06-28 10:44:51 -070043
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070044 function createConfirmationText() {
Simon Hunt3be29942016-06-28 10:44:51 -070045 var content = ds.createDiv(),
46 txt = msg[action];
47
48 content.append('p').text(
49 txt.adj + ' GUI components were ' + txt.op +
50 '. Press OK to update the GUI.'
51 );
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070052 return content;
53 }
54
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070055 function dOk() {
56 $log.debug('Refreshing GUI');
57 $window.location.reload();
58 }
59
60 function dCancel() {
61 $log.debug('Canceling GUI refresh');
62 }
63
Simon Hunt3be29942016-06-28 10:44:51 -070064 // NOTE: We use app-dialog (CSS) since we will most likely
65 // invoke this when we (de)activate apps.
66 // However we have added this to the masthead, because
67 // apps could be injected externally (via the onos-app
68 // command) and we might be looking at some other view.
69 ds.openDialog('app-dialog', dialogOpts)
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070070 .setTitle('Confirm GUI Refresh')
71 .addContent(createConfirmationText())
72 .addOk(dOk)
73 .addCancel(dCancel)
74 .bindKeys();
75 }
76
77 wss.bindHandlers({
Simon Hunt3be29942016-06-28 10:44:51 -070078 'guiAdded': function () { triggerRefresh('add') },
79 'guiRemoved': function () { triggerRefresh('rem') }
Thomas Vachuskafa74dd72016-03-20 19:11:12 -070080 });
81
Simon Hunt86388b12015-01-09 14:23:26 -080082 // delegate to NavService
83 self.toggleNav = function () {
84 ns.toggleNav();
85 };
86
Simon Hunt1169c952017-06-05 11:20:11 -070087 // onosUser is a global set via the index.html generated source
88 $scope.user = onosUser || '(no one)';
chengfan386620e2016-11-09 17:02:40 +080089 $scope.helpTip = 'Show help page for current view';
90
91 $scope.directTo = function () {
92 var curId = $location.path().replace('/', ''),
93 viewMap = $scope.onos['viewMap'],
94 helpUrl = viewMap[curId];
95 $window.open(helpUrl);
96 };
Steven Burrows530cf462016-04-12 16:04:37 +010097
Simon Huntdc6362a2014-12-18 19:55:23 -080098 $log.log('MastCtrl has been created');
Simon Hunta11b4eb2015-01-28 16:20:50 -080099 }])
100
101 // also define a service to allow lookup of mast height.
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700102 .factory('MastService', ['FnService', function (fs) {
Simon Hunta11b4eb2015-01-28 16:20:50 -0800103 return {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700104 mastHeight: function () {
105 return fs.isMobile() ? mastHeight + padMobile : mastHeight;
106 }
Simon Hunta11b4eb2015-01-28 16:20:50 -0800107 }
Simon Huntc2202d52014-12-16 13:30:15 -0800108 }]);
109
110}());