mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-18 21:44: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 Meta:
|
||||
model = Todo
|
||||
exclude = ('tags',)
|
||||
exclude = ('tags', 'google_calendar_id', 'creation_date', 'last_update',)
|
||||
|
||||
class ChangeTaskOrderSerializer(serializers.Serializer):
|
||||
list_board_id = serializers.IntegerField(
|
||||
|
||||
@ -35,7 +35,7 @@ class TodoViewSet(viewsets.ModelViewSet):
|
||||
def create(self, request, *args, **kwargs):
|
||||
try:
|
||||
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.is_valid(raise_exception=True)
|
||||
self.perform_create(serializer)
|
||||
|
||||
@ -197,19 +197,47 @@ function KanbanBoard() {
|
||||
</div>
|
||||
);
|
||||
|
||||
function createTask(columnId) {
|
||||
const newTask = {
|
||||
id: generateId(),
|
||||
columnId,
|
||||
content: `Task ${tasks.length + 1}`,
|
||||
function createTask(columnId, setTasks) {
|
||||
const newTaskData = {
|
||||
title: `Task ${tasks.length + 1}`,
|
||||
importance: 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) {
|
||||
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) {
|
||||
@ -328,16 +356,16 @@ function KanbanBoard() {
|
||||
if (isActiveATask && isOverAColumn) {
|
||||
setTasks(tasks => {
|
||||
const activeIndex = tasks.findIndex(t => t.id === activeId);
|
||||
|
||||
|
||||
tasks[activeIndex].columnId = overId;
|
||||
|
||||
axiosInstance.put(`todo/change_task_list_board/`, { todo_id:activeId, new_list_board_id:overId, new_index: 0})
|
||||
.then(response => {
|
||||
})
|
||||
|
||||
axiosInstance
|
||||
.put(`todo/change_task_list_board/`, { todo_id: activeId, new_list_board_id: overId, new_index: 0 })
|
||||
.then(response => {})
|
||||
.catch(error => {
|
||||
console.error('Error updating task columnId:', error);
|
||||
console.error("Error updating task columnId:", error);
|
||||
});
|
||||
|
||||
|
||||
return arrayMove(tasks, activeIndex, activeIndex);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user