feat: edit-task script setup
This commit is contained in:
parent
93b2482d4c
commit
cdf359da00
1 changed files with 70 additions and 73 deletions
|
@ -75,85 +75,82 @@
|
||||||
</card>
|
</card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import {defineComponent} from 'vue'
|
import {ref, reactive, computed, shallowReactive, watch, nextTick} from 'vue'
|
||||||
|
import {useRouter} from 'vue-router'
|
||||||
|
import {useI18n} from 'vue-i18n'
|
||||||
|
|
||||||
import AsyncEditor from '@/components/input/AsyncEditor'
|
import Editor from '@/components/input/AsyncEditor'
|
||||||
|
|
||||||
import TaskService from '../../services/task'
|
import TaskService from '@/services/task'
|
||||||
import TaskModel from '../../models/task'
|
import TaskModel from '@/models/task'
|
||||||
import priorities from '../../models/constants/priorities'
|
import EditLabels from './partials/editLabels.vue'
|
||||||
import EditLabels from './partials/editLabels'
|
import Reminders from './partials/reminders.vue'
|
||||||
import Reminders from './partials/reminders'
|
import ColorPicker from '../input/colorPicker.vue'
|
||||||
import ColorPicker from '../input/colorPicker'
|
|
||||||
|
|
||||||
export default defineComponent({
|
import {success} from '@/message'
|
||||||
name: 'edit-task',
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
taskService: new TaskService(),
|
|
||||||
|
|
||||||
priorities: priorities,
|
const {t} = useI18n()
|
||||||
editorActive: false,
|
const router = useRouter()
|
||||||
isTaskEdit: false,
|
|
||||||
taskEditTask: TaskModel,
|
const props = defineProps({
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
taskDetailRoute() {
|
|
||||||
return {
|
|
||||||
name: 'task.detail',
|
|
||||||
params: { id: this.taskEditTask.id },
|
|
||||||
state: { backdropView: this.$router.currentRoute.value.fullPath },
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
components: {
|
|
||||||
ColorPicker,
|
|
||||||
Reminders,
|
|
||||||
EditLabels,
|
|
||||||
editor: AsyncEditor,
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
task: {
|
task: {
|
||||||
type: TaskModel,
|
type: TaskModel,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
watch: {
|
|
||||||
task: {
|
const taskService = shallowReactive(new TaskService())
|
||||||
handler() {
|
|
||||||
this.taskEditTask = this.task
|
const editorActive = ref(false)
|
||||||
this.initTaskFields()
|
let taskEditTask: TaskModel | undefined
|
||||||
},
|
|
||||||
immediate: true,
|
|
||||||
},
|
// FIXME: this initialization should not be necessary here
|
||||||
},
|
function initTaskFields() {
|
||||||
methods: {
|
taskEditTask.dueDate =
|
||||||
initTaskFields() {
|
+new Date(props.task.dueDate) === 0 ? null : props.task.dueDate
|
||||||
this.taskEditTask.dueDate =
|
taskEditTask.startDate =
|
||||||
+new Date(this.task.dueDate) === 0 ? null : this.task.dueDate
|
+new Date(props.task.startDate) === 0
|
||||||
this.taskEditTask.startDate =
|
|
||||||
+new Date(this.task.startDate) === 0
|
|
||||||
? null
|
? null
|
||||||
: this.task.startDate
|
: props.task.startDate
|
||||||
this.taskEditTask.endDate =
|
taskEditTask.endDate =
|
||||||
+new Date(this.task.endDate) === 0 ? null : this.task.endDate
|
+new Date(props.task.endDate) === 0 ? null : props.task.endDate
|
||||||
// This makes the editor trigger its mounted function again which makes it forget every input
|
// This makes the editor trigger its mounted function again which makes it forget every input
|
||||||
// it currently has in its textarea. This is a counter-hack to a hack inside of vue-easymde
|
// it currently has in its textarea. This is a counter-hack to a hack inside of vue-easymde
|
||||||
// which made it impossible to detect change from the outside. Therefore the component would
|
// which made it impossible to detect change from the outside. Therefore the component would
|
||||||
// not update if new content from the outside was made available.
|
// not update if new content from the outside was made available.
|
||||||
// See https://github.com/NikulinIlya/vue-easymde/issues/3
|
// See https://github.com/NikulinIlya/vue-easymde/issues/3
|
||||||
this.editorActive = false
|
editorActive.value = false
|
||||||
this.$nextTick(() => (this.editorActive = true))
|
nextTick(() => (editorActive.value = true))
|
||||||
},
|
}
|
||||||
async editTaskSubmit() {
|
|
||||||
this.taskEditTask = await this.taskService.update(this.taskEditTask)
|
watch(
|
||||||
this.initTaskFields()
|
() => props.task,
|
||||||
this.$message.success({message: this.$t('task.detail.updateSuccess')})
|
() => {
|
||||||
},
|
if (!taskEditTask) {
|
||||||
|
taskEditTask = reactive(props.task)
|
||||||
|
} else {
|
||||||
|
Object.assign(taskEditTask, new TaskModel(props.task))
|
||||||
|
}
|
||||||
|
initTaskFields()
|
||||||
},
|
},
|
||||||
|
{immediate: true },
|
||||||
|
)
|
||||||
|
const taskDetailRoute = computed(() => {
|
||||||
|
return {
|
||||||
|
name: 'task.detail',
|
||||||
|
params: { id: taskEditTask.id },
|
||||||
|
state: { backdropView: router.currentRoute.value.fullPath },
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
async function editTaskSubmit() {
|
||||||
|
const newTask = await taskService.update(taskEditTask)
|
||||||
|
Object.assign(taskEditTask, newTask)
|
||||||
|
initTaskFields()
|
||||||
|
success({message: t('task.detail.updateSuccess')})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
Loading…
Reference in a new issue