feat(web): serve the dashboard and its interface
The front-end is plain JavaScript served as is: no build step to run before the bot starts, and no second toolchain to keep alive. A simple/advanced switch hides the technical panels without ever standing in for a permission. `npm run setup` starts the wizard alone, because the bot refuses to boot without a token and the `.env` has to be writable from somewhere. When the webhook and the dashboard share a port, a single HTTP server is started. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
23 files changed
+5850
-2
No files matched your search
@@ -0,0 +1,285 @@
|
||||
import { api } from '../core/api.js';
|
||||
import { formatBytes, formatRelative, h } from '../core/dom.js';
|
||||
import {
|
||||
badge,
|
||||
button,
|
||||
card,
|
||||
field,
|
||||
grid,
|
||||
input,
|
||||
modal,
|
||||
renderAsync,
|
||||
select,
|
||||
stat,
|
||||
table,
|
||||
textarea,
|
||||
toast,
|
||||
toggle,
|
||||
} from '../core/ui.js';
|
||||
|
||||
/** Organization page: identity, members, teams and repository inventory. */
|
||||
|
||||
const LEVELS = { STAFF: 1, DEV: 2, OWNER: 3 };
|
||||
|
||||
async function editOrganization(data, refresh) {
|
||||
const fullName = input({ value: data.fullName ?? '' });
|
||||
const description = textarea({ value: data.description ?? '' });
|
||||
const website = input({ value: data.website ?? '', placeholder: 'https://…' });
|
||||
const location = input({ value: data.location ?? '' });
|
||||
const visibility = select(
|
||||
[
|
||||
{ value: 'public', label: 'Publique' },
|
||||
{ value: 'limited', label: 'Limitée aux comptes connectés' },
|
||||
{ value: 'private', label: 'Privée' },
|
||||
],
|
||||
{ value: data.visibility ?? 'public' },
|
||||
);
|
||||
|
||||
const confirmed = await modal(
|
||||
'Modifier l’organisation',
|
||||
() => ({
|
||||
node: h(
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
field('Nom affiché', fullName),
|
||||
field('Description', description),
|
||||
field('Site web', website),
|
||||
field('Localisation', location),
|
||||
field('Visibilité', visibility),
|
||||
),
|
||||
submit: () => true,
|
||||
}),
|
||||
{ confirmLabel: 'Enregistrer' },
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
await api.patch('/api/organization', {
|
||||
full_name: fullName.value,
|
||||
description: description.value,
|
||||
website: website.value,
|
||||
location: location.value,
|
||||
visibility: visibility.value,
|
||||
});
|
||||
toast('Organisation mise à jour.');
|
||||
refresh();
|
||||
}
|
||||
|
||||
async function createRepository(refresh) {
|
||||
const name = input({ placeholder: 'mon-nouveau-depot' });
|
||||
const description = input({ placeholder: 'À quoi sert ce dépôt ?' });
|
||||
const defaultBranch = input({ value: 'main' });
|
||||
let isPrivate = false;
|
||||
let autoInit = true;
|
||||
|
||||
const confirmed = await modal(
|
||||
'Créer un dépôt',
|
||||
() => ({
|
||||
node: h(
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
field('Nom', name, { help: 'Lettres, chiffres, points, tirets et soulignés.' }),
|
||||
field('Description', description),
|
||||
field('Branche par défaut', defaultBranch),
|
||||
toggle(false, (checked) => (isPrivate = checked), 'Dépôt privé'),
|
||||
toggle(true, (checked) => (autoInit = checked), 'Initialiser avec un README'),
|
||||
),
|
||||
submit: () => name.value.trim() !== '',
|
||||
}),
|
||||
{ confirmLabel: 'Créer', tone: 'primary' },
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
const created = await api.post('/api/organization/repositories', {
|
||||
name: name.value.trim(),
|
||||
description: description.value,
|
||||
defaultBranch: defaultBranch.value,
|
||||
private: isPrivate,
|
||||
autoInit,
|
||||
});
|
||||
toast(`Dépôt ${created.fullName} créé.`);
|
||||
refresh();
|
||||
}
|
||||
|
||||
export function render(host, { state }) {
|
||||
const level = state.me.accessLevel;
|
||||
const refresh = () => render(host, { state });
|
||||
|
||||
return renderAsync(
|
||||
host,
|
||||
() => api.get('/api/organization'),
|
||||
(data) => {
|
||||
const totals = data.repositories.reduce(
|
||||
(accumulator, repository) => ({
|
||||
issues: accumulator.issues + (repository.openIssues ?? 0),
|
||||
pulls: accumulator.pulls + (repository.openPulls ?? 0),
|
||||
size: accumulator.size + (repository.sizeKb ?? 0) * 1024,
|
||||
}),
|
||||
{ issues: 0, pulls: 0, size: 0 },
|
||||
);
|
||||
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
h(
|
||||
'div',
|
||||
{ class: 'page-head' },
|
||||
h(
|
||||
'div',
|
||||
{},
|
||||
h('h1', { text: data.fullName || data.name }),
|
||||
h('p', { class: 'muted', text: data.description || 'Organisation Gitea de FWS.' }),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'row' },
|
||||
h('a', {
|
||||
class: 'btn btn-ghost',
|
||||
href: data.url,
|
||||
target: '_blank',
|
||||
rel: 'noreferrer',
|
||||
text: '↗ Voir sur Gitea',
|
||||
}),
|
||||
level >= LEVELS.DEV &&
|
||||
button('Nouveau dépôt', () => createRepository(refresh), { tone: 'primary' }),
|
||||
level >= LEVELS.OWNER &&
|
||||
button('Modifier', () => editOrganization(data, refresh), { tone: 'ghost' }),
|
||||
),
|
||||
),
|
||||
|
||||
card(
|
||||
'Chiffres clés',
|
||||
{},
|
||||
grid(
|
||||
stat('Dépôts', data.repositories.length, { tone: 'primary' }),
|
||||
stat('Membres', data.members.length),
|
||||
stat('Équipes', data.teams.length),
|
||||
stat('Issues ouvertes', totals.issues, { tone: totals.issues > 0 ? 'warning' : 'neutral' }),
|
||||
stat('PR ouvertes', totals.pulls),
|
||||
stat('Taille totale', formatBytes(totals.size)),
|
||||
),
|
||||
),
|
||||
|
||||
card(
|
||||
'Dépôts',
|
||||
{ subtitle: 'Clique sur un dépôt pour le gérer en détail.' },
|
||||
table(
|
||||
[
|
||||
{
|
||||
label: 'Dépôt',
|
||||
render: (repository) =>
|
||||
h(
|
||||
'div',
|
||||
{},
|
||||
h('a', { href: `#/repos/${repository.fullName}`, text: repository.name }),
|
||||
repository.description && h('div', { class: 'muted', text: repository.description }),
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'État',
|
||||
render: (repository) =>
|
||||
h(
|
||||
'div',
|
||||
{ class: 'row' },
|
||||
repository.private ? badge('Privé', 'warning') : badge('Public', 'success'),
|
||||
repository.archived && badge('Archivé', 'neutral'),
|
||||
repository.fork && badge('Fork', 'info'),
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'Langage',
|
||||
render: (repository) => repository.language || '—',
|
||||
className: 'advanced-only',
|
||||
},
|
||||
{ label: 'Issues', className: 'num', render: (repository) => repository.openIssues ?? 0 },
|
||||
{ label: 'PR', className: 'num', render: (repository) => repository.openPulls ?? 0 },
|
||||
{
|
||||
label: 'Releases',
|
||||
className: 'num advanced-only',
|
||||
render: (repository) => repository.releases ?? 0,
|
||||
},
|
||||
{
|
||||
label: 'Mise à jour',
|
||||
className: 'nowrap',
|
||||
render: (repository) => formatRelative(repository.updatedAt),
|
||||
},
|
||||
],
|
||||
data.repositories,
|
||||
{ empty: 'Aucun dépôt dans cette organisation.' },
|
||||
),
|
||||
),
|
||||
|
||||
card(
|
||||
'Membres',
|
||||
{ subtitle: `${data.members.length} compte(s) Gitea` },
|
||||
table(
|
||||
[
|
||||
{
|
||||
label: 'Compte',
|
||||
render: (member) =>
|
||||
h(
|
||||
'div',
|
||||
{ class: 'row' },
|
||||
member.avatar &&
|
||||
h('img', {
|
||||
src: member.avatar,
|
||||
alt: '',
|
||||
width: 24,
|
||||
height: 24,
|
||||
style: { borderRadius: '50%' },
|
||||
}),
|
||||
h('span', { text: member.login }),
|
||||
),
|
||||
},
|
||||
{ label: 'Nom', render: (member) => member.fullName || '—' },
|
||||
{ label: 'Admin', render: (member) => (member.isAdmin ? badge('Admin', 'danger') : '—') },
|
||||
{
|
||||
label: 'Dernière connexion',
|
||||
className: 'nowrap advanced-only',
|
||||
render: (member) => formatRelative(member.lastLogin),
|
||||
},
|
||||
],
|
||||
data.members,
|
||||
),
|
||||
),
|
||||
|
||||
card(
|
||||
'Équipes',
|
||||
{ advanced: true },
|
||||
table(
|
||||
[
|
||||
{ label: 'Équipe', key: 'name' },
|
||||
{ label: 'Description', render: (team) => team.description || '—' },
|
||||
{ label: 'Permission', render: (team) => badge(team.permission ?? '—', 'info') },
|
||||
{
|
||||
label: 'Tous les dépôts',
|
||||
render: (team) => (team.includesAllRepositories ? 'Oui' : 'Non'),
|
||||
},
|
||||
{
|
||||
label: '',
|
||||
render: (team) =>
|
||||
button(
|
||||
'Membres',
|
||||
async () => {
|
||||
const { members } = await api.get(`/api/organization/teams/${team.id}/members`);
|
||||
await modal(`Membres de ${team.name}`, () => ({
|
||||
node: table(
|
||||
[
|
||||
{ label: 'Compte', key: 'login' },
|
||||
{ label: 'Nom', render: (m) => m.fullName || '—' },
|
||||
],
|
||||
members,
|
||||
),
|
||||
submit: () => true,
|
||||
}));
|
||||
},
|
||||
{ tone: 'ghost' },
|
||||
),
|
||||
},
|
||||
],
|
||||
data.teams,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user