@floless/app 0.149.1 → 0.151.0
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/dist/floless-server.cjs +104263 -88361
- package/dist/schemas/drawing-check.profile.v1.schema.json +45 -2
- package/dist/schemas/steel.model.v2.schema.json +9 -0
- package/dist/skills/floless-app-approval/SKILL.md +79 -4
- package/dist/skills/floless-app-onboarding/SKILL.md +200 -87
- package/dist/skills/floless-app-onboarding/references/aware-runtime.md +27 -18
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +207 -0
- package/dist/skills/floless-app-routines/SKILL.md +4 -1
- package/dist/skills/floless-app-routines/references/routines-api.md +14 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +4 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +14 -9
- package/dist/skills/floless-app-workflows/SKILL.md +2 -2
- package/dist/templates/tekla-parser.flo +13 -3
- package/dist/web/agents.js +983 -0
- package/dist/web/app.css +556 -43
- package/dist/web/app.js +34 -112
- package/dist/web/aware.js +1774 -169
- package/dist/web/chat.css +62 -1
- package/dist/web/chat.js +1666 -59
- package/dist/web/commands-drawing-check.js +15 -0
- package/dist/web/commands-revit.js +5 -0
- package/dist/web/commands-shell.js +955 -53
- package/dist/web/commands-tekla-parser.js +8 -1
- package/dist/web/connections.js +57 -14
- package/dist/web/drawing-check-editor.html +10 -2
- package/dist/web/drawing-check-editor.js +569 -40
- package/dist/web/drawing-check-overlay.js +45 -2
- package/dist/web/guide.js +675 -0
- package/dist/web/index.html +162 -31
- package/dist/web/instructor.js +91 -8
- package/dist/web/leave-guard.js +1 -0
- package/dist/web/left-pane.js +20 -1
- package/dist/web/local-discovery.js +12 -2
- package/dist/web/model-editor.css +32 -32
- package/dist/web/model-panel-bridge.js +11 -3
- package/dist/web/model-viewport-lighting.js +4 -2
- package/dist/web/model-viewport-revit-adapter.js +3 -0
- package/dist/web/model-viewport-toolbar.js +6 -3
- package/dist/web/model-viewport.js +11 -1
- package/dist/web/revit-editor.css +14 -14
- package/dist/web/revit-editor.js +64 -12
- package/dist/web/steel-3d-core.js +133 -0
- package/dist/web/steel-3d-view.js +10 -0
- package/dist/web/steel-editor.html +171 -39
- package/dist/web/steel-model-v2-client-validation.js +11 -0
- package/dist/web/steel-model-v2-commands.js +80 -5
- package/dist/web/tool-updates.js +533 -0
- package/dist/web/workspaces.js +896 -123
- package/package.json +2 -2
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +0 -156
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
/* ──────────────────────────────────────────────────────────────────────────
|
|
2
|
+
Approve updated workflows (#1997) — the footer pill and its dialog.
|
|
3
|
+
|
|
4
|
+
The browser owns no decision here. The server (tool-updates-service.ts)
|
|
5
|
+
downloads new tool versions, asks AWARE which approved workflows they
|
|
6
|
+
affect, prepares each one, and words what changed. This file renders that
|
|
7
|
+
view and sends ONE thing back: the person's click, naming the batch it
|
|
8
|
+
showed. Every string shown is the server's, set with textContent.
|
|
9
|
+
|
|
10
|
+
States: a pill only when something is offered or needs the person; the
|
|
11
|
+
dialog lists "Ready to approve" cards, "Needs you" rows, the downloads
|
|
12
|
+
line and the consequence footnote; after the click, the results replace
|
|
13
|
+
the cards in a live region.
|
|
14
|
+
────────────────────────────────────────────────────────────────────────── */
|
|
15
|
+
(function () {
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
var $pill = document.getElementById('tool-updates');
|
|
19
|
+
var $modal = document.getElementById('tool-updates-modal');
|
|
20
|
+
if (!$pill || !$modal) return;
|
|
21
|
+
var $dialog = $modal.querySelector('.tool-updates-dialog');
|
|
22
|
+
var $title = document.getElementById('tool-updates-title');
|
|
23
|
+
var $body = document.getElementById('tool-updates-body');
|
|
24
|
+
var $live = document.getElementById('tool-updates-live');
|
|
25
|
+
var $foot = document.getElementById('tool-updates-foot');
|
|
26
|
+
var $check = document.getElementById('tool-updates-check');
|
|
27
|
+
var $cancel = document.getElementById('tool-updates-cancel');
|
|
28
|
+
var $approve = document.getElementById('tool-updates-approve');
|
|
29
|
+
|
|
30
|
+
var view = null;
|
|
31
|
+
var results = null;
|
|
32
|
+
|
|
33
|
+
// ── The view never goes back in time (#2013; also closes #1997's stale-answer race) ──────────────────────
|
|
34
|
+
// Every change to the view comes from a request this page sends — the server's `tool-updates-changed` broadcast only
|
|
35
|
+
// starts a re-read, which is a request like any other. Each request takes a ticket when it is SENT; its answer
|
|
36
|
+
// replaces the view only if no answer to a later-sent request has been applied yet. An older answer still shows its
|
|
37
|
+
// own results and sentence, never its view. Nothing here depends on a server counter, so a server restart with this
|
|
38
|
+
// tab still open changes nothing: the next answer simply applies.
|
|
39
|
+
var sentTicket = 0;
|
|
40
|
+
var appliedTicket = 0;
|
|
41
|
+
|
|
42
|
+
function nextTicket() { sentTicket += 1; return sentTicket; }
|
|
43
|
+
|
|
44
|
+
/** Apply `next` (a whole view, its cleanup beside it) from the request holding `ticket`. False when superseded. */
|
|
45
|
+
function applyView(ticket, next) {
|
|
46
|
+
if (!next || ticket < appliedTicket) return false;
|
|
47
|
+
appliedTicket = ticket;
|
|
48
|
+
view = next;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Apply a cleanup view on its own (Remove from list answers with only that part), under the same ticket rule. */
|
|
53
|
+
function applyCleanup(ticket, next) {
|
|
54
|
+
if (!view || !next || ticket < appliedTicket) return false;
|
|
55
|
+
appliedTicket = ticket;
|
|
56
|
+
view = Object.assign({}, view, { cleanup: next });
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
var busy = false;
|
|
60
|
+
var returnFocus = null;
|
|
61
|
+
|
|
62
|
+
function el(tag, cls, text) {
|
|
63
|
+
var node = document.createElement(tag);
|
|
64
|
+
if (cls) node.className = cls;
|
|
65
|
+
if (text != null) node.textContent = text;
|
|
66
|
+
return node;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function plural(n, one, many) { return n + ' ' + (n === 1 ? one : many); }
|
|
70
|
+
|
|
71
|
+
async function call(path, method, payload) {
|
|
72
|
+
var res = await fetch(path, { method: method || 'GET', headers: { 'content-type': 'application/json' }, body: payload });
|
|
73
|
+
var body = await res.json().catch(function () { return { ok: false, error: 'FloLess received an unreadable answer (HTTP ' + res.status + ').' }; });
|
|
74
|
+
if (!res.ok && body.ok !== true && !body.results) {
|
|
75
|
+
var error = new Error(body.error || ('HTTP ' + res.status));
|
|
76
|
+
error.body = body;
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
return body;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// #2013: AWARE's cleanup of unused tool versions, as the server words it (agent-store-cleanup.ts).
|
|
83
|
+
function cleanupNeeds() {
|
|
84
|
+
var c = view && view.cleanup;
|
|
85
|
+
return c && c.supported && Array.isArray(c.needsYou) ? c.needsYou : [];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ── The footer pill ────────────────────────────────────────────────────────
|
|
89
|
+
function paintPill() {
|
|
90
|
+
var offers = view && view.supported ? view.offers || [] : [];
|
|
91
|
+
var needs = view && view.supported ? view.needsYou || [] : [];
|
|
92
|
+
var cleanup = cleanupNeeds();
|
|
93
|
+
var urgent = offers.filter(function (o) { return !!o.advisory; }).length;
|
|
94
|
+
if (!offers.length && !needs.length && !cleanup.length) {
|
|
95
|
+
$pill.hidden = true;
|
|
96
|
+
$pill.removeAttribute('data-state');
|
|
97
|
+
if ($modal.classList.contains('show') && !results) paint();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
var text;
|
|
101
|
+
var state = 'offer';
|
|
102
|
+
if (offers.length) {
|
|
103
|
+
text = plural(offers.length, 'workflow update', 'workflow updates');
|
|
104
|
+
if (urgent) {
|
|
105
|
+
state = 'urgent';
|
|
106
|
+
// AWARE's notice says "urgent", never what kind: the pill does not call it a security fix.
|
|
107
|
+
text = urgent === offers.length && offers.length === 1 ? 'Urgent update · 1 workflow' : text + ' · ' + urgent + ' urgent';
|
|
108
|
+
} else if (view.nudge) {
|
|
109
|
+
state = 'nudge';
|
|
110
|
+
var days = Math.max.apply(null, offers.map(function (o) { return o.waitingDays || 0; }));
|
|
111
|
+
text += ' · waiting ' + plural(days, 'day', 'days');
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
state = 'needs';
|
|
115
|
+
var folders = cleanup.filter(function (c) { return c.kind !== 'unreadable'; }).length;
|
|
116
|
+
if (needs.length && cleanup.length) text = (needs.length + cleanup.length) + ' things need you';
|
|
117
|
+
else if (needs.length) text = plural(needs.length, 'workflow needs you', 'workflows need you');
|
|
118
|
+
else if (folders === cleanup.length) text = plural(folders, 'folder needs you', 'folders need you');
|
|
119
|
+
else text = plural(cleanup.length, 'item needs you', 'items need you');
|
|
120
|
+
}
|
|
121
|
+
$pill.textContent = text;
|
|
122
|
+
$pill.setAttribute('data-state', state);
|
|
123
|
+
$pill.hidden = false;
|
|
124
|
+
if ($modal.classList.contains('show') && !busy && !results) paint();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ── The dialog ─────────────────────────────────────────────────────────────
|
|
128
|
+
function toolLine(change) {
|
|
129
|
+
var row = el('div', 'tool-updates-change');
|
|
130
|
+
var name = el('span', 'tool-updates-change-line', change.line);
|
|
131
|
+
row.appendChild(name);
|
|
132
|
+
return row;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function offerCard(offer) {
|
|
136
|
+
var card = el('div', 'tool-updates-card');
|
|
137
|
+
card.setAttribute('data-app', offer.app);
|
|
138
|
+
var head = el('div', 'tool-updates-card-head');
|
|
139
|
+
head.appendChild(el('span', 'tool-updates-card-name', offer.workflowName));
|
|
140
|
+
if (offer.waitingDays >= 1) head.appendChild(el('span', 'tool-updates-waiting', 'waiting ' + plural(offer.waitingDays, 'day', 'days')));
|
|
141
|
+
card.appendChild(head);
|
|
142
|
+
(offer.changes || []).forEach(function (change) { card.appendChild(toolLine(change)); });
|
|
143
|
+
if (offer.effect) {
|
|
144
|
+
var effect = el('div', 'tool-updates-effect', offer.effect);
|
|
145
|
+
effect.setAttribute('data-effect', /^Only reads/.test(offer.effect) ? 'read' : 'write');
|
|
146
|
+
card.appendChild(effect);
|
|
147
|
+
}
|
|
148
|
+
var details = [];
|
|
149
|
+
(offer.changes || []).forEach(function (change) { (change.details || []).forEach(function (d) { details.push(d); }); });
|
|
150
|
+
if (offer.comparison) details.push(offer.comparison);
|
|
151
|
+
if (details.length) {
|
|
152
|
+
var more = el('details', 'tool-updates-more');
|
|
153
|
+
more.appendChild(el('summary', null, 'What changed for this workflow'));
|
|
154
|
+
details.forEach(function (line) { more.appendChild(el('div', 'tool-updates-more-line', line)); });
|
|
155
|
+
card.appendChild(more);
|
|
156
|
+
}
|
|
157
|
+
return card;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function needsRow(item) {
|
|
161
|
+
var row = el('div', 'tool-updates-needs');
|
|
162
|
+
row.setAttribute('data-app', item.app);
|
|
163
|
+
row.setAttribute('data-kind', item.kind);
|
|
164
|
+
var text = el('div', 'tool-updates-needs-text');
|
|
165
|
+
text.appendChild(el('span', 'tool-updates-needs-name', item.workflowName));
|
|
166
|
+
text.appendChild(el('span', 'tool-updates-needs-sentence', item.sentence));
|
|
167
|
+
row.appendChild(text);
|
|
168
|
+
var bridge = window.flolessBridge;
|
|
169
|
+
// Offered only for a workflow the Workflows page lists — one installed from a terminal cannot be opened here.
|
|
170
|
+
if (item.action === 'open-workflow' && bridge && typeof bridge.openApp === 'function'
|
|
171
|
+
&& typeof bridge.canOpenApp === 'function' && bridge.canOpenApp(item.app)) {
|
|
172
|
+
var openButton = el('button', 'tool-updates-open', 'Open workflow');
|
|
173
|
+
openButton.type = 'button';
|
|
174
|
+
openButton.setAttribute('data-command-id', 'shell.tool-updates-open-workflow');
|
|
175
|
+
openButton.setAttribute('data-tip', 'Open ' + item.workflowName + ' to do this');
|
|
176
|
+
openButton.addEventListener('click', function () {
|
|
177
|
+
close();
|
|
178
|
+
Promise.resolve(bridge.openApp(item.app)).catch(function (error) {
|
|
179
|
+
console.warn('could not open the workflow', error);
|
|
180
|
+
// Back to the dialog, with the reason in its live line (open() clears that line, so it is set after).
|
|
181
|
+
open($pill.hidden ? null : $pill);
|
|
182
|
+
$live.textContent = error.message;
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
row.appendChild(openButton);
|
|
186
|
+
}
|
|
187
|
+
return row;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var forgetting = null; // the path being removed from the list, while its request is in flight
|
|
191
|
+
|
|
192
|
+
function cleanupRow(item) {
|
|
193
|
+
var row = el('div', 'tool-updates-needs');
|
|
194
|
+
row.setAttribute('data-kind', 'cleanup-' + item.kind);
|
|
195
|
+
row.setAttribute('data-path', item.path);
|
|
196
|
+
var text = el('div', 'tool-updates-needs-text');
|
|
197
|
+
text.appendChild(el('span', 'tool-updates-needs-name', item.name || item.path));
|
|
198
|
+
text.appendChild(el('span', 'tool-updates-needs-sentence', item.sentence));
|
|
199
|
+
row.appendChild(text);
|
|
200
|
+
if (item.action === 'forget-folder') {
|
|
201
|
+
var busyHere = forgetting === item.path;
|
|
202
|
+
var button = el('button', 'tool-updates-open', busyHere ? 'Removing…' : 'Remove from list');
|
|
203
|
+
button.type = 'button';
|
|
204
|
+
button.disabled = busyHere || busy;
|
|
205
|
+
button.setAttribute('data-command-id', 'shell.tool-updates-forget-folder');
|
|
206
|
+
button.setAttribute('data-tip', 'Stop keeping old tool versions for the workflows in this folder');
|
|
207
|
+
button.setAttribute('aria-label', 'Remove ' + (item.name || item.path) + ' from the list');
|
|
208
|
+
button.addEventListener('click', function () { void forgetFolder(item); });
|
|
209
|
+
row.appendChild(button);
|
|
210
|
+
}
|
|
211
|
+
return row;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function forgetFolder(item) {
|
|
215
|
+
if (busy || forgetting) return;
|
|
216
|
+
var path = item.path;
|
|
217
|
+
var ok = false;
|
|
218
|
+
forgetting = path;
|
|
219
|
+
paint();
|
|
220
|
+
$live.textContent = 'Removing ' + (item.name || path) + ' from the list…';
|
|
221
|
+
var ticket = nextTicket();
|
|
222
|
+
try {
|
|
223
|
+
var body = await call('/api/tool-updates/forget-folder', 'POST', JSON.stringify({ path: path }));
|
|
224
|
+
applyCleanup(ticket, body.cleanup);
|
|
225
|
+
// The server answers 200 with ok:false when it kept the folder (it came back, or AWARE could not be asked).
|
|
226
|
+
ok = body.ok !== false;
|
|
227
|
+
$live.textContent = body.sentence || (ok ? 'Removed from the list.' : 'Nothing was removed from the list. Try again.');
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (error.body) applyCleanup(ticket, error.body.cleanup);
|
|
230
|
+
$live.textContent = error.message + ' Nothing was removed from the list.';
|
|
231
|
+
} finally {
|
|
232
|
+
forgetting = null;
|
|
233
|
+
paint();
|
|
234
|
+
paintPill();
|
|
235
|
+
// Focus never drops to the page: the next Remove button, else the section, else the title.
|
|
236
|
+
var next = $body.querySelector('[data-command-id="shell.tool-updates-forget-folder"]:not([disabled])');
|
|
237
|
+
var stay = !ok && $body.querySelector('.tool-updates-needs[data-path="' + CSS.escape(path) + '"] button');
|
|
238
|
+
var head = $body.querySelector('.tool-updates-section-head');
|
|
239
|
+
if (stay) stay.focus();
|
|
240
|
+
else if (next) next.focus();
|
|
241
|
+
else if (head) { head.tabIndex = -1; head.focus(); }
|
|
242
|
+
else $title.focus();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function cleanupLines() {
|
|
247
|
+
var c = view && view.cleanup;
|
|
248
|
+
if (!c) return [];
|
|
249
|
+
// An AWARE too old to clean up: one short line, no pill and no row.
|
|
250
|
+
if (!c.supported) return c.sentence ? [c.sentence] : [];
|
|
251
|
+
var lines = [];
|
|
252
|
+
if (c.sentence) lines.push(c.sentence);
|
|
253
|
+
if (c.waiting === 'runs') lines.push('Cleaning up unused tool versions waits until no workflow is running.');
|
|
254
|
+
else if (c.waiting === 'runs-unknown') lines.push('FloLess could not ask AWARE which workflows are running, so cleaning up unused tool versions waits and tries again later.');
|
|
255
|
+
else if (c.waiting === 'busy') lines.push('Cleaning up unused tool versions waits until AWARE is done with other tool work.');
|
|
256
|
+
else if (c.waiting === 'network-volume') lines.push('AWARE does not clean up tool versions stored on a network drive.');
|
|
257
|
+
var last = c.lastCleanup;
|
|
258
|
+
if (last && last.removed > 0) {
|
|
259
|
+
var at = new Date(last.at);
|
|
260
|
+
var when = isNaN(at.getTime()) ? '' : ' (' + at.toLocaleString([], { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' }) + ')';
|
|
261
|
+
var all = last.tools || [];
|
|
262
|
+
var tools = all.slice(0, 3).join(', ') + (all.length > 3 ? ' and ' + (all.length - 3) + ' more' : '');
|
|
263
|
+
lines.push('Cleaned up ' + plural(last.removed, 'unused tool version', 'unused tool versions') + (tools ? ': ' + tools : '') + when + '.');
|
|
264
|
+
}
|
|
265
|
+
return lines;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function section(title, count) {
|
|
269
|
+
var wrap = el('div', 'tool-updates-section');
|
|
270
|
+
wrap.appendChild(el('div', 'tool-updates-section-head', title + ' (' + count + ')'));
|
|
271
|
+
return wrap;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function resultRow(result) {
|
|
275
|
+
var row = el('div', 'tool-updates-result');
|
|
276
|
+
row.setAttribute('data-outcome', result.outcome);
|
|
277
|
+
row.setAttribute('data-app', result.app);
|
|
278
|
+
row.appendChild(el('span', 'tool-updates-result-mark', result.outcome === 'moved' ? '✓' : '!')).setAttribute('aria-hidden', 'true');
|
|
279
|
+
var text = el('div', 'tool-updates-result-text');
|
|
280
|
+
text.appendChild(el('span', 'tool-updates-result-name', result.workflowName));
|
|
281
|
+
text.appendChild(el('span', 'tool-updates-result-sentence', result.sentence));
|
|
282
|
+
if (result.label) text.appendChild(el('span', 'tool-updates-result-label', result.label));
|
|
283
|
+
row.appendChild(text);
|
|
284
|
+
return row;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function lastChecked() {
|
|
288
|
+
if (!view || !view.checkedAt) return '';
|
|
289
|
+
var at = new Date(view.checkedAt);
|
|
290
|
+
if (isNaN(at.getTime())) return '';
|
|
291
|
+
return 'Last checked ' + at.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) + '.';
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function downloadsLine() {
|
|
295
|
+
var d = view && view.downloads;
|
|
296
|
+
if (!d) return '';
|
|
297
|
+
if (d.error) return d.error;
|
|
298
|
+
if (d.waitingForRuns) return 'Waiting for ' + plural(d.waitingForRuns, 'run', 'runs') + ' to finish before downloading new tool versions (at most a day).';
|
|
299
|
+
// The same version downloaded again (after a manual downgrade, say) is named once.
|
|
300
|
+
var names = [];
|
|
301
|
+
(d.recent || []).forEach(function (r) {
|
|
302
|
+
var name = r.tool + ' ' + r.to;
|
|
303
|
+
if (names.indexOf(name) < 0) names.push(name);
|
|
304
|
+
});
|
|
305
|
+
names = names.slice(-3);
|
|
306
|
+
if (!names.length) return '';
|
|
307
|
+
return 'Downloaded in the background: ' + names.join(', ') + '.';
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** Where focus is inside the body, as something that survives a repaint (a refresh can land at any time). */
|
|
311
|
+
function focusKey() {
|
|
312
|
+
var active = document.activeElement;
|
|
313
|
+
if (!active || !$body.contains(active)) return null;
|
|
314
|
+
var row = active.closest && active.closest('.tool-updates-needs');
|
|
315
|
+
return {
|
|
316
|
+
command: active.getAttribute('data-command-id'),
|
|
317
|
+
path: row && row.getAttribute('data-path'),
|
|
318
|
+
app: row && row.getAttribute('data-app'),
|
|
319
|
+
head: active.classList.contains('tool-updates-section-head'),
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function restoreFocus(key) {
|
|
324
|
+
if (!key) return;
|
|
325
|
+
var target = null;
|
|
326
|
+
if (key.head) target = $body.querySelector('.tool-updates-section-head');
|
|
327
|
+
else if (key.command) {
|
|
328
|
+
target = Array.prototype.find.call($body.querySelectorAll('[data-command-id="' + key.command + '"]'), function (b) {
|
|
329
|
+
var row = b.closest('.tool-updates-needs');
|
|
330
|
+
return !row || (row.getAttribute('data-path') === key.path && row.getAttribute('data-app') === key.app);
|
|
331
|
+
}) || null;
|
|
332
|
+
}
|
|
333
|
+
if (target && target.offsetParent !== null) {
|
|
334
|
+
if (key.head) target.tabIndex = -1;
|
|
335
|
+
target.focus();
|
|
336
|
+
} else {
|
|
337
|
+
$title.focus(); // its row went away: never leave focus on the page behind the dialog
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function paint() {
|
|
342
|
+
var keepFocus = focusKey();
|
|
343
|
+
try { paintNow(); } finally { restoreFocus(keepFocus); }
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function paintNow() {
|
|
347
|
+
$body.textContent = '';
|
|
348
|
+
$foot.textContent = '';
|
|
349
|
+
var offers = (view && view.offers) || [];
|
|
350
|
+
var needs = (view && view.needsYou) || [];
|
|
351
|
+
if (view && !view.supported) {
|
|
352
|
+
$body.appendChild(el('div', 'tool-updates-summary', view.sentence || 'Tool updates are not available on this computer.'));
|
|
353
|
+
} else if (view && view.sentence) {
|
|
354
|
+
$body.appendChild(el('div', 'tool-updates-summary', view.sentence));
|
|
355
|
+
}
|
|
356
|
+
if (results) {
|
|
357
|
+
var done = section('Results', results.length);
|
|
358
|
+
done.querySelector('.tool-updates-section-head').id = 'tool-updates-results-head';
|
|
359
|
+
done.querySelector('.tool-updates-section-head').tabIndex = -1;
|
|
360
|
+
results.forEach(function (r) { done.appendChild(resultRow(r)); });
|
|
361
|
+
$body.appendChild(done);
|
|
362
|
+
} else {
|
|
363
|
+
var urgent = offers.filter(function (o) { return !!o.advisory; });
|
|
364
|
+
if (urgent.length) {
|
|
365
|
+
var banner = el('div', 'tool-updates-urgent');
|
|
366
|
+
banner.setAttribute('role', 'note');
|
|
367
|
+
banner.appendChild(el('div', 'tool-updates-urgent-head', 'AWARE marked ' + (urgent.length === 1 ? 'this update' : 'these updates') + ' urgent'));
|
|
368
|
+
urgent.forEach(function (o) { banner.appendChild(el('div', 'tool-updates-urgent-text', o.workflowName + ': ' + o.advisory)); });
|
|
369
|
+
banner.appendChild(el('div', 'tool-updates-urgent-note', 'Approving is still your decision.'));
|
|
370
|
+
$body.appendChild(banner);
|
|
371
|
+
}
|
|
372
|
+
if (offers.length) {
|
|
373
|
+
var ready = section('Ready to approve', offers.length);
|
|
374
|
+
offers.forEach(function (o) { ready.appendChild(offerCard(o)); });
|
|
375
|
+
$body.appendChild(ready);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
var cleanup = cleanupNeeds();
|
|
379
|
+
if (needs.length || cleanup.length) {
|
|
380
|
+
var needsSection = section('Needs you', needs.length + cleanup.length);
|
|
381
|
+
needs.forEach(function (n) { needsSection.appendChild(needsRow(n)); });
|
|
382
|
+
cleanup.forEach(function (n) { needsSection.appendChild(cleanupRow(n)); });
|
|
383
|
+
$body.appendChild(needsSection);
|
|
384
|
+
}
|
|
385
|
+
if (!results && !offers.length && !needs.length && !cleanup.length && view && view.supported && !view.sentence) {
|
|
386
|
+
$body.appendChild(el('div', 'tool-updates-summary', view.checking
|
|
387
|
+
? 'Checking which workflows a tool update affects…'
|
|
388
|
+
: 'All your workflows are on the tool versions you approved.'));
|
|
389
|
+
}
|
|
390
|
+
var dl = downloadsLine();
|
|
391
|
+
if (dl) $foot.appendChild(el('div', 'tool-updates-downloads', dl));
|
|
392
|
+
cleanupLines().forEach(function (line) { $foot.appendChild(el('div', 'tool-updates-downloads', line)); });
|
|
393
|
+
var checked = lastChecked();
|
|
394
|
+
if (checked) $foot.appendChild(el('div', 'tool-updates-downloads', checked));
|
|
395
|
+
if (!results && offers.length) {
|
|
396
|
+
$foot.appendChild(el('div', 'tool-updates-note', 'Approving moves these workflows to the new tool versions. Each workflow’s own steps stay exactly as you approved them. AWARE records this as your approval, made here in FloLess.'));
|
|
397
|
+
}
|
|
398
|
+
var canApprove = !results && offers.length > 0 && !!(view && view.batchId);
|
|
399
|
+
$approve.hidden = !canApprove;
|
|
400
|
+
if (canApprove) $approve.textContent = 'Approve ' + plural(offers.length, 'workflow', 'workflows');
|
|
401
|
+
$check.hidden = !!results || !(view && view.supported);
|
|
402
|
+
$cancel.textContent = results ? 'Done' : 'Not now';
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function setBusy(on, label) {
|
|
406
|
+
busy = on;
|
|
407
|
+
$modal.setAttribute('aria-busy', on ? 'true' : 'false');
|
|
408
|
+
[$check, $cancel, $approve].forEach(function (b) { b.disabled = on; });
|
|
409
|
+
Array.prototype.forEach.call($body.querySelectorAll('[data-command-id="shell.tool-updates-forget-folder"]'), function (b) { b.disabled = on || !!forgetting; });
|
|
410
|
+
if (on && label) $approve.textContent = label;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
async function refresh() {
|
|
414
|
+
var ticket = nextTicket();
|
|
415
|
+
try {
|
|
416
|
+
var body = await call('/api/tool-updates');
|
|
417
|
+
applyView(ticket, body);
|
|
418
|
+
} catch (error) {
|
|
419
|
+
// Keep the last answer on screen (and its pill): a dropped request is not "nothing to update".
|
|
420
|
+
console.warn('tool updates unavailable', error);
|
|
421
|
+
if ($modal.classList.contains('show') && !busy) $live.textContent = 'FloLess could not check for tool updates just now. What is shown is from the last check.';
|
|
422
|
+
}
|
|
423
|
+
paintPill();
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function open(fromEl) {
|
|
427
|
+
returnFocus = fromEl || (document.activeElement instanceof HTMLElement ? document.activeElement : null);
|
|
428
|
+
results = null;
|
|
429
|
+
$live.textContent = '';
|
|
430
|
+
paint();
|
|
431
|
+
$modal.classList.add('show');
|
|
432
|
+
// Focus the title, not the primary: approving is consequential and Enter on open must not do it.
|
|
433
|
+
setTimeout(function () { $title.focus(); }, 0);
|
|
434
|
+
void refresh().then(function () { if ($modal.classList.contains('show') && !busy && !results) paint(); });
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function close() {
|
|
438
|
+
if (busy) return;
|
|
439
|
+
$modal.classList.remove('show');
|
|
440
|
+
if (results) { results = null; }
|
|
441
|
+
if (returnFocus && document.contains(returnFocus)) returnFocus.focus();
|
|
442
|
+
returnFocus = null;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
$pill.addEventListener('click', function () { open($pill); });
|
|
446
|
+
$cancel.addEventListener('click', close);
|
|
447
|
+
$modal.addEventListener('mousedown', function (e) { if (e.target === $modal) close(); });
|
|
448
|
+
$modal.addEventListener('keydown', function (e) {
|
|
449
|
+
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); close(); return; }
|
|
450
|
+
if (e.key !== 'Tab') return;
|
|
451
|
+
var focusables = Array.prototype.filter.call(
|
|
452
|
+
$dialog.querySelectorAll('button, summary, [href], [tabindex]:not([tabindex="-1"])'),
|
|
453
|
+
function (n) { return !n.disabled && !n.hidden && n.offsetParent !== null; },
|
|
454
|
+
);
|
|
455
|
+
if (!focusables.length) return;
|
|
456
|
+
var first = focusables[0];
|
|
457
|
+
var last = focusables[focusables.length - 1];
|
|
458
|
+
if (e.shiftKey && (document.activeElement === first || document.activeElement === $title)) { e.preventDefault(); last.focus(); }
|
|
459
|
+
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
$check.addEventListener('click', async function () {
|
|
463
|
+
setBusy(true);
|
|
464
|
+
$live.textContent = 'Checking for new tool versions…';
|
|
465
|
+
try {
|
|
466
|
+
var ticket = nextTicket();
|
|
467
|
+
var answer = await call('/api/tool-updates/check', 'POST');
|
|
468
|
+
applyView(ticket, answer);
|
|
469
|
+
var n = (answer.offers || []).length;
|
|
470
|
+
$live.textContent = n ? plural(n, 'workflow is', 'workflows are') + ' ready to approve.' : 'No workflows to approve.';
|
|
471
|
+
// The cleanup pass Check now started keeps running after this answer, and may already have finished and been
|
|
472
|
+
// re-read: read the server again so this (older) answer never stands over a newer cleanup result.
|
|
473
|
+
void refresh();
|
|
474
|
+
} catch (error) {
|
|
475
|
+
$live.textContent = error.message;
|
|
476
|
+
} finally {
|
|
477
|
+
setBusy(false);
|
|
478
|
+
paint();
|
|
479
|
+
paintPill();
|
|
480
|
+
// The button was disabled while busy, which drops focus to the page: put it back where the person was.
|
|
481
|
+
if (!$check.hidden) $check.focus(); else $title.focus();
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
$approve.addEventListener('click', async function () {
|
|
486
|
+
if (!view || !view.batchId) return;
|
|
487
|
+
var apps = (view.offers || []).map(function (o) { return o.app; });
|
|
488
|
+
setBusy(true, 'Approving…');
|
|
489
|
+
$live.textContent = 'Approving ' + plural(apps.length, 'workflow', 'workflows') + '…';
|
|
490
|
+
try {
|
|
491
|
+
var ticket = nextTicket();
|
|
492
|
+
var body = await call('/api/tool-updates/approve', 'POST', JSON.stringify({ batchId: view.batchId, apps: apps }));
|
|
493
|
+
// The approval answer carries the batch view and, beside it, the cleanup view (#2013). Its results always show;
|
|
494
|
+
// its view only if nothing newer was applied while the approval ran.
|
|
495
|
+
if (body.view) applyView(ticket, Object.assign({}, body.view, { cleanup: body.cleanup !== undefined ? body.cleanup : (view && view.cleanup) }));
|
|
496
|
+
else applyCleanup(ticket, body.cleanup);
|
|
497
|
+
if (body.ok) {
|
|
498
|
+
results = body.results || [];
|
|
499
|
+
var moved = results.filter(function (r) { return r.outcome === 'moved'; }).length;
|
|
500
|
+
$live.textContent = moved === results.length
|
|
501
|
+
? plural(moved, 'workflow now runs', 'workflows now run') + ' on the new tool versions.'
|
|
502
|
+
: moved + ' of ' + results.length + ' moved. The others say why below.';
|
|
503
|
+
} else {
|
|
504
|
+
$live.textContent = body.sentence || body.error || 'Nothing was moved. Review it again.';
|
|
505
|
+
}
|
|
506
|
+
} catch (error) {
|
|
507
|
+
// The answer was lost on the way back: the server may have moved some workflows. Ask again rather than guess.
|
|
508
|
+
console.warn('approve answer not received', error);
|
|
509
|
+
await refresh();
|
|
510
|
+
$live.textContent = 'FloLess did not hear back after your approval, so it cannot say yet which workflows moved. The list below is what is still waiting.';
|
|
511
|
+
} finally {
|
|
512
|
+
setBusy(false);
|
|
513
|
+
paint();
|
|
514
|
+
paintPill();
|
|
515
|
+
var head = document.getElementById('tool-updates-results-head');
|
|
516
|
+
if (head) head.focus(); else $title.focus();
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
// The ≡ menu's "Tool updates…" — the way in when the pill has nothing to show (to check for new versions now).
|
|
521
|
+
if (typeof window.handleMenuAction === 'function') {
|
|
522
|
+
var previousMenuAction = window.handleMenuAction;
|
|
523
|
+
window.handleMenuAction = function (action) {
|
|
524
|
+
if (action === 'tool-updates') { open(document.getElementById('menu-btn')); return; }
|
|
525
|
+
previousMenuAction(action);
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
window.addEventListener('floless:tool-updates-changed', function () { void refresh(); });
|
|
530
|
+
window.addEventListener('floless:apps-changed', function () { void refresh(); });
|
|
531
|
+
window.flolessToolUpdates = { refresh: refresh, open: open };
|
|
532
|
+
void refresh();
|
|
533
|
+
})();
|