@crombolo/backoffice-host 0.44.0 → 0.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/plugin/app-preview/umbraco-package.json +1 -1
- package/plugin/bundles-client.js +6 -0
- package/plugin/bundles-installed.js +32 -3
- package/plugin/bundles-marketplace.js +74 -9
- package/plugin/bundles-signature-words.js +52 -0
- package/plugin/bundles-signature.js +35 -0
- package/plugin/ci-access-words.js +6 -0
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/media-jobs-words.js +21 -0
- package/plugin/media-jobs.js +95 -0
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/umbraco-package.json +19 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/backoffice-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Serves the Umbraco backoffice SPA: shell HTML, import map and package manifests.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@crombolo/core": "0.
|
|
36
|
-
"@crombolo/backoffice-dist": "0.
|
|
35
|
+
"@crombolo/core": "0.46.1",
|
|
36
|
+
"@crombolo/backoffice-dist": "0.46.1"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/plugin/bundles-client.js
CHANGED
|
@@ -27,6 +27,12 @@ export const searchMarketplace = (query) =>
|
|
|
27
27
|
|
|
28
28
|
export const listInstalled = () => json('/installed')
|
|
29
29
|
|
|
30
|
+
/** Where a version was built, and whether this site would install it (story 060). */
|
|
31
|
+
export const bundleSignature = (name, version) =>
|
|
32
|
+
json(
|
|
33
|
+
`/signature?name=${encodeURIComponent(name)}${version ? `&version=${encodeURIComponent(version)}` : ''}`,
|
|
34
|
+
)
|
|
35
|
+
|
|
30
36
|
export const installBundle = (
|
|
31
37
|
name,
|
|
32
38
|
version,
|
|
@@ -17,6 +17,7 @@ import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit
|
|
|
17
17
|
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
18
18
|
import { carriesTags } from './bundles-carries.js'
|
|
19
19
|
import { disableBundle, enableBundle, listInstalled, uninstallBundle } from './bundles-client.js'
|
|
20
|
+
import { signatureBlock, signatureStyles, signatureWords } from './bundles-signature.js'
|
|
20
21
|
|
|
21
22
|
/** Where each part of a bundle stands on this site, in the words of someone running it. */
|
|
22
23
|
function status(item) {
|
|
@@ -45,8 +46,10 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
45
46
|
_busy: { state: true },
|
|
46
47
|
_notice: { state: true },
|
|
47
48
|
_installs: { state: true },
|
|
49
|
+
_restartPending: { state: true },
|
|
48
50
|
_filter: { state: true },
|
|
49
51
|
_selected: { state: true },
|
|
52
|
+
_policy: { state: true },
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
constructor() {
|
|
@@ -56,6 +59,7 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
56
59
|
this._busy = ''
|
|
57
60
|
this._notice = ''
|
|
58
61
|
this._installs = true
|
|
62
|
+
this._restartPending = false
|
|
59
63
|
this._filter = ''
|
|
60
64
|
// Settings links a bundle's cards here, naming it in `?bundle=`.
|
|
61
65
|
this._selected = new URLSearchParams(window.location.search).get('bundle') ?? ''
|
|
@@ -72,6 +76,8 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
72
76
|
const result = await listInstalled()
|
|
73
77
|
this._items = result.items ?? []
|
|
74
78
|
this._installs = result.installs !== false
|
|
79
|
+
this._restartPending = Boolean(result.restartPending)
|
|
80
|
+
this._policy = result.policy
|
|
75
81
|
if (!this._items.some((item) => item.packageName === this._selected))
|
|
76
82
|
this._selected = this._items[0]?.packageName ?? ''
|
|
77
83
|
} catch (error) {
|
|
@@ -174,6 +180,11 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
174
180
|
const shown = this.#shown
|
|
175
181
|
return html`
|
|
176
182
|
${this._notice ? html`<div id="notice">${this._notice}</div>` : nothing}
|
|
183
|
+
${
|
|
184
|
+
this._restartPending
|
|
185
|
+
? html`<div id="restart">Installed changes take effect when the site restarts.</div>`
|
|
186
|
+
: nothing
|
|
187
|
+
}
|
|
177
188
|
<div id="columns">
|
|
178
189
|
<uui-box headline="Installed bundles" style="--uui-box-default-padding:0;">
|
|
179
190
|
<div id="filter">
|
|
@@ -196,7 +207,7 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
196
207
|
(item) => item.packageName,
|
|
197
208
|
(item) => html`<uui-ref-node
|
|
198
209
|
name=${item.name}
|
|
199
|
-
detail=${`${item.packageName} ${item.version}`}
|
|
210
|
+
detail=${`${item.packageName} ${item.version} · ${this.#words(item).label}`}
|
|
200
211
|
selectable
|
|
201
212
|
select-only
|
|
202
213
|
?selected=${item.packageName === this._selected}
|
|
@@ -212,6 +223,13 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
212
223
|
`
|
|
213
224
|
}
|
|
214
225
|
|
|
226
|
+
/** Signed or not (story 060); an unsigned one under a site that wants signatures says so. */
|
|
227
|
+
#words(item) {
|
|
228
|
+
const unsignedRefused =
|
|
229
|
+
item.provenance?.state === 'unsigned' && this._policy?.signatures === 'required'
|
|
230
|
+
return signatureWords(item.provenance, unsignedRefused ? 'unsigned' : null, this._policy)
|
|
231
|
+
}
|
|
232
|
+
|
|
215
233
|
#details(item) {
|
|
216
234
|
return html`<uui-box headline=${item.name}>
|
|
217
235
|
${item.description ? html`<p>${item.description}</p>` : nothing}
|
|
@@ -226,6 +244,8 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
226
244
|
<dd class="status">${status(item)}</dd>
|
|
227
245
|
<dt>Works with</dt>
|
|
228
246
|
<dd>Crombolo ${item.peerRange}</dd>
|
|
247
|
+
<dt>Signature</dt>
|
|
248
|
+
<dd>${signatureBlock(this.#words(item))}</dd>
|
|
229
249
|
</dl>
|
|
230
250
|
${this.#permissions(item)}
|
|
231
251
|
${
|
|
@@ -241,7 +261,9 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
241
261
|
</uui-box>`
|
|
242
262
|
}
|
|
243
263
|
|
|
244
|
-
static styles =
|
|
264
|
+
static styles = [
|
|
265
|
+
signatureStyles,
|
|
266
|
+
css`
|
|
245
267
|
.asks {
|
|
246
268
|
padding-left: 1.25em;
|
|
247
269
|
}
|
|
@@ -260,6 +282,12 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
260
282
|
border-left: 3px solid var(--uui-color-positive, #2bc37c);
|
|
261
283
|
background: var(--uui-color-surface-alt, #f3f3f5);
|
|
262
284
|
}
|
|
285
|
+
#restart {
|
|
286
|
+
margin-bottom: var(--uui-size-space-4, 12px);
|
|
287
|
+
padding: var(--uui-size-space-4, 12px);
|
|
288
|
+
border-left: 3px solid var(--uui-color-warning, #f0ac00);
|
|
289
|
+
background: var(--uui-color-surface-alt, #f3f3f5);
|
|
290
|
+
}
|
|
263
291
|
#columns {
|
|
264
292
|
display: grid;
|
|
265
293
|
grid-template-columns: minmax(240px, 1fr) 2fr;
|
|
@@ -307,7 +335,8 @@ export default class CromboloBundlesInstalledElement extends UmbLitElement {
|
|
|
307
335
|
opacity: 0.8;
|
|
308
336
|
font-size: 0.9em;
|
|
309
337
|
}
|
|
310
|
-
|
|
338
|
+
`,
|
|
339
|
+
]
|
|
311
340
|
}
|
|
312
341
|
|
|
313
342
|
customElements.define('crombolo-bundles-installed', CromboloBundlesInstalledElement)
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
|
|
17
17
|
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
18
18
|
import { carriesTags } from './bundles-carries.js'
|
|
19
|
-
import { installBundle, searchMarketplace } from './bundles-client.js'
|
|
19
|
+
import { bundleSignature, installBundle, searchMarketplace } from './bundles-client.js'
|
|
20
|
+
import { signatureBlock, signatureStyles, signatureWords } from './bundles-signature.js'
|
|
20
21
|
|
|
21
22
|
export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
22
23
|
static properties = {
|
|
@@ -34,6 +35,8 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
34
35
|
_consenting: { state: true },
|
|
35
36
|
_trusted: { state: true },
|
|
36
37
|
_asks: { state: true },
|
|
38
|
+
_reviewing: { state: true },
|
|
39
|
+
_signatures: { state: true },
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
constructor() {
|
|
@@ -53,6 +56,8 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
53
56
|
this._consenting = ''
|
|
54
57
|
this._trusted = false
|
|
55
58
|
this._asks = []
|
|
59
|
+
this._reviewing = ''
|
|
60
|
+
this._signatures = new Map()
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
connectedCallback() {
|
|
@@ -89,10 +94,62 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
89
94
|
this.#load()
|
|
90
95
|
}
|
|
91
96
|
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Where the version was built is checked first and shown (story 060), so the
|
|
99
|
+
* person sees signed or not, and whether this site would take it, before
|
|
100
|
+
* anything is installed.
|
|
101
|
+
*/
|
|
102
|
+
async #requestInstall(item) {
|
|
103
|
+
this._busy = item.name
|
|
104
|
+
this._notice = ''
|
|
105
|
+
try {
|
|
106
|
+
const checked = await bundleSignature(item.name, item.version)
|
|
107
|
+
if (!checked.ok) {
|
|
108
|
+
this._notice = checked.message ?? ''
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
this._signatures = new Map(this._signatures).set(item.name, checked)
|
|
112
|
+
this._reviewing = item.name
|
|
113
|
+
} catch (error) {
|
|
114
|
+
this._notice = error instanceof Error ? error.message : String(error)
|
|
115
|
+
} finally {
|
|
116
|
+
this._busy = ''
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#signature(item) {
|
|
121
|
+
const checked = this._signatures.get(item.name)
|
|
122
|
+
if (!checked) return nothing
|
|
123
|
+
return signatureBlock(signatureWords(checked.provenance, checked.refused, checked.policy))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The signature, and the install it leads to unless this site would refuse it. */
|
|
127
|
+
#review(item) {
|
|
128
|
+
const checked = this._signatures.get(item.name)
|
|
129
|
+
const refused =
|
|
130
|
+
Boolean(checked?.refused) ||
|
|
131
|
+
checked?.provenance?.state === 'invalid' ||
|
|
132
|
+
checked?.provenance?.state === 'unchecked'
|
|
133
|
+
return html`
|
|
134
|
+
${this.#signature(item)}
|
|
135
|
+
<div class="actions">
|
|
136
|
+
${
|
|
137
|
+
refused
|
|
138
|
+
? nothing
|
|
139
|
+
: html`<uui-button
|
|
140
|
+
look="primary"
|
|
141
|
+
label="Install"
|
|
142
|
+
.state=${this._busy === item.name ? 'waiting' : undefined}
|
|
143
|
+
@click=${() => this.#install(item, false)}></uui-button>`
|
|
144
|
+
}
|
|
145
|
+
<uui-button
|
|
146
|
+
look="secondary"
|
|
147
|
+
label="Cancel"
|
|
148
|
+
@click=${() => {
|
|
149
|
+
this._reviewing = ''
|
|
150
|
+
}}></uui-button>
|
|
151
|
+
</div>
|
|
152
|
+
`
|
|
96
153
|
}
|
|
97
154
|
|
|
98
155
|
#askConsent(item, asks) {
|
|
@@ -126,6 +183,7 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
126
183
|
return
|
|
127
184
|
}
|
|
128
185
|
this._consenting = ''
|
|
186
|
+
this._reviewing = ''
|
|
129
187
|
// The dependency line is what there is to commit, so it is shown rather
|
|
130
188
|
// than described: the install lives in this node's node_modules until it
|
|
131
189
|
// is in the site's repository.
|
|
@@ -164,6 +222,7 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
164
222
|
#consent(item) {
|
|
165
223
|
return html`
|
|
166
224
|
<div class="consent" role="group" aria-label="Install code that runs on the server">
|
|
225
|
+
${this.#signature(item)}
|
|
167
226
|
<p>
|
|
168
227
|
<strong>This bundle runs code on the server.</strong> Once your site's developers turn
|
|
169
228
|
it on, its code can read and change the site's data, files and settings.
|
|
@@ -271,7 +330,9 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
271
330
|
: html`<p class="meta">Add it to the site with <code>bun add ${item.name}</code>, then deploy.</p>`
|
|
272
331
|
: this._consenting === item.name
|
|
273
332
|
? this.#consent(item)
|
|
274
|
-
:
|
|
333
|
+
: this._reviewing === item.name
|
|
334
|
+
? this.#review(item)
|
|
335
|
+
: html`
|
|
275
336
|
<uui-button
|
|
276
337
|
look="primary"
|
|
277
338
|
label="Install"
|
|
@@ -288,7 +349,9 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
288
349
|
`
|
|
289
350
|
}
|
|
290
351
|
|
|
291
|
-
static styles =
|
|
352
|
+
static styles = [
|
|
353
|
+
signatureStyles,
|
|
354
|
+
css`
|
|
292
355
|
:host {
|
|
293
356
|
display: block;
|
|
294
357
|
padding: var(--uui-size-layout-1, 24px);
|
|
@@ -349,12 +412,14 @@ export default class CromboloBundlesMarketplaceElement extends UmbLitElement {
|
|
|
349
412
|
margin: 0 0 var(--uui-size-space-3, 9px);
|
|
350
413
|
padding-left: 1.25em;
|
|
351
414
|
}
|
|
352
|
-
.consent .actions
|
|
415
|
+
.consent .actions,
|
|
416
|
+
.actions {
|
|
353
417
|
display: flex;
|
|
354
418
|
gap: var(--uui-size-space-3, 9px);
|
|
355
419
|
margin-top: var(--uui-size-space-4, 12px);
|
|
356
420
|
}
|
|
357
|
-
|
|
421
|
+
`,
|
|
422
|
+
]
|
|
358
423
|
}
|
|
359
424
|
|
|
360
425
|
customElements.define('crombolo-bundles-marketplace', CromboloBundlesMarketplaceElement)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the Bundles screens say about where a bundle was built (story 060), in
|
|
3
|
+
* words for the person installing it. Pure, so it is tested without a browser.
|
|
4
|
+
*/
|
|
5
|
+
const short = (commit) => (commit ?? '').slice(0, 7)
|
|
6
|
+
const refName = (ref) => (ref ?? '').replace(/^refs\/(tags|heads)\//, '')
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {{ state: string, source?: { repository: string, ref: string, commit: string },
|
|
10
|
+
* links?: { commit?: string, tag?: string | null, run?: string | null }, reason?: string }} provenance
|
|
11
|
+
* @param {string | null | undefined} refused why this site would not install it, when it would not
|
|
12
|
+
* @param {{ signatures?: string, sources?: string[] } | undefined} policy
|
|
13
|
+
* @returns {{ tone: string, label: string, detail: string, links: { label: string, href: string }[], refusal: string }}
|
|
14
|
+
*/
|
|
15
|
+
export function signatureWords(provenance, refused, policy) {
|
|
16
|
+
const links = []
|
|
17
|
+
let tone = 'default'
|
|
18
|
+
let label = 'Not signed'
|
|
19
|
+
let detail = "Nobody has signed this bundle, so where it was built can't be checked."
|
|
20
|
+
if (provenance?.state === 'signed' && provenance.source) {
|
|
21
|
+
const { repository, ref, commit } = provenance.source
|
|
22
|
+
tone = 'positive'
|
|
23
|
+
label = 'Signed'
|
|
24
|
+
detail = `Built from github.com/${repository} at ${refName(ref)} (${short(commit)}).`
|
|
25
|
+
if (provenance.links?.commit) links.push({ label: 'Commit', href: provenance.links.commit })
|
|
26
|
+
if (provenance.links?.tag) links.push({ label: 'Release', href: provenance.links.tag })
|
|
27
|
+
if (provenance.links?.run) links.push({ label: 'Build', href: provenance.links.run })
|
|
28
|
+
} else if (provenance?.state === 'local') {
|
|
29
|
+
label = 'From this site'
|
|
30
|
+
detail = "Linked from this site's own code, not from a package registry."
|
|
31
|
+
} else if (provenance?.state === 'unchecked') {
|
|
32
|
+
tone = 'warning'
|
|
33
|
+
label = "Couldn't be checked right now"
|
|
34
|
+
detail =
|
|
35
|
+
"Its signature couldn't be checked just now, so it will not be installed. Try again in a few minutes."
|
|
36
|
+
} else if (provenance?.state === 'invalid') {
|
|
37
|
+
tone = 'danger'
|
|
38
|
+
label = "Signature doesn't match"
|
|
39
|
+
detail = provenance.reason?.startsWith('the bundle has changed')
|
|
40
|
+
? 'It has been changed since it was signed, so it will not be installed.'
|
|
41
|
+
: "Its signature can't be checked, so it will not be installed."
|
|
42
|
+
}
|
|
43
|
+
let refusal = ''
|
|
44
|
+
if (refused && provenance?.state !== 'invalid' && provenance?.state !== 'unchecked') {
|
|
45
|
+
tone = 'danger'
|
|
46
|
+
refusal =
|
|
47
|
+
provenance?.state === 'signed' && policy?.sources?.length
|
|
48
|
+
? `This site only installs signed bundles from ${policy.sources.join(', ')}.`
|
|
49
|
+
: 'This site only installs signed bundles.'
|
|
50
|
+
}
|
|
51
|
+
return { tone, label, detail, links, refusal }
|
|
52
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The signature as the Bundles screens show it (story 060): a tag, a line, its links, any refusal. */
|
|
2
|
+
import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
3
|
+
|
|
4
|
+
export { signatureWords } from './bundles-signature-words.js'
|
|
5
|
+
|
|
6
|
+
/** @param {ReturnType<typeof import('./bundles-signature-words.js').signatureWords>} words */
|
|
7
|
+
export function signatureBlock(words) {
|
|
8
|
+
return html`
|
|
9
|
+
<div class="signature" data-tone=${words.tone}>
|
|
10
|
+
<uui-tag look=${words.tone === 'positive' ? 'primary' : 'secondary'} color=${words.tone === 'default' ? 'default' : words.tone}>${words.label}</uui-tag>
|
|
11
|
+
<span>${words.detail}</span>
|
|
12
|
+
${words.links.map(
|
|
13
|
+
(link) => html`<a href=${link.href} target="_blank" rel="noopener">${link.label}</a>`,
|
|
14
|
+
)}
|
|
15
|
+
${words.refusal ? html`<p class="refusal">${words.refusal}</p>` : nothing}
|
|
16
|
+
</div>
|
|
17
|
+
`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The block's look, for the screens that show it. */
|
|
21
|
+
export const signatureStyles = css`
|
|
22
|
+
.signature {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-wrap: wrap;
|
|
25
|
+
align-items: center;
|
|
26
|
+
gap: var(--uui-size-space-3, 9px);
|
|
27
|
+
margin: var(--uui-size-space-3, 9px) 0;
|
|
28
|
+
font-size: 0.9em;
|
|
29
|
+
}
|
|
30
|
+
.signature .refusal {
|
|
31
|
+
flex-basis: 100%;
|
|
32
|
+
margin: 0;
|
|
33
|
+
color: var(--uui-color-danger, #d42054);
|
|
34
|
+
}
|
|
35
|
+
`
|
|
@@ -23,6 +23,12 @@ export const CI_PERMISSIONS = [
|
|
|
23
23
|
label: 'Change structure and code',
|
|
24
24
|
explain: 'Push a whole site, or apply a bundle that changes its types, views, styles or code.',
|
|
25
25
|
},
|
|
26
|
+
{
|
|
27
|
+
verb: 'Crombolo.Remote.InstallCode',
|
|
28
|
+
label: 'Install code',
|
|
29
|
+
explain:
|
|
30
|
+
'Install bundles and the code a bundle carries, which runs on the server after a restart.',
|
|
31
|
+
},
|
|
26
32
|
]
|
|
27
33
|
|
|
28
34
|
/** A provider by the address its tokens come from. */
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What the header says about a large media change running in the background (story 246). Pure. */
|
|
2
|
+
|
|
3
|
+
const count = (n) => n.toLocaleString('en')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {{ state: string, progress?: { done: number, total?: number } | null }} job
|
|
7
|
+
* @returns {{ tone: string, label: string }}
|
|
8
|
+
*/
|
|
9
|
+
export function mediaJobWords(job) {
|
|
10
|
+
if (job.state === 'failed') return { tone: 'danger', label: "A media change didn't finish" }
|
|
11
|
+
if (job.state === 'succeeded') return { tone: 'positive', label: 'Media updated' }
|
|
12
|
+
const progress = job.progress
|
|
13
|
+
if (progress?.total)
|
|
14
|
+
return {
|
|
15
|
+
tone: 'default',
|
|
16
|
+
label: `Updating media: ${count(progress.done)} of ${count(progress.total)}`,
|
|
17
|
+
}
|
|
18
|
+
if (progress?.done)
|
|
19
|
+
return { tone: 'default', label: `Updating media: ${count(progress.done)} done` }
|
|
20
|
+
return { tone: 'default', label: 'Updating media…' }
|
|
21
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A header app that follows a large media change queued in the background (story
|
|
3
|
+
* 246): told the job's id when it is queued, it reads its progress until it
|
|
4
|
+
* finishes, then reloads the Media tree and the recycle bin.
|
|
5
|
+
*/
|
|
6
|
+
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action'
|
|
7
|
+
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'
|
|
8
|
+
import { UmbRequestReloadChildrenOfEntityEvent } from '@umbraco-cms/backoffice/entity-action'
|
|
9
|
+
import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
10
|
+
import { UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT } from '@umbraco-cms/backoffice/management-api'
|
|
11
|
+
import { mediaJobWords } from './media-jobs-words.js'
|
|
12
|
+
|
|
13
|
+
const POLL_MS = 2000
|
|
14
|
+
const SHOWN_AFTER_MS = 5000
|
|
15
|
+
|
|
16
|
+
const statusUrl = (id) =>
|
|
17
|
+
`${(document.querySelector('base')?.getAttribute('href') ?? '/umbraco/').replace(/\/$/, '')}/crombolo/api/media-jobs/${encodeURIComponent(id)}`
|
|
18
|
+
|
|
19
|
+
export default class CromboloMediaJobsElement extends UmbElementMixin(LitElement) {
|
|
20
|
+
static properties = { _jobs: { state: true } }
|
|
21
|
+
|
|
22
|
+
#actions
|
|
23
|
+
#timer
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
super()
|
|
27
|
+
/** @type {Map<string, { state: string, progress?: object | null }>} */
|
|
28
|
+
this._jobs = new Map()
|
|
29
|
+
this.consumeContext(UMB_ACTION_EVENT_CONTEXT, (context) => {
|
|
30
|
+
this.#actions = context
|
|
31
|
+
})
|
|
32
|
+
this.consumeContext(UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT, (context) => {
|
|
33
|
+
if (!context) return
|
|
34
|
+
this.observe(
|
|
35
|
+
context.byEventSourcesAndEventTypes(['Crombolo:MediaJob'], ['Queued']),
|
|
36
|
+
(event) => {
|
|
37
|
+
if (!event?.key || this._jobs.has(event.key)) return
|
|
38
|
+
this._jobs = new Map(this._jobs).set(event.key, { state: 'queued' })
|
|
39
|
+
this.#poll()
|
|
40
|
+
},
|
|
41
|
+
)
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
disconnectedCallback() {
|
|
46
|
+
super.disconnectedCallback()
|
|
47
|
+
clearTimeout(this.#timer)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async #poll() {
|
|
51
|
+
clearTimeout(this.#timer)
|
|
52
|
+
const running = [...this._jobs].filter(
|
|
53
|
+
([, job]) => job.state === 'queued' || job.state === 'running',
|
|
54
|
+
)
|
|
55
|
+
if (running.length === 0) return
|
|
56
|
+
const next = new Map(this._jobs)
|
|
57
|
+
for (const [id] of running) {
|
|
58
|
+
const response = await fetch(statusUrl(id), { credentials: 'include' }).catch(() => undefined)
|
|
59
|
+
// Someone without the Media section is not told about it.
|
|
60
|
+
if (response?.status === 403 || response?.status === 404) next.delete(id)
|
|
61
|
+
if (!response?.ok) continue
|
|
62
|
+
const job = await response.json()
|
|
63
|
+
next.set(id, job)
|
|
64
|
+
if (job.state === 'succeeded' || job.state === 'failed') this.#finished(id)
|
|
65
|
+
}
|
|
66
|
+
this._jobs = next
|
|
67
|
+
this.#timer = setTimeout(() => this.#poll(), POLL_MS)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#finished(id) {
|
|
71
|
+
for (const entityType of ['media-root', 'media-recycle-bin-root'])
|
|
72
|
+
this.#actions?.dispatchEvent(
|
|
73
|
+
new UmbRequestReloadChildrenOfEntityEvent({ entityType, unique: null }),
|
|
74
|
+
)
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
const next = new Map(this._jobs)
|
|
77
|
+
next.delete(id)
|
|
78
|
+
this._jobs = next
|
|
79
|
+
}, SHOWN_AFTER_MS)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
render() {
|
|
83
|
+
if (this._jobs.size === 0) return nothing
|
|
84
|
+
return html`${[...this._jobs.values()].map((job) => {
|
|
85
|
+
const words = mediaJobWords(job)
|
|
86
|
+
return html`<uui-tag look="primary" color=${words.tone}>${words.label}</uui-tag>`
|
|
87
|
+
})}`
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static styles = css`
|
|
91
|
+
:host { display: flex; align-items: center; gap: var(--uui-size-space-2); padding: 0 var(--uui-size-space-3); }
|
|
92
|
+
`
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
customElements.define('crombolo-media-jobs', CromboloMediaJobsElement)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "../../backoffice-dist/dist/umbraco-package-schema.json",
|
|
3
3
|
"name": "Crombolo",
|
|
4
4
|
"id": "Crombolo.Core",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.46.1",
|
|
6
6
|
"allowPublicAccess": false,
|
|
7
7
|
"extensions": [
|
|
8
8
|
{
|
|
@@ -82,6 +82,17 @@
|
|
|
82
82
|
"description": "Push a whole site, or apply a bundle that changes its content types, views, styles or code"
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
|
+
{
|
|
86
|
+
"type": "entityUserPermission",
|
|
87
|
+
"alias": "Crombolo.UserPermission.Remote.InstallCode",
|
|
88
|
+
"name": "Crombolo Remote InstallCode Permission",
|
|
89
|
+
"forEntityTypes": ["crombolo-remote"],
|
|
90
|
+
"meta": {
|
|
91
|
+
"verbs": ["Crombolo.Remote.InstallCode"],
|
|
92
|
+
"label": "Install code on this site",
|
|
93
|
+
"description": "Install bundles and the code a bundle carries, which runs on the server after a restart. Administrators only have this when a group gives it to them: give it to a group of its own rather than Administrators"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
85
96
|
{
|
|
86
97
|
"type": "entityUserPermission",
|
|
87
98
|
"alias": "Crombolo.UserPermission.Media.Read",
|
|
@@ -457,6 +468,13 @@
|
|
|
457
468
|
"element": "/crombolo-plugin/bundles-changed.js",
|
|
458
469
|
"weight": 999
|
|
459
470
|
},
|
|
471
|
+
{
|
|
472
|
+
"type": "headerApp",
|
|
473
|
+
"alias": "Crombolo.HeaderApp.MediaJobs",
|
|
474
|
+
"name": "Crombolo Media Changes In Progress",
|
|
475
|
+
"element": "/crombolo-plugin/media-jobs.js",
|
|
476
|
+
"weight": 998
|
|
477
|
+
},
|
|
460
478
|
{
|
|
461
479
|
"type": "headerApp",
|
|
462
480
|
"kind": "button",
|