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>
This commit is contained in:
1 parent
d2256e2211
commit
fcc82d82d6
6 files changed
+732
-6
No files matched your search
@@ -270,16 +270,60 @@ export function removeCard(id) {
|
|||||||
return getDatabase().prepare('DELETE FROM project_cards WHERE id = ?').run(id).changes;
|
return getDatabase().prepare('DELETE FROM project_cards WHERE id = ?').run(id).changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Cards carried by one member, across every board of the guild. */
|
const parseAssignedCard = (row) => ({
|
||||||
|
...parseCard(row),
|
||||||
|
column_is_done: Boolean(row.column_is_done),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cards carried by one member, across every board of the guild (M19).
|
||||||
|
*
|
||||||
|
* The column travels with the card: « what am I on today » cannot be answered
|
||||||
|
* without knowing whether a card is still open, and asking per card turns the
|
||||||
|
* page into a staircase of queries. `done_column_id` comes along for the same
|
||||||
|
* reason — finishing a card from here is then a single move.
|
||||||
|
*/
|
||||||
export function listCardsForAssignee(guildId, assigneeId) {
|
export function listCardsForAssignee(guildId, assigneeId) {
|
||||||
return getDatabase()
|
return getDatabase()
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT c.*, b.name AS board_name, b.repository
|
`SELECT c.*,
|
||||||
|
b.name AS board_name,
|
||||||
|
b.scope AS board_scope,
|
||||||
|
b.repository,
|
||||||
|
col.name AS column_name,
|
||||||
|
col.is_done AS column_is_done,
|
||||||
|
(SELECT d.id FROM project_columns d
|
||||||
|
WHERE d.board_id = b.id AND d.is_done = 1
|
||||||
|
ORDER BY d.position, d.id LIMIT 1) AS done_column_id
|
||||||
FROM project_cards c
|
FROM project_cards c
|
||||||
JOIN project_boards b ON b.id = c.board_id
|
JOIN project_boards b ON b.id = c.board_id
|
||||||
|
JOIN project_columns col ON col.id = c.column_id
|
||||||
WHERE b.guild_id = ? AND c.assignee_id = ?
|
WHERE b.guild_id = ? AND c.assignee_id = ?
|
||||||
ORDER BY c.due_at IS NULL, c.due_at, c.id`,
|
ORDER BY c.due_at IS NULL, c.due_at, c.id`,
|
||||||
)
|
)
|
||||||
.all(guildId, assigneeId)
|
.all(guildId, assigneeId)
|
||||||
.map(parseCard);
|
.map(parseAssignedCard);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Who carries cards, and how many are still open.
|
||||||
|
*
|
||||||
|
* Lets the page offer a picker without asking Discord for the member list,
|
||||||
|
* which is unavailable whenever the bot is offline — precisely when someone is
|
||||||
|
* most likely to be looking at the dashboard.
|
||||||
|
*/
|
||||||
|
export function listAssignees(guildId) {
|
||||||
|
return getDatabase()
|
||||||
|
.prepare(
|
||||||
|
`SELECT c.assignee_id AS assigneeId,
|
||||||
|
COUNT(*) AS total,
|
||||||
|
SUM(CASE WHEN col.is_done = 1 THEN 0 ELSE 1 END) AS open
|
||||||
|
FROM project_cards c
|
||||||
|
JOIN project_boards b ON b.id = c.board_id
|
||||||
|
JOIN project_columns col ON col.id = c.column_id
|
||||||
|
WHERE b.guild_id = ? AND c.assignee_id IS NOT NULL AND c.assignee_id <> ''
|
||||||
|
GROUP BY c.assignee_id
|
||||||
|
ORDER BY open DESC, total DESC`,
|
||||||
|
)
|
||||||
|
.all(guildId);
|
||||||
}
|
}
|
||||||
@@ -13,8 +13,10 @@ import {
|
|||||||
getCard,
|
getCard,
|
||||||
getColumn,
|
getColumn,
|
||||||
getOrgBoard,
|
getOrgBoard,
|
||||||
|
listAssignees,
|
||||||
listBoards,
|
listBoards,
|
||||||
listCards,
|
listCards,
|
||||||
|
listCardsForAssignee,
|
||||||
listColumns,
|
listColumns,
|
||||||
moveCard,
|
moveCard,
|
||||||
removeBoard,
|
removeBoard,
|
||||||
@@ -77,6 +79,18 @@ const publicColumn = (column) => ({
|
|||||||
isDone: column.is_done,
|
isDone: column.is_done,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** A card seen from outside its board: it has to say where it comes from (M19). */
|
||||||
|
const publicTask = (card) => ({
|
||||||
|
...publicCard(card),
|
||||||
|
boardId: card.board_id,
|
||||||
|
boardName: card.board_name,
|
||||||
|
boardScope: card.board_scope,
|
||||||
|
repository: card.repository,
|
||||||
|
columnName: card.column_name,
|
||||||
|
isDone: card.column_is_done,
|
||||||
|
doneColumnId: card.done_column_id ?? null,
|
||||||
|
});
|
||||||
|
|
||||||
function board(id) {
|
function board(id) {
|
||||||
const found = getBoard(Number.parseInt(id, 10));
|
const found = getBoard(Number.parseInt(id, 10));
|
||||||
if (!found || found.guild_id !== guildId()) throw notFound('Tableau introuvable.');
|
if (!found || found.guild_id !== guildId()) throw notFound('Tableau introuvable.');
|
||||||
@@ -150,6 +164,45 @@ async function announce(client, { board: owner, card, action, actor, column }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function registerProjectRoutes(router) {
|
export function registerProjectRoutes(router) {
|
||||||
|
// --- My tasks --------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* What one member carries, across every board (M19).
|
||||||
|
*
|
||||||
|
* The boards answer « where does the work stand ». This answers « what am I
|
||||||
|
* on », which is the question someone actually opens a dashboard with, and no
|
||||||
|
* board alone can answer it once the work is spread over several.
|
||||||
|
*/
|
||||||
|
router.get(
|
||||||
|
'/api/me/tasks',
|
||||||
|
async ({ query, actor }) => {
|
||||||
|
const assigneeId = String(query.get('assignee') ?? '').trim() || actor.userId;
|
||||||
|
if (!assigneeId) throw badRequest('Aucun membre à qui rattacher des cartes.');
|
||||||
|
|
||||||
|
const cards = listCardsForAssignee(guildId(), assigneeId);
|
||||||
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
|
const open = cards.filter((entry) => !entry.column_is_done);
|
||||||
|
const dated = (entry, test) => entry.due_at && test(String(entry.due_at).slice(0, 10));
|
||||||
|
|
||||||
|
return {
|
||||||
|
assigneeId,
|
||||||
|
self: assigneeId === actor.userId,
|
||||||
|
assignees: listAssignees(guildId()),
|
||||||
|
counts: {
|
||||||
|
total: cards.length,
|
||||||
|
open: open.length,
|
||||||
|
done: cards.length - open.length,
|
||||||
|
overdue: open.filter((entry) => dated(entry, (due) => due < today)).length,
|
||||||
|
dueToday: open.filter((entry) => dated(entry, (due) => due === today)).length,
|
||||||
|
},
|
||||||
|
cards: cards.map(publicTask),
|
||||||
|
// Resolving costs a round trip to the forge, which the sidebar counter
|
||||||
|
// has no use for — it asks for the numbers and skips it.
|
||||||
|
issues: query.get('issues') === '0' ? {} : await resolveIssues(cards),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{ access: ACCESS_LEVELS.STAFF },
|
||||||
|
);
|
||||||
|
|
||||||
// --- Boards ----------------------------------------------------------------
|
// --- Boards ----------------------------------------------------------------
|
||||||
router.get(
|
router.get(
|
||||||
'/api/projects',
|
'/api/projects',
|
||||||
|
|||||||
+53
-3
@@ -21,6 +21,14 @@ const ROUTES = [
|
|||||||
module: './views/overview.js',
|
module: './views/overview.js',
|
||||||
level: LEVELS.STAFF,
|
level: LEVELS.STAFF,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'tasks',
|
||||||
|
icon: '✓',
|
||||||
|
label: 'Mes tâches',
|
||||||
|
group: 'Pilotage',
|
||||||
|
module: './views/tasks.js',
|
||||||
|
level: LEVELS.STAFF,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'org',
|
path: 'org',
|
||||||
icon: '⬡',
|
icon: '⬡',
|
||||||
@@ -190,10 +198,18 @@ function liveIndicator() {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sidebar() {
|
/**
|
||||||
const visible = ROUTES.filter(
|
* Pages the visitor can actually reach. Shared with the palette so a search
|
||||||
(route) => state.me.accessLevel >= route.level && (!route.advanced || state.mode === 'advanced'),
|
* never offers a page that would answer with « niveau d’accès supérieur ».
|
||||||
|
*/
|
||||||
|
function visibleRoutes() {
|
||||||
|
return ROUTES.filter(
|
||||||
|
(route) => (state.me?.accessLevel ?? 0) >= route.level && (!route.advanced || state.mode === 'advanced'),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sidebar() {
|
||||||
|
const visible = visibleRoutes();
|
||||||
|
|
||||||
const groups = [];
|
const groups = [];
|
||||||
for (const route of visible) {
|
for (const route of visible) {
|
||||||
@@ -222,6 +238,9 @@ function sidebar() {
|
|||||||
{ href: `#/${route.path}`, dataset: { route: route.path } },
|
{ href: `#/${route.path}`, dataset: { route: route.path } },
|
||||||
h('span', { class: 'nav-icon', text: route.icon }),
|
h('span', { class: 'nav-icon', text: route.icon }),
|
||||||
h('span', { text: route.label }),
|
h('span', { text: route.label }),
|
||||||
|
// A page you have to open to know whether it needs you is a page
|
||||||
|
// you stop opening; the count is what makes it a morning habit.
|
||||||
|
route.path === 'tasks' && h('span', { class: 'nav-count', hidden: true }),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
@@ -286,6 +305,7 @@ async function renderView(host) {
|
|||||||
const route = ROUTES.find((entry) => entry.path === (segments[0] ?? ''));
|
const route = ROUTES.find((entry) => entry.path === (segments[0] ?? ''));
|
||||||
resetSubscriptions();
|
resetSubscriptions();
|
||||||
highlightNav();
|
highlightNav();
|
||||||
|
refreshTaskCount();
|
||||||
host.scrollIntoView?.({ block: 'start' });
|
host.scrollIntoView?.({ block: 'start' });
|
||||||
|
|
||||||
if (!route) {
|
if (!route) {
|
||||||
@@ -334,9 +354,39 @@ export function render() {
|
|||||||
mount(app, shell);
|
mount(app, shell);
|
||||||
applyModeButtons(shell);
|
applyModeButtons(shell);
|
||||||
highlightNav(shell);
|
highlightNav(shell);
|
||||||
|
refreshTaskCount();
|
||||||
renderView(main);
|
renderView(main);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open cards assigned to the viewer, shown on the sidebar entry.
|
||||||
|
*
|
||||||
|
* Asked for with `issues=0`: the counter needs a number, not a round trip to
|
||||||
|
* the forge to resolve every linked issue. Throttled, because navigating is not
|
||||||
|
* a reason to ask again.
|
||||||
|
*/
|
||||||
|
const TASK_COUNT_TTL_MS = 60_000;
|
||||||
|
let taskCountAt = 0;
|
||||||
|
|
||||||
|
async function refreshTaskCount(force = false) {
|
||||||
|
if (!qs('.nav-count')) return;
|
||||||
|
if (!force && Date.now() - taskCountAt < TASK_COUNT_TTL_MS) return;
|
||||||
|
taskCountAt = Date.now();
|
||||||
|
|
||||||
|
const data = await api.get('/api/me/tasks', { issues: '0' }).catch(() => null);
|
||||||
|
// The shell may have been rebuilt while the request was in flight.
|
||||||
|
const node = qs('.nav-count');
|
||||||
|
if (!node || !data) return;
|
||||||
|
|
||||||
|
const { open, overdue } = data.counts;
|
||||||
|
node.textContent = open > 99 ? '99+' : String(open);
|
||||||
|
node.hidden = open === 0;
|
||||||
|
node.dataset.tone = overdue > 0 ? 'late' : 'normal';
|
||||||
|
node.title = overdue > 0 ? `${overdue} carte(s) en retard` : `${open} carte(s) à faire`;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('fws:tasks-changed', () => refreshTaskCount(true));
|
||||||
|
|
||||||
/** Names the interface actually being served, archive deployments being easy to get wrong. */
|
/** Names the interface actually being served, archive deployments being easy to get wrong. */
|
||||||
async function showBuild() {
|
async function showBuild() {
|
||||||
const health = await api.get('/api/health').catch(() => null);
|
const health = await api.get('/api/health').catch(() => null);
|
||||||
|
|||||||
@@ -1079,6 +1079,109 @@ body[data-mode='simple'] .advanced-only {
|
|||||||
border-bottom-color: var(--blue);
|
border-bottom-color: var(--blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --- My tasks ------------------------------------------------------------- */
|
||||||
|
|
||||||
|
.task-list {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.task {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.55rem 0.2rem;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
.task:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
.task-done .task-title {
|
||||||
|
text-decoration: line-through;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
.task-check {
|
||||||
|
flex: none;
|
||||||
|
width: 1.35rem;
|
||||||
|
height: 1.35rem;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 2px solid var(--border);
|
||||||
|
background: none;
|
||||||
|
color: var(--green);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.task-check:hover:not(:disabled) {
|
||||||
|
border-color: var(--green);
|
||||||
|
}
|
||||||
|
.task-check:disabled {
|
||||||
|
cursor: default;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
.task-body {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.task-title {
|
||||||
|
display: block;
|
||||||
|
color: var(--text);
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 0.94rem;
|
||||||
|
}
|
||||||
|
.task-meta {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
margin-top: 0.15rem;
|
||||||
|
}
|
||||||
|
.task-issue {
|
||||||
|
font-size: 0.78rem;
|
||||||
|
color: var(--gitea);
|
||||||
|
}
|
||||||
|
.task-due {
|
||||||
|
flex: none;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: var(--text-muted);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.task-due-late {
|
||||||
|
color: var(--red);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.task-archive {
|
||||||
|
padding: 0.8rem 1.1rem;
|
||||||
|
}
|
||||||
|
.task-archive summary {
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 0.92rem;
|
||||||
|
}
|
||||||
|
.task-picker {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-count {
|
||||||
|
margin-left: auto;
|
||||||
|
min-width: 1.4rem;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 0.72rem;
|
||||||
|
font-weight: 700;
|
||||||
|
border-radius: 999px;
|
||||||
|
padding: 0.05rem 0.35rem;
|
||||||
|
background: var(--surface);
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
.nav-count[data-tone='late'] {
|
||||||
|
background: color-mix(in srgb, var(--red) 24%, transparent);
|
||||||
|
color: var(--red);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Anchored near the top rather than centred: the list grows downwards, and a
|
||||||
|
dialog that re-centres itself on every keystroke is unusable. */
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.shell {
|
.shell {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
|
|||||||
@@ -0,0 +1,249 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { createServer } from 'node:http';
|
||||||
|
import { after, before, beforeEach, describe, it } from 'node:test';
|
||||||
|
import { ACCESS_LEVELS } from '../src/config/constants.js';
|
||||||
|
import { closeDatabase, getDatabase, initDatabase } from '../src/database/index.js';
|
||||||
|
import {
|
||||||
|
addCard,
|
||||||
|
createBoard,
|
||||||
|
listAssignees,
|
||||||
|
listCardsForAssignee,
|
||||||
|
listColumns,
|
||||||
|
} from '../src/database/repositories/project-repository.js';
|
||||||
|
import { createApiToken } from '../src/database/repositories/web-session-repository.js';
|
||||||
|
import { hashToken } from '../src/web/auth/session.js';
|
||||||
|
import { createHandler } from '../src/web/server.js';
|
||||||
|
|
||||||
|
/** « Mes tâches » — cards gathered across every board (M19). */
|
||||||
|
|
||||||
|
const GUILD = '';
|
||||||
|
const ME = '111';
|
||||||
|
const OTHER = '222';
|
||||||
|
|
||||||
|
/** Whole days from today, in the `YYYY-MM-DD` shape the cards store. */
|
||||||
|
const dayOffset = (days) => {
|
||||||
|
const date = new Date();
|
||||||
|
date.setDate(date.getDate() + days);
|
||||||
|
return date.toISOString().slice(0, 10);
|
||||||
|
};
|
||||||
|
|
||||||
|
let board;
|
||||||
|
let columns;
|
||||||
|
|
||||||
|
function seed() {
|
||||||
|
getDatabase().exec('DELETE FROM project_boards;');
|
||||||
|
board = createBoard({ guildId: GUILD, scope: 'repo', repository: 'FWS/FWS-Arch', name: 'FWS Arch' });
|
||||||
|
columns = listColumns(board.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const put = (title, overrides = {}) =>
|
||||||
|
addCard({ boardId: board.id, columnId: columns[0].id, title, ...overrides });
|
||||||
|
|
||||||
|
describe('cards gathered by assignee', () => {
|
||||||
|
before(() => initDatabase(':memory:'));
|
||||||
|
after(() => closeDatabase());
|
||||||
|
beforeEach(seed);
|
||||||
|
|
||||||
|
it('carries the column each card sits in', () => {
|
||||||
|
put('Une tâche', { assigneeId: ME });
|
||||||
|
const [task] = listCardsForAssignee(GUILD, ME);
|
||||||
|
|
||||||
|
assert.equal(task.column_name, 'À faire');
|
||||||
|
assert.equal(task.column_is_done, false);
|
||||||
|
assert.equal(task.board_name, 'FWS Arch');
|
||||||
|
assert.equal(task.repository, 'FWS/FWS-Arch');
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Finishing a card from the list is one move, so the target travels with it. */
|
||||||
|
it('names the column that would finish the card', () => {
|
||||||
|
put('Une tâche', { assigneeId: ME });
|
||||||
|
const done = columns.at(-1);
|
||||||
|
|
||||||
|
assert.equal(listCardsForAssignee(GUILD, ME)[0].done_column_id, done.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('marks a card already in the finished column', () => {
|
||||||
|
addCard({ boardId: board.id, columnId: columns.at(-1).id, title: 'Livrée', assigneeId: ME });
|
||||||
|
assert.equal(listCardsForAssignee(GUILD, ME)[0].column_is_done, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('orders by deadline, undated last', () => {
|
||||||
|
put('plus tard', { assigneeId: ME, dueAt: dayOffset(9) });
|
||||||
|
put('sans date', { assigneeId: ME });
|
||||||
|
put('demain', { assigneeId: ME, dueAt: dayOffset(1) });
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
listCardsForAssignee(GUILD, ME).map((task) => task.title),
|
||||||
|
['demain', 'plus tard', 'sans date'],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignores what belongs to someone else', () => {
|
||||||
|
put('à moi', { assigneeId: ME });
|
||||||
|
put('à l’autre', { assigneeId: OTHER });
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
listCardsForAssignee(GUILD, ME).map((task) => task.title),
|
||||||
|
['à moi'],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lists who carries cards, finished ones excluded from the open count', () => {
|
||||||
|
put('ouverte', { assigneeId: ME });
|
||||||
|
addCard({ boardId: board.id, columnId: columns.at(-1).id, title: 'close', assigneeId: ME });
|
||||||
|
put('autre', { assigneeId: OTHER });
|
||||||
|
|
||||||
|
const [mine] = listAssignees(GUILD).filter((entry) => entry.assigneeId === ME);
|
||||||
|
assert.equal(mine.total, 2);
|
||||||
|
assert.equal(mine.open, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('leaves unassigned cards out of the roster', () => {
|
||||||
|
put('orpheline');
|
||||||
|
assert.deepEqual(listAssignees(GUILD), []);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('my tasks over HTTP', () => {
|
||||||
|
const TOKEN = 'fws_tasks-test';
|
||||||
|
const ANONYMOUS = 'fws_tasks-anon';
|
||||||
|
let app;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
initDatabase(':memory:');
|
||||||
|
createApiToken({
|
||||||
|
name: 'tasks',
|
||||||
|
tokenHash: hashToken(TOKEN),
|
||||||
|
prefix: TOKEN.slice(0, 12),
|
||||||
|
accessLevel: ACCESS_LEVELS.STAFF,
|
||||||
|
createdBy: ME,
|
||||||
|
});
|
||||||
|
// A token with nobody behind it: there is no « me » to answer for.
|
||||||
|
createApiToken({
|
||||||
|
name: 'anonyme',
|
||||||
|
tokenHash: hashToken(ANONYMOUS),
|
||||||
|
prefix: ANONYMOUS.slice(0, 12),
|
||||||
|
accessLevel: ACCESS_LEVELS.STAFF,
|
||||||
|
});
|
||||||
|
|
||||||
|
app = createServer(createHandler({ client: null, setupOnly: false }));
|
||||||
|
await new Promise((resolve) => app.listen(0, '127.0.0.1', resolve));
|
||||||
|
});
|
||||||
|
after(async () => {
|
||||||
|
await new Promise((resolve) => app.close(resolve));
|
||||||
|
closeDatabase();
|
||||||
|
});
|
||||||
|
beforeEach(seed);
|
||||||
|
|
||||||
|
const call = (path, token = TOKEN) =>
|
||||||
|
fetch(`http://127.0.0.1:${app.address().port}${path}`, {
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
const tasks = (query = '') => call(`/api/me/tasks${query}`).then((response) => response.json());
|
||||||
|
|
||||||
|
it('refuses a visitor without a session', async () => {
|
||||||
|
const response = await fetch(`http://127.0.0.1:${app.address().port}/api/me/tasks`);
|
||||||
|
assert.equal(response.status, 401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('answers with the caller’s own cards', async () => {
|
||||||
|
put('à moi', { assigneeId: ME });
|
||||||
|
put('à l’autre', { assigneeId: OTHER });
|
||||||
|
|
||||||
|
const body = await tasks();
|
||||||
|
assert.equal(body.self, true);
|
||||||
|
assert.equal(body.assigneeId, ME);
|
||||||
|
assert.deepEqual(
|
||||||
|
body.cards.map((task) => task.title),
|
||||||
|
['à moi'],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('counts what is late, due today and finished', async () => {
|
||||||
|
put('en retard', { assigneeId: ME, dueAt: dayOffset(-2) });
|
||||||
|
put('aujourd’hui', { assigneeId: ME, dueAt: dayOffset(0) });
|
||||||
|
put('plus tard', { assigneeId: ME, dueAt: dayOffset(30) });
|
||||||
|
addCard({ boardId: board.id, columnId: columns.at(-1).id, title: 'faite', assigneeId: ME });
|
||||||
|
|
||||||
|
const { counts } = await tasks();
|
||||||
|
assert.deepEqual(counts, { total: 4, open: 3, done: 1, overdue: 1, dueToday: 1 });
|
||||||
|
});
|
||||||
|
|
||||||
|
/** A finished card must not be counted as late, however old its deadline. */
|
||||||
|
it('never calls a finished card late', async () => {
|
||||||
|
addCard({
|
||||||
|
boardId: board.id,
|
||||||
|
columnId: columns.at(-1).id,
|
||||||
|
title: 'livrée en retard',
|
||||||
|
assigneeId: ME,
|
||||||
|
dueAt: dayOffset(-40),
|
||||||
|
});
|
||||||
|
|
||||||
|
const { counts } = await tasks();
|
||||||
|
assert.equal(counts.overdue, 0);
|
||||||
|
assert.equal(counts.done, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tells the page where each card lives and how to finish it', async () => {
|
||||||
|
put('une carte', { assigneeId: ME });
|
||||||
|
const [task] = (await tasks()).cards;
|
||||||
|
|
||||||
|
assert.equal(task.boardId, board.id);
|
||||||
|
assert.equal(task.boardName, 'FWS Arch');
|
||||||
|
assert.equal(task.columnName, 'À faire');
|
||||||
|
assert.equal(task.isDone, false);
|
||||||
|
assert.equal(task.doneColumnId, columns.at(-1).id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('looks at another member when asked', async () => {
|
||||||
|
put('à l’autre', { assigneeId: OTHER });
|
||||||
|
|
||||||
|
const body = await tasks(`?assignee=${OTHER}`);
|
||||||
|
assert.equal(body.self, false);
|
||||||
|
assert.equal(body.assigneeId, OTHER);
|
||||||
|
assert.equal(body.cards.length, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('offers the members who carry cards', async () => {
|
||||||
|
put('à moi', { assigneeId: ME });
|
||||||
|
put('à l’autre', { assigneeId: OTHER });
|
||||||
|
|
||||||
|
const ids = (await tasks()).assignees.map((entry) => entry.assigneeId).sort();
|
||||||
|
assert.deepEqual(ids, [ME, OTHER]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('explains itself when the caller has no identity', async () => {
|
||||||
|
const response = await call('/api/me/tasks', ANONYMOUS);
|
||||||
|
assert.equal(response.status, 400);
|
||||||
|
assert.match((await response.json()).error, /membre/i);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips the forge when only the counters are wanted', async () => {
|
||||||
|
put('liée', { assigneeId: ME, issueRef: 'FWS/FWS-Arch#1' });
|
||||||
|
|
||||||
|
assert.deepEqual((await tasks('?issues=0')).issues, {});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user