Ports View: Allow filtering by >, >=, <, <= operators
ONOS-6877
Change-Id: I319b7fe090fed759314ae28fc658c24d7f090970
diff --git a/web/gui/src/main/webapp/app/view/port/port.html b/web/gui/src/main/webapp/app/view/port/port.html
index f6e9b2e..7a5caa6 100644
--- a/web/gui/src/main/webapp/app/view/port/port.html
+++ b/web/gui/src/main/webapp/app/view/port/port.html
@@ -96,7 +96,7 @@
</td>
</tr>
- <tr ng-repeat="port in tableData | filter:queryFilter track by $index"
+ <tr ng-repeat="port in tableData | filter: customFilter(queryFilter, query) track by $index"
ng-repeat-complete row-id="{{port.id}}">
<td>{{port.id}}</td>
<td ng-class="(isDelta() ? 'delta' : 'right')">{{port.pkt_rx}}</td>
diff --git a/web/gui/src/main/webapp/app/view/port/port.js b/web/gui/src/main/webapp/app/view/port/port.js
index 5bf7871..915c6d5 100644
--- a/web/gui/src/main/webapp/app/view/port/port.js
+++ b/web/gui/src/main/webapp/app/view/port/port.js
@@ -143,13 +143,65 @@
return nzFilter;
};
- Object.defineProperty($scope, 'queryFilter', {
- get: function () {
+ function getOperatorFromQuery(query) {
+
+ var operator = query.split(' '),
+ opFunc = null;
+
+ if (operator[0] === '>') {
+ opFunc = _.gt;
+ } else if (operator[0] === '>=') {
+ opFunc = _.gte;
+ } else if (operator[0] === '<') {
+ opFunc = _.lt;
+ } else if (operator[0] === '<=') {
+ opFunc = _.lte;
+ } else {
+ return {
+ operator: opFunc,
+ searchText: query,
+ };
+ }
+
+ return {
+ operator: opFunc,
+ searchText: operator[1],
+ };
+ }
+
+ $scope.customFilter = function (prop, val) {
+ if (!val) {
+ return;
+ }
+
+ var search = getOperatorFromQuery(val),
+ operator = search.operator,
+ searchText = search.searchText;
+
+ if (operator) {
+ return function (row) {
+ var queryBy = $scope.queryBy || '$';
+
+ if (queryBy !== '$') {
+ var rowValue = parseInt(row[$scope.queryBy].replace(/,/g, ''));
+ return operator(rowValue, parseInt(searchText)) ? row : null;
+ } else {
+ var keys = _.keysIn(row);
+
+ for (var i = 0, l = keys.length; i < l; i++) {
+ var rowValue = parseInt(row[keys[i]].replace(/,/g, ''));
+ if (operator(rowValue, parseInt(searchText))) {
+ return row;
+ }
+ }
+ }
+ };
+ } else {
var out = {};
out[$scope.queryBy || '$'] = $scope.query;
return out;
- },
- });
+ }
+ };
restoreConfigFromPrefs();
$log.log('OvPortCtrl has been created');