vikunja-frontend/src/services/task.ts

121 lines
3.1 KiB
TypeScript
Raw Normal View History

import AbstractService from './abstractService'
2022-09-06 11:36:01 +02:00
import TaskModel from '@/models/task'
import type {ITask} from '@/modelTypes/ITask'
import AttachmentService from './attachment'
Kanban (#118) Add error message when trying to create an invalid new task in a bucket Prevent creation of new buckets if the bucket title is empty Disable deleting a bucket if it's the last one Disable dragging tasks when they are being updated Fix transition when opening tasks Send the user to list view by default Show loading spinner when updating multiple tasks Add loading spinner when moving tasks Add loading animation when bucket is loading / updating etc Add bucket title edit Fix creating new buckets Add loading animation Add removing buckets Fix creating a new bucket after tasks were moved Fix warning about labels on tasks Fix labels on tasks not updating after retrieval from api Fix property width Add closing and mobile design Make the task detail popup look good Move list views Move task detail view in a popup Add link to tasks Add saving the new task position after it was moved Fix creating new bucket Fix creating a new task Cleanup Disable user selection for task cards Fix drag placeholder Add dragging style to task Add placeholder + change animation duration More cleanup Cleanup / docs Working of dragging and dropping tasks Adjust markup and styling for new library Change kanban library to something that works Add basic calculation of new positions Don't try to create empty tasks Add indicator if a task is done Add moving tasks between buckets Make empty buckets a little smaller Add gimmick for button description Fix color Fix scrolling bucket layout Add creating a new bucket Add hiding the task input field Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/118
2020-04-26 01:11:34 +02:00
import LabelService from './label'
2020-03-02 21:55:22 +01:00
import {formatISO} from 'date-fns'
import {colorFromHex} from '@/helpers/color/colorFromHex'
2020-12-08 15:43:51 +01:00
const parseDate = date => {
if (date) {
return formatISO(new Date(date))
}
return null
}
2022-07-21 18:56:31 +02:00
export default class TaskService extends AbstractService<ITask> {
constructor() {
super({
create: '/lists/{listId}',
2019-03-10 13:59:17 +01:00
getAll: '/tasks/all',
2019-11-24 14:16:24 +01:00
get: '/tasks/{id}',
update: '/tasks/{id}',
delete: '/tasks/{id}',
})
}
modelFactory(data) {
return new TaskModel(data)
}
beforeUpdate(model) {
2019-04-29 23:41:39 +02:00
return this.processModel(model)
}
beforeCreate(model) {
return this.processModel(model)
}
2021-09-11 17:53:03 +02:00
processModel(updatedModel) {
const model = { ...updatedModel }
model.title = model.title?.trim()
// Ensure that listId is an int
model.listId = Number(model.listId)
2019-04-29 23:41:39 +02:00
// Convert dates into an iso string
2020-12-08 15:43:51 +01:00
model.dueDate = parseDate(model.dueDate)
model.startDate = parseDate(model.startDate)
model.endDate = parseDate(model.endDate)
model.doneAt = parseDate(model.doneAt)
model.created = formatISO(new Date(model.created))
model.updated = formatISO(new Date(model.updated))
// remove all nulls, these would create empty reminders
for (const index in model.reminderDates) {
if (model.reminderDates[index] === null) {
model.reminderDates.splice(index, 1)
}
}
// Make normal timestamps from js dates
if (model.reminderDates.length > 0) {
2019-04-29 23:41:39 +02:00
model.reminderDates = model.reminderDates.map(r => {
return formatISO(new Date(r))
2019-04-29 23:41:39 +02:00
})
}
// Make the repeating amount to seconds
let repeatAfterSeconds = 0
if (model.repeatAfter !== null && (model.repeatAfter.amount !== null || model.repeatAfter.amount !== 0)) {
switch (model.repeatAfter.type) {
case 'hours':
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60
break
case 'days':
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60 * 24
break
case 'weeks':
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60 * 24 * 7
break
case 'months':
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60 * 24 * 30
break
case 'years':
repeatAfterSeconds = model.repeatAfter.amount * 60 * 60 * 24 * 365
break
}
}
model.repeatAfter = repeatAfterSeconds
model.hexColor = colorFromHex(model.hexColor)
2019-04-30 22:18:06 +02:00
2019-11-24 14:16:24 +01:00
// Do the same for all related tasks
Object.keys(model.relatedTasks).forEach(relationKind => {
model.relatedTasks[relationKind] = model.relatedTasks[relationKind].map(t => {
2019-11-24 14:16:24 +01:00
return this.processModel(t)
})
})
// Process all attachments to preven parsing errors
if (model.attachments.length > 0) {
const attachmentService = new AttachmentService()
model.attachments.map(a => {
return attachmentService.processModel(a)
})
}
Kanban (#118) Add error message when trying to create an invalid new task in a bucket Prevent creation of new buckets if the bucket title is empty Disable deleting a bucket if it's the last one Disable dragging tasks when they are being updated Fix transition when opening tasks Send the user to list view by default Show loading spinner when updating multiple tasks Add loading spinner when moving tasks Add loading animation when bucket is loading / updating etc Add bucket title edit Fix creating new buckets Add loading animation Add removing buckets Fix creating a new bucket after tasks were moved Fix warning about labels on tasks Fix labels on tasks not updating after retrieval from api Fix property width Add closing and mobile design Make the task detail popup look good Move list views Move task detail view in a popup Add link to tasks Add saving the new task position after it was moved Fix creating new bucket Fix creating a new task Cleanup Disable user selection for task cards Fix drag placeholder Add dragging style to task Add placeholder + change animation duration More cleanup Cleanup / docs Working of dragging and dropping tasks Adjust markup and styling for new library Change kanban library to something that works Add basic calculation of new positions Don't try to create empty tasks Add indicator if a task is done Add moving tasks between buckets Make empty buckets a little smaller Add gimmick for button description Fix color Fix scrolling bucket layout Add creating a new bucket Add hiding the task input field Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/118
2020-04-26 01:11:34 +02:00
// Preprocess all labels
if (model.labels.length > 0) {
Kanban (#118) Add error message when trying to create an invalid new task in a bucket Prevent creation of new buckets if the bucket title is empty Disable deleting a bucket if it's the last one Disable dragging tasks when they are being updated Fix transition when opening tasks Send the user to list view by default Show loading spinner when updating multiple tasks Add loading spinner when moving tasks Add loading animation when bucket is loading / updating etc Add bucket title edit Fix creating new buckets Add loading animation Add removing buckets Fix creating a new bucket after tasks were moved Fix warning about labels on tasks Fix labels on tasks not updating after retrieval from api Fix property width Add closing and mobile design Make the task detail popup look good Move list views Move task detail view in a popup Add link to tasks Add saving the new task position after it was moved Fix creating new bucket Fix creating a new task Cleanup Disable user selection for task cards Fix drag placeholder Add dragging style to task Add placeholder + change animation duration More cleanup Cleanup / docs Working of dragging and dropping tasks Adjust markup and styling for new library Change kanban library to something that works Add basic calculation of new positions Don't try to create empty tasks Add indicator if a task is done Add moving tasks between buckets Make empty buckets a little smaller Add gimmick for button description Fix color Fix scrolling bucket layout Add creating a new bucket Add hiding the task input field Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/118
2020-04-26 01:11:34 +02:00
const labelService = new LabelService()
model.labels = model.labels.map(l => labelService.processModel(l))
}
2022-07-21 00:42:36 +02:00
return model as ITask
}
}