diff --git a/src/rules.vue b/src/rules.vue index aae7180..8c726d7 100644 --- a/src/rules.vue +++ b/src/rules.vue @@ -125,7 +125,10 @@
- +
Matcher {{ countRuleMatchers }} @@ -188,6 +191,7 @@ /> +
Cooldown {{ countRuleCooldowns }} @@ -254,6 +258,7 @@ /> +
Conditions {{ countRuleConditions }} @@ -344,6 +349,58 @@ /> + + +
+ Exceptions {{ countRuleExceptions }} +
+ + + + + + + + + Add + + + + + + + {{ ex }} + + + + + +
@@ -604,6 +661,10 @@ export default { return count }, + countRuleExceptions() { + return (this.models.rule?.disable_on_match_messages || []).length + }, + countRuleMatchers() { let count = 0 count += this.models.rule.match_channels ? 1 : 0 @@ -627,6 +688,7 @@ export default { filter: '', models: { addAction: '', + addException: '', rule: {}, }, @@ -679,6 +741,18 @@ export default { this.models.rule.actions.push({ attributes: {}, type: this.models.addAction }) }, + addException() { + this.validateRegex(this.models.addException, false) + .then(ok => { + if (!ok) { + return + } + + this.models.rule.disable_on_match_messages.push(this.models.addException) + this.models.addException = '' + }) + }, + deleteRule(uuid) { this.$bvModal.msgBoxConfirm('Do you really want to delete this rule?', { buttonSize: 'sm', @@ -843,6 +917,10 @@ export default { this.models.rule.actions = this.models.rule.actions.filter((_, i) => i !== idx) }, + removeException(ex) { + this.models.rule.disable_on_match_messages = this.models.rule.disable_on_match_messages.filter(r => r !== ex) + }, + saveRule(evt) { if (!this.validateRule()) { evt.preventDefault() @@ -1004,19 +1082,31 @@ export default { return Boolean(duration.match(/^(?:\d+(?:s|m|h))+$/)) }, + validateExceptionRegex() { + return this.validateRegex(this.models.addException, false) + .then(res => Vue.set(this.models, 'addException__validation', res)) + }, + validateMatcherRegex() { if (this.models.rule.match_message === '') { Vue.set(this.models.rule, 'match_message__validation', true) return } - return axios.put(`config-editor/validate-regex?regexp=${encodeURIComponent(this.models.rule.match_message)}`) - .then(() => { - Vue.set(this.models.rule, 'match_message__validation', true) - }) - .catch(() => { - Vue.set(this.models.rule, 'match_message__validation', false) + return this.validateRegex(this.models.rule.match_message, true) + .then(res => Vue.set(this.models.rule, 'match_message__validation', res)) + }, + + validateRegex(regex, allowEmpty = true) { + if (regex === '' && !allowEmpty) { + return new Promise(resolve => { + resolve(false) }) + } + + return axios.put(`config-editor/validate-regex?regexp=${encodeURIComponent(regex)}`) + .then(() => true) + .catch(() => false) }, validateRule() {