blob: 7aad374701783c602720069ea5e4954a2b4543c9 [file] [log] [blame]
Bri Prebilic Coleac829e42015-05-05 13:42:06 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Bri Prebilic Coleac829e42015-05-05 13:42:06 -07003 *
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 Burrows1c2a9682017-07-14 16:52:46 +010025 var $log, $scope, $location, tbs, ns, ps;
Viswanath KSPd25440b2017-07-21 13:48:06 +053026
27 var nz = 'nzFilter',
28 del = 'showDelta';
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070029
Simon Hunt105bc4e2017-07-21 11:07:01 -070030 // internal state
31 var nzFilter = true,
32 showDelta = false;
33
Viswanath KSPd25440b2017-07-21 13:48:06 +053034 var defaultPortPrefsState = {
Steven Burrows1c2a9682017-07-14 16:52:46 +010035 nzFilter: 1,
36 showDelta: 0,
Viswanath KSPd25440b2017-07-21 13:48:06 +053037 };
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 Hunt105bc4e2017-07-21 11:07:01 -070073
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070074 angular.module('ovPort', [])
Steven Burrows1c2a9682017-07-14 16:52:46 +010075 .controller('OvPortCtrl', [
76 '$log', '$scope', '$location',
77 'TableBuilderService', 'NavService', 'PrefsService',
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070078
Steven Burrows1c2a9682017-07-14 16:52:46 +010079 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 KSPd25440b2017-07-21 13:48:06 +053088
Steven Burrows1c2a9682017-07-14 16:52:46 +010089 $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 Coleac829e42015-05-05 13:42:06 -070095
Steven Burrows1c2a9682017-07-14 16:52:46 +010096 params = $location.search();
97 if (params.hasOwnProperty('devId')) {
98 $scope.devId = params['devId'];
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -070099 }
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700100
Steven Burrows1c2a9682017-07-14 16:52:46 +0100101 $scope.payloadParams = {
102 nzFilter: nzFilter,
103 showDelta: showDelta,
104 };
Viswanath KSPd25440b2017-07-21 13:48:06 +0530105
Steven Burrows1c2a9682017-07-14 16:52:46 +0100106 tableApi = tbs.buildTable({
107 scope: $scope,
108 tag: 'port',
109 query: params,
110 });
Viswanath KSPd25440b2017-07-21 13:48:06 +0530111
Steven Burrows1c2a9682017-07-14 16:52:46 +0100112 function filterToggleState() {
113 return {
114 nzFilter: nzFilter,
115 showDelta: showDelta,
116 };
117 }
Viswanath KSPd25440b2017-07-21 13:48:06 +0530118
Steven Burrows1c2a9682017-07-14 16:52:46 +0100119 $scope.nav = function (path) {
120 if ($scope.devId) {
121 ns.navTo(path, { devId: $scope.devId });
122 }
123 };
Viswanath KSPd25440b2017-07-21 13:48:06 +0530124
Steven Burrows1c2a9682017-07-14 16:52:46 +0100125 $scope.toggleNZ = function () {
126 toggleNZState();
127 $scope.payloadParams = filterToggleState();
128 tableApi.forceRefesh();
129 };
kalagesa1101dbb2016-12-20 23:34:28 +0530130
Steven Burrows1c2a9682017-07-14 16:52:46 +0100131 $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 Coleac829e42015-05-05 13:42:06 -0700156}());