feat: repeatAfter script setup (#1928)
continuous-integration/drone/push Build is passing Details

Co-authored-by: Dominik Pschenitschni <mail@celement.de>
Reviewed-on: #1928
Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
Dominik Pschenitschni 2022-05-14 14:58:21 +00:00 committed by konrad
parent 9a42713b04
commit 6737bb37b4
1 changed files with 50 additions and 52 deletions

View File

@ -26,7 +26,7 @@
<div class="field has-addons is-fullwidth"> <div class="field has-addons is-fullwidth">
<div class="control"> <div class="control">
<input <input
:disabled="disabled || null" :disabled="disabled || undefined"
@change="updateData" @change="updateData"
class="input" class="input"
:placeholder="$t('task.repeat.specifyAmount')" :placeholder="$t('task.repeat.specifyAmount')"
@ -36,7 +36,11 @@
</div> </div>
<div class="control"> <div class="control">
<div class="select"> <div class="select">
<select :disabled="disabled || null" @change="updateData" v-model="repeatAfter.type"> <select
v-model="repeatAfter.type"
@change="updateData"
:disabled="disabled || undefined"
>
<option value="hours">{{ $t('task.repeat.hours') }}</option> <option value="hours">{{ $t('task.repeat.hours') }}</option>
<option value="days">{{ $t('task.repeat.days') }}</option> <option value="days">{{ $t('task.repeat.days') }}</option>
<option value="weeks">{{ $t('task.repeat.weeks') }}</option> <option value="weeks">{{ $t('task.repeat.weeks') }}</option>
@ -50,23 +54,12 @@
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import {defineComponent} from 'vue' import {ref, reactive, watch} from 'vue'
import repeatModes from '@/models/constants/taskRepeatModes' import repeatModes from '@/models/constants/taskRepeatModes'
import TaskModel from '@/models/task'
export default defineComponent({ const props = defineProps({
name: 'repeatAfter',
data() {
return {
task: {},
repeatAfter: {
amount: 0,
type: '',
},
repeatModes,
}
},
props: {
modelValue: { modelValue: {
default: () => {}, default: () => {},
required: true, required: true,
@ -75,36 +68,41 @@ export default defineComponent({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
}, })
emits: ['update:modelValue', 'change'],
watch: { const emit = defineEmits(['update:modelValue', 'change'])
modelValue: {
handler(value) { const task = ref<TaskModel>({})
this.task = value const repeatAfter = reactive({
amount: 0,
type: '',
})
watch(
() => props.modelValue,
(value) => {
task.value = value
if (typeof value.repeatAfter !== 'undefined') { if (typeof value.repeatAfter !== 'undefined') {
this.repeatAfter = value.repeatAfter Object.assign(repeatAfter, value.repeatAfter)
} }
}, },
immediate: true, {immediate: true},
}, )
},
methods: { function updateData() {
updateData() { if (task.value.repeatMode !== repeatModes.REPEAT_MODE_DEFAULT && repeatAfter.amount === 0) {
if (this.task.repeatMode !== repeatModes.REPEAT_MODE_DEFAULT && this.repeatAfter.amount === 0) {
return return
} }
this.task.repeatAfter = this.repeatAfter Object.assign(task.value.repeatAfter, repeatAfter)
this.$emit('update:modelValue', this.task) emit('update:modelValue', task.value)
this.$emit('change') emit('change')
}, }
setRepeatAfter(amount, type) {
this.repeatAfter.amount = amount function setRepeatAfter(amount: number, type) {
this.repeatAfter.type = type Object.assign(repeatAfter, { amount, type})
this.updateData() updateData()
}, }
},
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>