Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions apps/workflowengine/src/components/Checks/FileMimeType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
v-if="!isPredefined"
:value="currentValue.id"
type="text"
:placeholder="t('workflowengine', 'e.g. httpd/unix-directory')"
:placeholder="t('workflowengine', 'e.g. /^application\\/xml$/')"
@input="updateCustom">
</div>
</template>
Expand All @@ -56,13 +56,33 @@ export default {
type: String,
default: '',
},

operator: {
type: String,
default: '',
},
},

emits: ['update:model-value'],

data() {
return {
predefinedTypes: [
literalOperators: ['is', '!is'],
regexOperators: ['matches', '!matches'],
predefinedLiteralTypes: [
{
icon: 'icon-folder',
label: t('workflowengine', 'Folder'),
id: 'httpd/unix-directory',
},
{
iconUrl: imagePath('core', 'filetypes/application-pdf'),
label: t('workflowengine', 'PDF documents'),
id: 'application/pdf',
},
],

predefinedRegexTypes: [
{
iconUrl: imagePath('core', 'filetypes/audio'),
label: t('workflowengine', 'Audio'),
Expand All @@ -71,7 +91,7 @@ export default {
{
icon: 'icon-folder',
label: t('workflowengine', 'Folder'),
id: 'httpd/unix-directory',
id: '/^httpd\\/unix-directory$/',
},
{
icon: 'icon-picture',
Expand All @@ -86,7 +106,7 @@ export default {
{
iconUrl: imagePath('core', 'filetypes/application-pdf'),
label: t('workflowengine', 'PDF documents'),
id: 'application/pdf',
id: '/^application\\/pdf$/',
},
{
iconUrl: imagePath('core', 'filetypes/video'),
Expand All @@ -100,16 +120,17 @@ export default {
},

computed: {
availablePredefinedTypes() {
return this.literalOperators.includes(this.operator) ? this.predefinedLiteralTypes : this.predefinedRegexTypes
},

options() {
return [...this.predefinedTypes, this.customValue]
const customTypes = this.regexOperators.includes(this.operator) ? [this.customValue] : []
return [...this.availablePredefinedTypes, ...customTypes]
},

isPredefined() {
const matchingPredefined = this.predefinedTypes.find((type) => this.newValue === type.id)
if (matchingPredefined) {
return true
}
return false
return this.availablePredefinedTypes.some((type) => this.newValue === type.id)
},

customValue() {
Expand All @@ -121,7 +142,7 @@ export default {
},

currentValue() {
const matchingPredefined = this.predefinedTypes.find((type) => this.newValue === type.id)
const matchingPredefined = this.availablePredefinedTypes.find((type) => this.newValue === type.id)
if (matchingPredefined) {
return matchingPredefined
}
Expand All @@ -137,6 +158,15 @@ export default {
modelValue() {
this.updateInternalValue()
},

// If user changed operation from is/!is to matches/!matches (or vice versa), reset value
operator(newVal, oldVal) {
const switchedGroups = (this.literalOperators.includes(oldVal) && this.regexOperators.includes(newVal))
|| (this.regexOperators.includes(oldVal) && this.literalOperators.includes(newVal))
if (switchedGroups) {
this.setValue(this.options[0])
}
},
},

methods: {
Expand Down
4 changes: 2 additions & 2 deletions dist/workflowengine-workflowengine.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/workflowengine-workflowengine.js.map

Large diffs are not rendered by default.

Loading