landing.ts
TypeScript · 141 рядків
1// Лендінг: чотири вкладки — стенд (схема: ERP-емулятор і WGS зверху, під ними WMS, WTS, WES, під WES — ТСД; решта — серед презентацій), ТЗ з дослідженнями й відкритими питаннями, презентації, дослідження зі статусами й матеріалами.
2import { catalog, type ResearchEntry } from './catalog.ts'
3import { esc, serviceLink } from './render.ts'
4import { services, type Service } from './services.ts'
5
6function badge(r: ResearchEntry) {
7 return `<span class="badge ${r.statusKind}">${esc(r.short)}</span>`
8}
9
10function status(s: Service) {
11 return `<span class="status"><span class="dot" data-status="${s.id}"></span><span class="addr">${s.domain ? esc(s.domain) : `:${s.lanPort}`}</span></span>`
12}
13
14function card(s: Service, tag: string, title: string, summary: string, path = '', cls = '') {
15 return `<article class="card${cls ? ` ${cls}` : ''}">
16 <div class="card-h"><span class="tag">${esc(tag)}</span>${status(s)}</div>
17 <h3>${esc(title)}</h3>
18 ${summary ? `<p>${esc(summary)}</p>` : ''}
19 <div class="actions">${serviceLink(s, 'Відкрити ↗', 'btn', path)}</div>
20 </article>`
21}
22
23export async function landing() {
24 const c = await catalog()
25 const rs = new Map(c.research.map(r => [r.id, r]))
26 const protos = services.filter(s => s.kind !== 'portal' && !s.presentation)
27 const shows = services.filter(s => s.presentation)
28
29 // Стенд — схемою (як іде потік): зверху ERP-емулятор (мала) і WGS, нижче WMS, WTS, WES, під WES — ТСД (мала). Місце — клас slot-* (portal.css).
30 const SLOTS: [string, string][] = [['erp-emulator', 'slot-erp small'], ['wms-master', 'slot-wgs'], ['wms-admin', 'slot-wms'], ['topology', 'slot-wts'], ['engine', 'slot-wes']]
31 const tag = (s: Service) => s.label ?? `${s.product ?? ''} · ${s.kind === 'lab' ? 'дослід' : 'прототип'}`
32 const placed = SLOTS.map(([id, cls]) => [protos.find(s => s.id === id), cls] as const).filter((x): x is readonly [Service, string] => !!x[0])
33 const wes = protos.find(s => s.id === 'engine')
34 const tsd = wes?.views?.find(v => v.path === 'tsd/')
35 const stand = [
36 ...placed.map(([s, cls]) => card(s, tag(s), s.title, '', '', cls)), // без описів: схема, а не каталог
37 ...(wes && tsd ? [card(wes, 'ТСД', 'ТСД — екрани виконавця', '', tsd.path, 'slot-tsd small')] : []),
38 // сервіси поза схемою — після неї, звичайними картками
39 ...protos.filter(s => !SLOTS.some(([id]) => id === s.id)).flatMap(s => [
40 card(s, tag(s), s.title, s.summary),
41 ...(s.views ?? []).filter(v => !v.presentation).map(v => card(s, `${s.product ?? ''} · прототип`, v.title, v.summary, v.path)),
42 ]),
43 ]
44 // Окремі екрани сервісів стенда, винесені в презентації
45 const shownViews = protos.flatMap(s => (s.views ?? []).filter(v => v.presentation)
46 .map(v => card(s, [s.product, ...(s.research ?? [])].filter(Boolean).join(' · '), v.title, v.summary, v.path)))
47
48 const docs = c.docs.map(d => {
49 const research = d.research.map(id => rs.get(id)).filter(r => r?.href)
50 .map(r => `<a class="chip" href="${esc(r!.href!)}" title="${esc(r!.title)}">${r!.id} ${badge(r!)}</a>`).join('')
51 const open = d.open.map(o => `<a class="qid" href="${esc(o.href)}">${o.label}</a>`).join('')
52 return `<article class="card spec">
53 <h3><a href="${esc(d.href)}">${esc(d.title)}</a></h3>
54 <p>${esc(d.summary)}</p>
55 ${open ? `<details class="meta"><summary>Відкриті питання <span class="count warn">${d.open.length}</span></summary><div class="qids">${open}</div></details>` : '<div class="meta muted small">Відкритих питань немає</div>'}
56 ${research ? `<details class="meta"><summary>Дослідження <span class="count">${d.research.filter(id => rs.get(id)?.href).length}</span></summary><div class="chips">${research}</div></details>` : ''}
57 </article>`
58 }).join('')
59
60 const presentations = [
61 ...c.presentations.map(p => {
62 const r = rs.get(p.research)
63 return `<article class="card">
64 <div class="card-h"><span class="tag">${p.research}</span>${r ? badge(r) : ''}</div>
65 <h3>${esc(p.title)}</h3>
66 <p>${r ? esc(r.title) : ''}</p>
67 <div class="actions"><a class="btn" href="${p.href}" target="_blank">Відкрити ↗</a>${r?.href ? `<a class="btn ghost" href="${esc(r.href)}">Документ ${r.id}</a>` : ''}</div>
68 </article>`
69 }),
70 ...shows.map(s => card(s, (s.research ?? []).join(', '), s.title, s.summary)),
71 ...shownViews,
72 ].join('')
73
74 const rows = [...c.research].reverse().map(r => {
75 const mats = [
76 ...c.presentations.filter(p => p.research === r.id).map(p => `<a class="mat" href="${p.href}" target="_blank">Презентація ↗</a>`),
77 ...services.filter(s => s.research?.includes(r.id)).map(s => serviceLink(s, esc(s.title) + ' ↗', 'mat')),
78 ...r.materials.map(m => `<a class="mat code" href="${esc(m.href)}">${esc(m.label)}</a>`),
79 ].join('')
80 const rest = r.status.length > r.short.length ? r.status.slice(r.short.length).replace(/^[\s—,]+/, '') : ''
81 return `<tr class="${r.statusKind}${r.archived ? ' hidden' : ''}" data-kind="${r.statusKind}"${r.archived ? ' data-archived="1"' : ''}>
82 <td class="rid">${r.href ? `<a href="${esc(r.href)}">${r.id}</a>` : r.id}</td>
83 <td>${r.href ? `<a href="${esc(r.href)}">${esc(r.title)}</a>` : esc(r.title)}${mats ? `<div class="mats">${mats}</div>` : ''}</td>
84 <td>${badge(r)}${rest ? `<div class="muted small">${esc(rest)}</div>` : ''}</td>
85 <td class="date">${esc(r.date)}</td>
86 </tr>`
87 }).join('')
88 const active = c.research.filter(r => !r.archived)
89 const count = (k: string) => active.filter(r => r.statusKind === k).length
90 const filters: [string, string, number][] = [
91 ['all', 'Актуальні', active.length], ['accepted', 'Прийнято', count('accepted')],
92 ['draft', 'Чернетки', count('draft')], ['closed', 'Закрито', count('closed')], ['archive', 'Архів', c.research.length - active.length],
93 ]
94
95 return `<!doctype html>
96<html lang="uk">
97<head>
98<meta charset="utf-8">
99<meta name="viewport" content="width=device-width, initial-scale=1">
100<title>Складська платформа · techtools</title>
101<link rel="stylesheet" href="/assets/portal.css">
102<link rel="icon" href="/assets/icon.svg">
103</head>
104<body class="landing">
105<header class="top">
106 <a class="brand" href="/"><img src="/assets/icon.svg" alt="" width="22" height="22">Складська платформа</a>
107 <nav class="tabs" aria-label="Розділи">
108 <a href="#stand">Стенд <span class="count" id="stand-count">${stand.length}</span></a>
109 <a href="#tz">ТЗ <span class="count">${c.docs.length}</span></a>
110 <a href="#pres">Презентації <span class="count">${c.presentations.length + shows.length + shownViews.length}</span></a>
111 <a href="#research">Дослідження <span class="count">${active.length}</span></a>
112 </nav>
113 <a class="settings" href="/stand" title="Порти, бази, домени стенда">Налаштування</a>
114</header>
115<main class="wrap">
116 <section class="tab" id="stand">
117 <div class="cards stand-map">${stand.join('')}</div>
118 </section>
119
120 <section class="tab" id="tz">
121 <div class="cards">${docs}</div>
122 </section>
123
124 <section class="tab" id="pres">
125 <div class="cards">${presentations}</div>
126 </section>
127
128 <section class="tab" id="research">
129 <div class="filters" role="group" aria-label="Фільтр за статусом">${filters.map(([k, label, n], i) => `<button type="button" data-filter="${k}"${i ? '' : ' aria-pressed="true"'}>${label} <span class="count">${n}</span></button>`).join('')}<a class="registry-link" href="/research/">Реєстр R-* повністю</a></div>
130 <div class="table-wrap"><table class="registry research-table">
131 <thead><tr><th>ID</th><th>Дослідження й матеріали</th><th>Статус</th><th>Дата</th></tr></thead>
132 <tbody>${rows}</tbody>
133 </table></div>
134 </section>
135</main>
136<footer class="foot wrap">Репозиторій techtools · <a href="/README.md">README</a></footer>
137<script src="/assets/portal.js"></script>
138</body>
139</html>`
140}
141