init
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { t } from './i18n/index.js';
|
||||
import { getTask, updateTask } from './store.js';
|
||||
import { formatLocalDate, generateUniqueId } from './utils.js';
|
||||
|
||||
export function addSystemEntries(task, changes) {
|
||||
const timeline = [...task.timeline];
|
||||
const fields = [
|
||||
['progressNotes', 'progressNotesUpdated', 'progressNotesUpdated', (a, b) => ({ value: b })],
|
||||
['status', 'status-change', 'statusChanged', (a, b) => ({ from: a, to: b })],
|
||||
['progress', 'progress-update', 'progressUpdated', (a, b) => ({ from: a, to: b })],
|
||||
['assignee', 'status-change', 'assigneeChanged', (a, b) => ({ from: a, to: b })],
|
||||
['dueDate', 'status-change', 'dueDateChanged', (a, b) => ({ from: a, to: b })],
|
||||
['priority', 'status-change', 'priorityChanged', (a, b) => ({ from: a, to: b })],
|
||||
];
|
||||
const used = new Set(timeline.map((item) => item.id));
|
||||
fields.forEach(([field, type, key, values]) => {
|
||||
if (Object.hasOwn(changes, field) && task[field] !== changes[field])
|
||||
timeline.push({
|
||||
id: generateUniqueId(used),
|
||||
date: formatLocalDate(),
|
||||
type,
|
||||
content: '',
|
||||
event: { key, values: values(task[field], changes[field]) },
|
||||
userType: 'system',
|
||||
});
|
||||
});
|
||||
return timeline;
|
||||
}
|
||||
export function addTimelineEntry(taskId, content) {
|
||||
const task = getTask(taskId);
|
||||
if (!task || !content.trim()) return false;
|
||||
const id = generateUniqueId(new Set(task.timeline.map((item) => item.id)));
|
||||
task.timeline.push({
|
||||
id,
|
||||
date: formatLocalDate(),
|
||||
type: 'manual-entry',
|
||||
content: content.trim(),
|
||||
user: task.assignee || t('defaultUser'),
|
||||
});
|
||||
updateTask(taskId, { timeline: task.timeline });
|
||||
return true;
|
||||
}
|
||||
export function updateTimelineEntry(taskId, timelineId, content) {
|
||||
const task = getTask(taskId);
|
||||
const item = task?.timeline.find((entry) => entry.id === timelineId);
|
||||
if (!item || !content.trim()) return false;
|
||||
const wasSystem = item.userType === 'system';
|
||||
item.content = content.trim();
|
||||
item.type = 'manual-entry';
|
||||
if (wasSystem || !item.user) item.user = task.assignee || t('defaultUser');
|
||||
delete item.event;
|
||||
delete item.userType;
|
||||
updateTask(taskId, { timeline: task.timeline });
|
||||
return true;
|
||||
}
|
||||
export function deleteTimelineEntry(taskId, timelineId) {
|
||||
const task = getTask(taskId);
|
||||
if (!task) return false;
|
||||
const timeline = task.timeline.filter((item) => item.id !== timelineId);
|
||||
if (timeline.length === task.timeline.length) return false;
|
||||
updateTask(taskId, { timeline });
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user