Only update SNMP fields if changed
Use ng-change to determine if the SNMP fields, Address and Port,
have changed and should be updated.
Tested: Only see the rest calls when the fields have changed.
Change-Id: I324c9c422a8b6dfb8816925167953e16099f8044
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/app/configuration/controllers/snmp-controller.html b/app/configuration/controllers/snmp-controller.html
index 3fd9aa3..f4b7279 100644
--- a/app/configuration/controllers/snmp-controller.html
+++ b/app/configuration/controllers/snmp-controller.html
@@ -12,11 +12,11 @@
<div class="snmp__managers" ng-repeat="manager in managers track by $index">
<div class="snmp__manager-field">
<label>SNMP Manager Server</label>
- <input class="inline" id="snmp-manager{{$index+1}}-address" type="text" ng-model="manager.address" ng-blur="managers[$index].address = manager.address"/>
+ <input class="inline" id="snmp-manager{{$index+1}}-address" ng-change="manager.update_address = true" type="text" ng-model="manager.address" ng-blur="managers[$index].address = manager.address"/>
</div>
<div class="snmp__manager-field">
<label>Port</label>
- <input class="inline" id="snmp-manager{{$index+1}}-port" type="text" ng-model="manager.port" ng-blur="managers[$index].port = manager.port"/>
+ <input class="inline" id="snmp-manager{{$index+1}}-port" type="text" ng-change="manager.update_port = true" ng-model="manager.port" ng-blur="managers[$index].port = manager.port"/>
</div>
<button class="snmp__manager-remove" ng-click="removeSNMPManager($index)">Remove</button>
</div>
diff --git a/app/configuration/controllers/snmp-controller.js b/app/configuration/controllers/snmp-controller.js
index 782ee1c..a2f5e2b 100644
--- a/app/configuration/controllers/snmp-controller.js
+++ b/app/configuration/controllers/snmp-controller.js
@@ -26,7 +26,9 @@
$scope.managers.push({
path: key,
port: data.data[key].Port,
- address: data.data[key].Address
+ update_port: false,
+ address: data.data[key].Address,
+ update_address: false
})
}
},
@@ -85,11 +87,14 @@
promises.push(addManager(
$scope.managers[i].address, $scope.managers[i].port));
} else {
- // TODO: Check if we actually need to update the existing managers
- promises.push(setManagerAddress(
- $scope.managers[i].path, $scope.managers[i].address));
- promises.push(setManagerPort(
- $scope.managers[i].path, $scope.managers[i].port));
+ if ($scope.managers[i].update_address) {
+ promises.push(setManagerAddress(
+ $scope.managers[i].path, $scope.managers[i].address));
+ }
+ if ($scope.managers[i].update_port) {
+ promises.push(setManagerPort(
+ $scope.managers[i].path, $scope.managers[i].port));
+ }
}
}