Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [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 | /* |
| 18 | ONOS GUI -- Port View Module |
| 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
| 24 | // injected references |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 25 | var $log, $scope, $location, tbs, ns, ps; |
Viswanath KSP | d25440b | 2017-07-21 13:48:06 +0530 | [diff] [blame] | 26 | |
| 27 | var nz = 'nzFilter', |
| 28 | del = 'showDelta'; |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 29 | |
Simon Hunt | 105bc4e | 2017-07-21 11:07:01 -0700 | [diff] [blame] | 30 | // internal state |
| 31 | var nzFilter = true, |
| 32 | showDelta = false; |
| 33 | |
Viswanath KSP | d25440b | 2017-07-21 13:48:06 +0530 | [diff] [blame] | 34 | var defaultPortPrefsState = { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 35 | nzFilter: 1, |
| 36 | showDelta: 0, |
Viswanath KSP | d25440b | 2017-07-21 13:48:06 +0530 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | var prefsState = {}; |
| 40 | |
| 41 | function updatePrefsState(what, b) { |
| 42 | prefsState[what] = b ? 1 : 0; |
| 43 | ps.setPrefs('port_prefs', prefsState); |
| 44 | } |
| 45 | |
| 46 | function toggleNZState(b) { |
| 47 | if (b === undefined) { |
| 48 | nzFilter = !nzFilter; |
| 49 | } else { |
| 50 | nzFilter = b; |
| 51 | } |
| 52 | updatePrefsState(nz, nzFilter); |
| 53 | } |
| 54 | |
| 55 | function toggleDeltaState(b) { |
| 56 | if (b === undefined) { |
| 57 | showDelta = !showDelta; |
| 58 | } else { |
| 59 | showDelta = b; |
| 60 | } |
| 61 | updatePrefsState(del, b); |
| 62 | } |
| 63 | |
| 64 | function restoreConfigFromPrefs() { |
| 65 | prefsState = ps.asNumbers( |
| 66 | ps.getPrefs('port_prefs', defaultPortPrefsState) |
| 67 | ); |
| 68 | |
| 69 | $log.debug('Port - Prefs State:', prefsState); |
| 70 | toggleDeltaState(prefsState.showDelta); |
| 71 | toggleNZState(prefsState.nzFilter); |
| 72 | } |
Simon Hunt | 105bc4e | 2017-07-21 11:07:01 -0700 | [diff] [blame] | 73 | |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 74 | angular.module('ovPort', []) |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 75 | .controller('OvPortCtrl', [ |
| 76 | '$log', '$scope', '$location', |
| 77 | 'TableBuilderService', 'NavService', 'PrefsService', |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 78 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 79 | function (_$log_, _$scope_, _$location_, _tbs_, _ns_, _ps_) { |
| 80 | var params; |
| 81 | var tableApi; |
| 82 | $log = _$log_; |
| 83 | $scope = _$scope_; |
| 84 | $location = _$location_; |
| 85 | tbs = _tbs_; |
| 86 | ns = _ns_; |
| 87 | ps = _ps_; |
Viswanath KSP | d25440b | 2017-07-21 13:48:06 +0530 | [diff] [blame] | 88 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 89 | $scope.deviceTip = 'Show device table'; |
| 90 | $scope.flowTip = 'Show flow view for this device'; |
| 91 | $scope.groupTip = 'Show group view for this device'; |
| 92 | $scope.meterTip = 'Show meter view for selected device'; |
| 93 | $scope.toggleDeltaTip = 'Toggle port delta statistics'; |
| 94 | $scope.toggleNZTip = 'Toggle non zero port statistics'; |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 95 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 96 | params = $location.search(); |
| 97 | if (params.hasOwnProperty('devId')) { |
| 98 | $scope.devId = params['devId']; |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 99 | } |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 100 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 101 | $scope.payloadParams = { |
| 102 | nzFilter: nzFilter, |
| 103 | showDelta: showDelta, |
| 104 | }; |
Viswanath KSP | d25440b | 2017-07-21 13:48:06 +0530 | [diff] [blame] | 105 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 106 | tableApi = tbs.buildTable({ |
| 107 | scope: $scope, |
| 108 | tag: 'port', |
| 109 | query: params, |
| 110 | }); |
Viswanath KSP | d25440b | 2017-07-21 13:48:06 +0530 | [diff] [blame] | 111 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 112 | function filterToggleState() { |
| 113 | return { |
| 114 | nzFilter: nzFilter, |
| 115 | showDelta: showDelta, |
| 116 | }; |
| 117 | } |
Viswanath KSP | d25440b | 2017-07-21 13:48:06 +0530 | [diff] [blame] | 118 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 119 | $scope.nav = function (path) { |
| 120 | if ($scope.devId) { |
| 121 | ns.navTo(path, { devId: $scope.devId }); |
| 122 | } |
| 123 | }; |
Viswanath KSP | d25440b | 2017-07-21 13:48:06 +0530 | [diff] [blame] | 124 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 125 | $scope.toggleNZ = function () { |
| 126 | toggleNZState(); |
| 127 | $scope.payloadParams = filterToggleState(); |
| 128 | tableApi.forceRefesh(); |
| 129 | }; |
kalagesa | 1101dbb | 2016-12-20 23:34:28 +0530 | [diff] [blame] | 130 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 131 | $scope.toggleDelta = function () { |
| 132 | toggleDeltaState(); |
| 133 | $scope.payloadParams = filterToggleState(); |
| 134 | tableApi.forceRefesh(); |
| 135 | }; |
| 136 | |
| 137 | $scope.isDelta = function () { |
| 138 | return showDelta; |
| 139 | }; |
| 140 | |
| 141 | $scope.isNZ = function () { |
| 142 | return nzFilter; |
| 143 | }; |
| 144 | |
| 145 | Object.defineProperty($scope, 'queryFilter', { |
| 146 | get: function () { |
| 147 | var out = {}; |
| 148 | out[$scope.queryBy || '$'] = $scope.query; |
| 149 | return out; |
| 150 | }, |
| 151 | }); |
| 152 | |
| 153 | restoreConfigFromPrefs(); |
| 154 | $log.log('OvPortCtrl has been created'); |
| 155 | }]); |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 156 | }()); |