Files
FWS-DiscordBot/src/web/public/views/tasks.js
T
nocodeandClaude Opus 5 fcc82d82d6 feat(projects): gather the cards one member carries
A board answers "where does the work stand". Nobody opens a dashboard to
ask that first: they ask what is on them today, and once the work is
spread over several boards no single board can answer it.

The cards assigned to a member are now listed on a page of their own,
grouped by deadline, with a counter on the sidebar entry — a page you
have to open to know whether it needs you is a page you stop opening.
The column travels with each card, so finishing one from the list is a
single move rather than a detour through its board.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-24 18:45:03 +02:00

250 lines
7.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.
import { api } from '../core/api.js';
import { formatRelative, h, mount } from '../core/dom.js';
import { autoRefresh } from '../core/live.js';
import { badge, card, notice, renderAsync, select, stat, toast } from '../core/ui.js';
/**
* « Mes tâches » — every card one member carries, across every board (M19).
*
* A board answers « where does the work stand ». Nobody opens a dashboard to
* ask that first: they ask what is on them today, and once the work is spread
* over several boards no single board can say.
*/
const today = () => new Date().toISOString().slice(0, 10);
const day = (value) => (value ? String(value).slice(0, 10) : null);
const plus = (days) => {
const date = new Date();
date.setDate(date.getDate() + days);
return date.toISOString().slice(0, 10);
};
/**
* Buckets, in the order someone wants to be told about them: what is late,
* what is due, then everything else. A card with no date is not urgent but is
* not invisible either — it sits at the bottom rather than nowhere.
*/
function bucketOf(task) {
if (task.isDone) return 'done';
const due = day(task.dueAt);
if (!due) return 'undated';
if (due < today()) return 'overdue';
if (due === today()) return 'today';
return due <= plus(7) ? 'week' : 'later';
}
const BUCKETS = [
{ key: 'overdue', title: 'En retard' },
{ key: 'today', title: 'Pour aujourd’hui' },
{ key: 'week', title: 'Cette semaine' },
{ key: 'later', title: 'Plus tard' },
{ key: 'undated', title: 'Sans échéance' },
];
/** Member names, asked once: the picker must not cost a roster fetch per render. */
let memberNames = null;
async function names() {
if (memberNames) return memberNames;
const data = await api.get('/api/discord/members', { limit: 200 }).catch(() => null);
memberNames = new Map((data?.members ?? []).map((member) => [member.id, member.displayName]));
return memberNames;
}
async function finish(task, reload) {
if (!task.doneColumnId) {
toast('Ce tableau n’a pas de colonne « terminé ».', 'error');
return;
}
await api.post(`/api/projects/${task.boardId}/cards/${task.id}/move`, {
columnId: task.doneColumnId,
position: 0,
});
toast(`« ${task.title} » est terminée.`);
// The shell owns the sidebar counter; it has no reason to know this view.
document.dispatchEvent(new CustomEvent('fws:tasks-changed'));
reload();
}
function taskRow(task, issues, reload) {
const issue = task.issueRef ? issues[task.issueRef] : null;
const due = day(task.dueAt);
const late = !task.isDone && due && due < today();
return h(
'li',
{ class: task.isDone ? 'task task-done' : 'task', dataset: { bucket: bucketOf(task) } },
h(
'button',
{
class: 'task-check',
type: 'button',
title: task.isDone ? 'Déjà terminée' : 'Marquer comme terminée',
disabled: task.isDone || !task.doneColumnId,
onClick: () => finish(task, reload),
},
h('span', { text: task.isDone ? '✓' : '' }),
),
h(
'div',
{ class: 'task-body' },
h(
'a',
{ class: 'task-title', href: `#/projects/${task.boardId}`, title: 'Ouvrir le tableau' },
task.title,
),
h(
'div',
{ class: 'task-meta' },
h('span', { class: 'muted', text: task.boardName }),
badge(task.columnName, task.isDone ? 'success' : 'neutral'),
task.labels.map((label) => badge(label, 'info')),
issue &&
h(
'a',
{ href: issue.htmlUrl, target: '_blank', rel: 'noreferrer', class: 'task-issue' },
`${task.issueRef} · ${issue.state === 'closed' ? 'fermée' : 'ouverte'}`,
),
!issue && task.issueRef && h('span', { class: 'muted', text: task.issueRef }),
),
),
due &&
h(
'span',
{ class: late ? 'task-due task-due-late' : 'task-due', title: due },
formatRelative(`${due}T12:00:00Z`),
),
);
}
/**
* Returns its node right away and fills it once the names arrive: waiting on
* Discord would hold up the tasks, which are the point of the page.
*/
function picker(data, reload) {
if (data.assignees.length < 2) return null;
const host = h('span', { class: 'task-picker' });
const build = (resolved) =>
mount(
host,
select(
[
{ value: '', label: 'Moi' },
...data.assignees.map((entry) => ({
value: entry.assigneeId,
label: `${resolved.get(entry.assigneeId) ?? entry.assigneeId} (${entry.open})`,
})),
],
{
value: data.self ? '' : data.assigneeId,
'aria-label': 'Voir les tâches de',
onChange: (event) => reload(event.target.value),
},
),
);
if (memberNames) build(memberNames);
else names().then(build);
return host;
}
export function render(host) {
let assignee = '';
const load = () => api.get('/api/me/tasks', { assignee });
const reload = (next) => {
if (next !== undefined) assignee = next;
return draw();
};
const draw = () =>
renderAsync(host, load, (data) => {
const grouped = new Map(BUCKETS.map((bucket) => [bucket.key, []]));
const done = [];
for (const task of data.cards) {
const bucket = bucketOf(task);
if (bucket === 'done') done.push(task);
else grouped.get(bucket).push(task);
}
const owner = data.self ? 'toi' : (memberNames?.get(data.assigneeId) ?? `le membre ${data.assigneeId}`);
return h(
'div',
{ class: 'stack' },
h(
'div',
{ class: 'page-head' },
h(
'div',
{},
h('h1', { text: data.self ? 'Mes tâches' : 'Tâches assignées' }),
h('p', {
class: 'muted',
text: `Toutes les cartes assignées à ${owner}, tous tableaux confondus, la plus urgente en premier.`,
}),
),
h('div', { class: 'row' }, picker(data, reload)),
),
h(
'div',
{ class: 'grid' },
stat('À faire', data.counts.open, { tone: data.counts.open > 0 ? 'primary' : 'neutral' }),
stat('En retard', data.counts.overdue, {
tone: data.counts.overdue > 0 ? 'danger' : 'neutral',
}),
stat('Pour aujourd’hui', data.counts.dueToday, {
tone: data.counts.dueToday > 0 ? 'warning' : 'neutral',
}),
stat('Terminées', data.counts.done),
),
data.cards.length === 0 &&
notice(
data.self
? 'Rien ne t’est assigné. Ouvre un tableau et mets ton nom sur une carte pour la voir apparaître ici.'
: 'Aucune carte n’est assignée à ce membre.',
'info',
),
BUCKETS.map((bucket) => {
const tasks = grouped.get(bucket.key);
if (tasks.length === 0) return null;
return card(
bucket.title,
{ subtitle: `${tasks.length} carte(s)` },
h(
'ul',
{ class: 'task-list' },
tasks.map((task) => taskRow(task, data.issues, () => reload())),
),
);
}),
done.length > 0 &&
h(
'details',
{ class: 'card task-archive' },
h('summary', { text: `Terminées (${done.length})` }),
h(
'ul',
{ class: 'task-list' },
done.map((task) => taskRow(task, data.issues, () => reload())),
),
),
);
});
autoRefresh(() => draw(), { topics: ['projects', 'tick'] });
return draw();
}