This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/services/task.js
konrad c7845bb9c1
All checks were successful
continuous-integration/drone/push Build is passing
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: #118
2020-04-25 23:11:34 +00:00

109 lines
2.9 KiB
JavaScript

import AbstractService from './abstractService'
import TaskModel from '../models/task'
import AttachmentService from './attachment'
import LabelService from './label'
import {formatISO} from 'date-fns'
export default class TaskService extends AbstractService {
constructor() {
super({
create: '/lists/{listId}',
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(model) {
// Ensure that listId is an int
model.listId = Number(model.listId)
// Convert dates into an iso string
model.dueDate = model.dueDate === null ? null : formatISO(new Date(model.dueDate))
model.startDate = model.startDate === null ? null : formatISO(new Date(model.startDate))
model.endDate = model.endDate === null ? null : formatISO(new Date(model.endDate))
model.created = formatISO(model.created)
model.updated = formatISO(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) {
model.reminderDates = model.reminderDates.map(r => {
return formatISO(new Date(r))
})
}
// Make the repeating amount to seconds
let repeatAfterSeconds = 0
if (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
if (model.hexColor.substring(0, 1) === '#') {
model.hexColor = model.hexColor.substring(1, 7)
}
// 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
}
}