Skip to content

Commit 16d0eb9

Browse files
Merge pull request #164 from tmgr-dev/TM-159-pri-soxranenii-zadac
Частичное обновление задачи
2 parents 5590f52 + 9a6cb11 commit 16d0eb9

6 files changed

Lines changed: 159 additions & 69 deletions

File tree

‎src/components/tasks/TaskBoardCard.vue‎

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -497,53 +497,53 @@
497497
hour12: false,
498498
});
499499
},
500-
async handleStartTimer() {
501-
if (!this.task.id || this.isLoadingTimer) return;
500+
async handleStartTimer() {
501+
if (!this.task.id || this.isLoadingTimer) return;
502502
503-
this.isLoadingTimer = true;
504-
try {
505-
const updatedTask = await startTaskTimeCounter(this.task.id);
506-
Object.assign(this.task, updatedTask);
507-
this.$store.commit('incrementReloadTasksKey');
508-
this.$emit('timer-started', updatedTask);
503+
this.isLoadingTimer = true;
504+
try {
505+
const updatedTask = await startTaskTimeCounter(this.task.id);
506+
Object.assign(this.task, updatedTask);
507+
this.$store.commit('updateSingleTask', updatedTask);
508+
this.$emit('timer-started', updatedTask);
509509
510-
const taskStatus = this.statuses.find(
511-
(s) => s.id === this.task.status_id,
512-
);
513-
if (taskStatus && taskStatus.type === 'default') {
514-
const activeStatus = this.statuses.find((s) => s.type === 'active');
515-
if (activeStatus) {
516-
const shouldSwitch = confirm(
517-
`Task "${this.task.title}" is in backlog. Switch to "${activeStatus.name}" status?`,
518-
);
519-
if (shouldSwitch) {
520-
await updateTaskStatus(this.task.id, activeStatus.id);
521-
this.task.status_id = activeStatus.id;
522-
this.$store.commit('incrementReloadTasksKey');
523-
}
510+
const taskStatus = this.statuses.find(
511+
(s) => s.id === this.task.status_id,
512+
);
513+
if (taskStatus && taskStatus.type === 'default') {
514+
const activeStatus = this.statuses.find((s) => s.type === 'active');
515+
if (activeStatus) {
516+
const shouldSwitch = confirm(
517+
`Task "${this.task.title}" is in backlog. Switch to "${activeStatus.name}" status?`,
518+
);
519+
if (shouldSwitch) {
520+
await updateTaskStatus(this.task.id, activeStatus.id);
521+
this.task.status_id = activeStatus.id;
522+
this.$store.commit('updateSingleTask', this.task);
524523
}
525524
}
526-
} catch (e) {
527-
console.error('Failed to start timer:', e);
528-
} finally {
529-
this.isLoadingTimer = false;
530525
}
531-
},
532-
async handleStopTimer() {
533-
if (!this.task.id || this.isLoadingTimer) return;
526+
} catch (e) {
527+
console.error('Failed to start timer:', e);
528+
} finally {
529+
this.isLoadingTimer = false;
530+
}
531+
},
532+
async handleStopTimer() {
533+
if (!this.task.id || this.isLoadingTimer) return;
534534
535-
this.isLoadingTimer = true;
536-
try {
537-
const updatedTask = await stopTaskTimeCounter(this.task.id);
538-
Object.assign(this.task, updatedTask);
539-
this.$store.commit('incrementReloadTasksKey');
540-
this.$emit('timer-stopped', updatedTask);
541-
} catch (e) {
542-
console.error('Failed to stop timer:', e);
543-
} finally {
544-
this.isLoadingTimer = false;
545-
}
546-
},
535+
this.isLoadingTimer = true;
536+
try {
537+
const updatedTask = await stopTaskTimeCounter(this.task.id);
538+
Object.assign(this.task, updatedTask);
539+
this.$store.commit('updateSingleTask', updatedTask);
540+
this.$emit('timer-stopped', updatedTask);
541+
} catch (e) {
542+
console.error('Failed to stop timer:', e);
543+
} finally {
544+
this.isLoadingTimer = false;
545+
}
546+
},
547547
updateTimer() {
548548
if (!this.task.start_time) {
549549
return;

‎src/pages/Board.vue‎

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -712,31 +712,37 @@
712712
pusherSubscriptionId: '',
713713
}),
714714
715-
watch: {
716-
'$store.state.reloadTasksKey'() {
717-
this.loadTasks();
718-
},
719-
'$store.state.currentTaskIdForModal'(newVal, oldVal) {
720-
if (oldVal && !newVal) {
721-
this.$nextTick(() => {
722-
this.updateScrollContainers();
723-
});
724-
}
725-
},
726-
$route() {
727-
this.isMobile = window.innerWidth <= 768;
728-
},
715+
watch: {
716+
'$store.state.reloadTasksKey'() {
717+
this.loadTasks();
718+
},
719+
'$store.state.updatedTaskKey'() {
720+
const updatedTask = this.$store.state.updatedTaskData;
721+
if (updatedTask) {
722+
this.updateSingleTaskInBoard(updatedTask);
723+
}
724+
},
725+
'$store.state.currentTaskIdForModal'(newVal, oldVal) {
726+
if (oldVal && !newVal) {
727+
this.$nextTick(() => {
728+
this.updateScrollContainers();
729+
});
730+
}
731+
},
732+
$route() {
733+
this.isMobile = window.innerWidth <= 768;
734+
},
729735
730-
chosenUser: function () {
731-
this.loadTasks();
732-
},
733-
searchText: function () {
734-
this.loadTasks();
735-
},
736-
chosenCategory: function () {
737-
this.loadTasks();
738-
},
736+
chosenUser: function () {
737+
this.loadTasks();
738+
},
739+
searchText: function () {
740+
this.loadTasks();
739741
},
742+
chosenCategory: function () {
743+
this.loadTasks();
744+
},
745+
},
740746
computed: {
741747
userSettings() {
742748
return this.$store.state.userSettings ?? {};
@@ -754,6 +760,56 @@
754760
},
755761
},
756762
methods: {
763+
updateSingleTaskInBoard(updatedTask) {
764+
let taskFound = false;
765+
const taskStatusId = Number(updatedTask.status_id);
766+
767+
for (const column of this.columns) {
768+
const taskIndex = column.tasks.findIndex(t => t.id === updatedTask.id);
769+
770+
if (taskIndex !== -1) {
771+
taskFound = true;
772+
const currentColumnStatusId = Number(column.status?.id);
773+
774+
if (currentColumnStatusId === taskStatusId) {
775+
this.$set(column.tasks, taskIndex, updatedTask);
776+
} else {
777+
column.tasks.splice(taskIndex, 1);
778+
const newColumn = this.columns.find(c => Number(c.status?.id) === taskStatusId);
779+
if (newColumn) {
780+
newColumn.tasks.unshift(updatedTask);
781+
}
782+
}
783+
break;
784+
}
785+
}
786+
787+
if (!taskFound) {
788+
const targetColumn = this.columns.find(c => Number(c.status?.id) === taskStatusId);
789+
if (targetColumn) {
790+
targetColumn.tasks.unshift(updatedTask);
791+
}
792+
}
793+
794+
this.columns = this.columns.map((column) => {
795+
const tasksInColumn = column.tasks;
796+
const taskCount = tasksInColumn.length;
797+
const summary = tasksInColumn.reduce(
798+
(acc, task) => task.common_time + acc,
799+
0,
800+
);
801+
const summaryInHours = this.formatTime(summary);
802+
const overtimeSeconds = this.calculateColumnOvertime(tasksInColumn);
803+
const overtimeFormatted = this.formatOvertime(overtimeSeconds);
804+
805+
return {
806+
...column,
807+
summary: summaryInHours,
808+
taskCount: taskCount,
809+
overtime: overtimeFormatted
810+
};
811+
});
812+
},
757813
scrollHorizontally() {
758814
document.querySelector('.board-container').scrollTo({
759815
left: document.querySelector('.board-container').scrollLeft + 200,

‎src/pages/NewForm.vue‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@
788788
}
789789
}
790790
791-
// Trigger reload of tasks list
792791
store.commit('incrementReloadTasksKey');
793792
} catch (e) {
794793
console.error(e);
@@ -875,7 +874,7 @@
875874
876875
const id = taskId.value || (form.value.id as number);
877876
form.value = await updateTask(id, form.value as Task, instanceId);
878-
store.commit('incrementReloadTasksKey');
877+
store.commit('updateSingleTask', form.value);
879878
880879
// Ensure no auto-save will happen after this manual save
881880
// We need to set this after the save operation completes
@@ -929,7 +928,7 @@
929928
suppressAutoSavingForOnce.value = true;
930929
const id = taskId.value || (form.value.id as number);
931930
form.value = await stopTaskTimeCounter(id);
932-
store.commit('incrementReloadTasksKey');
931+
store.commit('updateSingleTask', form.value);
933932
} catch (e) {
934933
console.error(e);
935934
} finally {
@@ -943,7 +942,7 @@
943942
suppressAutoSavingForOnce.value = true;
944943
const id = taskId.value || (form.value.id as number);
945944
form.value = await startTaskTimeCounter(id);
946-
store.commit('incrementReloadTasksKey');
945+
store.commit('updateSingleTask', form.value);
947946
} catch (e) {
948947
console.error(e);
949948
} finally {
@@ -995,7 +994,7 @@
995994
const id = backlogStatusChangeConfirm.value.taskId;
996995
await updateTaskStatus(id, activeStatus.id);
997996
form.value.status_id = activeStatus.id;
998-
store.commit('incrementReloadTasksKey');
997+
store.commit('updateSingleTask', form.value);
999998
} catch (e) {
1000999
console.error('Failed to change status:', e);
10011000
} finally {

‎src/pages/TasksListPage.vue‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@
230230
231231
watch(selectedCategory, loadTasks);
232232
watch(() => store.state.reloadTasksKey, loadTasks);
233+
watch(() => store.state.updatedTaskKey, () => {
234+
const updatedTask = store.state.updatedTaskData;
235+
if (updatedTask) {
236+
updateSingleTaskInList(updatedTask);
237+
}
238+
});
233239
watch(() => route.name, (newName) => {
234240
if (newName) {
235241
setDocumentTitle(h1[newName] || 'Task List');
@@ -319,6 +325,27 @@
319325
function resetFilters() {
320326
selectedCategory.value = null;
321327
}
328+
329+
function updateSingleTaskInList(updatedTask: Task) {
330+
const taskIndex = tasks.value.findIndex(t => t.id === updatedTask.id);
331+
332+
if (taskIndex !== -1) {
333+
const shouldStayInList = !status.value || updatedTask.status === status.value;
334+
335+
if (shouldStayInList) {
336+
tasks.value.splice(taskIndex, 1, updatedTask);
337+
} else {
338+
tasks.value.splice(taskIndex, 1);
339+
pagination.value.total = Math.max(0, pagination.value.total - 1);
340+
}
341+
} else {
342+
const shouldBeInList = !status.value || updatedTask.status === status.value;
343+
if (shouldBeInList) {
344+
tasks.value.unshift(updatedTask);
345+
pagination.value.total++;
346+
}
347+
}
348+
}
322349
</script>
323350

324351
<template>

‎src/store/index.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const state = {
3333
openModals: 0,
3434
modalStack: [],
3535
urlManuallyChanged: false,
36+
updatedTaskData: null,
37+
updatedTaskKey: 0,
3638
};
3739

3840
const getters = {
@@ -81,6 +83,10 @@ const mutations = {
8183
state.workspacesById = workspaces;
8284
}
8385
},
86+
updateSingleTask(state, task) {
87+
state.updatedTaskData = task;
88+
state.updatedTaskKey = (state.updatedTaskKey || 0) + 1;
89+
},
8490
setToken(state, token) {
8591
if (token == null) {
8692
localStorage.removeItem('token');

‎src/types/store.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface RootState {
5858
openModals: number;
5959
modalStack: string[];
6060
urlManuallyChanged: boolean;
61+
updatedTaskData: any | null;
62+
updatedTaskKey: number;
6163
}
6264

6365
export interface RootGetters {

0 commit comments

Comments
 (0)