@d86e/hive-panel 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/panel.css +56 -0
- package/public/panel.js +444 -5
- package/src/data.js +92 -4
- package/src/server.js +19 -1
package/package.json
CHANGED
package/public/panel.css
CHANGED
|
@@ -1242,3 +1242,59 @@ dialog.hive-dialog .hive-dialog-body { flex: 1 1 auto; min-height: 0; overflow:
|
|
|
1242
1242
|
.hive-run-failure { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--hive-line-2); }
|
|
1243
1243
|
.hive-run-failure-text { margin-top: 2px; color: var(--hive-fg-soft); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
|
|
1244
1244
|
|
|
1245
|
+
/* The panel fills the host; each lane owns its height and scrollbar. */
|
|
1246
|
+
.hive-viewport { height: 100%; min-height: 0; overflow: hidden; }
|
|
1247
|
+
.hive { height: 100%; min-height: 0; overflow: hidden; }
|
|
1248
|
+
.hive-main { min-height: 0; }
|
|
1249
|
+
.hive-board { flex: 1 1 auto; min-height: 0; }
|
|
1250
|
+
.hive-stage { flex: 1 1 auto; min-height: 0; }
|
|
1251
|
+
.hive-lanes { flex: 1 1 auto; align-items: stretch; min-height: 0; }
|
|
1252
|
+
.hive-lane { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
|
|
1253
|
+
.hive-lane-head { flex: 0 0 auto; }
|
|
1254
|
+
.hive-lane-cards { flex: 1 1 auto; min-height: 0; max-height: none; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
|
|
1255
|
+
.hive-skeleton { flex: 1 1 auto; min-height: 0; }
|
|
1256
|
+
@media (max-width: 920px) {
|
|
1257
|
+
.hive-viewport { height: auto; min-height: 100dvh; overflow: auto; }
|
|
1258
|
+
.hive { height: auto; min-height: 100dvh; overflow: visible; }
|
|
1259
|
+
.hive-main { display: flex; flex-direction: column; min-height: 0; }
|
|
1260
|
+
.hive-board { flex: 0 0 auto; min-height: 600px; }
|
|
1261
|
+
.hive-stage { min-height: 560px; }
|
|
1262
|
+
.hive-lanes { flex-direction: column; min-height: 0; overflow-x: visible; overflow-y: visible; }
|
|
1263
|
+
.hive-lane { flex: 0 0 520px; width: 100%; min-height: 520px; }
|
|
1264
|
+
.hive-lane-cards { min-height: 480px; max-height: none; }
|
|
1265
|
+
.hive-skeleton { grid-template-columns: 1fr; min-height: 0; }
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
/* Task search and per-lane pagination controls. */
|
|
1269
|
+
.hive-search { flex: 0 0 auto; padding: 8px 10px 0; }
|
|
1270
|
+
.hive-search-input { box-sizing: border-box; width: 100%; padding: 5px 8px; border: 1px solid var(--hive-line); border-radius: var(--hive-radius-sm); background: var(--hive-bg-layer-1); color: var(--hive-fg); font: inherit; font-size: 12px; }
|
|
1271
|
+
.hive-search-input:focus { outline: 1px solid var(--hive-selected); outline-offset: 0; }
|
|
1272
|
+
.hive-search-results { margin-top: 6px; padding: 6px; border: 1px solid var(--hive-line-2); border-radius: var(--hive-radius-md); background: var(--hive-bg-layer-1); }
|
|
1273
|
+
.hive-search-results.is-hidden { display: none; }
|
|
1274
|
+
.hive-search-summary, .hive-search-empty { color: var(--hive-fg-faint); font-size: 11px; line-height: 1.5; }
|
|
1275
|
+
.hive-search-result { display: flex; align-items: center; gap: 6px; width: 100%; padding: 4px 6px; border: 0; background: transparent; color: var(--hive-fg); font: inherit; font-size: 12px; text-align: left; cursor: pointer; }
|
|
1276
|
+
.hive-search-result:hover { background: var(--hive-hover); }
|
|
1277
|
+
.hive-search-status { flex: 0 0 auto; font-size: 10px; }
|
|
1278
|
+
.hive-search-status.is-done { color: var(--hive-ok); }
|
|
1279
|
+
.hive-search-status.is-failed { color: var(--hive-danger); }
|
|
1280
|
+
.hive-search-status.is-claimed { color: var(--hive-accent); }
|
|
1281
|
+
.hive-search-status.is-pending { color: var(--hive-fg-faint); }
|
|
1282
|
+
.hive-search-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1283
|
+
.hive-search-id { flex: 0 0 auto; color: var(--hive-fg-faint); font-family: var(--hive-mono); font-size: 10.5px; }
|
|
1284
|
+
.hive-lane-paging { flex: 0 0 auto; padding: 0 7px 7px; }
|
|
1285
|
+
.hive-lane-more { width: 100%; padding: 3px 6px; font-size: 11px; }
|
|
1286
|
+
.hive-lane-page-error { margin-top: 4px; color: var(--hive-danger); font-size: 10.5px; line-height: 1.4; overflow-wrap: anywhere; }
|
|
1287
|
+
.hive-lane-page-error.is-hidden, .hive-lane-more.is-hidden { display: none; }
|
|
1288
|
+
|
|
1289
|
+
.hive-lane-loading { padding: 6px 8px; color: var(--hive-fg-faint); font-size: 11px; line-height: 1.5; text-align: center; }
|
|
1290
|
+
.hive-lane-loading.is-hidden { display: none; }
|
|
1291
|
+
|
|
1292
|
+
.hive-lane-head-actions { display: inline-flex; align-items: center; gap: 3px; margin-left: auto; }
|
|
1293
|
+
.hive-lane-more-top, .hive-lane-latest { padding: 1px 5px; font-size: 10px; font-weight: 600; letter-spacing: 0; line-height: 1.4; text-transform: none; }
|
|
1294
|
+
.hive-lane-more-top.is-hidden, .hive-lane-latest.is-hidden { display: none; }
|
|
1295
|
+
|
|
1296
|
+
.hive-lane-recycle { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; padding: 4px 7px; border-bottom: 1px solid var(--hive-line-2); background: var(--hive-bg-layer-2); color: var(--hive-fg-soft); font-size: 10px; line-height: 1.4; }
|
|
1297
|
+
.hive-lane-recycle.is-hidden { display: none; }
|
|
1298
|
+
.hive-lane-recycle-text { min-width: 0; overflow-wrap: anywhere; }
|
|
1299
|
+
.hive-lane-recycle-reload { flex: 0 0 auto; padding: 1px 5px; font-size: 10px; }
|
|
1300
|
+
|
package/public/panel.js
CHANGED
|
@@ -10,6 +10,8 @@ const MAX_EVENTS = 80;
|
|
|
10
10
|
const DEFAULT_SNAPSHOT_URL = "/api/snapshot";
|
|
11
11
|
const DEFAULT_ACTIONS_URL = "/api/actions";
|
|
12
12
|
const DEFAULT_SUPERVISOR_URL = "/api/hive-runner";
|
|
13
|
+
const DEFAULT_TASKS_URL = "/api/tasks";
|
|
14
|
+
const DEFAULT_TASK_URL = "/api/tasks/{id}";
|
|
13
15
|
const QUEEN_DISMISS_KEY = "hive.queenNoticeDismissed";
|
|
14
16
|
const DEFAULT_INTERVAL_MS = 3000;
|
|
15
17
|
|
|
@@ -2067,6 +2069,57 @@ dialog.hive-dialog .hive-dialog-body { flex: 1 1 auto; min-height: 0; overflow:
|
|
|
2067
2069
|
.hive-run-field-label { flex: 0 0 auto; color: var(--hive-fg-faint); font-size: 11px; font-weight: 600; line-height: 1.5; }
|
|
2068
2070
|
.hive-run-failure { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--hive-line-2); }
|
|
2069
2071
|
.hive-run-failure-text { margin-top: 2px; color: var(--hive-fg-soft); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
|
|
2072
|
+
/* The panel fills the host; each lane owns its height and scrollbar. */
|
|
2073
|
+
.hive-viewport { height: 100%; min-height: 0; overflow: hidden; }
|
|
2074
|
+
.hive { height: 100%; min-height: 0; overflow: hidden; }
|
|
2075
|
+
.hive-main { min-height: 0; }
|
|
2076
|
+
.hive-board { flex: 1 1 auto; min-height: 0; }
|
|
2077
|
+
.hive-stage { flex: 1 1 auto; min-height: 0; }
|
|
2078
|
+
.hive-lanes { flex: 1 1 auto; align-items: stretch; min-height: 0; }
|
|
2079
|
+
.hive-lane { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
|
|
2080
|
+
.hive-lane-head { flex: 0 0 auto; }
|
|
2081
|
+
.hive-lane-cards { flex: 1 1 auto; min-height: 0; max-height: none; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
|
|
2082
|
+
.hive-skeleton { flex: 1 1 auto; min-height: 0; }
|
|
2083
|
+
@media (max-width: 920px) {
|
|
2084
|
+
.hive-viewport { height: auto; min-height: 100dvh; overflow: auto; }
|
|
2085
|
+
.hive { height: auto; min-height: 100dvh; overflow: visible; }
|
|
2086
|
+
.hive-main { display: flex; flex-direction: column; min-height: 0; }
|
|
2087
|
+
.hive-board { flex: 0 0 auto; min-height: 600px; }
|
|
2088
|
+
.hive-stage { min-height: 560px; }
|
|
2089
|
+
.hive-lanes { flex-direction: column; min-height: 0; overflow-x: visible; overflow-y: visible; }
|
|
2090
|
+
.hive-lane { flex: 0 0 520px; width: 100%; min-height: 520px; }
|
|
2091
|
+
.hive-lane-cards { min-height: 480px; max-height: none; }
|
|
2092
|
+
.hive-skeleton { grid-template-columns: 1fr; min-height: 0; }
|
|
2093
|
+
}
|
|
2094
|
+
/* Task search and per-lane pagination controls. */
|
|
2095
|
+
.hive-search { flex: 0 0 auto; padding: 8px 10px 0; }
|
|
2096
|
+
.hive-search-input { box-sizing: border-box; width: 100%; padding: 5px 8px; border: 1px solid var(--hive-line); border-radius: var(--hive-radius-sm); background: var(--hive-bg-layer-1); color: var(--hive-fg); font: inherit; font-size: 12px; }
|
|
2097
|
+
.hive-search-input:focus { outline: 1px solid var(--hive-selected); outline-offset: 0; }
|
|
2098
|
+
.hive-search-results { margin-top: 6px; padding: 6px; border: 1px solid var(--hive-line-2); border-radius: var(--hive-radius-md); background: var(--hive-bg-layer-1); }
|
|
2099
|
+
.hive-search-results.is-hidden { display: none; }
|
|
2100
|
+
.hive-search-summary, .hive-search-empty { color: var(--hive-fg-faint); font-size: 11px; line-height: 1.5; }
|
|
2101
|
+
.hive-search-result { display: flex; align-items: center; gap: 6px; width: 100%; padding: 4px 6px; border: 0; background: transparent; color: var(--hive-fg); font: inherit; font-size: 12px; text-align: left; cursor: pointer; }
|
|
2102
|
+
.hive-search-result:hover { background: var(--hive-hover); }
|
|
2103
|
+
.hive-search-status { flex: 0 0 auto; font-size: 10px; }
|
|
2104
|
+
.hive-search-status.is-done { color: var(--hive-ok); }
|
|
2105
|
+
.hive-search-status.is-failed { color: var(--hive-danger); }
|
|
2106
|
+
.hive-search-status.is-claimed { color: var(--hive-accent); }
|
|
2107
|
+
.hive-search-status.is-pending { color: var(--hive-fg-faint); }
|
|
2108
|
+
.hive-search-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2109
|
+
.hive-search-id { flex: 0 0 auto; color: var(--hive-fg-faint); font-family: var(--hive-mono); font-size: 10.5px; }
|
|
2110
|
+
.hive-lane-paging { flex: 0 0 auto; padding: 0 7px 7px; }
|
|
2111
|
+
.hive-lane-more { width: 100%; padding: 3px 6px; font-size: 11px; }
|
|
2112
|
+
.hive-lane-page-error { margin-top: 4px; color: var(--hive-danger); font-size: 10.5px; line-height: 1.4; overflow-wrap: anywhere; }
|
|
2113
|
+
.hive-lane-page-error.is-hidden, .hive-lane-more.is-hidden { display: none; }
|
|
2114
|
+
.hive-lane-loading { padding: 6px 8px; color: var(--hive-fg-faint); font-size: 11px; line-height: 1.5; text-align: center; }
|
|
2115
|
+
.hive-lane-loading.is-hidden { display: none; }
|
|
2116
|
+
.hive-lane-head-actions { display: inline-flex; align-items: center; gap: 3px; margin-left: auto; }
|
|
2117
|
+
.hive-lane-more-top, .hive-lane-latest { padding: 1px 5px; font-size: 10px; font-weight: 600; letter-spacing: 0; line-height: 1.4; text-transform: none; }
|
|
2118
|
+
.hive-lane-more-top.is-hidden, .hive-lane-latest.is-hidden { display: none; }
|
|
2119
|
+
.hive-lane-recycle { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; padding: 4px 7px; border-bottom: 1px solid var(--hive-line-2); background: var(--hive-bg-layer-2); color: var(--hive-fg-soft); font-size: 10px; line-height: 1.4; }
|
|
2120
|
+
.hive-lane-recycle.is-hidden { display: none; }
|
|
2121
|
+
.hive-lane-recycle-text { min-width: 0; overflow-wrap: anywhere; }
|
|
2122
|
+
.hive-lane-recycle-reload { flex: 0 0 auto; padding: 1px 5px; font-size: 10px; }
|
|
2070
2123
|
`;
|
|
2071
2124
|
|
|
2072
2125
|
const LANE_LABEL_KEYS = Object.freeze({
|
|
@@ -2098,6 +2151,18 @@ export const messages = Object.freeze({
|
|
|
2098
2151
|
"pane.board": "Task board",
|
|
2099
2152
|
"pane.events": "events",
|
|
2100
2153
|
"board.filtersAria": "Filter by state",
|
|
2154
|
+
"board.loadMore": "Load more",
|
|
2155
|
+
"board.latest": "Back to latest",
|
|
2156
|
+
"board.recycled": "Recycled {count} older tasks",
|
|
2157
|
+
"board.reloadLatest": "Reload latest",
|
|
2158
|
+
"board.latestAria": "Scroll back to the newest tasks",
|
|
2159
|
+
"board.loading": "Loading…",
|
|
2160
|
+
"board.loadFailed": "Could not load more",
|
|
2161
|
+
"board.retry": "Retry",
|
|
2162
|
+
"board.searchPlaceholder": "Search task id or title",
|
|
2163
|
+
"board.searchAria": "Search tasks by id or title",
|
|
2164
|
+
"board.searchEmpty": "No matching tasks",
|
|
2165
|
+
"board.searchResults": "{count} matching tasks",
|
|
2101
2166
|
"board.all": "all",
|
|
2102
2167
|
"board.showAll": "Show all tasks",
|
|
2103
2168
|
"board.filterChip": "Show {lane} tasks ({count})",
|
|
@@ -2395,6 +2460,18 @@ export const messages = Object.freeze({
|
|
|
2395
2460
|
"pane.board": "任务看板",
|
|
2396
2461
|
"pane.events": "事件",
|
|
2397
2462
|
"board.filtersAria": "按状态筛选",
|
|
2463
|
+
"board.loadMore": "加载更多",
|
|
2464
|
+
"board.latest": "回到最新",
|
|
2465
|
+
"board.recycled": "已回收更早的 {count} 条",
|
|
2466
|
+
"board.reloadLatest": "重新加载",
|
|
2467
|
+
"board.latestAria": "滚动回最新任务",
|
|
2468
|
+
"board.loading": "加载中…",
|
|
2469
|
+
"board.loadFailed": "加载失败",
|
|
2470
|
+
"board.retry": "重试",
|
|
2471
|
+
"board.searchPlaceholder": "搜索任务 ID 或标题",
|
|
2472
|
+
"board.searchAria": "按 ID 或标题搜索任务",
|
|
2473
|
+
"board.searchEmpty": "没有匹配任务",
|
|
2474
|
+
"board.searchResults": "{count} 个匹配任务",
|
|
2398
2475
|
"board.all": "全部",
|
|
2399
2476
|
"board.showAll": "显示全部任务",
|
|
2400
2477
|
"board.filterChip": "只看{lane}任务({count})",
|
|
@@ -3077,6 +3154,21 @@ export function renderModel(snapshot) {
|
|
|
3077
3154
|
error: rawRoles ? asString(rawRoles.error) || null : null,
|
|
3078
3155
|
};
|
|
3079
3156
|
|
|
3157
|
+
const rawLanePages = isRecord(source.lanePages) ? source.lanePages : null;
|
|
3158
|
+
const lanePages = {};
|
|
3159
|
+
for (const state of LANE_ORDER) {
|
|
3160
|
+
const rows = lanes[state];
|
|
3161
|
+
const raw = rawLanePages && isRecord(rawLanePages[state]) ? rawLanePages[state] : null;
|
|
3162
|
+
const total = raw ? asCount(raw.total, rows.length) : rows.length;
|
|
3163
|
+
const cursor = raw ? asCount(raw.cursor, rows.length) : rows.length;
|
|
3164
|
+
lanePages[state] = {
|
|
3165
|
+
loaded: rows.length,
|
|
3166
|
+
total,
|
|
3167
|
+
cursor,
|
|
3168
|
+
hasMore: raw ? raw.hasMore === true || rows.length < total : false,
|
|
3169
|
+
};
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3080
3172
|
return {
|
|
3081
3173
|
at: asString(source.at),
|
|
3082
3174
|
repo: asString(source.repo),
|
|
@@ -3087,6 +3179,7 @@ export function renderModel(snapshot) {
|
|
|
3087
3179
|
writable,
|
|
3088
3180
|
lanes,
|
|
3089
3181
|
laneOrder: [...LANE_ORDER],
|
|
3182
|
+
lanePages,
|
|
3090
3183
|
taskList: tasks.map(normalizeCard),
|
|
3091
3184
|
stats: normalizeStats(source.stats, tasks),
|
|
3092
3185
|
agents: normalizeAgents(source.board),
|
|
@@ -3781,6 +3874,8 @@ export function mount(root, options = {}) {
|
|
|
3781
3874
|
const snapshotUrl = asString(opts.snapshotUrl) || DEFAULT_SNAPSHOT_URL;
|
|
3782
3875
|
const supervisorUrl = asString(opts.supervisorUrl) || DEFAULT_SUPERVISOR_URL;
|
|
3783
3876
|
const actionsUrl = (asString(opts.actionsUrl) || DEFAULT_ACTIONS_URL).replace(/\/+$/, "");
|
|
3877
|
+
const tasksUrl = asString(opts.tasksUrl) || DEFAULT_TASKS_URL;
|
|
3878
|
+
const taskUrl = asString(opts.taskUrl) || DEFAULT_TASK_URL;
|
|
3784
3879
|
|
|
3785
3880
|
const requestedInterval = Number(opts.intervalMs);
|
|
3786
3881
|
const intervalMs =
|
|
@@ -4072,6 +4167,22 @@ export function mount(root, options = {}) {
|
|
|
4072
4167
|
const stage = element(doc, "div", "hive-stage");
|
|
4073
4168
|
const stageChips = element(doc, "div", "hive-stage-chips");
|
|
4074
4169
|
setAttr(stageChips, "aria-label", translate("board.filtersAria"));
|
|
4170
|
+
const searchBox = element(doc, "div", "hive-search");
|
|
4171
|
+
const searchInput = element(doc, "input", "hive-search-input");
|
|
4172
|
+
setAttr(searchInput, "type", "search");
|
|
4173
|
+
setAttr(searchInput, "placeholder", translate("board.searchPlaceholder"));
|
|
4174
|
+
setAttr(searchInput, "aria-label", translate("board.searchAria"));
|
|
4175
|
+
const searchResults = element(doc, "div", "hive-search-results is-hidden");
|
|
4176
|
+
searchBox.appendChild(searchInput);
|
|
4177
|
+
searchBox.appendChild(searchResults);
|
|
4178
|
+
stage.appendChild(searchBox);
|
|
4179
|
+
searchInput.addEventListener("input", () => {
|
|
4180
|
+
void runSearch(searchInput.value);
|
|
4181
|
+
});
|
|
4182
|
+
searchInput.addEventListener("keydown", (event) => {
|
|
4183
|
+
if (event && event.key === "Enter") void runSearch(searchInput.value);
|
|
4184
|
+
});
|
|
4185
|
+
|
|
4075
4186
|
const lanesNode = element(doc, "div", "hive-lanes");
|
|
4076
4187
|
const filterEmpty = element(doc, "div", "hive-filter-empty", "");
|
|
4077
4188
|
stage.appendChild(stageChips);
|
|
@@ -6134,6 +6245,39 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
6134
6245
|
body.appendChild(part.section);
|
|
6135
6246
|
}
|
|
6136
6247
|
|
|
6248
|
+
async function openCardDetail(card, lane, trigger) {
|
|
6249
|
+
// Open immediately from the list row so the click never waits on I/O, then
|
|
6250
|
+
// refresh the dialog from the id-only detail endpoint when it arrives.
|
|
6251
|
+
openDrawer(card, lane, trigger);
|
|
6252
|
+
let detail = null;
|
|
6253
|
+
let detailLane = lane;
|
|
6254
|
+
if (fetchImpl && card && card.id) {
|
|
6255
|
+
let url = taskUrl;
|
|
6256
|
+
if (url.includes("{id}")) url = url.replace("{id}", encodeURIComponent(String(card.id)));
|
|
6257
|
+
else url = url.replace(/\/+$/, "") + "/" + encodeURIComponent(String(card.id));
|
|
6258
|
+
try {
|
|
6259
|
+
const response = await fetchImpl(url, {
|
|
6260
|
+
cache: "no-store",
|
|
6261
|
+
headers: { accept: "application/json" },
|
|
6262
|
+
});
|
|
6263
|
+
if (response && response.ok !== false) {
|
|
6264
|
+
const payload = await response.json();
|
|
6265
|
+
const task = payload && isRecord(payload.task) ? payload.task : isRecord(payload) ? payload : null;
|
|
6266
|
+
if (task && task.id) {
|
|
6267
|
+
detail = task;
|
|
6268
|
+
detailLane = asString(task.state) || lane;
|
|
6269
|
+
}
|
|
6270
|
+
}
|
|
6271
|
+
} catch (error) {
|
|
6272
|
+
reportError(error);
|
|
6273
|
+
}
|
|
6274
|
+
}
|
|
6275
|
+
if (destroyed || !detail) return;
|
|
6276
|
+
if (drawerState && drawerState.card && drawerState.card.id === card.id) {
|
|
6277
|
+
openDrawer(normalizeCard(detail), detailLane, trigger);
|
|
6278
|
+
}
|
|
6279
|
+
}
|
|
6280
|
+
|
|
6137
6281
|
function openDrawer(card, lane, trigger) {
|
|
6138
6282
|
closeHelp(false);
|
|
6139
6283
|
closePlanDialog(false);
|
|
@@ -6970,12 +7114,12 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
6970
7114
|
setAttr(node, "tabindex", "0");
|
|
6971
7115
|
setAttr(node, "role", "button");
|
|
6972
7116
|
node.addEventListener("click", () => {
|
|
6973
|
-
if (node._hiveCard)
|
|
7117
|
+
if (node._hiveCard) void openCardDetail(node._hiveCard, node._hiveLane, node);
|
|
6974
7118
|
});
|
|
6975
7119
|
node.addEventListener("keydown", (event) => {
|
|
6976
7120
|
if (!event || (event.key !== "Enter" && event.key !== " ")) return;
|
|
6977
7121
|
if (typeof event.preventDefault === "function") event.preventDefault();
|
|
6978
|
-
if (node._hiveCard)
|
|
7122
|
+
if (node._hiveCard) void openCardDetail(node._hiveCard, node._hiveLane, node);
|
|
6979
7123
|
});
|
|
6980
7124
|
node._hiveTitle = element(doc, "div", "hive-card-title", "");
|
|
6981
7125
|
node.appendChild(node._hiveTitle);
|
|
@@ -7018,6 +7162,12 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
7018
7162
|
}
|
|
7019
7163
|
}
|
|
7020
7164
|
|
|
7165
|
+
function resetLaneScroll() {
|
|
7166
|
+
for (const state of laneRenderState.values()) {
|
|
7167
|
+
state.list.scrollTop = 0;
|
|
7168
|
+
}
|
|
7169
|
+
}
|
|
7170
|
+
|
|
7021
7171
|
function selectStageFilter(filter) {
|
|
7022
7172
|
stageFilter = filter;
|
|
7023
7173
|
for (const entry of stageChipEntries) {
|
|
@@ -7025,6 +7175,7 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
7025
7175
|
setAttr(entry.chip, "aria-pressed", entry.filter === filter ? "true" : "false");
|
|
7026
7176
|
}
|
|
7027
7177
|
if (lastModel) renderLanes(lastModel);
|
|
7178
|
+
resetLaneScroll();
|
|
7028
7179
|
}
|
|
7029
7180
|
|
|
7030
7181
|
function cardSortTime(card) {
|
|
@@ -7052,8 +7203,11 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
7052
7203
|
}
|
|
7053
7204
|
|
|
7054
7205
|
const LANE_ROW_HEIGHT = 28;
|
|
7055
|
-
const LANE_ROW_BUFFER =
|
|
7206
|
+
const LANE_ROW_BUFFER = 4;
|
|
7207
|
+
const LANE_MAX_ROWS = 20;
|
|
7056
7208
|
const LANE_VIEWPORT_FALLBACK = 480;
|
|
7209
|
+
const LANE_DATA_LIMIT = 5000;
|
|
7210
|
+
const LANE_PAGE_SIZE = 200;
|
|
7057
7211
|
|
|
7058
7212
|
function createLaneState(lane) {
|
|
7059
7213
|
const column = element(doc, "section", "hive-lane hive-lane-" + lane);
|
|
@@ -7061,7 +7215,24 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
7061
7215
|
head.appendChild(element(doc, "span", "hive-lane-name", laneLabel(lane)));
|
|
7062
7216
|
const count = element(doc, "span", "hive-count", "0");
|
|
7063
7217
|
head.appendChild(count);
|
|
7218
|
+
const headActions = element(doc, "span", "hive-lane-head-actions");
|
|
7219
|
+
const topMore = element(doc, "button", "hive-btn hive-btn-ghost hive-lane-more-top is-hidden", translate("board.loadMore"));
|
|
7220
|
+
setAttr(topMore, "type", "button");
|
|
7221
|
+
const latest = element(doc, "button", "hive-btn hive-btn-ghost hive-lane-latest", translate("board.latest"));
|
|
7222
|
+
setAttr(latest, "type", "button");
|
|
7223
|
+
setAttr(latest, "title", translate("board.latestAria"));
|
|
7224
|
+
setAttr(latest, "aria-label", translate("board.latestAria"));
|
|
7225
|
+
headActions.appendChild(topMore);
|
|
7226
|
+
headActions.appendChild(latest);
|
|
7227
|
+
head.appendChild(headActions);
|
|
7064
7228
|
column.appendChild(head);
|
|
7229
|
+
const recycle = element(doc, "div", "hive-lane-recycle is-hidden");
|
|
7230
|
+
const recycleText = element(doc, "span", "hive-lane-recycle-text", "");
|
|
7231
|
+
const recycleButton = element(doc, "button", "hive-btn hive-btn-ghost hive-lane-recycle-reload", translate("board.reloadLatest"));
|
|
7232
|
+
setAttr(recycleButton, "type", "button");
|
|
7233
|
+
recycle.appendChild(recycleText);
|
|
7234
|
+
recycle.appendChild(recycleButton);
|
|
7235
|
+
column.appendChild(recycle);
|
|
7065
7236
|
|
|
7066
7237
|
const list = element(doc, "div", "hive-lane-cards");
|
|
7067
7238
|
const inner = element(doc, "div", "hive-lane-virtual");
|
|
@@ -7070,7 +7241,42 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
7070
7241
|
lanesNode.appendChild(column);
|
|
7071
7242
|
|
|
7072
7243
|
const state = { lane, column, list, inner, count, cards: [], visible: new Map() };
|
|
7073
|
-
|
|
7244
|
+
const loadingRow = element(doc, "div", "hive-lane-loading is-hidden", translate("board.loading"));
|
|
7245
|
+
list.appendChild(loadingRow);
|
|
7246
|
+
list.addEventListener("scroll", () => {
|
|
7247
|
+
renderLaneVirtual(state);
|
|
7248
|
+
maybeLoadNextPage(state);
|
|
7249
|
+
});
|
|
7250
|
+
const paging = element(doc, "div", "hive-lane-paging");
|
|
7251
|
+
const more = element(doc, "button", "hive-btn hive-btn-ghost hive-lane-more is-hidden", translate("board.loadMore"));
|
|
7252
|
+
setAttr(more, "type", "button");
|
|
7253
|
+
const pageError = element(doc, "div", "hive-lane-page-error is-hidden", "");
|
|
7254
|
+
paging.appendChild(more);
|
|
7255
|
+
paging.appendChild(pageError);
|
|
7256
|
+
column.appendChild(paging);
|
|
7257
|
+
state.more = more;
|
|
7258
|
+
state.pageError = pageError;
|
|
7259
|
+
state.loadingRow = loadingRow;
|
|
7260
|
+
state.recycle = recycle;
|
|
7261
|
+
state.recycleText = recycleText;
|
|
7262
|
+
state.recycleButton = recycleButton;
|
|
7263
|
+
state.recycled = 0;
|
|
7264
|
+
state.loadingPage = false;
|
|
7265
|
+
state.pageFailure = "";
|
|
7266
|
+
more.addEventListener("click", () => {
|
|
7267
|
+
void loadLanePage(state.lane, state);
|
|
7268
|
+
});
|
|
7269
|
+
topMore.addEventListener("click", () => {
|
|
7270
|
+
void loadLanePage(state.lane, state);
|
|
7271
|
+
});
|
|
7272
|
+
recycleButton.addEventListener("click", () => {
|
|
7273
|
+
void reloadLaneLatest(state.lane, state);
|
|
7274
|
+
});
|
|
7275
|
+
latest.addEventListener("click", () => {
|
|
7276
|
+
state.list.scrollTop = 0;
|
|
7277
|
+
});
|
|
7278
|
+
state.topMore = topMore;
|
|
7279
|
+
state.latest = latest;
|
|
7074
7280
|
return state;
|
|
7075
7281
|
}
|
|
7076
7282
|
|
|
@@ -7084,7 +7290,8 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
7084
7290
|
: LANE_VIEWPORT_FALLBACK;
|
|
7085
7291
|
const scrollTop = Number(state.list.scrollTop) || 0;
|
|
7086
7292
|
const start = Math.max(0, Math.floor(scrollTop / row) - LANE_ROW_BUFFER);
|
|
7087
|
-
|
|
7293
|
+
let end = Math.min(total, Math.ceil((scrollTop + viewport) / row) + LANE_ROW_BUFFER);
|
|
7294
|
+
if (end - start > LANE_MAX_ROWS) end = start + LANE_MAX_ROWS;
|
|
7088
7295
|
const height = total === 0 ? 0 : total * row - 2;
|
|
7089
7296
|
setStyle(state.inner, "height", String(height) + "px");
|
|
7090
7297
|
|
|
@@ -7105,6 +7312,211 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
7105
7312
|
state.count.textContent = String(total);
|
|
7106
7313
|
}
|
|
7107
7314
|
|
|
7315
|
+
let searchSeq = 0;
|
|
7316
|
+
|
|
7317
|
+
function taskSearchUrl(query) {
|
|
7318
|
+
const params = ["search=" + encodeURIComponent(query), "limit=200"];
|
|
7319
|
+
return tasksUrl + (tasksUrl.includes("?") ? "&" : "?") + params.join("&");
|
|
7320
|
+
}
|
|
7321
|
+
|
|
7322
|
+
function renderSearchResults(items, total) {
|
|
7323
|
+
clearNode(searchResults);
|
|
7324
|
+
searchResults.className = "hive-search-results";
|
|
7325
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
7326
|
+
searchResults.appendChild(element(doc, "div", "hive-search-empty", translate("board.searchEmpty")));
|
|
7327
|
+
return;
|
|
7328
|
+
}
|
|
7329
|
+
searchResults.appendChild(
|
|
7330
|
+
element(
|
|
7331
|
+
doc,
|
|
7332
|
+
"div",
|
|
7333
|
+
"hive-search-summary",
|
|
7334
|
+
translate("board.searchResults").replace("{count}", String(asCount(total, items.length))),
|
|
7335
|
+
),
|
|
7336
|
+
);
|
|
7337
|
+
for (const taskData of items) {
|
|
7338
|
+
const task = normalizeCard(taskData);
|
|
7339
|
+
const button = element(doc, "button", "hive-search-result");
|
|
7340
|
+
setAttr(button, "type", "button");
|
|
7341
|
+
button.appendChild(element(doc, "span", "hive-search-status is-" + safeClassToken(task.state), "●"));
|
|
7342
|
+
button.appendChild(element(doc, "span", "hive-search-title", task.title || task.id));
|
|
7343
|
+
button.appendChild(element(doc, "span", "hive-search-id", task.id));
|
|
7344
|
+
button.addEventListener("click", () => {
|
|
7345
|
+
void openCardDetail(task, task.state, null);
|
|
7346
|
+
});
|
|
7347
|
+
searchResults.appendChild(button);
|
|
7348
|
+
}
|
|
7349
|
+
}
|
|
7350
|
+
|
|
7351
|
+
async function runSearch(rawQuery) {
|
|
7352
|
+
const query = asString(rawQuery).trim();
|
|
7353
|
+
resetLaneScroll();
|
|
7354
|
+
searchSeq += 1;
|
|
7355
|
+
const seq = searchSeq;
|
|
7356
|
+
if (!query) {
|
|
7357
|
+
clearNode(searchResults);
|
|
7358
|
+
searchResults.className = "hive-search-results is-hidden";
|
|
7359
|
+
return;
|
|
7360
|
+
}
|
|
7361
|
+
if (!fetchImpl) return;
|
|
7362
|
+
try {
|
|
7363
|
+
const response = await fetchImpl(taskSearchUrl(query), {
|
|
7364
|
+
cache: "no-store",
|
|
7365
|
+
headers: { accept: "application/json" },
|
|
7366
|
+
});
|
|
7367
|
+
if (!response || response.ok === false) throw new Error("task search failed");
|
|
7368
|
+
const payload = await response.json();
|
|
7369
|
+
if (destroyed || seq !== searchSeq) return;
|
|
7370
|
+
const items = Array.isArray(payload && payload.items) ? payload.items : [];
|
|
7371
|
+
renderSearchResults(items, payload && payload.total);
|
|
7372
|
+
} catch (error) {
|
|
7373
|
+
if (!destroyed && seq === searchSeq) {
|
|
7374
|
+
clearNode(searchResults);
|
|
7375
|
+
searchResults.className = "hive-search-results";
|
|
7376
|
+
searchResults.appendChild(element(doc, "div", "hive-search-empty", translate("board.searchEmpty")));
|
|
7377
|
+
}
|
|
7378
|
+
reportError(error);
|
|
7379
|
+
}
|
|
7380
|
+
}
|
|
7381
|
+
|
|
7382
|
+
function taskPageUrl(state, cursor) {
|
|
7383
|
+
let url = tasksUrl;
|
|
7384
|
+
const params = [];
|
|
7385
|
+
if (url.includes("{state}")) url = url.replace("{state}", encodeURIComponent(state));
|
|
7386
|
+
else params.push("state=" + encodeURIComponent(state));
|
|
7387
|
+
if (url.includes("{cursor}")) url = url.replace("{cursor}", encodeURIComponent(String(cursor)));
|
|
7388
|
+
else params.push("cursor=" + encodeURIComponent(String(cursor)));
|
|
7389
|
+
params.push("limit=200");
|
|
7390
|
+
return url + (url.includes("?") ? "&" : "?") + params.join("&");
|
|
7391
|
+
}
|
|
7392
|
+
|
|
7393
|
+
function pageErrorMessage(error) {
|
|
7394
|
+
return asString(error && error.message) || translate("board.loadFailed");
|
|
7395
|
+
}
|
|
7396
|
+
|
|
7397
|
+
function maybeLoadNextPage(state) {
|
|
7398
|
+
if (destroyed || state.loadingPage || !lastModel) return;
|
|
7399
|
+
const page = lastModel.lanePages ? lastModel.lanePages[state.lane] : null;
|
|
7400
|
+
if (!page || !page.hasMore) return;
|
|
7401
|
+
const list = state.list;
|
|
7402
|
+
const scrollTop = Number(list.scrollTop) || 0;
|
|
7403
|
+
const clientHeight = Number(list.clientHeight) || 0;
|
|
7404
|
+
const scrollHeight = Number(list.scrollHeight) || 0;
|
|
7405
|
+
if (scrollHeight <= 0 || clientHeight <= 0) return;
|
|
7406
|
+
if (scrollTop + clientHeight >= scrollHeight - 24) {
|
|
7407
|
+
void loadLanePage(state.lane, state);
|
|
7408
|
+
}
|
|
7409
|
+
}
|
|
7410
|
+
|
|
7411
|
+
async function loadLanePage(lane, state) {
|
|
7412
|
+
if (destroyed || state.loadingPage) return;
|
|
7413
|
+
const model = lastModel;
|
|
7414
|
+
const page = model && model.lanePages ? model.lanePages[lane] : null;
|
|
7415
|
+
if (!page || !page.hasMore || !fetchImpl) return;
|
|
7416
|
+
state.loadingPage = true;
|
|
7417
|
+
state.pageFailure = "";
|
|
7418
|
+
state.more.disabled = true;
|
|
7419
|
+
state.more.textContent = translate("board.loading");
|
|
7420
|
+
state.topMore.disabled = true;
|
|
7421
|
+
state.topMore.textContent = translate("board.loading");
|
|
7422
|
+
state.loadingRow.className = "hive-lane-loading";
|
|
7423
|
+
state.pageError.className = "hive-lane-page-error is-hidden";
|
|
7424
|
+
const list = state.list;
|
|
7425
|
+
const beforeTop = Number(list.scrollTop) || 0;
|
|
7426
|
+
let added = 0;
|
|
7427
|
+
try {
|
|
7428
|
+
const response = await fetchImpl(taskPageUrl(lane, page.cursor), {
|
|
7429
|
+
cache: "no-store",
|
|
7430
|
+
headers: { accept: "application/json" },
|
|
7431
|
+
});
|
|
7432
|
+
if (!response || response.ok === false) {
|
|
7433
|
+
throw new Error("tasks page failed with status " + (response ? response.status : "none"));
|
|
7434
|
+
}
|
|
7435
|
+
const payload = await response.json();
|
|
7436
|
+
const items = Array.isArray(payload && payload.items)
|
|
7437
|
+
? payload.items
|
|
7438
|
+
: Array.isArray(payload && payload.tasks)
|
|
7439
|
+
? payload.tasks
|
|
7440
|
+
: null;
|
|
7441
|
+
if (!items) throw new Error("tasks page returned no items");
|
|
7442
|
+
const total = asCount(payload && payload.total, page.total);
|
|
7443
|
+
const cursor = asCount(payload && payload.cursor, page.cursor + items.length);
|
|
7444
|
+
const hasMore = payload && payload.hasMore === true ? true : cursor < total;
|
|
7445
|
+
if (!lastSnapshot) throw new Error("the board is not ready");
|
|
7446
|
+
const existing = Array.isArray(lastSnapshot.tasks) ? lastSnapshot.tasks : [];
|
|
7447
|
+
const seen = new Set(existing.map((task) => String(task && task.id)));
|
|
7448
|
+
const merged = [...existing];
|
|
7449
|
+
for (const task of items) {
|
|
7450
|
+
const id = String(task && task.id);
|
|
7451
|
+
if (!id || seen.has(id)) continue;
|
|
7452
|
+
seen.add(id);
|
|
7453
|
+
merged.push(task);
|
|
7454
|
+
added += 1;
|
|
7455
|
+
}
|
|
7456
|
+
let kept = merged;
|
|
7457
|
+
const laneRows = merged.filter((task) => (task && (task.state || "pending")) === lane);
|
|
7458
|
+
let dropped = 0;
|
|
7459
|
+
if (laneRows.length > LANE_DATA_LIMIT) {
|
|
7460
|
+
const dropIds = new Set(laneRows.slice(LANE_DATA_LIMIT).map((task) => String(task && task.id)));
|
|
7461
|
+
dropped = dropIds.size;
|
|
7462
|
+
kept = merged.filter((task) => !dropIds.has(String(task && task.id)));
|
|
7463
|
+
}
|
|
7464
|
+
state.recycled += dropped;
|
|
7465
|
+
const lanePages = { ...(isRecord(lastSnapshot.lanePages) ? lastSnapshot.lanePages : {}) };
|
|
7466
|
+
lanePages[lane] = { total, cursor, hasMore };
|
|
7467
|
+
setSnapshot({ ...lastSnapshot, tasks: kept, lanePages });
|
|
7468
|
+
} catch (error) {
|
|
7469
|
+
state.pageFailure = pageErrorMessage(error);
|
|
7470
|
+
reportError(error);
|
|
7471
|
+
} finally {
|
|
7472
|
+
state.loadingPage = false;
|
|
7473
|
+
state.loadingRow.className = "hive-lane-loading is-hidden";
|
|
7474
|
+
if (!destroyed && lastModel) renderLanes(lastModel);
|
|
7475
|
+
if (!destroyed && added > 0) {
|
|
7476
|
+
list.scrollTop = beforeTop;
|
|
7477
|
+
}
|
|
7478
|
+
}
|
|
7479
|
+
}
|
|
7480
|
+
|
|
7481
|
+
async function reloadLaneLatest(lane, state) {
|
|
7482
|
+
if (destroyed || state.loadingPage || !fetchImpl || !lastSnapshot) return;
|
|
7483
|
+
state.loadingPage = true;
|
|
7484
|
+
state.pageFailure = "";
|
|
7485
|
+
state.more.disabled = true;
|
|
7486
|
+
state.more.textContent = translate("board.loading");
|
|
7487
|
+
state.topMore.disabled = true;
|
|
7488
|
+
state.topMore.textContent = translate("board.loading");
|
|
7489
|
+
state.loadingRow.className = "hive-lane-loading";
|
|
7490
|
+
state.pageError.className = "hive-lane-page-error is-hidden";
|
|
7491
|
+
state.list.scrollTop = 0;
|
|
7492
|
+
try {
|
|
7493
|
+
const response = await fetchImpl(taskPageUrl(lane, 0), {
|
|
7494
|
+
cache: "no-store",
|
|
7495
|
+
headers: { accept: "application/json" },
|
|
7496
|
+
});
|
|
7497
|
+
if (!response || response.ok === false) throw new Error("tasks page failed with status " + (response ? response.status : "none"));
|
|
7498
|
+
const payload = await response.json();
|
|
7499
|
+
const items = Array.isArray(payload && payload.items) ? payload.items : [];
|
|
7500
|
+
const total = asCount(payload && payload.total, items.length);
|
|
7501
|
+
const cursor = asCount(payload && payload.cursor, items.length);
|
|
7502
|
+
const hasMore = payload && payload.hasMore === true ? true : cursor < total;
|
|
7503
|
+
const others = (Array.isArray(lastSnapshot.tasks) ? lastSnapshot.tasks : [])
|
|
7504
|
+
.filter((task) => (task && (task.state || "pending")) !== lane);
|
|
7505
|
+
const lanePages = { ...(isRecord(lastSnapshot.lanePages) ? lastSnapshot.lanePages : {}) };
|
|
7506
|
+
lanePages[lane] = { total, cursor, hasMore };
|
|
7507
|
+
state.recycled = 0;
|
|
7508
|
+
setSnapshot({ ...lastSnapshot, tasks: [...others, ...items], lanePages });
|
|
7509
|
+
state.list.scrollTop = 0;
|
|
7510
|
+
} catch (error) {
|
|
7511
|
+
state.pageFailure = pageErrorMessage(error);
|
|
7512
|
+
reportError(error);
|
|
7513
|
+
} finally {
|
|
7514
|
+
state.loadingPage = false;
|
|
7515
|
+
state.loadingRow.className = "hive-lane-loading is-hidden";
|
|
7516
|
+
if (!destroyed && lastModel) renderLanes(lastModel);
|
|
7517
|
+
}
|
|
7518
|
+
}
|
|
7519
|
+
|
|
7108
7520
|
function renderLanes(model) {
|
|
7109
7521
|
if (model.initialised === false) {
|
|
7110
7522
|
clearNode(lanesNode);
|
|
@@ -7127,6 +7539,31 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
7127
7539
|
if (stageFilter !== "all" && stageFilter !== lane) classes.push("is-filtered-out");
|
|
7128
7540
|
state.column.className = classes.join(" ");
|
|
7129
7541
|
renderLaneVirtual(state);
|
|
7542
|
+
const pageInfo = model.lanePages && model.lanePages[lane] ? model.lanePages[lane] : null;
|
|
7543
|
+
const loaded = cards.length;
|
|
7544
|
+
const total = pageInfo ? pageInfo.total : loaded;
|
|
7545
|
+
state.count.textContent = total > loaded ? loaded + " / " + total : String(loaded);
|
|
7546
|
+
const hasMore = Boolean(pageInfo && pageInfo.hasMore);
|
|
7547
|
+
state.more.className = "hive-btn hive-btn-ghost hive-lane-more" + (hasMore ? "" : " is-hidden");
|
|
7548
|
+
state.recycle.className = "hive-lane-recycle" + (state.recycled > 0 ? "" : " is-hidden");
|
|
7549
|
+
state.recycleText.textContent = state.recycled > 0
|
|
7550
|
+
? translate("board.recycled").replace("{count}", String(state.recycled)) + " · "
|
|
7551
|
+
: "";
|
|
7552
|
+
state.loadingRow.className = "hive-lane-loading" + (state.loadingPage ? "" : " is-hidden");
|
|
7553
|
+
state.topMore.className = "hive-btn hive-btn-ghost hive-lane-more-top" + (hasMore ? "" : " is-hidden");
|
|
7554
|
+
state.topMore.disabled = state.loadingPage === true;
|
|
7555
|
+
state.topMore.textContent = state.loadingPage ? translate("board.loading") : translate("board.loadMore");
|
|
7556
|
+
state.latest.className = "hive-btn hive-btn-ghost hive-lane-latest" + (loaded > 0 ? "" : " is-hidden");
|
|
7557
|
+
state.more.disabled = state.loadingPage === true;
|
|
7558
|
+
state.more.textContent = state.loadingPage
|
|
7559
|
+
? translate("board.loading")
|
|
7560
|
+
: state.pageFailure
|
|
7561
|
+
? translate("board.retry")
|
|
7562
|
+
: translate("board.loadMore");
|
|
7563
|
+
state.pageError.className = "hive-lane-page-error" + (state.pageFailure ? "" : " is-hidden");
|
|
7564
|
+
state.pageError.textContent = state.pageFailure
|
|
7565
|
+
? translate("board.loadFailed") + ": " + state.pageFailure
|
|
7566
|
+
: "";
|
|
7130
7567
|
seen.add(lane);
|
|
7131
7568
|
}
|
|
7132
7569
|
for (const [lane, state] of laneRenderState) {
|
|
@@ -7227,6 +7664,8 @@ function renderMarkdownInto(doc, host, source) {
|
|
|
7227
7664
|
// --- data flow -----------------------------------------------------------
|
|
7228
7665
|
|
|
7229
7666
|
function resetRepoState() {
|
|
7667
|
+
for (const state of laneRenderState.values()) state.recycled = 0;
|
|
7668
|
+
resetLaneScroll();
|
|
7230
7669
|
initRequestSeq += 1;
|
|
7231
7670
|
initBusy = false;
|
|
7232
7671
|
initOutput = null;
|
package/src/data.js
CHANGED
|
@@ -53,6 +53,88 @@ export function isInitialised(repo) {
|
|
|
53
53
|
return INIT_MARKERS.some((marker) => fs.existsSync(path.join(repo, marker)));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
export const TASK_PAGE_LIMIT = 200;
|
|
57
|
+
|
|
58
|
+
function taskSortTime(task) {
|
|
59
|
+
const value = task && (task.stateChangedAt || task.updatedAt || task.createdAt);
|
|
60
|
+
const time = Date.parse(value || "");
|
|
61
|
+
if (Number.isFinite(time)) return time;
|
|
62
|
+
const id = String((task && task.id) || "");
|
|
63
|
+
const numeric = id.match(/(\d+)$/);
|
|
64
|
+
return numeric ? Number(numeric[1]) : Number.NaN;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function compareTasksNewestFirst(left, right) {
|
|
68
|
+
const leftTime = taskSortTime(left);
|
|
69
|
+
const rightTime = taskSortTime(right);
|
|
70
|
+
if (Number.isFinite(leftTime) && Number.isFinite(rightTime) && leftTime !== rightTime) {
|
|
71
|
+
return rightTime - leftTime;
|
|
72
|
+
}
|
|
73
|
+
if (Number.isFinite(leftTime) !== Number.isFinite(rightTime)) return Number.isFinite(leftTime) ? -1 : 1;
|
|
74
|
+
return String((right && right.id) || "").localeCompare(String((left && left.id) || ""));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function readTasks(repo, env = process.env) {
|
|
78
|
+
const tasks = env.HIVE_TASKS_BIN || "hive-tasks";
|
|
79
|
+
const rows = json(tasks, ["list", "--json"], repo, []);
|
|
80
|
+
return Array.isArray(rows) ? rows.filter((row) => row && typeof row === "object") : [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function readStats(repo, env = process.env) {
|
|
84
|
+
const tasks = env.HIVE_TASKS_BIN || "hive-tasks";
|
|
85
|
+
return json(tasks, ["stats", "--json"], repo, null);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function laneTotal(stats, state, rows) {
|
|
89
|
+
const byState = stats && stats.byState && typeof stats.byState === "object" ? stats.byState : null;
|
|
90
|
+
const value = byState ? Number(byState[state]) : Number.NaN;
|
|
91
|
+
return Number.isFinite(value) && value >= 0 ? value : rows.length;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function paginateTasks(tasks, stats, limit = TASK_PAGE_LIMIT) {
|
|
95
|
+
const size = Number.isFinite(limit) && limit > 0 ? Math.min(200, Math.floor(limit)) : TASK_PAGE_LIMIT;
|
|
96
|
+
const lanePages = {};
|
|
97
|
+
for (const state of ["pending", "claimed", "done", "failed"]) {
|
|
98
|
+
const rows = (Array.isArray(tasks) ? tasks : [])
|
|
99
|
+
.filter((task) => task && (task.state || "pending") === state)
|
|
100
|
+
.sort(compareTasksNewestFirst);
|
|
101
|
+
const items = rows.slice(0, size);
|
|
102
|
+
const total = laneTotal(stats, state, rows);
|
|
103
|
+
lanePages[state] = {
|
|
104
|
+
items,
|
|
105
|
+
total,
|
|
106
|
+
cursor: items.length,
|
|
107
|
+
hasMore: items.length < total,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return lanePages;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function snapshotTasksPage(repo, { state = "", cursor = 0, limit = TASK_PAGE_LIMIT, search = "" } = {}, env = process.env) {
|
|
114
|
+
let rows = readTasks(repo, env);
|
|
115
|
+
const query = String(search || "").trim().toLowerCase();
|
|
116
|
+
if (state) rows = rows.filter((task) => (task.state || "pending") === state);
|
|
117
|
+
if (query) {
|
|
118
|
+
rows = rows.filter((task) =>
|
|
119
|
+
String(task.id || "").toLowerCase().includes(query) ||
|
|
120
|
+
String(task.title || "").toLowerCase().includes(query),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
rows.sort(compareTasksNewestFirst);
|
|
124
|
+
const total = rows.length;
|
|
125
|
+
const offset = Math.max(0, Math.floor(Number(cursor) || 0));
|
|
126
|
+
const size = Math.max(1, Math.min(200, Math.floor(Number(limit) || TASK_PAGE_LIMIT)));
|
|
127
|
+
const items = rows.slice(offset, offset + size);
|
|
128
|
+
const next = offset + items.length;
|
|
129
|
+
return { items, total, cursor: next, hasMore: next < total, state: String(state || ""), search: String(search || "") };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function findTaskById(repo, id, env = process.env) {
|
|
133
|
+
const wanted = String(id || "");
|
|
134
|
+
if (!wanted) return null;
|
|
135
|
+
return readTasks(repo, env).find((task) => String(task.id || "") === wanted) || null;
|
|
136
|
+
}
|
|
137
|
+
|
|
56
138
|
export function snapshot(repo, env = process.env) {
|
|
57
139
|
const initialised = isInitialised(repo);
|
|
58
140
|
const data = {
|
|
@@ -65,13 +147,19 @@ export function snapshot(repo, env = process.env) {
|
|
|
65
147
|
stats: null,
|
|
66
148
|
events: readEvents(repo),
|
|
67
149
|
};
|
|
68
|
-
if (!initialised)
|
|
150
|
+
if (!initialised) {
|
|
151
|
+
data.lanePages = paginateTasks([], null);
|
|
152
|
+
return data;
|
|
153
|
+
}
|
|
69
154
|
const hive = env.HIVE_BIN || "hive";
|
|
70
|
-
const tasks = env
|
|
155
|
+
const tasks = readTasks(repo, env);
|
|
156
|
+
const stats = readStats(repo, env);
|
|
157
|
+
const lanePages = paginateTasks(tasks, stats);
|
|
71
158
|
return {
|
|
72
159
|
...data,
|
|
73
160
|
board: json(hive, ["board", "--json"], repo, []),
|
|
74
|
-
tasks:
|
|
75
|
-
|
|
161
|
+
tasks: Object.values(lanePages).flatMap((page) => page.items),
|
|
162
|
+
lanePages,
|
|
163
|
+
stats,
|
|
76
164
|
};
|
|
77
165
|
}
|
package/src/server.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import http from "node:http";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { execFile } from "node:child_process";
|
|
5
|
-
import { snapshot } from "./data.js";
|
|
5
|
+
import { findTaskById, snapshot, snapshotTasksPage } from "./data.js";
|
|
6
6
|
import { listActions, runAction } from "./actions.js";
|
|
7
7
|
|
|
8
8
|
const MIME = { ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8", ".svg": "image/svg+xml" };
|
|
@@ -44,6 +44,24 @@ export function createServer({ repo, publicDir, env = process.env, writable = fa
|
|
|
44
44
|
return response.end(JSON.stringify(data));
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
if (request.method === "GET" && url.pathname === "/api/tasks") {
|
|
48
|
+
const page = snapshotTasksPage(repo, {
|
|
49
|
+
state: url.searchParams.get("state") || "",
|
|
50
|
+
cursor: url.searchParams.get("cursor") || "0",
|
|
51
|
+
limit: url.searchParams.get("limit") || "200",
|
|
52
|
+
search: url.searchParams.get("search") || url.searchParams.get("q") || "",
|
|
53
|
+
}, env);
|
|
54
|
+
response.writeHead(200, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
|
|
55
|
+
return response.end(JSON.stringify(page));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (request.method === "GET" && url.pathname.startsWith("/api/tasks/")) {
|
|
59
|
+
const id = decodeURIComponent(url.pathname.slice("/api/tasks/".length));
|
|
60
|
+
const task = findTaskById(repo, id, env);
|
|
61
|
+
response.writeHead(task ? 200 : 404, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
|
|
62
|
+
return response.end(JSON.stringify(task ? { ok: true, task } : { ok: false, error: "task not found" }));
|
|
63
|
+
}
|
|
64
|
+
|
|
47
65
|
if (url.pathname === "/api/actions") {
|
|
48
66
|
response.writeHead(200, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
|
|
49
67
|
return response.end(JSON.stringify({ writable, actions: listActions() }));
|