Files
pages/static/js/task-today.js
T
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming.

Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
2026-09-27 14:44:43 +09:00

37 lines
4.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(() => {
'use strict';
const app=document.getElementById('tasks-app');if(!app||app.dataset.view!=='today')return;
const ja=document.documentElement.lang.startsWith('ja'),t=(en,jp)=>ja?jp:en;
const el=(tag,value)=>{const n=document.createElement(tag);if(value!==undefined)n.textContent=value;return n;};
const panel=el('section');panel.id='tasks-day';panel.ariaLabel=t('Today overview','今日の見通し');
const cards=el('div');cards.className='task-day-cards';const stats={};
[['estimate',t('Remaining task estimates','未完了タスクの見積もり')],['allocated',t('Calendar time blocks','今日の時間枠')],['focus',t('Recorded focus time','記録済みの集中時間')]].forEach(([key,label])=>{const card=el('div');const value=el('strong','—');stats[key]=value;card.append(el('small',label),value);cards.append(card);});
const note=el('p');note.className='tasks-muted';note.role='status';
const details=el('details'),heading=el('summary',t('Today’s time blocks','今日の時間枠を表示')),list=el('ol');list.id='tasks-day-blocks';details.append(heading,list);
panel.append(cards,note,details);document.getElementById('tasks-help').after(panel);
let busy=false,queued=false,generation=0,controller,last=0;
const duration=ms=>{const minutes=Math.floor(ms/60000);return minutes>=60?`${Math.floor(minutes/60)}${t('h ','時間 ')}${minutes%60}${t('m','分')}`:`${minutes}${t(' min','分')}`;};
async function load(){
if(document.hidden){queued=true;return;}if(busy){queued=true;return;}
busy=true;queued=false;const ticket=++generation;controller=new AbortController();
try{
const res=await fetch('/_/api/v1/extension/organizer.tasks/today',{credentials:'same-origin',signal:AbortSignal.any([controller.signal,AbortSignal.timeout(15000)])});
if(!res.ok||res.redirected)throw Error(t('Overview unavailable. Refresh to retry.','集約情報を取得できません。更新して再試行してください。'));const data=await res.json();if(ticket!==generation)return;
last=Date.now();stats.estimate.textContent=duration(data.summary.estimate_minutes*60000)+(data.summary.tasks_partial?' +':'');stats.allocated.textContent=data.calendar_enabled?duration(data.allocated_ms)+(data.blocks_partial||data.unavailable_calendars?' +':''):'—';stats.focus.textContent=duration(data.summary.focus_ms)+(data.summary.focus_partial?' +':'');
const messages=[t('Estimates include unfinished tasks planned for today or due by today. Focus excludes breaks; values are as of refresh.','見積もりは今日取り組む・今日までが期限の未完了タスク。集中時間は休憩を除いた更新時点の記録です。')];
if(data.overlap_ms>0)messages.push(t('Overlapping allocations: ','時間枠の重複:')+duration(data.overlap_ms));
if(data.summary.tasks_partial||data.summary.focus_partial||data.blocks_partial)messages.push(t('Only a bounded subset is shown (+); totals may be incomplete.','表示上限に達したため一部のみの集計です(+)。'));
if(data.unavailable_calendars)messages.push(t('Some linked calendars are unavailable or no longer private/local.','取得できない、または非公開・ローカルの条件を満たさなくなったカレンダーがあります。'));
if(!data.calendar_enabled)messages.push(t('Calendar extension disabled.','カレンダー拡張は無効です。'));
note.textContent=messages.join(' ');list.replaceChildren();
const fmt=new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{timeZone:data.timezone,month:'numeric',day:'numeric',hour:'2-digit',minute:'2-digit'});
data.blocks.forEach(b=>{const row=el('li'),time=el('a',fmt.format(new Date(b.start_ms))+' – '+fmt.format(new Date(b.end_ms)));time.href=b.href;time.title=t('Open calendar event','カレンダーの予定を開く');const task=el('a',b.title);task.href='/v/plan/task/'+encodeURIComponent(b.task_uuid);row.append(time,task);list.append(row);});
if(!data.blocks.length)list.append(el('li',t('No linked time blocks today.','今日の関連する時間枠はありません。')));
}catch(e){if(e.name!=='AbortError')note.textContent=e.message;}
finally{busy=false;if(queued&&!document.hidden){queued=false;load();}}
}
app.addEventListener('task-today-refresh',load);document.getElementById('tasks-refresh').addEventListener('click',load);
document.addEventListener('visibilitychange',()=>{if(document.hidden){generation++;controller?.abort();}else if(queued||Date.now()-last>30000)load();});
load();
})();