diff --git a/public/app.js b/public/app.js index db49022..7b0f8f7 100644 --- a/public/app.js +++ b/public/app.js @@ -2093,12 +2093,32 @@ function actRow(p, meta) { } const actMeta = (files, commits) => [files ? t(files === 1 ? 'act.file1' : 'act.filesN', { n: files }) : '', commits ? t(commits === 1 ? 'act.commit1' : 'act.commitsN', { n: commits }) : ''].filter(Boolean).join(' ยท ') +const dayCommitsCache = {} function renderActDay() { const e = actData.days[actDay] document.getElementById('acDayTitle').textContent = fmtDay(actDay) - document.getElementById('acDay').innerHTML = e?.projects.length - ? `
${e.projects.map((p) => actRow(p.name, actMeta(p.files, p.commits))).join('')}
` - : `
${t('act.nothingDay')}
` + const el = document.getElementById('acDay') + if (!e?.projects.length) { el.innerHTML = `
${t('act.nothingDay')}
`; return } + const hasCommits = e.projects.some((p) => p.commits > 0) + el.innerHTML = `
${e.projects.map((p) => actRow(p.name, actMeta(p.files, p.commits))).join('')}
` + + (hasCommits ? `
${ic('git-commit-horizontal', 'sm')}${t('act.showCommits')}${ic('chevron-down', 'sm')}
` : '') + const det = document.getElementById('acCommits') + if (det) det.addEventListener('toggle', () => { if (det.open) loadDayCommits(actDay, det.querySelector('.acc-body')) }) +} +// lazy: commit messages for the selected day (only git projects, server-side) +async function loadDayCommits(day, box) { + if (box.dataset.loadedDay === day) return + box.dataset.loadedDay = day + box.innerHTML = `${t('info.loading')}` + let data = dayCommitsCache[day] + if (!data) { + try { data = await (await fetch('/api/activity/day?date=' + encodeURIComponent(day))).json() } + catch { box.dataset.loadedDay = ''; box.innerHTML = `${t('err.saveFailed')}`; return } + dayCommitsCache[day] = data + } + box.innerHTML = data.projects?.length + ? data.projects.map((p) => `
${escapeHtml(p.name)}
`).join('') + : `${t('act.nothingDay')}` } function renderActTop() { diff --git a/public/index.html b/public/index.html index 571abd8..70cd4a9 100644 --- a/public/index.html +++ b/public/index.html @@ -424,6 +424,16 @@ .aclist.spark-list button { grid-template-columns: minmax(0, 1fr) 72px auto; } .spark { display: inline-flex; align-items: flex-end; gap: 1px; height: 20px; width: 72px; } .spark i { flex: 1; min-width: 1px; background: color-mix(in srgb, var(--accent) 55%, transparent); border-radius: 1px; align-self: flex-end; } + /* expandable commit messages in the day detail */ + .accommits { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; } + .accommits > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); font-weight: 600; } + .accommits > summary::-webkit-details-marker { display: none; } + .accommits > summary > .i:last-child { margin-left: auto; transition: transform .18s; } + .accommits[open] > summary > .i:last-child { transform: rotate(180deg); } + .acc-body { margin-top: 8px; display: flex; flex-direction: column; gap: 10px; } + .acc-proj b { font-size: 12.5px; } + .acc-proj ul { margin: 4px 0 0; padding-left: 18px; } + .acc-proj li { font-size: 12.5px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; } .aclist { display: flex; flex-direction: column; gap: 2px; } .aclist button { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; border: none; background: none; padding: 6px 8px; margin: 0 -8px; border-radius: 7px; cursor: pointer; text-align: left; font: inherit; color: inherit; } .aclist button:hover { background: var(--surface-2); } diff --git a/server.js b/server.js index a6072e7..1f4d8ae 100644 --- a/server.js +++ b/server.js @@ -934,6 +934,21 @@ app.get('/api/projects/:name/activity', handle(async (req, res) => { res.json({ files: a.files ?? null, commits: a.commits, today: activity.dayOf(Date.now()) }) })) +// Commit messages of one local day (lazy, for the activity day detail). Only queries git projects. +app.get('/api/activity/day', handle(async (req, res) => { + const date = String(req.query.date ?? '') + if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) return res.status(400).json({ error: 'bad date' }) + const list = projectList().filter((p) => fs.existsSync(path.join(p.root.path, p.folder, '.git'))) + const out = await pool(list, 8, async (p) => { + const dir = path.join(p.root.path, p.folder) + const r = await run('git', ['-C', dir, 'log', `--since=${date} 00:00:00`, `--until=${date} 23:59:59`, + '--no-merges', '--format=%s'], { timeout: 8000 }).catch(() => ({ stdout: '' })) + const msgs = r.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean).slice(0, 30) + return msgs.length ? { name: p.key, msgs } : null + }) + res.json({ date, projects: out.filter(Boolean) }) +})) + // Storage page: every shown project with its scan result (size, split, cleanup candidates). app.get('/api/storage', (req, res) => { const list = projectList().map((p) => {