diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-12-19 13:22:27 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-12-19 15:22:41 +0100 |
commit | 0cdcdb305e608ca46fa259a59237273faa05a993 (patch) | |
tree | 73bd9d8b50d9c859120df702100f05bf87b15043 /apps/workflowengine | |
parent | 15b64c6abb0f83eab4e87695952b1355f270c02f (diff) | |
download | nextcloud-server-0cdcdb305e608ca46fa259a59237273faa05a993.tar.gz nextcloud-server-0cdcdb305e608ca46fa259a59237273faa05a993.zip |
Set operation mode according to the mime type value
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/workflowengine')
-rw-r--r-- | apps/workflowengine/src/components/Check.vue | 9 | ||||
-rw-r--r-- | apps/workflowengine/src/components/Checks/FileMimeType.vue | 1 | ||||
-rw-r--r-- | apps/workflowengine/src/components/Checks/file.js | 27 | ||||
-rw-r--r-- | apps/workflowengine/src/workflowengine.js | 12 |
4 files changed, 28 insertions, 21 deletions
diff --git a/apps/workflowengine/src/components/Check.vue b/apps/workflowengine/src/components/Check.vue index e77b9a0646f..96d686341fe 100644 --- a/apps/workflowengine/src/components/Check.vue +++ b/apps/workflowengine/src/components/Check.vue @@ -81,7 +81,11 @@ export default { }, operators() { if (!this.currentOption) { return [] } - return this.checks[this.currentOption.class].operators + const operators = this.checks[this.currentOption.class].operators + if (typeof operators === 'function') { + return operators(this.check) + } + return operators }, currentComponent() { if (!this.currentOption) { return [] } @@ -118,7 +122,8 @@ export default { return this.valid }, updateCheck() { - if (this.check.class !== this.currentOption.class) { + const matchingOperator = this.operators.findIndex((operator) => this.check.operator === operator.operator) + if (this.check.class !== this.currentOption.class || matchingOperator === -1) { this.currentOperator = this.operators[0] } this.check.class = this.currentOption.class diff --git a/apps/workflowengine/src/components/Checks/FileMimeType.vue b/apps/workflowengine/src/components/Checks/FileMimeType.vue index a9577c097de..1124f37e16c 100644 --- a/apps/workflowengine/src/components/Checks/FileMimeType.vue +++ b/apps/workflowengine/src/components/Checks/FileMimeType.vue @@ -120,7 +120,6 @@ export default { return result !== null }, setValue(value) { - // TODO: check if value requires a regex and set the check operator according to that if (value !== null) { this.newValue = value.pattern this.$emit('input', this.newValue) diff --git a/apps/workflowengine/src/components/Checks/file.js b/apps/workflowengine/src/components/Checks/file.js index 6c322a679b1..ee6a476a3a1 100644 --- a/apps/workflowengine/src/components/Checks/file.js +++ b/apps/workflowengine/src/components/Checks/file.js @@ -24,16 +24,24 @@ import { stringValidator, validateIPv4, validateIPv6 } from './../../helpers/val import FileMimeType from './FileMimeType' import FileSystemTag from './FileSystemTag' +const stringOrRegexOperators = (check) => { + if (check.value.startsWith('/')) { + return [ + { operator: 'matches', name: t('workflowengine', 'matches') }, + { operator: '!matches', name: t('workflowengine', 'does not match') }, + ] + } + return [ + { operator: 'is', name: t('workflowengine', 'is') }, + { operator: '!is', name: t('workflowengine', 'is not') }, + ] +} + const FileChecks = [ { class: 'OCA\\WorkflowEngine\\Check\\FileName', name: t('workflowengine', 'File name'), - operators: [ - { operator: 'is', name: t('workflowengine', 'is') }, - { operator: '!is', name: t('workflowengine', 'is not') }, - { operator: 'matches', name: t('workflowengine', 'matches') }, - { operator: '!matches', name: t('workflowengine', 'does not match') }, - ], + operators: stringOrRegexOperators, placeholder: (check) => { if (check.operator === 'matches' || check.operator === '!matches') { return '/^dummy-.+$/i' @@ -46,12 +54,7 @@ const FileChecks = [ { class: 'OCA\\WorkflowEngine\\Check\\FileMimeType', name: t('workflowengine', 'File MIME type'), - operators: [ - { operator: 'is', name: t('workflowengine', 'is') }, - { operator: '!is', name: t('workflowengine', 'is not') }, - { operator: 'matches', name: t('workflowengine', 'matches') }, - { operator: '!matches', name: t('workflowengine', 'does not match') }, - ], + operators: stringOrRegexOperators, component: FileMimeType, }, diff --git a/apps/workflowengine/src/workflowengine.js b/apps/workflowengine/src/workflowengine.js index 712f98fdfd0..b212e6be844 100644 --- a/apps/workflowengine/src/workflowengine.js +++ b/apps/workflowengine/src/workflowengine.js @@ -33,9 +33,9 @@ import ShippedChecks from './components/Checks' * @property {string} class - The PHP class name of the check * @property {Comparison[]} operators - A list of possible comparison operations running on the check * @property {Vue} component - A vue component to handle the rendering of options - * The component should handle the v-model directive properly, - * so it needs a value property to receive data and emit an input - * event once the data has changed + * The component should handle the v-model directive properly, + * so it needs a value property to receive data and emit an input + * event once the data has changed * @property {callable} placeholder - Return a placeholder of no custom component is used * @property {callable} validate - validate a check if no custom component is used **/ @@ -48,9 +48,9 @@ import ShippedChecks from './components/Checks' * @property {string} operation - Default value for the operation field * @property {string} color - Custom color code to be applied for the operator selector * @property {Vue} component - A vue component to handle the rendering of options - * The component should handle the v-model directive properly, - * so it needs a value property to receive data and emit an input - * event once the data has changed + * The component should handle the v-model directive properly, + * so it needs a value property to receive data and emit an input + * event once the data has changed */ /** |