nacho-python 0.0.1__py3-none-any.whl
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.
- nacho/__init__.py +39 -0
- nacho/_version.py +4 -0
- nacho/cli/__init__.py +11 -0
- nacho/cli/main.py +638 -0
- nacho/config.py +544 -0
- nacho/env.py +117 -0
- nacho/event.py +409 -0
- nacho/schema.py +121 -0
- nacho/server/__init__.py +35 -0
- nacho/server/app.py +515 -0
- nacho/server/auth.py +93 -0
- nacho/server/models.py +165 -0
- nacho/server/runtime.py +452 -0
- nacho/server/ui/index.html +1282 -0
- nacho/storage/__init__.py +27 -0
- nacho/storage/base.py +33 -0
- nacho/storage/file.py +40 -0
- nacho/storage/remote.py +293 -0
- nacho/utils/__init__.py +14 -0
- nacho/utils/io.py +143 -0
- nacho/utils/path.py +145 -0
- nacho_python-0.0.1.dist-info/METADATA +605 -0
- nacho_python-0.0.1.dist-info/RECORD +27 -0
- nacho_python-0.0.1.dist-info/WHEEL +5 -0
- nacho_python-0.0.1.dist-info/entry_points.txt +2 -0
- nacho_python-0.0.1.dist-info/licenses/LICENSE +21 -0
- nacho_python-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1282 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Nacho — Configuration Manager</title>
|
|
7
|
+
<style>
|
|
8
|
+
/* --------------------------------------------------------------------- */
|
|
9
|
+
/* Theme */
|
|
10
|
+
/* --------------------------------------------------------------------- */
|
|
11
|
+
:root {
|
|
12
|
+
--bg: #f6f6f3;
|
|
13
|
+
--surface: #ffffff;
|
|
14
|
+
--surface-2: #f0f0ec;
|
|
15
|
+
--border: #e3e3dc;
|
|
16
|
+
--text: #1e1e1b;
|
|
17
|
+
--muted: #76766c;
|
|
18
|
+
--accent: #d6892a;
|
|
19
|
+
--accent-fg: #ffffff;
|
|
20
|
+
--danger: #c4463a;
|
|
21
|
+
--ok: #2f9e5f;
|
|
22
|
+
--c-str: #2f8f4e;
|
|
23
|
+
--c-num: #2f6fb0;
|
|
24
|
+
--c-kw: #9b5cb8;
|
|
25
|
+
--radius: 8px;
|
|
26
|
+
--mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
|
|
27
|
+
--sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
28
|
+
}
|
|
29
|
+
@media (prefers-color-scheme: dark) {
|
|
30
|
+
:root {
|
|
31
|
+
--bg: #1a1a17;
|
|
32
|
+
--surface: #232320;
|
|
33
|
+
--surface-2: #2c2c27;
|
|
34
|
+
--border: #38382f;
|
|
35
|
+
--text: #ececea;
|
|
36
|
+
--muted: #9a9a8f;
|
|
37
|
+
--accent: #e0a44a;
|
|
38
|
+
--accent-fg: #1a1a17;
|
|
39
|
+
--danger: #e0685c;
|
|
40
|
+
--ok: #4cb878;
|
|
41
|
+
--c-str: #6cc28a;
|
|
42
|
+
--c-num: #6aa8e0;
|
|
43
|
+
--c-kw: #c08fda;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
* { box-sizing: border-box; }
|
|
48
|
+
html, body { height: 100%; }
|
|
49
|
+
body {
|
|
50
|
+
margin: 0;
|
|
51
|
+
font-family: var(--sans);
|
|
52
|
+
background: var(--bg);
|
|
53
|
+
color: var(--text);
|
|
54
|
+
font-size: 14px;
|
|
55
|
+
line-height: 1.5;
|
|
56
|
+
}
|
|
57
|
+
button { font-family: inherit; font-size: 13px; cursor: pointer; }
|
|
58
|
+
input, textarea, select { font-family: inherit; font-size: 13px; }
|
|
59
|
+
h1, h2, h3 { margin: 0; font-weight: 600; }
|
|
60
|
+
.hidden { display: none !important; }
|
|
61
|
+
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
|
|
62
|
+
|
|
63
|
+
/* --------------------------------------------------------------------- */
|
|
64
|
+
/* Wordmark */
|
|
65
|
+
/* --------------------------------------------------------------------- */
|
|
66
|
+
.wordmark {
|
|
67
|
+
font-weight: 650;
|
|
68
|
+
letter-spacing: -0.022em;
|
|
69
|
+
font-family: var(--sans);
|
|
70
|
+
user-select: none;
|
|
71
|
+
}
|
|
72
|
+
.wordmark .wm-dot { color: var(--accent); }
|
|
73
|
+
|
|
74
|
+
/* --------------------------------------------------------------------- */
|
|
75
|
+
/* Buttons & form controls */
|
|
76
|
+
/* --------------------------------------------------------------------- */
|
|
77
|
+
.btn {
|
|
78
|
+
border: 1px solid var(--border);
|
|
79
|
+
background: var(--surface);
|
|
80
|
+
color: var(--text);
|
|
81
|
+
padding: 6px 12px;
|
|
82
|
+
border-radius: var(--radius);
|
|
83
|
+
transition: background .12s, border-color .12s;
|
|
84
|
+
}
|
|
85
|
+
.btn:hover { background: var(--surface-2); }
|
|
86
|
+
.btn:disabled { opacity: .5; cursor: not-allowed; }
|
|
87
|
+
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
|
|
88
|
+
.btn.primary:hover { filter: brightness(1.06); }
|
|
89
|
+
.btn.danger { color: var(--danger); border-color: var(--border); }
|
|
90
|
+
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
|
|
91
|
+
.btn.sm { padding: 4px 9px; font-size: 12px; }
|
|
92
|
+
|
|
93
|
+
.select {
|
|
94
|
+
border: 1px solid var(--border);
|
|
95
|
+
background: var(--surface);
|
|
96
|
+
color: var(--text);
|
|
97
|
+
border-radius: var(--radius);
|
|
98
|
+
padding: 5px 8px;
|
|
99
|
+
font-size: 12px;
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
}
|
|
102
|
+
.select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
|
|
103
|
+
.select.mini { padding: 3px 6px; font-size: 11px; }
|
|
104
|
+
|
|
105
|
+
.field { margin-bottom: 14px; }
|
|
106
|
+
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
|
|
107
|
+
.field-head {
|
|
108
|
+
display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px;
|
|
109
|
+
}
|
|
110
|
+
.field-head label { margin: 0; }
|
|
111
|
+
.input, textarea.input {
|
|
112
|
+
width: 100%;
|
|
113
|
+
padding: 8px 10px;
|
|
114
|
+
border: 1px solid var(--border);
|
|
115
|
+
border-radius: var(--radius);
|
|
116
|
+
background: var(--bg);
|
|
117
|
+
color: var(--text);
|
|
118
|
+
}
|
|
119
|
+
.input:focus, textarea.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
|
|
120
|
+
textarea.code {
|
|
121
|
+
font-family: var(--mono);
|
|
122
|
+
font-size: 12.5px;
|
|
123
|
+
line-height: 1.6;
|
|
124
|
+
resize: vertical;
|
|
125
|
+
white-space: pre;
|
|
126
|
+
tab-size: 2;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* --------------------------------------------------------------------- */
|
|
130
|
+
/* Code editor (transparent textarea over a highlighted backdrop) */
|
|
131
|
+
/* --------------------------------------------------------------------- */
|
|
132
|
+
.code-wrap {
|
|
133
|
+
position: relative;
|
|
134
|
+
height: 440px;
|
|
135
|
+
border: 1px solid var(--border);
|
|
136
|
+
border-radius: var(--radius);
|
|
137
|
+
background: var(--bg);
|
|
138
|
+
overflow: hidden;
|
|
139
|
+
}
|
|
140
|
+
.code-wrap.focus { outline: 2px solid var(--accent); outline-offset: -2px; }
|
|
141
|
+
.code-hl, .code-input {
|
|
142
|
+
position: absolute;
|
|
143
|
+
inset: 0;
|
|
144
|
+
margin: 0;
|
|
145
|
+
padding: 10px 12px;
|
|
146
|
+
border: 0;
|
|
147
|
+
font-family: var(--mono);
|
|
148
|
+
font-size: 12.5px;
|
|
149
|
+
line-height: 1.6;
|
|
150
|
+
tab-size: 2;
|
|
151
|
+
white-space: pre;
|
|
152
|
+
}
|
|
153
|
+
.code-hl {
|
|
154
|
+
z-index: 0;
|
|
155
|
+
overflow: hidden;
|
|
156
|
+
pointer-events: none;
|
|
157
|
+
color: var(--text);
|
|
158
|
+
}
|
|
159
|
+
.code-hl code { font: inherit; }
|
|
160
|
+
.code-input {
|
|
161
|
+
z-index: 1;
|
|
162
|
+
overflow: auto;
|
|
163
|
+
background: transparent;
|
|
164
|
+
color: transparent;
|
|
165
|
+
caret-color: var(--text);
|
|
166
|
+
resize: none;
|
|
167
|
+
}
|
|
168
|
+
.code-input:focus { outline: none; }
|
|
169
|
+
.code-input::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
|
|
170
|
+
.tok-key { color: var(--accent); }
|
|
171
|
+
.tok-str { color: var(--c-str); }
|
|
172
|
+
.tok-num { color: var(--c-num); }
|
|
173
|
+
.tok-kw { color: var(--c-kw); }
|
|
174
|
+
.tok-comment { color: var(--muted); font-style: italic; }
|
|
175
|
+
|
|
176
|
+
/* --------------------------------------------------------------------- */
|
|
177
|
+
/* Connect view */
|
|
178
|
+
/* --------------------------------------------------------------------- */
|
|
179
|
+
#connect-view {
|
|
180
|
+
height: 100%;
|
|
181
|
+
display: flex;
|
|
182
|
+
align-items: center;
|
|
183
|
+
justify-content: center;
|
|
184
|
+
}
|
|
185
|
+
.connect-card {
|
|
186
|
+
width: 340px;
|
|
187
|
+
background: var(--surface);
|
|
188
|
+
border: 1px solid var(--border);
|
|
189
|
+
border-radius: 12px;
|
|
190
|
+
padding: 28px;
|
|
191
|
+
}
|
|
192
|
+
.connect-card .wordmark { font-size: 26px; }
|
|
193
|
+
.connect-card .sub { color: var(--muted); margin: 2px 0 20px; }
|
|
194
|
+
.connect-error { color: var(--danger); font-size: 12px; margin-top: 8px; min-height: 16px; }
|
|
195
|
+
|
|
196
|
+
/* --------------------------------------------------------------------- */
|
|
197
|
+
/* App layout */
|
|
198
|
+
/* --------------------------------------------------------------------- */
|
|
199
|
+
#app-view { height: 100%; display: flex; flex-direction: column; }
|
|
200
|
+
.topbar {
|
|
201
|
+
display: flex;
|
|
202
|
+
align-items: center;
|
|
203
|
+
gap: 12px;
|
|
204
|
+
padding: 10px 16px;
|
|
205
|
+
border-bottom: 1px solid var(--border);
|
|
206
|
+
background: var(--surface);
|
|
207
|
+
}
|
|
208
|
+
.topbar .wordmark { font-size: 17px; }
|
|
209
|
+
.topbar .ver { color: var(--muted); font-size: 12px; }
|
|
210
|
+
.topbar .spacer { flex: 1; }
|
|
211
|
+
.badge {
|
|
212
|
+
font-size: 11px;
|
|
213
|
+
padding: 2px 8px;
|
|
214
|
+
border-radius: 20px;
|
|
215
|
+
background: var(--surface-2);
|
|
216
|
+
color: var(--muted);
|
|
217
|
+
border: 1px solid var(--border);
|
|
218
|
+
}
|
|
219
|
+
.badge.ro { color: var(--danger); }
|
|
220
|
+
|
|
221
|
+
.layout { flex: 1; display: flex; min-height: 0; }
|
|
222
|
+
.sidebar {
|
|
223
|
+
width: 250px;
|
|
224
|
+
border-right: 1px solid var(--border);
|
|
225
|
+
background: var(--surface);
|
|
226
|
+
display: flex;
|
|
227
|
+
flex-direction: column;
|
|
228
|
+
}
|
|
229
|
+
.sidebar-head {
|
|
230
|
+
display: flex;
|
|
231
|
+
align-items: center;
|
|
232
|
+
justify-content: space-between;
|
|
233
|
+
padding: 12px 14px;
|
|
234
|
+
border-bottom: 1px solid var(--border);
|
|
235
|
+
}
|
|
236
|
+
.sidebar-head h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
|
|
237
|
+
.app-list { overflow-y: auto; flex: 1; padding: 6px; }
|
|
238
|
+
.app-item {
|
|
239
|
+
padding: 8px 10px;
|
|
240
|
+
border-radius: var(--radius);
|
|
241
|
+
cursor: pointer;
|
|
242
|
+
display: flex;
|
|
243
|
+
align-items: baseline;
|
|
244
|
+
justify-content: space-between;
|
|
245
|
+
gap: 8px;
|
|
246
|
+
}
|
|
247
|
+
.app-item:hover { background: var(--surface-2); }
|
|
248
|
+
.app-item.active { background: var(--accent); color: var(--accent-fg); }
|
|
249
|
+
.app-item.active .app-rev { color: var(--accent-fg); opacity: .8; }
|
|
250
|
+
.app-item .app-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
251
|
+
.app-rev { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
|
|
252
|
+
|
|
253
|
+
.content { flex: 1; overflow-y: auto; padding: 20px 24px; min-width: 0; }
|
|
254
|
+
.empty-state { color: var(--muted); text-align: center; margin-top: 80px; }
|
|
255
|
+
|
|
256
|
+
/* App detail */
|
|
257
|
+
.detail-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
|
|
258
|
+
.detail-head h2 { font-size: 18px; }
|
|
259
|
+
.detail-head .desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
|
|
260
|
+
.detail-head .spacer { flex: 1; }
|
|
261
|
+
.meta-row { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
|
|
262
|
+
.live-dot {
|
|
263
|
+
display: inline-block; width: 8px; height: 8px; border-radius: 50%;
|
|
264
|
+
background: var(--muted); margin-right: 5px; vertical-align: middle;
|
|
265
|
+
}
|
|
266
|
+
.live-dot.on { background: var(--ok); }
|
|
267
|
+
|
|
268
|
+
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
|
|
269
|
+
.tab {
|
|
270
|
+
padding: 7px 14px;
|
|
271
|
+
border: none;
|
|
272
|
+
background: none;
|
|
273
|
+
color: var(--muted);
|
|
274
|
+
border-bottom: 2px solid transparent;
|
|
275
|
+
margin-bottom: -1px;
|
|
276
|
+
}
|
|
277
|
+
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }
|
|
278
|
+
|
|
279
|
+
.editor-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
|
|
280
|
+
.editor-toolbar .spacer { flex: 1; }
|
|
281
|
+
.editor-status { font-size: 12px; color: var(--muted); }
|
|
282
|
+
.editor-status.dirty { color: var(--accent); }
|
|
283
|
+
|
|
284
|
+
.notice {
|
|
285
|
+
padding: 8px 12px;
|
|
286
|
+
border-radius: var(--radius);
|
|
287
|
+
font-size: 12.5px;
|
|
288
|
+
margin-bottom: 10px;
|
|
289
|
+
border: 1px solid var(--border);
|
|
290
|
+
}
|
|
291
|
+
.notice.error { color: var(--danger); border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
|
|
292
|
+
.notice.ok { color: var(--ok); border-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, transparent); }
|
|
293
|
+
.notice.warn { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
|
|
294
|
+
.notice ul { margin: 4px 0 0; padding-left: 18px; }
|
|
295
|
+
.notice .notice-actions { margin-top: 6px; display: flex; gap: 8px; }
|
|
296
|
+
|
|
297
|
+
/* --------------------------------------------------------------------- */
|
|
298
|
+
/* Modal */
|
|
299
|
+
/* --------------------------------------------------------------------- */
|
|
300
|
+
#modal-overlay {
|
|
301
|
+
position: fixed; inset: 0;
|
|
302
|
+
z-index: 1000;
|
|
303
|
+
background: rgba(0,0,0,.4);
|
|
304
|
+
display: flex; align-items: center; justify-content: center;
|
|
305
|
+
padding: 20px;
|
|
306
|
+
}
|
|
307
|
+
.modal {
|
|
308
|
+
background: var(--surface);
|
|
309
|
+
border: 1px solid var(--border);
|
|
310
|
+
border-radius: 12px;
|
|
311
|
+
width: 440px;
|
|
312
|
+
max-width: 100%;
|
|
313
|
+
max-height: 90vh;
|
|
314
|
+
overflow-y: auto;
|
|
315
|
+
padding: 22px;
|
|
316
|
+
}
|
|
317
|
+
.modal h3 { margin-bottom: 16px; font-size: 16px; }
|
|
318
|
+
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
|
|
319
|
+
.modal-error { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 4px; }
|
|
320
|
+
|
|
321
|
+
/* --------------------------------------------------------------------- */
|
|
322
|
+
/* Toast */
|
|
323
|
+
/* --------------------------------------------------------------------- */
|
|
324
|
+
#toast {
|
|
325
|
+
position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
|
|
326
|
+
background: var(--text); color: var(--bg);
|
|
327
|
+
padding: 9px 16px; border-radius: var(--radius); font-size: 13px;
|
|
328
|
+
opacity: 0; transition: opacity .2s; pointer-events: none;
|
|
329
|
+
}
|
|
330
|
+
#toast.show { opacity: 1; }
|
|
331
|
+
</style>
|
|
332
|
+
</head>
|
|
333
|
+
<body>
|
|
334
|
+
|
|
335
|
+
<!-- ===================== Connect view ===================== -->
|
|
336
|
+
<div id="connect-view">
|
|
337
|
+
<div class="connect-card">
|
|
338
|
+
<div class="wordmark">Nacho<span class="wm-dot">.</span></div>
|
|
339
|
+
<div class="sub">Configuration Manager</div>
|
|
340
|
+
<div class="field">
|
|
341
|
+
<label for="key-input">API key</label>
|
|
342
|
+
<input id="key-input" class="input" type="password" placeholder="Enter API key" autocomplete="off" />
|
|
343
|
+
</div>
|
|
344
|
+
<button id="connect-btn" class="btn primary" style="width:100%">Connect</button>
|
|
345
|
+
<div id="connect-error" class="connect-error"></div>
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
|
|
349
|
+
<!-- ===================== App view ===================== -->
|
|
350
|
+
<div id="app-view" class="hidden">
|
|
351
|
+
<div class="topbar">
|
|
352
|
+
<span class="wordmark">Nacho<span class="wm-dot">.</span></span>
|
|
353
|
+
<span class="ver" id="server-ver"></span>
|
|
354
|
+
<span class="badge ro hidden" id="ro-badge">read-only</span>
|
|
355
|
+
<span class="spacer"></span>
|
|
356
|
+
<button class="btn sm" id="disconnect-btn">Disconnect</button>
|
|
357
|
+
</div>
|
|
358
|
+
<div class="layout">
|
|
359
|
+
<aside class="sidebar">
|
|
360
|
+
<div class="sidebar-head">
|
|
361
|
+
<h3>Apps</h3>
|
|
362
|
+
<button class="btn sm primary" id="new-app-btn">+ New</button>
|
|
363
|
+
</div>
|
|
364
|
+
<div class="app-list" id="app-list"></div>
|
|
365
|
+
</aside>
|
|
366
|
+
<main class="content" id="content">
|
|
367
|
+
<div class="empty-state">Select an app, or create one to get started.</div>
|
|
368
|
+
</main>
|
|
369
|
+
</div>
|
|
370
|
+
</div>
|
|
371
|
+
|
|
372
|
+
<div id="modal-overlay" class="hidden"></div>
|
|
373
|
+
<div id="toast"></div>
|
|
374
|
+
|
|
375
|
+
<script>
|
|
376
|
+
"use strict";
|
|
377
|
+
/* ===================================================================== */
|
|
378
|
+
/* State */
|
|
379
|
+
/* ===================================================================== */
|
|
380
|
+
const FORMATS = ["json", "yaml", "toml"];
|
|
381
|
+
const state = {
|
|
382
|
+
apiKey: localStorage.getItem("nacho_api_key") || "",
|
|
383
|
+
authRequired: true,
|
|
384
|
+
readOnly: false,
|
|
385
|
+
apps: {}, // name -> info
|
|
386
|
+
selected: null, // app name
|
|
387
|
+
revision: null,
|
|
388
|
+
configObj: {}, // server-truth config object
|
|
389
|
+
configFormat: localStorage.getItem("nacho_config_format") || "json",
|
|
390
|
+
pristine: "", // editor text of configObj in configFormat
|
|
391
|
+
schema: null, // server-truth schema object or null
|
|
392
|
+
schemaFormat: localStorage.getItem("nacho_schema_format") || "json",
|
|
393
|
+
schemaPristine: "",
|
|
394
|
+
ws: null,
|
|
395
|
+
wsRetry: null,
|
|
396
|
+
activeTab: "config",
|
|
397
|
+
};
|
|
398
|
+
let configEd = null; // code editor for the config tab
|
|
399
|
+
let schemaEd = null; // code editor for the schema tab
|
|
400
|
+
|
|
401
|
+
const $ = (id) => document.getElementById(id);
|
|
402
|
+
const esc = (s) => String(s == null ? "" : s).replace(/[&<>"]/g,
|
|
403
|
+
(c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c]));
|
|
404
|
+
const fmtOptions = (sel) =>
|
|
405
|
+
FORMATS.map((f) => '<option value="' + f + '"' + (f === sel ? " selected" : "") +
|
|
406
|
+
">" + f.toUpperCase() + "</option>").join("");
|
|
407
|
+
|
|
408
|
+
/* ===================================================================== */
|
|
409
|
+
/* HTTP helper */
|
|
410
|
+
/* ===================================================================== */
|
|
411
|
+
async function api(method, path, body) {
|
|
412
|
+
const headers = {};
|
|
413
|
+
if (body !== undefined) headers["Content-Type"] = "application/json";
|
|
414
|
+
if (state.apiKey) headers["Authorization"] = "Bearer " + state.apiKey;
|
|
415
|
+
const resp = await fetch(path, {
|
|
416
|
+
method,
|
|
417
|
+
headers,
|
|
418
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
419
|
+
});
|
|
420
|
+
let payload = null;
|
|
421
|
+
const text = await resp.text();
|
|
422
|
+
if (text) { try { payload = JSON.parse(text); } catch (_) { payload = text; } }
|
|
423
|
+
if (!resp.ok) {
|
|
424
|
+
const err = new Error("Request failed");
|
|
425
|
+
err.status = resp.status;
|
|
426
|
+
err.detail = payload && payload.detail !== undefined ? payload.detail : payload;
|
|
427
|
+
throw err;
|
|
428
|
+
}
|
|
429
|
+
return { data: payload, headers: resp.headers };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function errText(err) {
|
|
433
|
+
if (err.status === 401 || err.status === 403) return "Unauthorized — check your API key.";
|
|
434
|
+
const d = err.detail;
|
|
435
|
+
if (d == null) return "Request failed (" + (err.status || "network") + ").";
|
|
436
|
+
if (typeof d === "string") return d;
|
|
437
|
+
if (d.error === "revision_conflict")
|
|
438
|
+
return "Revision conflict: server is at " + d.actual + ", you sent " + d.expected + ".";
|
|
439
|
+
return JSON.stringify(d);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/* ----- Format conversion (json / yaml / toml), handled server-side ----- */
|
|
443
|
+
async function convertFormat(data, from, to) {
|
|
444
|
+
if (from === to && typeof data === "string") return data;
|
|
445
|
+
const { data: res } = await api("POST", "/api/convert", { data: data, from: from, to: to });
|
|
446
|
+
return res.data;
|
|
447
|
+
}
|
|
448
|
+
async function serialize(obj, fmt) {
|
|
449
|
+
if (fmt === "json") return JSON.stringify(obj, null, 2);
|
|
450
|
+
return convertFormat(obj, "json", fmt);
|
|
451
|
+
}
|
|
452
|
+
async function serializeSafe(obj, fmt, label) {
|
|
453
|
+
try { return { text: await serialize(obj, fmt), fmt: fmt }; }
|
|
454
|
+
catch (_) {
|
|
455
|
+
toast("Cannot show " + label + " as " + fmt.toUpperCase() + " — showing JSON instead.");
|
|
456
|
+
return { text: JSON.stringify(obj, null, 2), fmt: "json" };
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/* ===================================================================== */
|
|
461
|
+
/* Cookie (needed so the WebSocket handshake can authenticate) */
|
|
462
|
+
/* ===================================================================== */
|
|
463
|
+
function setAuthCookie(key) {
|
|
464
|
+
document.cookie = "NACHO_api_key=" + key + "; path=/; SameSite=Strict";
|
|
465
|
+
}
|
|
466
|
+
function clearAuthCookie() {
|
|
467
|
+
document.cookie = "NACHO_api_key=; path=/; Max-Age=0; SameSite=Strict";
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/* ===================================================================== */
|
|
471
|
+
/* Toast */
|
|
472
|
+
/* ===================================================================== */
|
|
473
|
+
let toastTimer = null;
|
|
474
|
+
function toast(msg) {
|
|
475
|
+
const t = $("toast");
|
|
476
|
+
t.textContent = msg;
|
|
477
|
+
t.classList.add("show");
|
|
478
|
+
clearTimeout(toastTimer);
|
|
479
|
+
toastTimer = setTimeout(() => t.classList.remove("show"), 2600);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/* ===================================================================== */
|
|
483
|
+
/* Syntax highlighting — json / yaml / toml */
|
|
484
|
+
/* ===================================================================== */
|
|
485
|
+
function escHtml(s) {
|
|
486
|
+
return s.replace(/[&<>]/g, (c) => ({ "&": "&", "<": "<", ">": ">" }[c]));
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function highlightJSON(src) {
|
|
490
|
+
return escHtml(src).replace(
|
|
491
|
+
/("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g,
|
|
492
|
+
(m, str, colon, kw, num) => {
|
|
493
|
+
if (str !== undefined) {
|
|
494
|
+
const cls = colon ? "tok-key" : "tok-str";
|
|
495
|
+
return '<span class="' + cls + '">' + str + "</span>" + (colon || "");
|
|
496
|
+
}
|
|
497
|
+
if (kw !== undefined) return '<span class="tok-kw">' + kw + "</span>";
|
|
498
|
+
return '<span class="tok-num">' + num + "</span>";
|
|
499
|
+
}
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// Highlight a scalar fragment (already HTML-escaped): strings, keywords, numbers.
|
|
504
|
+
function highlightScalar(v) {
|
|
505
|
+
return v.replace(
|
|
506
|
+
/("(?:\\.|[^"\\])*"|'[^']*')|\b(true|false|null|yes|no)\b|(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/gi,
|
|
507
|
+
(m, str, kw, num) => {
|
|
508
|
+
if (str !== undefined) return '<span class="tok-str">' + str + "</span>";
|
|
509
|
+
if (kw !== undefined) return '<span class="tok-kw">' + kw + "</span>";
|
|
510
|
+
return '<span class="tok-num">' + num + "</span>";
|
|
511
|
+
}
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function highlightYAML(src) {
|
|
516
|
+
return escHtml(src).split("\n").map((line) => {
|
|
517
|
+
let m = line.match(/^(\s*)(#.*)$/);
|
|
518
|
+
if (m) return m[1] + '<span class="tok-comment">' + m[2] + "</span>";
|
|
519
|
+
m = line.match(/^(\s*(?:-\s+)?)([^:#\s][^:#]*?)(:)(\s.*|)$/);
|
|
520
|
+
if (m) return m[1] + '<span class="tok-key">' + m[2] + "</span>" + m[3] + highlightScalar(m[4]);
|
|
521
|
+
m = line.match(/^(\s*-\s+)(.*)$/);
|
|
522
|
+
if (m) return m[1] + highlightScalar(m[2]);
|
|
523
|
+
return highlightScalar(line);
|
|
524
|
+
}).join("\n");
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
function highlightTOML(src) {
|
|
528
|
+
return escHtml(src).split("\n").map((line) => {
|
|
529
|
+
let m = line.match(/^(\s*)(#.*)$/);
|
|
530
|
+
if (m) return m[1] + '<span class="tok-comment">' + m[2] + "</span>";
|
|
531
|
+
m = line.match(/^(\s*)(\[\[?[^\]]*\]\]?)(\s*)$/);
|
|
532
|
+
if (m) return m[1] + '<span class="tok-key">' + m[2] + "</span>" + m[3];
|
|
533
|
+
m = line.match(/^(\s*)([A-Za-z0-9_."\-]+)(\s*=\s*)(.*)$/);
|
|
534
|
+
if (m) return m[1] + '<span class="tok-key">' + m[2] + "</span>" + m[3] + highlightScalar(m[4]);
|
|
535
|
+
return highlightScalar(line);
|
|
536
|
+
}).join("\n");
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function highlight(text, lang) {
|
|
540
|
+
if (lang === "yaml") return highlightYAML(text);
|
|
541
|
+
if (lang === "toml") return highlightTOML(text);
|
|
542
|
+
return highlightJSON(text);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/* ===================================================================== */
|
|
546
|
+
/* Code editor — transparent textarea over a highlighted backdrop */
|
|
547
|
+
/* ===================================================================== */
|
|
548
|
+
function mountCodeEditor(host, opts) {
|
|
549
|
+
opts = opts || {};
|
|
550
|
+
let lang = opts.language || "json";
|
|
551
|
+
const wrap = document.createElement("div");
|
|
552
|
+
wrap.className = "code-wrap";
|
|
553
|
+
const pre = document.createElement("pre");
|
|
554
|
+
pre.className = "code-hl";
|
|
555
|
+
pre.setAttribute("aria-hidden", "true");
|
|
556
|
+
const code = document.createElement("code");
|
|
557
|
+
pre.appendChild(code);
|
|
558
|
+
const ta = document.createElement("textarea");
|
|
559
|
+
ta.className = "code-input";
|
|
560
|
+
ta.spellcheck = false;
|
|
561
|
+
ta.autocapitalize = "off";
|
|
562
|
+
ta.setAttribute("autocomplete", "off");
|
|
563
|
+
if (opts.readOnly) ta.readOnly = true;
|
|
564
|
+
wrap.append(pre, ta);
|
|
565
|
+
host.appendChild(wrap);
|
|
566
|
+
|
|
567
|
+
const render = () => { code.innerHTML = highlight(ta.value, lang) + "\n"; };
|
|
568
|
+
const sync = () => { pre.scrollTop = ta.scrollTop; pre.scrollLeft = ta.scrollLeft; };
|
|
569
|
+
|
|
570
|
+
ta.addEventListener("input", () => {
|
|
571
|
+
render(); sync();
|
|
572
|
+
if (opts.onInput) opts.onInput();
|
|
573
|
+
});
|
|
574
|
+
ta.addEventListener("scroll", sync);
|
|
575
|
+
ta.addEventListener("focus", () => wrap.classList.add("focus"));
|
|
576
|
+
ta.addEventListener("blur", () => wrap.classList.remove("focus"));
|
|
577
|
+
ta.addEventListener("keydown", (e) => {
|
|
578
|
+
if (e.key !== "Tab") return;
|
|
579
|
+
e.preventDefault();
|
|
580
|
+
ta.setRangeText(" ", ta.selectionStart, ta.selectionEnd, "end");
|
|
581
|
+
ta.dispatchEvent(new Event("input"));
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
ta.value = opts.value || "";
|
|
585
|
+
render();
|
|
586
|
+
|
|
587
|
+
return {
|
|
588
|
+
textarea: ta,
|
|
589
|
+
get value() { return ta.value; },
|
|
590
|
+
set value(v) { ta.value = v; render(); sync(); },
|
|
591
|
+
setLanguage(l) { lang = l; render(); },
|
|
592
|
+
focus() { ta.focus(); },
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/* ===================================================================== */
|
|
597
|
+
/* Connect flow */
|
|
598
|
+
/* ===================================================================== */
|
|
599
|
+
async function boot() {
|
|
600
|
+
let health = {};
|
|
601
|
+
try {
|
|
602
|
+
const r = await fetch("/health");
|
|
603
|
+
health = await r.json();
|
|
604
|
+
} catch (_) { /* server may still be coming up */ }
|
|
605
|
+
state.authRequired = health.auth_required !== false;
|
|
606
|
+
state.readOnly = !!health.read_only;
|
|
607
|
+
$("server-ver").textContent = health.version ? "v" + health.version : "";
|
|
608
|
+
|
|
609
|
+
if (!state.authRequired) { state.apiKey = ""; await enterApp(); return; }
|
|
610
|
+
if (state.apiKey && (await tryConnect())) return;
|
|
611
|
+
showConnect();
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function showConnect() {
|
|
615
|
+
$("connect-view").classList.remove("hidden");
|
|
616
|
+
$("app-view").classList.add("hidden");
|
|
617
|
+
$("key-input").value = state.apiKey;
|
|
618
|
+
$("key-input").focus();
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
async function tryConnect() {
|
|
622
|
+
try {
|
|
623
|
+
await api("GET", "/api/apps");
|
|
624
|
+
await enterApp();
|
|
625
|
+
return true;
|
|
626
|
+
} catch (err) {
|
|
627
|
+
if (err.status === 401 || err.status === 403) return false;
|
|
628
|
+
$("connect-error").textContent = errText(err);
|
|
629
|
+
return false;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
$("connect-btn").onclick = async () => {
|
|
634
|
+
const key = $("key-input").value.trim();
|
|
635
|
+
$("connect-error").textContent = "";
|
|
636
|
+
if (!key) { $("connect-error").textContent = "API key is required."; return; }
|
|
637
|
+
state.apiKey = key;
|
|
638
|
+
setAuthCookie(key);
|
|
639
|
+
if (await tryConnect()) {
|
|
640
|
+
localStorage.setItem("nacho_api_key", key);
|
|
641
|
+
} else if (!$("connect-error").textContent) {
|
|
642
|
+
$("connect-error").textContent = "Invalid API key.";
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
$("key-input").addEventListener("keydown", (e) => {
|
|
646
|
+
if (e.key === "Enter") $("connect-btn").click();
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
$("disconnect-btn").onclick = () => {
|
|
650
|
+
closeWs();
|
|
651
|
+
state.apiKey = "";
|
|
652
|
+
state.selected = null;
|
|
653
|
+
localStorage.removeItem("nacho_api_key");
|
|
654
|
+
clearAuthCookie();
|
|
655
|
+
showConnect();
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
async function enterApp() {
|
|
659
|
+
if (state.apiKey) setAuthCookie(state.apiKey);
|
|
660
|
+
$("connect-view").classList.add("hidden");
|
|
661
|
+
$("app-view").classList.remove("hidden");
|
|
662
|
+
$("ro-badge").classList.toggle("hidden", !state.readOnly);
|
|
663
|
+
await refreshApps();
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/* ===================================================================== */
|
|
667
|
+
/* App list */
|
|
668
|
+
/* ===================================================================== */
|
|
669
|
+
async function refreshApps() {
|
|
670
|
+
const { data } = await api("GET", "/api/apps");
|
|
671
|
+
state.apps = data.data || {};
|
|
672
|
+
renderAppList();
|
|
673
|
+
if (state.selected && !state.apps[state.selected]) state.selected = null;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function renderAppList() {
|
|
677
|
+
const list = $("app-list");
|
|
678
|
+
const names = Object.keys(state.apps).sort();
|
|
679
|
+
if (!names.length) {
|
|
680
|
+
list.innerHTML = '<div class="empty-state" style="margin-top:24px">No apps yet.</div>';
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
list.innerHTML = "";
|
|
684
|
+
for (const name of names) {
|
|
685
|
+
const info = state.apps[name];
|
|
686
|
+
const div = document.createElement("div");
|
|
687
|
+
div.className = "app-item" + (name === state.selected ? " active" : "");
|
|
688
|
+
div.innerHTML = '<span class="app-name">' + esc(name) + "</span>" +
|
|
689
|
+
'<span class="app-rev">r' + esc(info.revision) + "</span>";
|
|
690
|
+
div.onclick = () => selectApp(name);
|
|
691
|
+
list.appendChild(div);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/* ===================================================================== */
|
|
696
|
+
/* App detail */
|
|
697
|
+
/* ===================================================================== */
|
|
698
|
+
async function selectApp(name) {
|
|
699
|
+
if (state.selected === name) return;
|
|
700
|
+
if (!confirmDiscard()) return;
|
|
701
|
+
state.selected = name;
|
|
702
|
+
renderAppList();
|
|
703
|
+
await loadAppDetail(name);
|
|
704
|
+
openWs(name);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
async function loadAppDetail(name) {
|
|
708
|
+
let configObj, schemaObj;
|
|
709
|
+
try {
|
|
710
|
+
const cfg = await api("GET", "/api/apps/" + encodeURIComponent(name) + "/config");
|
|
711
|
+
configObj = cfg.data;
|
|
712
|
+
state.revision = parseInt(cfg.headers.get("X-Nacho-Revision"), 10) || state.apps[name].revision;
|
|
713
|
+
const sch = await api("GET", "/api/apps/" + encodeURIComponent(name) + "/schema");
|
|
714
|
+
schemaObj = sch.data.data.schema;
|
|
715
|
+
} catch (err) {
|
|
716
|
+
$("content").innerHTML = '<div class="notice error">' + esc(errText(err)) + "</div>";
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
state.configObj = configObj;
|
|
720
|
+
state.schema = schemaObj;
|
|
721
|
+
|
|
722
|
+
const cfg = await serializeSafe(configObj, state.configFormat, "configuration");
|
|
723
|
+
state.configFormat = cfg.fmt;
|
|
724
|
+
state.pristine = cfg.text;
|
|
725
|
+
|
|
726
|
+
if (schemaObj) {
|
|
727
|
+
const sch = await serializeSafe(schemaObj, state.schemaFormat, "schema");
|
|
728
|
+
state.schemaFormat = sch.fmt;
|
|
729
|
+
state.schemaPristine = sch.text;
|
|
730
|
+
} else {
|
|
731
|
+
state.schemaPristine = "";
|
|
732
|
+
}
|
|
733
|
+
renderDetail();
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
function renderDetail() {
|
|
737
|
+
const name = state.selected;
|
|
738
|
+
const info = state.apps[name] || {};
|
|
739
|
+
const c = $("content");
|
|
740
|
+
c.innerHTML = `
|
|
741
|
+
<div class="detail-head">
|
|
742
|
+
<div>
|
|
743
|
+
<h2>${esc(name)}</h2>
|
|
744
|
+
<div class="desc">${esc(info.description || "No description")}</div>
|
|
745
|
+
<div class="meta-row">
|
|
746
|
+
<span><span class="live-dot" id="live-dot"></span><span id="live-label">offline</span></span>
|
|
747
|
+
<span>revision <b id="rev-label">${esc(state.revision)}</b></span>
|
|
748
|
+
<span>${esc(info.connections || 0)} watcher(s)</span>
|
|
749
|
+
<span>schema: <b id="schema-flag">${state.schema ? "yes" : "none"}</b></span>
|
|
750
|
+
</div>
|
|
751
|
+
</div>
|
|
752
|
+
<span class="spacer"></span>
|
|
753
|
+
<button class="btn sm" id="meta-btn">Edit</button>
|
|
754
|
+
<button class="btn sm danger" id="delete-btn">Delete</button>
|
|
755
|
+
</div>
|
|
756
|
+
<div class="tabs">
|
|
757
|
+
<button class="tab" data-tab="config">Configuration</button>
|
|
758
|
+
<button class="tab" data-tab="schema">Schema</button>
|
|
759
|
+
</div>
|
|
760
|
+
<div id="tab-body"></div>
|
|
761
|
+
`;
|
|
762
|
+
$("meta-btn").onclick = openMetaModal;
|
|
763
|
+
$("delete-btn").onclick = deleteApp;
|
|
764
|
+
c.querySelectorAll(".tab").forEach((t) => {
|
|
765
|
+
t.onclick = () => switchTab(t.dataset.tab);
|
|
766
|
+
});
|
|
767
|
+
switchTab(state.activeTab);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
function switchTab(tab) {
|
|
771
|
+
if (tab !== state.activeTab && !confirmDiscard()) return;
|
|
772
|
+
state.activeTab = tab;
|
|
773
|
+
configEd = null;
|
|
774
|
+
schemaEd = null;
|
|
775
|
+
document.querySelectorAll(".tab").forEach((t) => {
|
|
776
|
+
t.classList.toggle("active", t.dataset.tab === tab);
|
|
777
|
+
});
|
|
778
|
+
if (tab === "config") renderConfigTab();
|
|
779
|
+
else renderSchemaTab();
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/* ----- Configuration tab ----- */
|
|
783
|
+
function renderConfigTab(text) {
|
|
784
|
+
const ro = state.readOnly ? "disabled" : "";
|
|
785
|
+
$("tab-body").innerHTML = `
|
|
786
|
+
<div id="config-notice"></div>
|
|
787
|
+
<div class="editor-toolbar">
|
|
788
|
+
<select class="select" id="config-format" title="Editor format">${fmtOptions(state.configFormat)}</select>
|
|
789
|
+
<button class="btn sm" id="format-btn">Format</button>
|
|
790
|
+
<button class="btn sm" id="validate-btn">Validate</button>
|
|
791
|
+
<button class="btn sm" id="reload-btn">Reload</button>
|
|
792
|
+
<span class="spacer"></span>
|
|
793
|
+
<span class="editor-status" id="editor-status"></span>
|
|
794
|
+
<button class="btn sm primary" id="save-btn" ${ro}>Save</button>
|
|
795
|
+
</div>
|
|
796
|
+
<div id="config-host"></div>
|
|
797
|
+
`;
|
|
798
|
+
configEd = mountCodeEditor($("config-host"), {
|
|
799
|
+
value: text !== undefined ? text : state.pristine,
|
|
800
|
+
language: state.configFormat,
|
|
801
|
+
readOnly: state.readOnly,
|
|
802
|
+
onInput: updateDirty,
|
|
803
|
+
});
|
|
804
|
+
$("config-format").onchange = (e) => changeConfigFormat(e.target.value);
|
|
805
|
+
$("format-btn").onclick = formatConfig;
|
|
806
|
+
$("validate-btn").onclick = validateConfig;
|
|
807
|
+
$("reload-btn").onclick = () => { if (confirmDiscard()) loadAppDetail(state.selected); };
|
|
808
|
+
$("save-btn").onclick = saveConfig;
|
|
809
|
+
updateDirty();
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
async function changeConfigFormat(fmt) {
|
|
813
|
+
if (fmt === state.configFormat) return;
|
|
814
|
+
let editorText = "", pristineText = "";
|
|
815
|
+
try {
|
|
816
|
+
if (configEd.value.trim())
|
|
817
|
+
editorText = await convertFormat(configEd.value, state.configFormat, fmt);
|
|
818
|
+
pristineText = await serialize(state.configObj, fmt);
|
|
819
|
+
} catch (e) {
|
|
820
|
+
configNotice('<div class="notice error">Cannot convert to ' + fmt.toUpperCase() +
|
|
821
|
+
": " + esc(errText(e)) + "</div>");
|
|
822
|
+
$("config-format").value = state.configFormat;
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
state.configFormat = fmt;
|
|
826
|
+
localStorage.setItem("nacho_config_format", fmt);
|
|
827
|
+
state.pristine = pristineText;
|
|
828
|
+
renderConfigTab(editorText);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/* ----- Schema tab ----- */
|
|
832
|
+
function renderSchemaTab(text) {
|
|
833
|
+
const ro = state.readOnly ? "disabled" : "";
|
|
834
|
+
$("tab-body").innerHTML = `
|
|
835
|
+
<div id="schema-notice"></div>
|
|
836
|
+
<div class="editor-toolbar">
|
|
837
|
+
<select class="select" id="schema-format" title="Editor format">${fmtOptions(state.schemaFormat)}</select>
|
|
838
|
+
<button class="btn sm" id="schema-format-btn">Format</button>
|
|
839
|
+
<button class="btn sm" id="schema-clear-btn" ${ro}>Clear schema</button>
|
|
840
|
+
<span class="spacer"></span>
|
|
841
|
+
<span class="editor-status" id="schema-status"></span>
|
|
842
|
+
<button class="btn sm primary" id="schema-save-btn" ${ro}>Save schema</button>
|
|
843
|
+
</div>
|
|
844
|
+
<div id="schema-host"></div>
|
|
845
|
+
<p class="hint">A JSON Schema validates every config write. An empty editor
|
|
846
|
+
clears the schema. Saving re-checks the current configuration against it.</p>
|
|
847
|
+
`;
|
|
848
|
+
schemaEd = mountCodeEditor($("schema-host"), {
|
|
849
|
+
value: text !== undefined ? text : state.schemaPristine,
|
|
850
|
+
language: state.schemaFormat,
|
|
851
|
+
readOnly: state.readOnly,
|
|
852
|
+
onInput: updateSchemaDirty,
|
|
853
|
+
});
|
|
854
|
+
$("schema-format").onchange = (e) => changeSchemaFormat(e.target.value);
|
|
855
|
+
$("schema-format-btn").onclick = formatSchema;
|
|
856
|
+
$("schema-clear-btn").onclick = () => { schemaEd.value = ""; updateSchemaDirty(); };
|
|
857
|
+
$("schema-save-btn").onclick = saveSchema;
|
|
858
|
+
updateSchemaDirty();
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
async function changeSchemaFormat(fmt) {
|
|
862
|
+
if (fmt === state.schemaFormat) return;
|
|
863
|
+
let editorText = "", pristineText = "";
|
|
864
|
+
try {
|
|
865
|
+
if (schemaEd.value.trim())
|
|
866
|
+
editorText = await convertFormat(schemaEd.value, state.schemaFormat, fmt);
|
|
867
|
+
if (state.schema) pristineText = await serialize(state.schema, fmt);
|
|
868
|
+
} catch (e) {
|
|
869
|
+
schemaNotice('<div class="notice error">Cannot convert to ' + fmt.toUpperCase() +
|
|
870
|
+
": " + esc(errText(e)) + "</div>");
|
|
871
|
+
$("schema-format").value = state.schemaFormat;
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
state.schemaFormat = fmt;
|
|
875
|
+
localStorage.setItem("nacho_schema_format", fmt);
|
|
876
|
+
state.schemaPristine = pristineText;
|
|
877
|
+
renderSchemaTab(editorText);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/* ----- Dirty tracking ----- */
|
|
881
|
+
function isConfigDirty() { return configEd && configEd.value !== state.pristine; }
|
|
882
|
+
function isSchemaDirty() { return schemaEd && schemaEd.value !== state.schemaPristine; }
|
|
883
|
+
function anyDirty() { return isConfigDirty() || isSchemaDirty(); }
|
|
884
|
+
|
|
885
|
+
function setStatus(id, dirty) {
|
|
886
|
+
const s = $(id);
|
|
887
|
+
if (!s) return;
|
|
888
|
+
s.textContent = dirty ? "● Unsaved changes" : "Saved";
|
|
889
|
+
s.classList.toggle("dirty", dirty);
|
|
890
|
+
}
|
|
891
|
+
function updateDirty() { setStatus("editor-status", isConfigDirty()); }
|
|
892
|
+
function updateSchemaDirty() { setStatus("schema-status", isSchemaDirty()); }
|
|
893
|
+
|
|
894
|
+
function confirmDiscard() {
|
|
895
|
+
if (!anyDirty()) return true;
|
|
896
|
+
return confirm("You have unsaved changes. Discard them?");
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/* ----- Configuration actions ----- */
|
|
900
|
+
function configNotice(html) { const n = $("config-notice"); if (n) n.innerHTML = html || ""; }
|
|
901
|
+
|
|
902
|
+
async function formatConfig() {
|
|
903
|
+
try {
|
|
904
|
+
if (!configEd.value.trim()) return;
|
|
905
|
+
configEd.value = await convertFormat(configEd.value, state.configFormat, state.configFormat);
|
|
906
|
+
updateDirty();
|
|
907
|
+
configNotice("");
|
|
908
|
+
} catch (e) {
|
|
909
|
+
configNotice('<div class="notice error">' + esc(errText(e)) + "</div>");
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
async function validateConfig() {
|
|
914
|
+
try {
|
|
915
|
+
const { data } = await api("POST",
|
|
916
|
+
"/api/apps/" + encodeURIComponent(state.selected) + "/validate",
|
|
917
|
+
{ data: configEd.value, format: state.configFormat });
|
|
918
|
+
if (data.valid) {
|
|
919
|
+
configNotice('<div class="notice ok">Configuration is valid against the schema.</div>');
|
|
920
|
+
} else {
|
|
921
|
+
configNotice('<div class="notice error">Validation failed:<ul>' +
|
|
922
|
+
data.errors.map((e) => "<li>" + esc(e) + "</li>").join("") + "</ul></div>");
|
|
923
|
+
}
|
|
924
|
+
} catch (err) {
|
|
925
|
+
configNotice('<div class="notice error">' + esc(errText(err)) + "</div>");
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
async function saveConfig() {
|
|
930
|
+
try {
|
|
931
|
+
const { data } = await api("PUT",
|
|
932
|
+
"/api/apps/" + encodeURIComponent(state.selected) + "/config",
|
|
933
|
+
{ data: configEd.value, format: state.configFormat, revision: state.revision });
|
|
934
|
+
applyRevision(data.revision);
|
|
935
|
+
state.configObj = data.data;
|
|
936
|
+
state.pristine = await serialize(state.configObj, state.configFormat);
|
|
937
|
+
configEd.value = state.pristine;
|
|
938
|
+
updateDirty();
|
|
939
|
+
configNotice("");
|
|
940
|
+
toast("Configuration saved (revision " + state.revision + ")");
|
|
941
|
+
await refreshApps();
|
|
942
|
+
} catch (err) {
|
|
943
|
+
if (err.status === 409) {
|
|
944
|
+
configNotice('<div class="notice warn">' + esc(errText(err)) +
|
|
945
|
+
'<div class="notice-actions">' +
|
|
946
|
+
'<button class="btn sm" id="conflict-reload">Reload latest</button></div></div>');
|
|
947
|
+
$("conflict-reload").onclick = () => loadAppDetail(state.selected);
|
|
948
|
+
} else {
|
|
949
|
+
configNotice('<div class="notice error">' + esc(errText(err)) + "</div>");
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/* ----- Schema actions ----- */
|
|
955
|
+
function schemaNotice(html) { const n = $("schema-notice"); if (n) n.innerHTML = html || ""; }
|
|
956
|
+
|
|
957
|
+
async function formatSchema() {
|
|
958
|
+
try {
|
|
959
|
+
if (!schemaEd.value.trim()) { schemaNotice(""); return; }
|
|
960
|
+
schemaEd.value = await convertFormat(schemaEd.value, state.schemaFormat, state.schemaFormat);
|
|
961
|
+
updateSchemaDirty();
|
|
962
|
+
schemaNotice("");
|
|
963
|
+
} catch (e) {
|
|
964
|
+
schemaNotice('<div class="notice error">' + esc(errText(e)) + "</div>");
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
async function saveSchema() {
|
|
969
|
+
const raw = schemaEd.value.trim();
|
|
970
|
+
const body = { revision: state.revision };
|
|
971
|
+
if (raw) { body.schema = schemaEd.value; body.schema_format = state.schemaFormat; }
|
|
972
|
+
else { body.schema = null; }
|
|
973
|
+
try {
|
|
974
|
+
const { data } = await api("PUT",
|
|
975
|
+
"/api/apps/" + encodeURIComponent(state.selected) + "/schema", body);
|
|
976
|
+
applyRevision(data.revision);
|
|
977
|
+
state.schema = data.schema;
|
|
978
|
+
state.schemaPristine = data.schema ? await serialize(data.schema, state.schemaFormat) : "";
|
|
979
|
+
schemaEd.value = state.schemaPristine;
|
|
980
|
+
updateSchemaDirty();
|
|
981
|
+
const flag = $("schema-flag");
|
|
982
|
+
if (flag) flag.textContent = state.schema ? "yes" : "none";
|
|
983
|
+
schemaNotice('<div class="notice ok">' +
|
|
984
|
+
(state.schema ? "Schema saved." : "Schema cleared.") + "</div>");
|
|
985
|
+
toast("Schema updated (revision " + state.revision + ")");
|
|
986
|
+
await refreshApps();
|
|
987
|
+
} catch (err) {
|
|
988
|
+
if (err.status === 409) {
|
|
989
|
+
schemaNotice('<div class="notice warn">' + esc(errText(err)) +
|
|
990
|
+
'<div class="notice-actions">' +
|
|
991
|
+
'<button class="btn sm" id="schema-conflict-reload">Reload latest</button></div></div>');
|
|
992
|
+
$("schema-conflict-reload").onclick = () => loadAppDetail(state.selected);
|
|
993
|
+
} else {
|
|
994
|
+
// A 400 here usually means the current config violates the new schema.
|
|
995
|
+
schemaNotice('<div class="notice error">Schema rejected: ' + esc(errText(err)) + "</div>");
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function applyRevision(rev) {
|
|
1001
|
+
if (rev == null) return;
|
|
1002
|
+
state.revision = rev;
|
|
1003
|
+
const label = $("rev-label");
|
|
1004
|
+
if (label) label.textContent = rev;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
async function deleteApp() {
|
|
1008
|
+
const name = state.selected;
|
|
1009
|
+
if (!confirm('Delete app "' + name + '"? This cannot be undone.')) return;
|
|
1010
|
+
try {
|
|
1011
|
+
await api("DELETE", "/api/apps/" + encodeURIComponent(name));
|
|
1012
|
+
closeWs();
|
|
1013
|
+
state.selected = null;
|
|
1014
|
+
$("content").innerHTML =
|
|
1015
|
+
'<div class="empty-state">Select an app, or create one to get started.</div>';
|
|
1016
|
+
await refreshApps();
|
|
1017
|
+
toast('App "' + name + '" deleted');
|
|
1018
|
+
} catch (err) {
|
|
1019
|
+
toast(errText(err));
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/* ===================================================================== */
|
|
1024
|
+
/* WebSocket — live updates */
|
|
1025
|
+
/* ===================================================================== */
|
|
1026
|
+
function closeWs() {
|
|
1027
|
+
clearTimeout(state.wsRetry);
|
|
1028
|
+
if (state.ws) {
|
|
1029
|
+
state.ws.onclose = null;
|
|
1030
|
+
try { state.ws.close(); } catch (_) {}
|
|
1031
|
+
state.ws = null;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
function openWs(name, attempt) {
|
|
1036
|
+
closeWs();
|
|
1037
|
+
attempt = attempt || 0;
|
|
1038
|
+
const proto = location.protocol === "https:" ? "wss" : "ws";
|
|
1039
|
+
const ws = new WebSocket(proto + "://" + location.host + "/ws/" + encodeURIComponent(name));
|
|
1040
|
+
state.ws = ws;
|
|
1041
|
+
ws.onopen = () => { setLive(true); attempt = 0; };
|
|
1042
|
+
ws.onclose = () => {
|
|
1043
|
+
setLive(false);
|
|
1044
|
+
// Reconnect with exponential backoff, and give up after a few tries so a
|
|
1045
|
+
// genuinely unreachable socket does not spam the console forever.
|
|
1046
|
+
if (state.selected === name && attempt < 5) {
|
|
1047
|
+
const delay = Math.min(30000, 2000 * Math.pow(2, attempt));
|
|
1048
|
+
state.wsRetry = setTimeout(() => openWs(name, attempt + 1), delay);
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
ws.onmessage = (ev) => {
|
|
1052
|
+
let msg;
|
|
1053
|
+
try { msg = JSON.parse(ev.data); } catch (_) { return; }
|
|
1054
|
+
if (msg.app !== state.selected) return;
|
|
1055
|
+
if (msg.type === "initial_config" || msg.type === "update") onRemoteUpdate(msg);
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function setLive(on) {
|
|
1060
|
+
const dot = $("live-dot"), label = $("live-label");
|
|
1061
|
+
if (dot) dot.classList.toggle("on", on);
|
|
1062
|
+
if (label) label.textContent = on ? "live" : "offline";
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
async function onRemoteUpdate(msg) {
|
|
1066
|
+
applyRevision(msg.revision);
|
|
1067
|
+
if (msg.data !== undefined) {
|
|
1068
|
+
state.configObj = msg.data;
|
|
1069
|
+
if (state.activeTab === "config" && configEd) {
|
|
1070
|
+
let incoming;
|
|
1071
|
+
try { incoming = await serialize(msg.data, state.configFormat); }
|
|
1072
|
+
catch (_) { incoming = JSON.stringify(msg.data, null, 2); }
|
|
1073
|
+
if (!isConfigDirty()) {
|
|
1074
|
+
state.pristine = incoming;
|
|
1075
|
+
configEd.value = incoming;
|
|
1076
|
+
updateDirty();
|
|
1077
|
+
} else {
|
|
1078
|
+
state.pristine = incoming;
|
|
1079
|
+
configNotice('<div class="notice warn">This config changed on the server ' +
|
|
1080
|
+
"(revision " + esc(msg.revision) + "). Your unsaved edits are still here." +
|
|
1081
|
+
'<div class="notice-actions">' +
|
|
1082
|
+
'<button class="btn sm" id="accept-remote">Load server version</button></div></div>');
|
|
1083
|
+
$("accept-remote").onclick = () => {
|
|
1084
|
+
configEd.value = incoming;
|
|
1085
|
+
updateDirty();
|
|
1086
|
+
configNotice("");
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
// The schema is not carried in WS payloads — refresh it when it may be stale.
|
|
1092
|
+
if (state.activeTab === "schema" && schemaEd && !isSchemaDirty()) {
|
|
1093
|
+
try {
|
|
1094
|
+
const sch = await api("GET",
|
|
1095
|
+
"/api/apps/" + encodeURIComponent(state.selected) + "/schema");
|
|
1096
|
+
state.schema = sch.data.data.schema;
|
|
1097
|
+
state.schemaPristine = state.schema
|
|
1098
|
+
? await serialize(state.schema, state.schemaFormat) : "";
|
|
1099
|
+
schemaEd.value = state.schemaPristine;
|
|
1100
|
+
updateSchemaDirty();
|
|
1101
|
+
const flag = $("schema-flag");
|
|
1102
|
+
if (flag) flag.textContent = state.schema ? "yes" : "none";
|
|
1103
|
+
} catch (_) { /* leave the current view as-is */ }
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
/* ===================================================================== */
|
|
1108
|
+
/* Modals */
|
|
1109
|
+
/* ===================================================================== */
|
|
1110
|
+
function openModal(html) {
|
|
1111
|
+
const ov = $("modal-overlay");
|
|
1112
|
+
ov.innerHTML = '<div class="modal">' + html + "</div>";
|
|
1113
|
+
ov.classList.remove("hidden");
|
|
1114
|
+
ov.onclick = (e) => { if (e.target === ov) closeModal(); };
|
|
1115
|
+
// Pull focus off whatever was behind the overlay (e.g. a code editor) so
|
|
1116
|
+
// keystrokes land in the modal, not the editor underneath it.
|
|
1117
|
+
if (document.activeElement && document.activeElement.blur) {
|
|
1118
|
+
document.activeElement.blur();
|
|
1119
|
+
}
|
|
1120
|
+
const first = ov.querySelector("input, textarea, select, button");
|
|
1121
|
+
if (first) first.focus();
|
|
1122
|
+
// Keep Tab focus inside the modal while it is open.
|
|
1123
|
+
ov.onkeydown = (e) => {
|
|
1124
|
+
if (e.key !== "Tab") return;
|
|
1125
|
+
const f = ov.querySelectorAll("input, textarea, select, button");
|
|
1126
|
+
if (!f.length) return;
|
|
1127
|
+
const first = f[0], last = f[f.length - 1];
|
|
1128
|
+
if (e.shiftKey && document.activeElement === first) {
|
|
1129
|
+
e.preventDefault(); last.focus();
|
|
1130
|
+
} else if (!e.shiftKey && document.activeElement === last) {
|
|
1131
|
+
e.preventDefault(); first.focus();
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
function closeModal() {
|
|
1136
|
+
$("modal-overlay").classList.add("hidden");
|
|
1137
|
+
$("modal-overlay").innerHTML = "";
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
// Convert a plain modal textarea between formats, tracking the current format
|
|
1141
|
+
// in a data attribute so the next switch knows the source format.
|
|
1142
|
+
async function changeModalFormat(taId, selId) {
|
|
1143
|
+
const ta = $(taId), sel = $(selId);
|
|
1144
|
+
const from = ta.dataset.fmt || "json";
|
|
1145
|
+
const to = sel.value;
|
|
1146
|
+
if (from === to) return;
|
|
1147
|
+
if (ta.value.trim()) {
|
|
1148
|
+
try { ta.value = await convertFormat(ta.value, from, to); }
|
|
1149
|
+
catch (e) {
|
|
1150
|
+
$("m-error").textContent = "Cannot convert to " + to.toUpperCase() + ": " + errText(e);
|
|
1151
|
+
sel.value = from;
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
ta.dataset.fmt = to;
|
|
1156
|
+
$("m-error").textContent = "";
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
function openNewAppModal() {
|
|
1160
|
+
openModal(`
|
|
1161
|
+
<h3>New app</h3>
|
|
1162
|
+
<div class="field">
|
|
1163
|
+
<label>Name (letters, digits, <code>-</code>, <code>_</code>)</label>
|
|
1164
|
+
<input class="input" id="m-name" placeholder="my-service" />
|
|
1165
|
+
</div>
|
|
1166
|
+
<div class="field">
|
|
1167
|
+
<label>Description (optional)</label>
|
|
1168
|
+
<input class="input" id="m-desc" />
|
|
1169
|
+
</div>
|
|
1170
|
+
<div class="field">
|
|
1171
|
+
<div class="field-head">
|
|
1172
|
+
<label>Initial configuration</label>
|
|
1173
|
+
<select class="select mini" id="m-config-format">${fmtOptions("json")}</select>
|
|
1174
|
+
</div>
|
|
1175
|
+
<textarea class="input code" id="m-config" rows="6" data-fmt="json">{}</textarea>
|
|
1176
|
+
</div>
|
|
1177
|
+
<div class="field">
|
|
1178
|
+
<div class="field-head">
|
|
1179
|
+
<label>Schema (optional)</label>
|
|
1180
|
+
<select class="select mini" id="m-schema-format">${fmtOptions("json")}</select>
|
|
1181
|
+
</div>
|
|
1182
|
+
<textarea class="input code" id="m-schema" rows="5" data-fmt="json"
|
|
1183
|
+
placeholder="Leave empty for no schema"></textarea>
|
|
1184
|
+
</div>
|
|
1185
|
+
<div class="modal-error" id="m-error"></div>
|
|
1186
|
+
<div class="modal-actions">
|
|
1187
|
+
<button class="btn" id="m-cancel">Cancel</button>
|
|
1188
|
+
<button class="btn primary" id="m-create">Create app</button>
|
|
1189
|
+
</div>
|
|
1190
|
+
`);
|
|
1191
|
+
$("m-config-format").onchange = () => changeModalFormat("m-config", "m-config-format");
|
|
1192
|
+
$("m-schema-format").onchange = () => changeModalFormat("m-schema", "m-schema-format");
|
|
1193
|
+
$("m-cancel").onclick = closeModal;
|
|
1194
|
+
$("m-create").onclick = createApp;
|
|
1195
|
+
$("m-name").focus();
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
async function createApp() {
|
|
1199
|
+
const name = $("m-name").value.trim();
|
|
1200
|
+
const desc = $("m-desc").value.trim();
|
|
1201
|
+
if (!name) { $("m-error").textContent = "Name is required."; return; }
|
|
1202
|
+
const body = {
|
|
1203
|
+
name,
|
|
1204
|
+
data: $("m-config").value.trim() || "{}",
|
|
1205
|
+
format: $("m-config-format").value,
|
|
1206
|
+
};
|
|
1207
|
+
if (desc) body.description = desc;
|
|
1208
|
+
const schemaRaw = $("m-schema").value.trim();
|
|
1209
|
+
if (schemaRaw) {
|
|
1210
|
+
body.schema = schemaRaw;
|
|
1211
|
+
body.schema_format = $("m-schema-format").value;
|
|
1212
|
+
}
|
|
1213
|
+
try {
|
|
1214
|
+
await api("POST", "/api/apps", body);
|
|
1215
|
+
closeModal();
|
|
1216
|
+
await refreshApps();
|
|
1217
|
+
await selectApp(name);
|
|
1218
|
+
toast('App "' + name + '" created');
|
|
1219
|
+
} catch (e) {
|
|
1220
|
+
$("m-error").textContent = errText(e);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
function openMetaModal() {
|
|
1225
|
+
const info = state.apps[state.selected] || {};
|
|
1226
|
+
openModal(`
|
|
1227
|
+
<h3>Edit app</h3>
|
|
1228
|
+
<div class="field">
|
|
1229
|
+
<label>Name</label>
|
|
1230
|
+
<input class="input" id="m-name" value="${esc(state.selected)}" />
|
|
1231
|
+
</div>
|
|
1232
|
+
<div class="field">
|
|
1233
|
+
<label>Description</label>
|
|
1234
|
+
<input class="input" id="m-desc" value="${esc(info.description || "")}" />
|
|
1235
|
+
</div>
|
|
1236
|
+
<div class="modal-error" id="m-error"></div>
|
|
1237
|
+
<div class="modal-actions">
|
|
1238
|
+
<button class="btn" id="m-cancel">Cancel</button>
|
|
1239
|
+
<button class="btn primary" id="m-save">Save</button>
|
|
1240
|
+
</div>
|
|
1241
|
+
`);
|
|
1242
|
+
$("m-cancel").onclick = closeModal;
|
|
1243
|
+
$("m-save").onclick = saveMeta;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
async function saveMeta() {
|
|
1247
|
+
const name = $("m-name").value.trim();
|
|
1248
|
+
const desc = $("m-desc").value.trim();
|
|
1249
|
+
if (!name) { $("m-error").textContent = "Name is required."; return; }
|
|
1250
|
+
try {
|
|
1251
|
+
const { data } = await api("PATCH",
|
|
1252
|
+
"/api/apps/" + encodeURIComponent(state.selected) + "/metadata",
|
|
1253
|
+
{ name, description: desc, revision: state.revision });
|
|
1254
|
+
closeModal();
|
|
1255
|
+
const renamed = data.app.name !== state.selected;
|
|
1256
|
+
state.selected = data.app.name;
|
|
1257
|
+
state.revision = data.app.revision;
|
|
1258
|
+
await refreshApps();
|
|
1259
|
+
if (renamed) { closeWs(); openWs(state.selected); }
|
|
1260
|
+
renderAppList();
|
|
1261
|
+
await loadAppDetail(state.selected);
|
|
1262
|
+
toast("App updated");
|
|
1263
|
+
} catch (e) {
|
|
1264
|
+
$("m-error").textContent = errText(e);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
$("new-app-btn").onclick = openNewAppModal;
|
|
1269
|
+
document.addEventListener("keydown", (e) => {
|
|
1270
|
+
if (e.key === "Escape" && !$("modal-overlay").classList.contains("hidden")) closeModal();
|
|
1271
|
+
});
|
|
1272
|
+
window.addEventListener("beforeunload", (e) => {
|
|
1273
|
+
if (anyDirty()) { e.preventDefault(); e.returnValue = ""; }
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
/* ===================================================================== */
|
|
1277
|
+
/* Go */
|
|
1278
|
+
/* ===================================================================== */
|
|
1279
|
+
boot();
|
|
1280
|
+
</script>
|
|
1281
|
+
</body>
|
|
1282
|
+
</html>
|