forked from vikunja/frontend
kolaente
befa6f27bb
fix: project table view fix: e2e tests fix: typo in readme fix: list view route fix: don't wait until background is loaded for list to show fix: rename component imports fix: lint fix: parse task text fix: use list card grid fix: use correct class names fix: i18n keys fix: load project fix: task overview fix: list view spacing fix: find project fix: setLoading when updating a project fix: loading saved filter fix: project store loading fix: color picker import fix: cypress tests feat: migrate old list settings chore: add const for project settings fix: wrong projecten rename from lists chore: rename unused variable fix: editor list fix: shortcut list class name fix: pagination list class name fix: notifications list class name fix: list view variable name chore: clarify comment fix: i18n keys fix: router imports fix: comment chore: remove debugging leftover fix: remove duplicate variables fix: change comment fix: list view variable name fix: list view css class name fix: list item property name fix: name update tasks function correctly fix: update comment fix: project create route fix: list view class names fix: list view component name fix: result list class name fix: animation class list name fix: change debug log fix: revert a few navigation changes fix: use @ for imports of all views fix: rename link share list class fix: remove unused css class fix: dynamically import project components again
121 lines
3.2 KiB
TypeScript
121 lines
3.2 KiB
TypeScript
import AbstractService from './abstractService'
|
|
import TaskModel from '@/models/task'
|
|
import type {ITask} from '@/modelTypes/ITask'
|
|
import AttachmentService from './attachment'
|
|
import LabelService from './label'
|
|
|
|
import {colorFromHex} from '@/helpers/color/colorFromHex'
|
|
import {SECONDS_A_DAY, SECONDS_A_HOUR, SECONDS_A_WEEK, SECONDS_A_MONTH, SECONDS_A_YEAR} from '@/constants/date'
|
|
|
|
const parseDate = date => {
|
|
if (date) {
|
|
return new Date(date).toISOString()
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
export default class TaskService extends AbstractService<ITask> {
|
|
constructor() {
|
|
super({
|
|
create: '/projects/{projectId}',
|
|
getAll: '/tasks/all',
|
|
get: '/tasks/{id}',
|
|
update: '/tasks/{id}',
|
|
delete: '/tasks/{id}',
|
|
})
|
|
}
|
|
|
|
modelFactory(data) {
|
|
return new TaskModel(data)
|
|
}
|
|
|
|
beforeUpdate(model) {
|
|
return this.processModel(model)
|
|
}
|
|
|
|
beforeCreate(model) {
|
|
return this.processModel(model)
|
|
}
|
|
|
|
processModel(updatedModel) {
|
|
const model = { ...updatedModel }
|
|
|
|
model.title = model.title?.trim()
|
|
|
|
// Ensure that projectId is an int
|
|
model.projectId = Number(model.projectId)
|
|
|
|
// Convert dates into an iso string
|
|
model.dueDate = parseDate(model.dueDate)
|
|
model.startDate = parseDate(model.startDate)
|
|
model.endDate = parseDate(model.endDate)
|
|
model.doneAt = parseDate(model.doneAt)
|
|
model.created = new Date(model.created).toISOString()
|
|
model.updated = new Date(model.updated).toISOString()
|
|
|
|
// 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) {
|
|
model.reminderDates = model.reminderDates.map(r => {
|
|
return new Date(r).toISOString()
|
|
})
|
|
}
|
|
|
|
// 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 * SECONDS_A_HOUR
|
|
break
|
|
case 'days':
|
|
repeatAfterSeconds = model.repeatAfter.amount * SECONDS_A_DAY
|
|
break
|
|
case 'weeks':
|
|
repeatAfterSeconds = model.repeatAfter.amount * SECONDS_A_WEEK
|
|
break
|
|
case 'months':
|
|
repeatAfterSeconds = model.repeatAfter.amount * SECONDS_A_MONTH
|
|
break
|
|
case 'years':
|
|
repeatAfterSeconds = model.repeatAfter.amount * SECONDS_A_YEAR
|
|
break
|
|
}
|
|
}
|
|
model.repeatAfter = repeatAfterSeconds
|
|
|
|
model.hexColor = colorFromHex(model.hexColor)
|
|
|
|
// Do the same for all related tasks
|
|
Object.keys(model.relatedTasks).forEach(relationKind => {
|
|
model.relatedTasks[relationKind] = model.relatedTasks[relationKind].map(t => {
|
|
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)
|
|
})
|
|
}
|
|
|
|
// Preprocess all labels
|
|
if (model.labels.length > 0) {
|
|
const labelService = new LabelService()
|
|
model.labels = model.labels.map(l => labelService.processModel(l))
|
|
}
|
|
|
|
return model as ITask
|
|
}
|
|
}
|
|
|