Commit 1d8cc180 by Bence Dányi

firewall_gui: more compact controller generation

parent fb6cb5ee
/** /**
* List of firewall collections, keys are RESTful url suffixes, * List of firewall collections, controllers/routes will be dynamically created from them.
* values are templates. *
* @type {Object} * E.g., from the `rule` controller, the RESTful url `/rules/` will be generated,
* and the `/static/partials/rule-list.html` template will be used.
* @type {Array}
*/ */
var listControllers = { var listControllers = ['rule', 'host', 'vlan', 'vlangroup', 'hostgroup', 'firewall'];
rules: 'rule-list',
hosts: 'host-list',
vlans: 'vlan-list',
vlangroups: 'vlangroup-list',
hostgroups: 'hostgroup-list',
firewalls: 'firewall-list',
};
var module = angular.module('firewall', []).config( var module = angular.module('firewall', []).config(
['$routeProvider', function($routeProvider) { ['$routeProvider', function($routeProvider) {
for(var i in listControllers) { for (var i in listControllers) {
$routeProvider.when('/'+i+'/', { var c = listControllers[i];
templateUrl: '/static/partials/'+listControllers[i]+'.html', $routeProvider.when('/' + c + 's/', {
controller: ListController('/firewall/'+i+'/') templateUrl: '/static/partials/' + c + '-list.html',
controller: ListController('/firewall/' + c + 's/')
}); });
} }
$routeProvider.otherwise({ $routeProvider.otherwise({
...@@ -34,11 +30,11 @@ function range(a, b) { ...@@ -34,11 +30,11 @@ function range(a, b) {
function matchAnything(obj, query) { function matchAnything(obj, query) {
var expr = new RegExp(query, 'i') var expr = new RegExp(query, 'i')
for(var i in obj) { for (var i in obj) {
var prop = obj[i]; var prop = obj[i];
if(typeof prop === 'number' && prop == query) return true; if (typeof prop === 'number' && prop == query) return true;
if(typeof prop === 'string' && prop.match(expr)) return true; if (typeof prop === 'string' && prop.match(expr)) return true;
if(typeof prop === 'object' && matchAnything(prop, query)) return true; if (typeof prop === 'object' && matchAnything(prop, query)) return true;
} }
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment