feat(tasks): add daily and weekly recurring occurrences
This commit is contained in:
1 parent
47bded8af7
commit
8d148d31dd
25 files changed
+141
-23
No files matched your search
+1
-1
@@ -3,7 +3,7 @@
|
||||
const DRAFT_KEY = 'lifeos_today_draft_v1';
|
||||
const localDay = () => { const d = new Date(); return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`; };
|
||||
const escapeHtml = value => String(value || '').replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[char]));
|
||||
const APP_VERSION = '1.25.0';
|
||||
const APP_VERSION = '1.26.0';
|
||||
window.LifeOSVersion = APP_VERSION;
|
||||
const appIds = ['today', 'timeline', 'museum', 'insights', 'profile', 'tasks', 'calendar', 'system', 'browser', 'terminal', 'database'];
|
||||
const t = (key, values) => LifeI18n.t(key, values);
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
const stored = records();
|
||||
return {
|
||||
app: 'Life OS',
|
||||
version: window.LifeOSVersion || '1.25.0',
|
||||
version: window.LifeOSVersion || '1.26.0',
|
||||
schemaVersion: BACKUP_SCHEMA,
|
||||
exportedAt: new Date().toISOString(),
|
||||
profile: json('lifeos_profile', {}),
|
||||
|
||||
+18
-5
@@ -34,28 +34,41 @@
|
||||
Object.assign(goal, { title, description: String(description).trim().slice(0, 240), targetDate, showOnDesktop: Boolean(targetDate && showOnDesktop), updatedAt: new Date().toISOString() });
|
||||
persistBoard(data); return goal;
|
||||
},
|
||||
createTask({ title, dueDate = '', goalId = '', priority = 'normal' }) {
|
||||
createTask({ title, dueDate = '', goalId = '', priority = 'normal', repeat = 'none' }) {
|
||||
title = required(title, 140);
|
||||
if (!validDate(dueDate)) throw new Error('invalidDate');
|
||||
if (!['normal', 'high', 'low'].includes(priority)) throw new Error('invalidPriority');
|
||||
if (!['none','daily','weekly'].includes(repeat) || (repeat !== 'none' && !dueDate)) throw new Error('invalidDate');
|
||||
const data = board();
|
||||
if (goalId && !data.goals.some(goal => goal.id === goalId)) throw new Error('notFound');
|
||||
const task = { id: `task_${crypto.randomUUID()}`, title, dueDate, goalId, priority, done: false, createdAt: new Date().toISOString() };
|
||||
const task = { id: `task_${crypto.randomUUID()}`, title, dueDate, goalId, priority, repeat, done: false, createdAt: new Date().toISOString() };
|
||||
data.tasks.push(task); persistBoard(data); return task;
|
||||
},
|
||||
updateTask(id, { title, dueDate = '', goalId = '', priority = 'normal' }) {
|
||||
updateTask(id, { title, dueDate = '', goalId = '', priority = 'normal', repeat }) {
|
||||
title = required(title, 140);
|
||||
if (!validDate(dueDate)) throw new Error('invalidDate');
|
||||
if (!['normal', 'high', 'low'].includes(priority)) throw new Error('invalidPriority');
|
||||
const data = board(), task = data.tasks.find(item => item.id === id);
|
||||
if (!task || (goalId && !data.goals.some(goal => goal.id === goalId))) throw new Error('notFound');
|
||||
Object.assign(task, { title, dueDate, goalId, priority, updatedAt: new Date().toISOString() });
|
||||
repeat = repeat ?? task.repeat ?? 'none';
|
||||
if (!['none','daily','weekly'].includes(repeat) || (repeat !== 'none' && !dueDate)) throw new Error('invalidDate');
|
||||
Object.assign(task, { title, dueDate, goalId, priority, repeat, updatedAt: new Date().toISOString() });
|
||||
persistBoard(data); return task;
|
||||
},
|
||||
setTaskDone(id, done) {
|
||||
const data = board(), task = data.tasks.find(item => item.id === id);
|
||||
if (!task) throw new Error('notFound');
|
||||
if (!task || task.trashedAt) throw new Error('notFound');
|
||||
task.done = done; task.completedAt = done ? new Date().toISOString() : null;
|
||||
if (done && ['daily','weekly'].includes(task.repeat) && !task.nextOccurrenceId) {
|
||||
const step=task.repeat==='daily'?1:7, base=Date.parse(`${task.dueDate}T00:00:00Z`), today=Date.parse(`${day()}T00:00:00Z`);
|
||||
if (!Number.isFinite(base)) throw new Error('invalidDate');
|
||||
const advances=Math.max(1,Math.floor((today-base)/(864e5*step))+1);
|
||||
const dueDate=new Date(base+advances*step*864e5).toISOString().slice(0,10);
|
||||
const series=task.repeatSeriesId || task.id, occurrence=(task.occurrence || 0)+1;
|
||||
const nextId=`${series}_occ_${occurrence}`;
|
||||
task.repeatSeriesId=series; task.nextOccurrenceId=nextId;
|
||||
if (!data.tasks.some(item=>item.id===nextId)) data.tasks.push({id:nextId,title:task.title,dueDate,goalId:task.goalId,priority:task.priority,repeat:task.repeat,repeatSeriesId:series,occurrence,previousOccurrenceId:task.id,done:false,createdAt:task.completedAt});
|
||||
}
|
||||
persistBoard(data); return task;
|
||||
},
|
||||
setGoalDone(id, done) {
|
||||
|
||||
Loaded 3 of 25 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user