Show authenticated daily operation records
This commit is contained in:
@@ -106,12 +106,28 @@ function renderLedger() {
|
||||
table.append(head, body); wrapper.append(table); host.append(wrapper);
|
||||
}
|
||||
function showView(view) {
|
||||
const evolution = view === 'evolution';
|
||||
$('#report-view').hidden = evolution; $('#evolution-view').hidden = !evolution;
|
||||
for (const [selector, active] of [['#show-report', !evolution], ['#show-evolution', evolution]]) {
|
||||
for (const name of ['report', 'evolution', 'daily']) $(`#${name}-view`).hidden = view !== name;
|
||||
for (const [selector, active] of [['#show-report', view === 'report'], ['#show-evolution', view === 'evolution'], ['#show-daily', view === 'daily']]) {
|
||||
$(selector).classList.toggle('active', active); $(selector).setAttribute('aria-pressed', String(active));
|
||||
}
|
||||
}
|
||||
async function openDaily() {
|
||||
showView('daily');
|
||||
const host = $('#daily-content'); host.replaceChildren(el('p', '正在读取每日记录…', 'muted'));
|
||||
history.replaceState(null, '', '/?view=daily');
|
||||
try {
|
||||
const data = await api('/api/daily');
|
||||
host.replaceChildren();
|
||||
if (data.invalid_count) host.append(el('p', `${data.invalid_count} 条记录无法读取,请检查数据文件。`, 'error'));
|
||||
if (!data.records.length) host.append(el('p', '暂无每日记录。', 'empty'));
|
||||
for (const record of data.records) {
|
||||
const day = el('details', undefined, 'report-section');
|
||||
const heading = el('summary', record.date); day.append(heading);
|
||||
for (const [title, field] of [['已计划', 'planned'], ['实际执行', 'executed'], ['证据', 'evidence'], ['成本', 'costs'], ['复盘', 'review'], ['明日任务', 'tomorrow']]) day.append(listSection(title, record[field]));
|
||||
host.append(day);
|
||||
}
|
||||
} catch (error) { host.replaceChildren(el('p', error.message, 'error')); }
|
||||
}
|
||||
function renderEvolution(data) {
|
||||
const host = $('#evolution-content'); host.replaceChildren();
|
||||
const events = Array.isArray(data?.events) ? data.events : [];
|
||||
@@ -163,8 +179,10 @@ async function loadDashboard() {
|
||||
const initialView = params.get('view');
|
||||
if (selected && dashboard.reports.some(r => r.id === selected)) await openReport(selected); else renderReport(dashboard.latest);
|
||||
if (initialView === 'evolution') await openEvolution();
|
||||
if (initialView === 'daily') await openDaily();
|
||||
}
|
||||
$('#show-evolution').addEventListener('click', openEvolution);
|
||||
$('#show-daily').addEventListener('click', openDaily);
|
||||
$('#show-report').addEventListener('click', () => { showView('report'); history.replaceState(null, '', currentReportId ? `/?report=${encodeURIComponent(currentReportId)}` : '/'); });
|
||||
$('#login-form').addEventListener('submit', async event => {
|
||||
event.preventDefault(); const button = event.currentTarget.querySelector('button'); button.disabled = true; $('#login-error').textContent = '';
|
||||
@@ -172,7 +190,7 @@ $('#login-form').addEventListener('submit', async event => {
|
||||
catch (error) { $('#login-error').textContent = error.message; } finally { button.disabled = false; }
|
||||
});
|
||||
$('#logout').addEventListener('click', async () => {
|
||||
try { await api('/api/logout', { method: 'POST', body: '{}' }); dashboard = null; $('#report-content').replaceChildren(); $('#evolution-content').replaceChildren(); currentReportId = undefined; showView('report'); $('#ledger').replaceChildren(); $('#report-nav').replaceChildren(); showLogin(); }
|
||||
try { await api('/api/logout', { method: 'POST', body: '{}' }); dashboard = null; $('#report-content').replaceChildren(); $('#evolution-content').replaceChildren(); $('#daily-content').replaceChildren(); currentReportId = undefined; showView('report'); $('#ledger').replaceChildren(); $('#report-nav').replaceChildren(); showLogin(); }
|
||||
catch (error) { $('#global-error').textContent = error.message; }
|
||||
});
|
||||
(async () => {
|
||||
|
||||
Reference in New Issue
Block a user