-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbindings.go.html
More file actions
570 lines (552 loc) · 24.7 KB
/
Copy pathbindings.go.html
File metadata and controls
570 lines (552 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
{{/* Copyright (c) ClaceIO, LLC */}}
{{/* SPDX-License-Identifier: Apache-2.0 */}}
{{/* Bindings page (/bindings): services table plus base/derived/auto
binding tables. HTMX partial: block binding_groups
*/}}
{{/* binding_service renders the service name and type for a binding row */}}
{{ define "binding_service" }}
{{ if .service_name }}
<span class="font-mono text-xs">{{ .service_name }}</span>
{{ end }}
{{ if .service_type }}
<span class="badge badge-ghost badge-xs">{{ .service_type }}</span>
{{ else if not .service_name }}
<span
class="text-xs text-base-content/70 tooltip tooltip-right"
data-tip="{{ .source }}"
>config only</span
>
{{ end }}
{{ end }}
{{/* binding_config renders the config keys summary cell content */}}
{{ define "binding_config" }}
{{ if .config_keys }}
<span
class="text-xs text-base-content/70 font-mono tooltip tooltip-right"
data-tip="{{ range .config_keys }}{{ . }}{{ end }}"
>{{ len .config_keys }} keys</span
>
{{ else }}
<span class="text-xs text-base-content/70">-</span>
{{ end }}
{{ end }}
{{/* binding_badges renders the staged changes marker */}}
{{ define "binding_badges" }}
{{ if .has_staged }}
<span
class="badge badge-warning badge-xs badge-soft tooltip tooltip-left"
data-tip="staging has changes not applied to prod: {{ range .staged_grants }}
{{ . }}
{{ end }}"
>pending</span
>
{{ end }}
{{ end }}
{{/* binding_updated renders the update age cell content */}}
{{ define "binding_updated" }}
{{ if .update_time }}
{{ template "time_ago" .update_time }}
{{ end }}
{{ end }}
{{/* binding_actions renders the row action buttons.
Context: dict with Path, AppPath, Editable (grants can be updated) and
Perms (the user's management permissions)
*/}}
{{ define "binding_actions" }}
<div class="inline-flex items-center gap-0.5">
{{ if .Editable }}
<a
class="btn btn-xs btn-ghost btn-square tooltip tooltip-left {{ if not (index .Perms "binding:update") }}
btn-disabled
{{ end }}"
{{ if index .Perms "binding:update" }}
href="{{ .AppPath }}/bindings/update?path={{ .Path }}"
{{ else }}
aria-disabled="true" tabindex="-1"
{{ end }}
aria-label="Edit grants of {{ .Path }}"
data-tip="{{ if index .Perms "binding:update" }}
Edit grants
{{ else }}
requires binding:update
{{ end }}">
<svg
aria-hidden="true"
focusable="false"
class="w-3.5 h-3.5"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round">
<path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z" />
</svg>
</a>
{{ end }}
<button
class="btn btn-xs btn-ghost btn-square text-error tooltip tooltip-left"
aria-label="Delete binding {{ .Path }}"
{{ if index .Perms "binding:delete" }}
data-tip="Delete binding" hx-post="{{ .AppPath }}/bindings/delete"
hx-disabled-elt="this" hx-vals='{"path": "{{ .Path }}"}'
hx-confirm="Delete binding {{ .Path }}? Apps referencing it will fail to
load." hx-target="#binding-groups" hx-swap="innerHTML transition:true"
hx-include="#page-search" hx-indicator="#page-progress"
{{ else }}
disabled data-tip="requires binding:delete"
{{ end }}>
<svg
aria-hidden="true"
focusable="false"
class="w-3.5 h-3.5"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round">
<path d="M3 6h18" />
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" />
<path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
<path d="M10 11v6" />
<path d="M14 11v6" />
</svg>
</button>
</div>
{{ end }}
<!DOCTYPE html>
<html lang="en">
{{ template "head" . }}
<body class="min-h-screen bg-base-200">
<div class="drawer lg:drawer-open">
{{ template "drawer_toggle" }}
<div class="drawer-content">
<main class="p-4 lg:p-6 space-y-4 max-w-6xl">
<!-- Header -->
<div
class="page-header flex items-center gap-2 flex-wrap mb-2 md:mb-6">
{{ template "hamburger" . }}
<div>
{{ template "page_title" "OpenRun Bindings" }}
<p class="page-desc text-sm text-base-content/70">
{{ .Data.Total }} bindings - connect apps to services
</p>
</div>
<div class="page-actions ml-auto flex items-center gap-2">
<label
class="input input-sm flex-1 min-w-0 sm:flex-none sm:w-48 sm:focus-within:w-60 transition-[width] duration-300 flex">
<kbd class="kbd kbd-xs hidden sm:inline-flex" aria-hidden="true"
>⌘K</kbd
>
<input
id="page-search"
type="search"
name="query"
aria-label="Filter bindings"
value="{{ .Data.Query }}"
placeholder="Filter bindings…"
hx-get="{{ .AppPath }}/bindings"
hx-trigger="input changed delay:300ms, search"
hx-push-url="true"
hx-target="#binding-groups"
hx-swap="innerHTML transition:true"
hx-indicator="#page-progress" />
</label>
<a
class="btn btn-sm btn-outline transition-transform duration-150 active:scale-95 {{ if not (index .Data.Perms "service:create") }}
btn-disabled tooltip tooltip-bottom
{{ end }}"
{{ if index .Data.Perms "service:create" }}
href="{{ .AppPath }}/bindings/services/create"
{{ else }}
data-tip="requires service:create" aria-disabled="true"
tabindex="-1"
{{ end }}>
+ New service
</a>
<a
class="btn btn-sm btn-primary transition-transform duration-150 active:scale-95 {{ if not (index .Data.Perms "binding:create") }}
btn-disabled tooltip tooltip-bottom
{{ end }}"
{{ if index .Data.Perms "binding:create" }}
href="{{ .AppPath }}/bindings/create"
{{ else }}
data-tip="requires binding:create" aria-disabled="true"
tabindex="-1"
{{ end }}>
+ New binding
</a>
</div>
</div>
{{ template "page_progress" }}
<div id="binding-groups" class="space-y-4">
{{ block "binding_groups" . }}
{{ template "flash_alerts" .Data }}
<!-- Service entries, the targets bindings attach to -->
<div class="card bg-base-100 border border-base-300">
<div
class="px-4 py-2.5 border-b border-base-300 flex items-center gap-2 flex-wrap">
<h2 class="text-sm font-medium">Services</h2>
<span class="text-xs text-base-content/70"
>{{ len .Data.Services }} services - bindings connect apps
to these</span
>
</div>
{{ if .Data.ServicesError }}
<p class="text-sm text-base-content/70 px-4 py-4 break-all">
{{ .Data.ServicesError }}
</p>
{{ else if .Data.Services }}
<div class="overflow-x-auto">
<table class="table table-sm">
<thead>
<tr>
<th scope="col">Service</th>
<th scope="col" class="hidden sm:table-cell">Type</th>
<th scope="col" class="hidden md:table-cell">
Config
</th>
<th scope="col" class="hidden lg:table-cell">
Staging
</th>
<th scope="col" class="hidden xl:table-cell">
Updated
</th>
<th scope="col" class="text-right">Actions</th>
</tr>
</thead>
<tbody>
{{ range .Data.Services }}
<tr class="group hover:bg-base-200/60">
<td class="font-mono text-xs font-medium">
{{ .id }}
{{ if .is_default }}
<span
class="badge badge-primary badge-xs badge-soft tooltip tooltip-right"
data-tip="default {{ .service_type }} service"
>default</span
>
{{ end }}
</td>
<td class="hidden sm:table-cell">
<span class="badge badge-ghost badge-xs"
>{{ .service_type }}</span
>
</td>
<td class="hidden md:table-cell">
{{ range .config_keys }}
<span
class="badge badge-outline badge-xs font-mono"
>{{ . }}</span
>
{{ else }}
<span class="text-base-content/70 text-xs"
>-</span
>
{{ end }}
</td>
<td
class="font-mono text-xs text-base-content/70 hidden lg:table-cell">
{{ if .staging }}
{{ .staging }}
{{ else }}
-
{{ end }}
</td>
<td
class="text-xs text-base-content/70 whitespace-nowrap hidden xl:table-cell">
{{ if .update_time }}
{{ template "time_ago" .update_time }}
{{ end }}
</td>
<td class="text-right whitespace-nowrap">
<div class="inline-flex items-center gap-0.5">
<button
class="btn btn-xs btn-ghost text-error tooltip tooltip-left"
{{ if index $.Data.Perms "service:delete" }}
data-tip="Delete service"
hx-post="{{ $.AppPath }}/bindings/services/delete"
hx-vals='{"id": "{{ .id }}"}'
hx-confirm="Delete service {{ .id }}?
Bindings referencing it will stop working."
hx-target="#binding-groups"
hx-swap="innerHTML transition:true"
hx-include="#page-search"
hx-disabled-elt="this"
hx-indicator="#page-progress"
{{ else }}
disabled data-tip="requires service:delete"
{{ end }}>
delete
</button>
</div>
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
{{ else }}
<div
class="px-4 py-4 text-sm text-base-content/70 flex items-center gap-3 flex-wrap">
<span>No services configured yet</span>
<a
class="btn btn-xs btn-outline transition-transform duration-150 active:scale-95 {{ if not (index .Data.Perms "service:create") }}
btn-disabled tooltip tooltip-top
{{ end }}"
{{ if index .Data.Perms "service:create" }}
href="{{ .AppPath }}/bindings/services/create"
{{ else }}
data-tip="requires service:create"
{{ end }}
>+ New service</a
>
</div>
{{ end }}
</div>
{{ if .Data.Base }}
<div class="card bg-base-100 border border-base-300">
<div
class="px-4 py-2.5 border-b border-base-300 flex items-center gap-2 flex-wrap">
<h2 class="text-sm font-medium">Base bindings</h2>
<span class="text-xs text-base-content/70"
>bind directly to a service</span
>
</div>
<div class="overflow-x-auto">
<table class="table table-sm">
<thead>
<tr>
<th scope="col">Binding</th>
<th scope="col">Service</th>
<th scope="col" class="hidden lg:table-cell">
Config
</th>
<th scope="col" class="hidden lg:table-cell">By</th>
<th scope="col" class="hidden xl:table-cell">
Updated
</th>
<th scope="col" class="text-right">Actions</th>
</tr>
</thead>
<tbody>
{{ range .Data.Base }}
<tr class="group hover:bg-base-200/60">
<td>
<span class="font-mono font-medium break-all"
>{{ .path }}</span
>
{{ template "binding_badges" . }}
</td>
<td>{{ template "binding_service" . }}</td>
<td class="hidden lg:table-cell">
{{ template "binding_config" . }}
</td>
<td
class="text-xs text-base-content/70 whitespace-nowrap hidden lg:table-cell max-w-32 truncate tooltip tooltip-left"
data-tip="{{ .created_by }}">
{{ if .created_by }}
{{ .created_by }}
{{ else }}
-
{{ end }}
</td>
<td
class="text-xs text-base-content/70 whitespace-nowrap hidden xl:table-cell">
{{ template "binding_updated" . }}
</td>
<td class="text-right whitespace-nowrap">
{{ template "binding_actions" (dict "Path" .path "AppPath" $.AppPath "Editable" false "Perms" $.Data.Perms) }}
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</div>
{{ end }}
{{ if .Data.Derived }}
<div class="card bg-base-100 border border-base-300">
<div
class="px-4 py-2.5 border-b border-base-300 flex items-center gap-2 flex-wrap">
<h2 class="text-sm font-medium">Derived bindings</h2>
<span class="text-xs text-base-content/70"
>extend a base binding with grants and config
overrides</span
>
</div>
<div class="overflow-x-auto">
<table class="table table-sm">
<thead>
<tr>
<th scope="col">Binding</th>
<th scope="col">Base binding</th>
<th scope="col" class="hidden md:table-cell">
Service
</th>
<th scope="col">Grants</th>
<th scope="col" class="hidden lg:table-cell">
Config
</th>
<th scope="col" class="hidden lg:table-cell">By</th>
<th scope="col" class="hidden xl:table-cell">
Updated
</th>
<th scope="col" class="text-right">Actions</th>
</tr>
</thead>
<tbody>
{{ range .Data.Derived }}
<tr class="group hover:bg-base-200/60">
<td>
<span class="font-mono font-medium break-all"
>{{ .path }}</span
>
{{ template "binding_badges" . }}
</td>
<td class="font-mono text-xs">
{{ .derived_from }}
</td>
<td class="hidden md:table-cell">
{{ template "binding_service" . }}
</td>
<td class="space-x-1">
{{ range .grants }}
<span
class="badge badge-xs badge-soft {{ if hasPrefix "full" (lower .) }}
badge-warning
{{ else }}
badge-primary
{{ end }} font-mono"
>{{ . }}</span
>
{{ else }}
<span class="text-xs text-base-content/70"
>no grants</span
>
{{ end }}
</td>
<td class="hidden lg:table-cell">
{{ template "binding_config" . }}
</td>
<td
class="text-xs text-base-content/70 whitespace-nowrap hidden lg:table-cell max-w-32 truncate tooltip tooltip-left"
data-tip="{{ .created_by }}">
{{ if .created_by }}
{{ .created_by }}
{{ else }}
-
{{ end }}
</td>
<td
class="text-xs text-base-content/70 whitespace-nowrap hidden xl:table-cell">
{{ template "binding_updated" . }}
</td>
<td class="text-right whitespace-nowrap">
{{ template "binding_actions" (dict "Path" .path "AppPath" $.AppPath "Editable" true "Perms" $.Data.Perms) }}
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</div>
{{ end }}
{{ if .Data.Auto }}
<div
class="card bg-base-100 border border-dashed border-base-300">
<div
class="px-4 py-2.5 border-b border-base-300 flex items-center gap-2 flex-wrap">
<span class="badge badge-outline badge-xs">auto</span>
<h2 class="text-sm font-medium">Auto bindings</h2>
<span class="text-xs text-base-content/70"
>created automatically when an app references a service
directly</span
>
</div>
<div class="overflow-x-auto">
<table class="table table-sm">
<thead>
<tr>
<th scope="col">App</th>
<th scope="col">Service</th>
<th scope="col" class="hidden lg:table-cell">
Config
</th>
<th scope="col" class="hidden xl:table-cell">
Updated
</th>
</tr>
</thead>
<tbody>
{{ range .Data.Auto }}
<tr class="hover:bg-base-200/60">
<td>
<span
class="font-mono font-medium tooltip tooltip-right"
data-tip="{{ .path }}"
>{{ .app_path }}</span
>
{{ template "binding_badges" . }}
</td>
<td>{{ template "binding_service" . }}</td>
<td class="hidden lg:table-cell">
{{ template "binding_config" . }}
</td>
<td
class="text-xs text-base-content/70 whitespace-nowrap hidden xl:table-cell">
{{ template "binding_updated" . }}
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</div>
{{ end }}
{{ if and (not .Data.Base) (not .Data.Derived) (not .Data.Auto) }}
<div class="card bg-base-100 border border-base-300 py-10">
<div
class="flex flex-col items-center gap-2 text-center text-sm text-base-content/70">
{{ if .Data.Query }}
<span class="text-xl" aria-hidden="true">🔍</span>
<p>No bindings match "{{ .Data.Query }}"</p>
<button
class="btn btn-xs btn-outline transition-transform duration-150 active:scale-95"
onclick="const s = document.getElementById('page-search'); if (s) s.value = ''"
hx-get="{{ .AppPath }}/bindings"
hx-vals='{"query": ""}'
hx-target="#binding-groups"
hx-swap="innerHTML transition:true"
hx-push-url="true"
hx-indicator="#page-progress">
Clear search
</button>
{{ else }}
<span class="text-xl" aria-hidden="true">🔗</span>
<p>No bindings configured yet</p>
<a
class="btn btn-xs btn-primary transition-transform duration-150 active:scale-95 {{ if not (index .Data.Perms "binding:create") }}
btn-disabled tooltip tooltip-top
{{ end }}"
{{ if index .Data.Perms "binding:create" }}
href="{{ .AppPath }}/bindings/create"
{{ else }}
data-tip="requires binding:create"
{{ end }}
>+ New binding</a
>
{{ end }}
</div>
</div>
{{ end }}
{{ end }}
<!-- End of "binding_groups" block -->
</div>
</main>
</div>
{{ template "sidebar" . }}
</div>
</body>
</html>