Merge "Add switch filters"

This commit is contained in:
Jenkins 2014-09-16 22:13:19 +00:00 committed by Gerrit Code Review
commit 6dc22eaf8a
5 changed files with 53 additions and 39 deletions

View File

@ -290,23 +290,17 @@ compassAppDev.run(function($httpBackend, settings, $http) {
var switches = [{ var switches = [{
"id": 1, "id": 1,
"ip": "172.29.8.40", "ip": "172.29.8.40",
"filters": { "filters": "allow ports 1-10,20-51",
"ports": "1-10;20-51"
},
"state": "under_mointoring" "state": "under_mointoring"
}, { }, {
"id": 2, "id": 2,
"ip": "172.29.8.41", "ip": "172.29.8.41",
"filters": { "filters": "deny ports 1-100",
"ports": "1-100"
},
"state": "under_mointoring" "state": "under_mointoring"
}, { }, {
"id": 3, "id": 3,
"ip": "172.29.8.42", "ip": "172.29.8.42",
"filters": { "filters": "allow ports 1-50",
"ports": "1-100"
},
"state": "under_mointoring" "state": "under_mointoring"
}]; }];
return [200, switches, {}]; return [200, switches, {}];
@ -325,14 +319,18 @@ compassAppDev.run(function($httpBackend, settings, $http) {
var sw = { var sw = {
"id": id, "id": id,
"ip": "172.29.8.40", "ip": "172.29.8.40",
"filters": { "filters": "allow ports 1-10,20-51",
"ports": "1-10;20-51"
},
"state": state "state": state
}; };
return [200, sw, {}]; return [200, sw, {}];
}); });
$httpBackend.whenPUT(/\.*\/switches\/([0-9]|[1-9][0-9])$/).respond(function(method, url, data) {
console.log(method, url, data);
var sw = JSON.parse(data);
return [200, sw, {}];
});
$httpBackend.whenPOST(settings.apiUrlBase + '/switches').respond(function(method, url, data) { $httpBackend.whenPOST(settings.apiUrlBase + '/switches').respond(function(method, url, data) {
console.log(method, url, data); console.log(method, url, data);
var switchData = JSON.parse(data); var switchData = JSON.parse(data);
@ -509,23 +507,23 @@ compassAppDev.run(function($httpBackend, settings, $http) {
"user_id": 1, "user_id": 1,
"action": "Created New User", "action": "Created New User",
"timestamp": "2012-12-30 12:22:00" "timestamp": "2012-12-30 12:22:00"
}, { }, {
"user_id": 1, "user_id": 1,
"action": "Modified Admin Priviledges", "action": "Modified Admin Priviledges",
"timestamp": "2013-03-25 09:10:00" "timestamp": "2013-03-25 09:10:00"
}, { }, {
"user_id": 3, "user_id": 3,
"action": "Test Cluster", "action": "Test Cluster",
"timestamp": "2014-06-19 23:32:00" "timestamp": "2014-06-19 23:32:00"
}, { }, {
"user_id": 3, "user_id": 3,
"action": "Deleted User", "action": "Deleted User",
"timestamp": "2014-06-20 09:10:00" "timestamp": "2014-06-20 09:10:00"
}, { }, {
"user_id": 2, "user_id": 2,
"action": "Deleted Cluster", "action": "Deleted Cluster",
"timestamp": "2014-07-26 16:22:00" "timestamp": "2014-07-26 16:22:00"
}, { }, {
"user_id": 2, "user_id": 2,
"action": "Created New Cluster", "action": "Created New Cluster",
"timestamp": "2014-08-22 14:22:00" "timestamp": "2014-08-22 14:22:00"

View File

@ -37,7 +37,7 @@ angular.module('compass.server', [
$scope.tableParams = new ngTableParams({ $scope.tableParams = new ngTableParams({
page: 1, // show first page page: 1, // show first page
count: $scope.allservers.length // count per page count: $scope.allservers.length + 1 // count per page
}, { }, {
counts: [], // hide count-per-page box counts: [], // hide count-per-page box
total: $scope.allservers.length, // length of data total: $scope.allservers.length, // length of data

View File

@ -65,6 +65,11 @@ angular.module('compass.services', [])
this.postSwitches = function(sw) { this.postSwitches = function(sw) {
return $http.post(settings.apiUrlBase + '/switches', angular.toJson(sw)); return $http.post(settings.apiUrlBase + '/switches', angular.toJson(sw));
}; };
this.putSwitches = function(id, sw) {
return $http.put(settings.apiUrlBase + '/switches/' + id, angular.toJson(sw));
};
/* /*
this.postSwitchFilters = function(filters) { this.postSwitchFilters = function(filters) {
return $http.post(settings.apiUrlBase + '/switch-filters', angular.toJson(filters)); return $http.post(settings.apiUrlBase + '/switch-filters', angular.toJson(filters));

View File

@ -31,9 +31,9 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label no-padding-right">Port Filter</label> <label class="col-sm-3 control-label no-padding-right">Filters</label>
<div class="col-sm-9"> <div class="col-sm-9">
<input type="text" ng-model="filters.ports" placeholder="Port Filter"> <input type="text" ng-model="newswitch.filters" placeholder="Filters" popover-placement="right" popover-trigger="focus" popover-title="Example" popover="allow ports 1-100,150-200;">
</div> </div>
</div> </div>
</form> </form>
@ -42,6 +42,17 @@
<button class="btn btn-primary" ng-click="addSwitch()" ng-disabled="addSwitchForm.$invalid">Add</button> <button class="btn btn-primary" ng-click="addSwitch()" ng-disabled="addSwitchForm.$invalid">Add</button>
</div> </div>
</div> </div>
<div>
<div class="space-10"></div>
<alert ng-repeat="alert in alerts" type="danger" close="closeAlert()" >
<span ng-if="alert.message">
{{alert.message}}
</span>
<span ng-if="!alert.message">
Unknown error
</span>
</alert>
</div>
</div> </div>
</div> </div>
<div class="col-lg-6 col-md-6"> <div class="col-lg-6 col-md-6">
@ -90,7 +101,7 @@
</span> </span>
</td> </td>
<td>{{switch.ip}}</td> <td>{{switch.ip}}</td>
<td>{{switch.filters.ports}}</td> <td>{{switch.filters}}</td>
<td> <td>
<i class="ace-icon fa fa-pencil bigger-120 action green"></i> <i class="ace-icon fa fa-pencil bigger-120 action green"></i>
</td> </td>

View File

@ -33,14 +33,13 @@ angular.module('compass.findservers', [])
dataService.getSwitchById(scope.switchinfo.id).success(function(data) { dataService.getSwitchById(scope.switchinfo.id).success(function(data) {
if (data.state == "under_monitoring") { if (data.state == "under_monitoring") {
getMachines(); getMachines();
} else if(data.state === "initialized" || data.state === "repolling") } else if (data.state === "initialized" || data.state === "repolling")
if (fireTimer && checkSwitchCount < 15) { if (fireTimer && checkSwitchCount < 15) {
checkSwitchTimer = $timeout(checkSwitchState, 2000); checkSwitchTimer = $timeout(checkSwitchState, 2000);
} else { } else {
scope.polling = false; scope.polling = false;
scope.result = "error"; scope.result = "error";
} } else {
else {
scope.polling = false; scope.polling = false;
scope.result = "error"; scope.result = "error";
} }
@ -48,7 +47,7 @@ angular.module('compass.findservers', [])
}; };
scope.$watch('polling', function(newval, oldval) { scope.$watch('polling', function(newval, oldval) {
if(newval != oldval) { if (newval != oldval) {
if (newval == true) { if (newval == true) {
checkSwitchCount = 0; checkSwitchCount = 0;
fireTimer = true; fireTimer = true;
@ -145,23 +144,24 @@ angular.module('compass.findservers', [])
scope.newswitch = {} scope.newswitch = {}
scope.newswitch.credentials = {}; scope.newswitch.credentials = {};
scope.filters = {}; scope.alerts = [];
scope.addSwitch = function() { scope.addSwitch = function() {
scope.alerts = [];
dataService.postSwitches(scope.newswitch).success(function(switchData) { dataService.postSwitches(scope.newswitch).success(function(switchData) {
if (scope.filters) { scope.newswitch = {};
var filters = {
"filters": scope.filters
}; scope.switches.push(switchData);
dataService.putSwitchFilters(switchData.id, filters).success(function(filterData) {
switchData.filters = filterData.filters; }).error(function(response) {
scope.newswitch = {}; scope.alerts[0] = response;
scope.filters = {}; });
scope.switches.push(switchData); };
})
} scope.closeAlert = function() {
}) scope.alerts = [];
}; };
} }
}; };