fix(workflowengine): adapt check operator RequestTime to use web component

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
pull/50783/head
Arthur Schiwon 2025-03-25 16:26:55 +07:00
parent c24ead810d
commit f88ea21ddc
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
2 changed files with 20 additions and 13 deletions

@ -27,7 +27,6 @@
<script> <script>
import NcSelect from '@nextcloud/vue/components/NcSelect' import NcSelect from '@nextcloud/vue/components/NcSelect'
import moment from 'moment-timezone' import moment from 'moment-timezone'
import valueMixin from '../../mixins/valueMixin.js'
const zones = moment.tz.names() const zones = moment.tz.names()
export default { export default {
@ -35,13 +34,16 @@ export default {
components: { components: {
NcSelect, NcSelect,
}, },
mixins: [ emits: ['update:model-value'],
valueMixin,
],
props: { props: {
value: { modelValue: {
type: String, type: String,
default: '', default: '[]',
},
},
watch: {
modelValue() {
this.updateInternalValue()
}, },
}, },
data() { data() {
@ -53,21 +55,26 @@ export default {
endTime: null, endTime: null,
timezone: moment.tz.guess(), timezone: moment.tz.guess(),
}, },
stringifiedValue : '[]'
} }
}, },
mounted() { beforeMount() {
this.validate() // this is necessary to keep so the value is re-applied when a different
// check is being removed.
this.updateInternalValue()
}, },
methods: { methods: {
updateInternalValue(value) { updateInternalValue() {
try { try {
const data = JSON.parse(value) const data = JSON.parse(this.modelValue)
if (data.length === 2) { if (data.length === 2) {
this.newValue = { this.newValue = {
startTime: data[0].split(' ', 2)[0], startTime: data[0].split(' ', 2)[0],
endTime: data[1].split(' ', 2)[0], endTime: data[1].split(' ', 2)[0],
timezone: data[0].split(' ', 2)[1], timezone: data[0].split(' ', 2)[1],
} }
this.stringifiedValue = `["${this.newValue.startTime} ${this.newValue.timezone}","${this.newValue.endTime} ${this.newValue.timezone}"]`
this.validate()
} }
} catch (e) { } catch (e) {
// ignore invalid values // ignore invalid values
@ -89,8 +96,8 @@ export default {
this.newValue.timezone = moment.tz.guess() this.newValue.timezone = moment.tz.guess()
} }
if (this.validate()) { if (this.validate()) {
const output = `["${this.newValue.startTime} ${this.newValue.timezone}","${this.newValue.endTime} ${this.newValue.timezone}"]` this.stringifiedValue = `["${this.newValue.startTime} ${this.newValue.timezone}","${this.newValue.endTime} ${this.newValue.timezone}"]`
this.$emit('input', output) this.$emit('update:model-value', this.stringifiedValue)
} }
}, },
}, },

@ -28,7 +28,7 @@ const RequestChecks = [
{ operator: 'in', name: t('workflowengine', 'between') }, { operator: 'in', name: t('workflowengine', 'between') },
{ operator: '!in', name: t('workflowengine', 'not between') }, { operator: '!in', name: t('workflowengine', 'not between') },
], ],
component: RequestTime, element: registerCustomElement(RequestTime, 'oca-workflowengine-checks-request_time'),
}, },
{ {
class: 'OCA\\WorkflowEngine\\Check\\RequestUserAgent', class: 'OCA\\WorkflowEngine\\Check\\RequestUserAgent',