feat(projects): add the board interface
Drag and drop between columns, cards carrying an assignee, a due date, labels and a linked issue whose state shows on the card. An overloaded column says so in its header rather than blocking the drop. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
4 files changed
+501
No files matched your search
@@ -29,6 +29,14 @@ const ROUTES = [
|
||||
module: './views/organization.js',
|
||||
level: LEVELS.STAFF,
|
||||
},
|
||||
{
|
||||
path: 'projects',
|
||||
icon: '▦',
|
||||
label: 'Projets',
|
||||
group: 'Pilotage',
|
||||
module: './views/projects.js',
|
||||
level: LEVELS.STAFF,
|
||||
},
|
||||
{
|
||||
path: 'repos',
|
||||
icon: '◫',
|
||||
|
||||
@@ -71,6 +71,7 @@ function connect() {
|
||||
'gitea',
|
||||
'discord',
|
||||
'community',
|
||||
'projects',
|
||||
'settings',
|
||||
]) {
|
||||
source.addEventListener(topic, (event) => {
|
||||
|
||||
@@ -771,6 +771,73 @@ details > *:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* --- Kanban --------------------------------------------------------------- */
|
||||
|
||||
.kboard {
|
||||
display: flex;
|
||||
gap: 0.8rem;
|
||||
align-items: flex-start;
|
||||
overflow-x: auto;
|
||||
padding-bottom: 0.6rem;
|
||||
}
|
||||
|
||||
.kcolumn {
|
||||
flex: 0 0 280px;
|
||||
background: var(--bg-elevated);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 0.7rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.55rem;
|
||||
min-height: 8rem;
|
||||
}
|
||||
.kcolumn > header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
/* Only the border moves: a background change under a dragged card flickers. */
|
||||
.kcolumn-target {
|
||||
border-color: var(--blue);
|
||||
box-shadow: inset 0 0 0 1px var(--blue);
|
||||
}
|
||||
.kcolumn-over > header .muted {
|
||||
color: var(--amber);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.kcolumn-cards {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
min-height: 2.5rem;
|
||||
}
|
||||
|
||||
.kcard {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
padding: 0.6rem 0.7rem;
|
||||
cursor: grab;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
.kcard:hover {
|
||||
border-color: var(--blue);
|
||||
}
|
||||
.kcard h4 {
|
||||
font-size: 0.88rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.kcard.dragging {
|
||||
opacity: 0.4;
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
/* --- Simple / advanced mode ---------------------------------------------- */
|
||||
|
||||
body[data-mode='simple'] .advanced-only {
|
||||
|
||||
@@ -0,0 +1,425 @@
|
||||
import { api } from '../core/api.js';
|
||||
import { formatRelative, h, mount } from '../core/dom.js';
|
||||
import { autoRefresh } from '../core/live.js';
|
||||
import {
|
||||
badge,
|
||||
button,
|
||||
card,
|
||||
confirmDangerous,
|
||||
field,
|
||||
input,
|
||||
modal,
|
||||
notice,
|
||||
renderAsync,
|
||||
select,
|
||||
spinner,
|
||||
table,
|
||||
textarea,
|
||||
toast,
|
||||
toggle,
|
||||
} from '../core/ui.js';
|
||||
|
||||
/** Kanban boards: one per repository, one for the organization (M18). */
|
||||
|
||||
const LEVELS = { STAFF: 1, DEV: 2, OWNER: 3 };
|
||||
|
||||
const overdue = (dueAt) => dueAt && new Date(`${dueAt}Z`) < new Date();
|
||||
|
||||
// --- Board list --------------------------------------------------------------
|
||||
|
||||
function renderList(host, state) {
|
||||
const reload = () => renderList(host, state);
|
||||
|
||||
return renderAsync(
|
||||
host,
|
||||
async () => {
|
||||
const [projects, repositories] = await Promise.all([
|
||||
api.get('/api/projects'),
|
||||
api.get('/api/repositories').catch(() => ({ repositories: [] })),
|
||||
]);
|
||||
return { ...projects, repositories: repositories.repositories ?? [] };
|
||||
},
|
||||
(data) => {
|
||||
const taken = new Set(data.boards.map((entry) => entry.repository).filter(Boolean));
|
||||
const available = data.repositories.filter((entry) => !taken.has(entry.fullName));
|
||||
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
h(
|
||||
'div',
|
||||
{ class: 'page-head' },
|
||||
h(
|
||||
'div',
|
||||
{},
|
||||
h('h1', { text: 'Projets' }),
|
||||
h('p', {
|
||||
class: 'muted',
|
||||
text: 'Un tableau par dépôt, plus un pour l’organisation. Les cartes peuvent pointer vers une issue Gitea.',
|
||||
}),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'row' },
|
||||
!data.orgBoard &&
|
||||
button('Tableau de l’organisation', () => createBoard({ scope: 'org' }, reload), {
|
||||
tone: 'primary',
|
||||
}),
|
||||
available.length > 0 &&
|
||||
button('Tableau de dépôt', () => createBoard({ scope: 'repo', available }, reload), {
|
||||
tone: available.length > 0 && data.orgBoard ? 'primary' : 'ghost',
|
||||
}),
|
||||
),
|
||||
),
|
||||
|
||||
data.boards.length === 0 &&
|
||||
notice(
|
||||
'Aucun tableau pour l’instant. Commence par celui de l’organisation, puis ajoute ceux des dépôts.',
|
||||
'info',
|
||||
),
|
||||
|
||||
card(
|
||||
'Tableaux',
|
||||
{ subtitle: `${data.boards.length} tableau(x)` },
|
||||
table(
|
||||
[
|
||||
{
|
||||
label: 'Tableau',
|
||||
render: (entry) =>
|
||||
h(
|
||||
'div',
|
||||
{},
|
||||
h('strong', { text: entry.name }),
|
||||
h('div', {
|
||||
class: 'muted',
|
||||
text: entry.scope === 'org' ? 'Organisation' : entry.repository,
|
||||
}),
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'Portée',
|
||||
render: (entry) =>
|
||||
entry.scope === 'org' ? badge('Organisation', 'info') : badge('Dépôt', 'neutral'),
|
||||
},
|
||||
{ label: 'Colonnes', className: 'num', key: 'columns' },
|
||||
{ label: 'Cartes', className: 'num', key: 'cards' },
|
||||
{
|
||||
label: 'Modifié',
|
||||
className: 'nowrap',
|
||||
render: (entry) => formatRelative(entry.updatedAt),
|
||||
},
|
||||
],
|
||||
data.boards,
|
||||
{
|
||||
empty: 'Aucun tableau.',
|
||||
rowHref: (entry) => `#/projects/${entry.id}`,
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async function createBoard({ scope, available = [] }, reload) {
|
||||
const name = input({ placeholder: scope === 'org' ? 'Organisation FWS' : 'Nom du tableau' });
|
||||
const repository =
|
||||
scope === 'repo'
|
||||
? select(
|
||||
available.map((entry) => ({ value: entry.fullName, label: entry.fullName })),
|
||||
{},
|
||||
)
|
||||
: null;
|
||||
const description = input({ placeholder: 'À quoi sert ce tableau ?' });
|
||||
|
||||
const confirmed = await modal(
|
||||
scope === 'org' ? 'Tableau de l’organisation' : 'Nouveau tableau de dépôt',
|
||||
() => ({
|
||||
node: h(
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
repository && field('Dépôt', repository),
|
||||
field('Nom', name, { help: 'Laisse vide pour reprendre le nom du dépôt.' }),
|
||||
field('Description', description),
|
||||
h('p', {
|
||||
class: 'muted',
|
||||
text: 'Les colonnes À faire, En cours, En revue et Terminé sont créées automatiquement.',
|
||||
}),
|
||||
),
|
||||
submit: () => scope === 'org' || Boolean(repository?.value),
|
||||
}),
|
||||
{ confirmLabel: 'Créer', tone: 'primary' },
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
await api.post('/api/projects', {
|
||||
scope,
|
||||
repository: repository?.value,
|
||||
name: name.value.trim(),
|
||||
description: description.value.trim(),
|
||||
});
|
||||
toast('Tableau créé.');
|
||||
reload();
|
||||
}
|
||||
|
||||
// --- Board -------------------------------------------------------------------
|
||||
|
||||
function cardNode(entry, issues, board, reload) {
|
||||
const issue = entry.issueRef ? issues[entry.issueRef] : null;
|
||||
|
||||
const node = h(
|
||||
'article',
|
||||
{ class: 'kcard', draggable: 'true', dataset: { card: String(entry.id) } },
|
||||
h('h4', { text: entry.title }),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'row' },
|
||||
entry.labels.map((label) => badge(label, 'neutral')),
|
||||
issue &&
|
||||
badge(
|
||||
`${entry.issueRef} · ${issue.state === 'open' ? 'ouverte' : 'fermée'}`,
|
||||
issue.state === 'open' ? 'success' : 'neutral',
|
||||
),
|
||||
!issue && entry.issueRef && badge(entry.issueRef, 'neutral'),
|
||||
entry.dueAt && badge(formatRelative(entry.dueAt), overdue(entry.dueAt) ? 'danger' : 'warning'),
|
||||
),
|
||||
entry.assigneeId && h('div', { class: 'muted', text: `Assignée à ${entry.assigneeId}` }),
|
||||
);
|
||||
|
||||
node.addEventListener('dragstart', (event) => {
|
||||
event.dataTransfer.setData('text/plain', String(entry.id));
|
||||
event.dataTransfer.effectAllowed = 'move';
|
||||
node.classList.add('dragging');
|
||||
});
|
||||
node.addEventListener('dragend', () => node.classList.remove('dragging'));
|
||||
node.addEventListener('click', () => editCard(board, entry, reload));
|
||||
return node;
|
||||
}
|
||||
|
||||
function columnNode(column, issues, board, reload) {
|
||||
const count = column.cards.length;
|
||||
const over = column.wipLimit > 0 && count > column.wipLimit;
|
||||
|
||||
const list = h(
|
||||
'div',
|
||||
{ class: 'kcolumn-cards' },
|
||||
column.cards.map((entry) => cardNode(entry, issues, board, reload)),
|
||||
);
|
||||
|
||||
const node = h(
|
||||
'section',
|
||||
{ class: over ? 'kcolumn kcolumn-over' : 'kcolumn', dataset: { column: String(column.id) } },
|
||||
h(
|
||||
'header',
|
||||
{},
|
||||
h('strong', { text: column.name }),
|
||||
h(
|
||||
'span',
|
||||
{ class: 'muted' },
|
||||
h('span', { text: column.wipLimit > 0 ? `${count} / ${column.wipLimit}` : String(count) }),
|
||||
),
|
||||
),
|
||||
list,
|
||||
button('+ Carte', () => editCard(board, { columnId: column.id }, reload), { tone: 'ghost' }),
|
||||
);
|
||||
|
||||
// Dropping anywhere on the column appends; the API renumbers the rest.
|
||||
node.addEventListener('dragover', (event) => {
|
||||
event.preventDefault();
|
||||
node.classList.add('kcolumn-target');
|
||||
});
|
||||
node.addEventListener('dragleave', () => node.classList.remove('kcolumn-target'));
|
||||
node.addEventListener('drop', async (event) => {
|
||||
event.preventDefault();
|
||||
node.classList.remove('kcolumn-target');
|
||||
|
||||
const cardId = event.dataTransfer.getData('text/plain');
|
||||
if (!cardId) return;
|
||||
|
||||
const result = await api.post(`/api/projects/${board.id}/cards/${cardId}/move`, {
|
||||
columnId: column.id,
|
||||
position: column.cards.length,
|
||||
});
|
||||
if (result.overloaded) toast(`« ${column.name} » dépasse sa limite de ${column.wipLimit}.`, 'info');
|
||||
reload();
|
||||
});
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
async function editCard(board, entry, reload) {
|
||||
const existing = Boolean(entry.id);
|
||||
const title = input({ value: entry.title ?? '', placeholder: 'Ce qu’il y a à faire' });
|
||||
const body = textarea({ value: entry.body ?? '', placeholder: 'Contexte, critères d’acceptation…' });
|
||||
const assignee = input({ value: entry.assigneeId ?? '', placeholder: 'Identifiant Discord (facultatif)' });
|
||||
const issueRef = input({ value: entry.issueRef ?? '', placeholder: 'FWS/FWS-Arch#12 (facultatif)' });
|
||||
const labels = input({ value: (entry.labels ?? []).join(', '), placeholder: 'bug, urgent' });
|
||||
const dueAt = input({ type: 'date', value: (entry.dueAt ?? '').slice(0, 10) });
|
||||
|
||||
const confirmed = await modal(
|
||||
existing ? 'Modifier la carte' : 'Nouvelle carte',
|
||||
() => ({
|
||||
node: h(
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
field('Titre', title),
|
||||
field('Description', body),
|
||||
field('Assignée à', assignee, { help: 'Identifiant Discord du membre qui la porte.' }),
|
||||
field('Issue liée', issueRef, {
|
||||
help: 'Format `organisation/depot#12`. Son état s’affiche sur la carte.',
|
||||
}),
|
||||
field('Étiquettes', labels, { help: 'Séparées par des virgules.' }),
|
||||
field('Échéance', dueAt),
|
||||
),
|
||||
submit: () => title.value.trim().length >= 2,
|
||||
}),
|
||||
{ confirmLabel: existing ? 'Enregistrer' : 'Créer', tone: 'primary' },
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
const payload = {
|
||||
title: title.value.trim(),
|
||||
body: body.value,
|
||||
assigneeId: assignee.value.trim(),
|
||||
issueRef: issueRef.value.trim(),
|
||||
labels: labels.value
|
||||
.split(',')
|
||||
.map((label) => label.trim())
|
||||
.filter(Boolean),
|
||||
dueAt: dueAt.value || '',
|
||||
};
|
||||
|
||||
try {
|
||||
if (existing) await api.patch(`/api/projects/${board.id}/cards/${entry.id}`, payload);
|
||||
else await api.post(`/api/projects/${board.id}/cards`, { ...payload, columnId: entry.columnId });
|
||||
toast(existing ? 'Carte enregistrée.' : 'Carte créée.');
|
||||
reload();
|
||||
} catch (error) {
|
||||
toast(error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function renderBoard(host, state, id) {
|
||||
const level = state.me.accessLevel;
|
||||
const reload = () => renderBoard(host, state, id);
|
||||
autoRefresh(reload, { topics: ['mutation'], minIntervalMs: 3000 });
|
||||
|
||||
mount(host, spinner());
|
||||
let board;
|
||||
try {
|
||||
board = await api.get(`/api/projects/${id}`);
|
||||
} catch (error) {
|
||||
mount(host, notice(error.message, 'error'));
|
||||
return;
|
||||
}
|
||||
|
||||
const total = board.columns.reduce((sum, column) => sum + column.cards.length, 0);
|
||||
const done = board.columns
|
||||
.filter((column) => column.isDone)
|
||||
.reduce((sum, column) => sum + column.cards.length, 0);
|
||||
|
||||
mount(
|
||||
host,
|
||||
h(
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
h(
|
||||
'div',
|
||||
{ class: 'page-head' },
|
||||
h(
|
||||
'div',
|
||||
{},
|
||||
h('p', { class: 'muted' }, h('a', { href: '#/projects', text: '← Tous les tableaux' })),
|
||||
h('h1', { text: board.name }),
|
||||
h('p', {
|
||||
class: 'muted',
|
||||
text: board.description || (board.repository ?? 'Tableau de l’organisation'),
|
||||
}),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'row' },
|
||||
badge(`${total} carte(s)`, 'neutral'),
|
||||
badge(`${done} terminée(s)`, done > 0 ? 'success' : 'neutral'),
|
||||
),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'row' },
|
||||
board.repository &&
|
||||
button(
|
||||
'Importer les issues',
|
||||
async () => {
|
||||
const result = await api.post(`/api/projects/${board.id}/import`, {});
|
||||
toast(
|
||||
`${result.imported} carte(s) créée(s) dans « ${result.column} », ${result.skipped} déjà présente(s).`,
|
||||
);
|
||||
reload();
|
||||
},
|
||||
{ tone: 'ghost' },
|
||||
),
|
||||
button('Colonne', () => addColumn(board, reload), { tone: 'ghost' }),
|
||||
level >= LEVELS.OWNER &&
|
||||
button(
|
||||
'Supprimer',
|
||||
async () => {
|
||||
if (
|
||||
!(await confirmDangerous(
|
||||
'Supprimer le tableau',
|
||||
`« ${board.name} » et toutes ses cartes seront perdus.`,
|
||||
board.name,
|
||||
))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await api.delete(`/api/projects/${board.id}`, { confirm: board.name });
|
||||
toast('Tableau supprimé.');
|
||||
window.location.hash = '#/projects';
|
||||
},
|
||||
{ tone: 'danger' },
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
h(
|
||||
'div',
|
||||
{ class: 'kboard' },
|
||||
board.columns.map((column) => columnNode(column, board.issues ?? {}, board, reload)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async function addColumn(board, reload) {
|
||||
const name = input({ placeholder: 'Nom de la colonne' });
|
||||
const wipLimit = input({ type: 'number', value: 0, min: 0 });
|
||||
let isDone = false;
|
||||
|
||||
const confirmed = await modal(
|
||||
'Nouvelle colonne',
|
||||
() => ({
|
||||
node: h(
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
field('Nom', name),
|
||||
field('Limite de cartes', wipLimit, { help: '0 = pas de limite. Au-delà, la colonne est signalée.' }),
|
||||
toggle(false, (checked) => (isDone = checked), 'Les cartes déposées ici sont terminées'),
|
||||
),
|
||||
submit: () => name.value.trim() !== '',
|
||||
}),
|
||||
{ confirmLabel: 'Ajouter', tone: 'primary' },
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
await api.post(`/api/projects/${board.id}/columns`, {
|
||||
name: name.value.trim(),
|
||||
wipLimit: Number(wipLimit.value) || 0,
|
||||
isDone,
|
||||
});
|
||||
toast('Colonne ajoutée.');
|
||||
reload();
|
||||
}
|
||||
|
||||
export function render(host, { params, state }) {
|
||||
if (params.length >= 1) return renderBoard(host, state, params[0]);
|
||||
return renderList(host, state);
|
||||
}
|
||||
Reference in new issue
Block a user