mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-19 05:54:07 +01:00
Add create adn update task
This commit is contained in:
parent
dc154c0122
commit
8e3b91b8ac
@ -14,7 +14,7 @@ class TaskSerializer(serializers.ModelSerializer):
|
|||||||
class TaskCreateSerializer(serializers.ModelSerializer):
|
class TaskCreateSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Todo
|
model = Todo
|
||||||
exclude = ('tags',)
|
exclude = ('tags', 'google_calendar_id', 'creation_date', 'last_update',)
|
||||||
|
|
||||||
class ChangeTaskOrderSerializer(serializers.Serializer):
|
class ChangeTaskOrderSerializer(serializers.Serializer):
|
||||||
list_board_id = serializers.IntegerField(
|
list_board_id = serializers.IntegerField(
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class TodoViewSet(viewsets.ModelViewSet):
|
|||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
new_task_data = request.data
|
new_task_data = request.data
|
||||||
new_task_data['user'] = self.request.user
|
new_task_data['user'] = self.request.user.id
|
||||||
serializer = self.get_serializer(data=new_task_data)
|
serializer = self.get_serializer(data=new_task_data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
self.perform_create(serializer)
|
self.perform_create(serializer)
|
||||||
|
|||||||
@ -197,19 +197,47 @@ function KanbanBoard() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
function createTask(columnId) {
|
function createTask(columnId, setTasks) {
|
||||||
const newTask = {
|
const newTaskData = {
|
||||||
id: generateId(),
|
title: `Task ${tasks.length + 1}`,
|
||||||
columnId,
|
importance: 1,
|
||||||
content: `Task ${tasks.length + 1}`,
|
difficulty: 1,
|
||||||
|
challenge: false,
|
||||||
|
fromSystem: false,
|
||||||
|
is_active: false,
|
||||||
|
is_full_day_event: false,
|
||||||
|
completed: false,
|
||||||
|
priority: 1,
|
||||||
|
list_board: columnId,
|
||||||
};
|
};
|
||||||
|
|
||||||
setTasks([...tasks, newTask]);
|
axiosInstance
|
||||||
}
|
.post("todo/", newTaskData)
|
||||||
|
.then(response => {
|
||||||
|
const newTask = {
|
||||||
|
id: response.data.id,
|
||||||
|
columnId,
|
||||||
|
content: response.data.title,
|
||||||
|
};
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Error creating task:", error);
|
||||||
|
});
|
||||||
|
setTasks(tasks => [...tasks, newTask]);
|
||||||
|
}
|
||||||
|
|
||||||
function deleteTask(id) {
|
function deleteTask(id) {
|
||||||
const newTasks = tasks.filter(task => task.id !== id);
|
const newTasks = tasks.filter(task => task.id !== id);
|
||||||
setTasks(newTasks);
|
axiosInstance
|
||||||
|
.delete(`todo/${id}/`)
|
||||||
|
.then(response => {
|
||||||
|
setTasks(newTasks);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Error deleting Task:", error);
|
||||||
|
});
|
||||||
|
setTasks(newTasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTask(id, content) {
|
function updateTask(id, content) {
|
||||||
@ -328,16 +356,16 @@ function KanbanBoard() {
|
|||||||
if (isActiveATask && isOverAColumn) {
|
if (isActiveATask && isOverAColumn) {
|
||||||
setTasks(tasks => {
|
setTasks(tasks => {
|
||||||
const activeIndex = tasks.findIndex(t => t.id === activeId);
|
const activeIndex = tasks.findIndex(t => t.id === activeId);
|
||||||
|
|
||||||
tasks[activeIndex].columnId = overId;
|
tasks[activeIndex].columnId = overId;
|
||||||
|
|
||||||
axiosInstance.put(`todo/change_task_list_board/`, { todo_id:activeId, new_list_board_id:overId, new_index: 0})
|
axiosInstance
|
||||||
.then(response => {
|
.put(`todo/change_task_list_board/`, { todo_id: activeId, new_list_board_id: overId, new_index: 0 })
|
||||||
})
|
.then(response => {})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error updating task columnId:', error);
|
console.error("Error updating task columnId:", error);
|
||||||
});
|
});
|
||||||
|
|
||||||
return arrayMove(tasks, activeIndex, activeIndex);
|
return arrayMove(tasks, activeIndex, activeIndex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user