postprocess_action.js
119 lines
| 4.4 KiB
| application/javascript
|
JavascriptLexer
r112 | // Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors | |||
// | ||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||
// you may not use this file except in compliance with the License. | ||||
// You may obtain a copy of the License at | ||||
// | ||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||
// | ||||
// Unless required by applicable law or agreed to in writing, software | ||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
// See the License for the specific language governing permissions and | ||||
// limitations under the License. | ||||
r0 | ||||
angular.module('appenlight.directives.postProcessAction', []).directive('postProcessAction', ['applicationsPropertyResource', function (applicationsPropertyResource) { | ||||
return { | ||||
scope: {}, | ||||
r147 | bindToController: { | |||
r0 | action: '=', | |||
resource: '=' | ||||
}, | ||||
r147 | controller: postProcessActionController, | |||
controllerAs: 'ctrl', | ||||
r0 | restrict: 'E', | |||
r72 | templateUrl: 'directives/postprocess_action/postprocess_action.html' | |||
r0 | }; | |||
r147 | function postProcessActionController() { | |||
var vm = this; | ||||
vm.$onInit = function () { | ||||
console.log(vm); | ||||
var allOps = { | ||||
'eq': 'Equal', | ||||
'ne': 'Not equal', | ||||
'ge': 'Greater or equal', | ||||
'gt': 'Greater than', | ||||
'le': 'Lesser or equal', | ||||
'lt': 'Lesser than', | ||||
'startswith': 'Starts with', | ||||
'endswith': 'Ends with', | ||||
'contains': 'Contains' | ||||
}; | ||||
r0 | ||||
r147 | var fieldOps = {}; | |||
fieldOps['http_status'] = ['eq', 'ne', 'ge', 'le']; | ||||
fieldOps['group:priority'] = ['eq', 'ne', 'ge', 'le']; | ||||
fieldOps['duration'] = ['ge', 'le']; | ||||
fieldOps['url_domain'] = ['eq', 'ne', 'startswith', 'endswith', | ||||
'contains']; | ||||
fieldOps['url_path'] = ['eq', 'ne', 'startswith', 'endswith', | ||||
'contains']; | ||||
fieldOps['error'] = ['eq', 'ne', 'startswith', 'endswith', | ||||
'contains']; | ||||
fieldOps['tags:server_name'] = ['eq', 'ne', 'startswith', 'endswith', | ||||
'contains']; | ||||
fieldOps['group:occurences'] = ['eq', 'ne', 'ge', 'le']; | ||||
r0 | ||||
r147 | var possibleFields = { | |||
'__AND__': 'All met (composite rule)', | ||||
'__OR__': 'One met (composite rule)', | ||||
'__NOT__': 'Not met (composite rule)', | ||||
'http_status': 'HTTP Status', | ||||
'duration': 'Request duration', | ||||
'group:priority': 'Group -> Priority', | ||||
'url_domain': 'Domain', | ||||
'url_path': 'URL Path', | ||||
'error': 'Error', | ||||
'tags:server_name': 'Tag -> Server name', | ||||
'group:occurences': 'Group -> Occurences' | ||||
}; | ||||
r0 | ||||
r147 | vm.ruleDefinitions = { | |||
fieldOps: fieldOps, | ||||
allOps: allOps, | ||||
possibleFields: possibleFields | ||||
}; | ||||
r0 | ||||
r147 | vm.possibleActions = [ | |||
['1', 'Priority +1'], | ||||
['-1', 'Priority -1'] | ||||
]; | ||||
} | ||||
r0 | vm.deleteAction = function (action) { | |||
applicationsPropertyResource.remove({ | ||||
pkey: vm.action.pkey, | ||||
resourceId: vm.resource.resource_id, | ||||
key: 'postprocessing_rules' | ||||
}, function () { | ||||
vm.resource.postprocessing_rules.splice( | ||||
vm.resource.postprocessing_rules.indexOf(action), 1); | ||||
}); | ||||
}; | ||||
vm.saveAction = function () { | ||||
var params = { | ||||
'pkey': vm.action.pkey, | ||||
'resourceId': vm.resource.resource_id, | ||||
key: 'postprocessing_rules' | ||||
}; | ||||
applicationsPropertyResource.update(params, vm.action, | ||||
function (data) { | ||||
vm.action.dirty = false; | ||||
vm.errors = []; | ||||
}, function (response) { | ||||
if (response.status == 422) { | ||||
var errorDict = angular.fromJson(response.data); | ||||
vm.errors = _.values(errorDict); | ||||
} | ||||
}); | ||||
}; | ||||
r147 | vm.setDirty = function () { | |||
r0 | vm.action.dirty = true; | |||
console.log('set dirty'); | ||||
}; | ||||
} | ||||
}]); | ||||