Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
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 = { |
| 27 | edge: 'left' |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 28 | }, |
| 29 | msg = { |
| 30 | add: { adj: 'New', op: 'added'}, |
| 31 | rem: { adj: 'Some', op: 'removed'} |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 34 | angular.module('onosMast', ['onosNav']) |
| 35 | .controller('MastCtrl', |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 36 | ['$log', '$scope', '$location', '$window', 'WebSocketService', 'NavService', |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 37 | 'DialogService', |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 38 | |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 39 | function ($log, $scope, $location, $window, wss, ns, ds) { |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 40 | var self = this; |
| 41 | |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 42 | function triggerRefresh(action) { |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 43 | |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 44 | function createConfirmationText() { |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 45 | 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 Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 52 | return content; |
| 53 | } |
| 54 | |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 55 | 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 Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 64 | // 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 Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 70 | .setTitle('Confirm GUI Refresh') |
| 71 | .addContent(createConfirmationText()) |
| 72 | .addOk(dOk) |
| 73 | .addCancel(dCancel) |
| 74 | .bindKeys(); |
| 75 | } |
| 76 | |
| 77 | wss.bindHandlers({ |
Simon Hunt | 3be2994 | 2016-06-28 10:44:51 -0700 | [diff] [blame] | 78 | 'guiAdded': function () { triggerRefresh('add') }, |
| 79 | 'guiRemoved': function () { triggerRefresh('rem') } |
Thomas Vachuska | fa74dd7 | 2016-03-20 19:11:12 -0700 | [diff] [blame] | 80 | }); |
| 81 | |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 82 | // delegate to NavService |
| 83 | self.toggleNav = function () { |
| 84 | ns.toggleNav(); |
| 85 | }; |
| 86 | |
Simon Hunt | 365cc08 | 2017-06-05 11:20:11 -0700 | [diff] [blame^] | 87 | // onosUser is a global set via the index.html generated source |
| 88 | $scope.user = onosUser || '(no one)'; |
chengfan | 386620e | 2016-11-09 17:02:40 +0800 | [diff] [blame] | 89 | $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 Burrows | 530cf46 | 2016-04-12 16:04:37 +0100 | [diff] [blame] | 97 | |
Simon Hunt | dc6362a | 2014-12-18 19:55:23 -0800 | [diff] [blame] | 98 | $log.log('MastCtrl has been created'); |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 99 | }]) |
| 100 | |
| 101 | // also define a service to allow lookup of mast height. |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 102 | .factory('MastService', ['FnService', function (fs) { |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 103 | return { |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 104 | mastHeight: function () { |
| 105 | return fs.isMobile() ? mastHeight + padMobile : mastHeight; |
| 106 | } |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 107 | } |
Simon Hunt | c2202d5 | 2014-12-16 13:30:15 -0800 | [diff] [blame] | 108 | }]); |
| 109 | |
| 110 | }()); |