@crombolo/backoffice-host 0.53.2 → 0.54.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/approvals-tree.js +105 -0
- package/plugin/content-strip-items.js +20 -10
- package/plugin/definition-tree.js +157 -126
- package/plugin/dictionary-chip.js +233 -0
- package/plugin/dictionary-words-client.js +52 -0
- package/plugin/dictionary-words.js +196 -0
- package/plugin/form-word-input-model.js +33 -13
- package/plugin/form-word-input.js +21 -125
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/settings-cards.js +8 -1
- package/plugin/settings-section.js +43 -18
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/template-picker-modal.js +276 -0
- package/plugin/template-picker-model.js +77 -0
- package/plugin/template-picker.js +43 -0
- package/plugin/tsx-editors.js +5 -0
- package/plugin/tsx-highlighting.js +81 -0
- package/plugin/umbraco-package.json +96 -41
- package/plugin/workflow-client.js +3 -0
- package/plugin/workflow-designer.js +0 -7
- package/plugin/workflow-requests.js +111 -105
- package/plugin/workflow-send-condition.js +2 -0
- package/plugin/workflow-send-model.js +20 -0
- package/plugin/workflow-send-unpublish.js +2 -0
- package/plugin/workflow-send.js +231 -0
- package/plugin/workflow-tab.js +32 -86
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A form text that can name a dictionary item (
|
|
3
|
-
* items, and
|
|
4
|
-
* as `uui-input` does.
|
|
2
|
+
* A form text that can name a dictionary item (stories 294, 297): typing `{#`,
|
|
3
|
+
* or `#` at the start, offers the items, and a `{#key}` shows as a chip. It sends
|
|
4
|
+
* `change`, with `value`, as `uui-input` does.
|
|
5
5
|
*/
|
|
6
|
-
import { css, html, LitElement
|
|
7
|
-
import
|
|
6
|
+
import { css, html, LitElement } from '@umbraco-cms/backoffice/external/lit'
|
|
7
|
+
import './dictionary-words.js'
|
|
8
8
|
|
|
9
9
|
export default class CromboloFormWordInputElement extends LitElement {
|
|
10
10
|
static properties = {
|
|
@@ -13,107 +13,44 @@ export default class CromboloFormWordInputElement extends LitElement {
|
|
|
13
13
|
value: { type: String },
|
|
14
14
|
readonly: { type: Boolean },
|
|
15
15
|
words: { attribute: false },
|
|
16
|
-
_open: { state: true },
|
|
17
|
-
_active: { state: true },
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
constructor() {
|
|
21
19
|
super()
|
|
22
20
|
this.value = ''
|
|
23
21
|
this.words = []
|
|
24
|
-
this._open = false
|
|
25
|
-
this._active = 0
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get #found() {
|
|
29
|
-
return this.readonly ? { rows: [], more: false } : suggestions(this.words ?? [], this.value)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
#choose(word) {
|
|
33
|
-
this.value = `#${word.name}`
|
|
34
|
-
this._open = false
|
|
35
|
-
this.#changed()
|
|
36
22
|
}
|
|
37
23
|
|
|
38
24
|
#changed() {
|
|
39
25
|
this.dispatchEvent(new Event('change', { bubbles: true }))
|
|
40
26
|
}
|
|
41
27
|
|
|
42
|
-
#onInput(event) {
|
|
43
|
-
event.stopPropagation()
|
|
44
|
-
this.value = event.target.value ?? ''
|
|
45
|
-
this._active = 0
|
|
46
|
-
this._open = this.#found.rows.length > 0
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#onKeydown(event) {
|
|
50
|
-
const { rows } = this.#found
|
|
51
|
-
if (!this._open || rows.length === 0) return
|
|
52
|
-
if (event.key === 'Escape') {
|
|
53
|
-
event.stopPropagation()
|
|
54
|
-
this._open = false
|
|
55
|
-
} else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
56
|
-
event.preventDefault()
|
|
57
|
-
const step = event.key === 'ArrowDown' ? 1 : rows.length - 1
|
|
58
|
-
this._active = (this._active + step) % rows.length
|
|
59
|
-
} else if (event.key === 'Enter') {
|
|
60
|
-
event.preventDefault()
|
|
61
|
-
this.#choose(rows[this._active] ?? rows[0])
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
updated() {
|
|
66
|
-
const list = this.renderRoot.querySelector('[popover]')
|
|
67
|
-
if (!list) return
|
|
68
|
-
const box = this.renderRoot.querySelector('uui-input').getBoundingClientRect()
|
|
69
|
-
list.style.top = `${box.bottom + 2}px`
|
|
70
|
-
list.style.left = `${box.left}px`
|
|
71
|
-
list.style.minWidth = `${box.width}px`
|
|
72
|
-
list.showPopover()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
28
|
render() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
29
|
+
return html`<crombolo-dictionary-words
|
|
30
|
+
.value=${this.value ?? ''}
|
|
31
|
+
.words=${this.words}
|
|
32
|
+
?readonly=${this.readonly}
|
|
33
|
+
@input=${(event) => event.stopPropagation()}
|
|
34
|
+
@crombolo-word-choose=${(event) => {
|
|
35
|
+
event.stopPropagation()
|
|
36
|
+
this.value = event.detail.value
|
|
37
|
+
this.#changed()
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
<uui-input
|
|
80
41
|
label=${this.label}
|
|
81
42
|
placeholder=${this.placeholder ?? ''}
|
|
82
43
|
.value=${this.value ?? ''}
|
|
83
44
|
?readonly=${this.readonly}
|
|
84
|
-
@input=${
|
|
85
|
-
|
|
45
|
+
@input=${(event) => {
|
|
46
|
+
this.value = event.target.value ?? ''
|
|
47
|
+
}}
|
|
86
48
|
@change=${(event) => {
|
|
87
49
|
event.stopPropagation()
|
|
88
50
|
this.#changed()
|
|
89
51
|
}}
|
|
90
|
-
@blur=${() => {
|
|
91
|
-
this._open = false
|
|
92
|
-
}}
|
|
93
52
|
></uui-input>
|
|
94
|
-
|
|
95
|
-
<span class="status" role="status"
|
|
96
|
-
>${open ? `${rows.length} dictionary items. Use the arrow keys to choose one.` : ''}</span
|
|
97
|
-
>
|
|
98
|
-
${
|
|
99
|
-
open
|
|
100
|
-
? html`<div popover="manual" role="listbox" aria-label="Dictionary items">
|
|
101
|
-
${rows.map(
|
|
102
|
-
(word, index) => html`<div
|
|
103
|
-
role="option"
|
|
104
|
-
aria-selected=${index === this._active ? 'true' : 'false'}
|
|
105
|
-
@pointerdown=${(event) => {
|
|
106
|
-
event.preventDefault()
|
|
107
|
-
this.#choose(word)
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
<strong>${word.name}</strong> <span>${word.text}</span>
|
|
111
|
-
</div>`,
|
|
112
|
-
)}
|
|
113
|
-
${more ? html`<p class="more">Keep typing to narrow this down.</p>` : nothing}
|
|
114
|
-
</div>`
|
|
115
|
-
: nothing
|
|
116
|
-
}`
|
|
53
|
+
</crombolo-dictionary-words>`
|
|
117
54
|
}
|
|
118
55
|
|
|
119
56
|
static styles = css`
|
|
@@ -123,47 +60,6 @@ export default class CromboloFormWordInputElement extends LitElement {
|
|
|
123
60
|
uui-input {
|
|
124
61
|
width: 100%;
|
|
125
62
|
}
|
|
126
|
-
.word {
|
|
127
|
-
margin: var(--uui-size-space-1) 0 0;
|
|
128
|
-
color: var(--uui-color-text-alt);
|
|
129
|
-
font-size: var(--uui-type-small-size);
|
|
130
|
-
}
|
|
131
|
-
.status {
|
|
132
|
-
position: absolute;
|
|
133
|
-
width: 1px;
|
|
134
|
-
height: 1px;
|
|
135
|
-
overflow: hidden;
|
|
136
|
-
clip-path: inset(50%);
|
|
137
|
-
}
|
|
138
|
-
[popover] {
|
|
139
|
-
position: fixed;
|
|
140
|
-
inset: auto;
|
|
141
|
-
margin: 0;
|
|
142
|
-
padding: var(--uui-size-space-1);
|
|
143
|
-
max-width: 28rem;
|
|
144
|
-
background: var(--uui-color-surface);
|
|
145
|
-
color: var(--uui-color-text);
|
|
146
|
-
border: 1px solid var(--uui-color-border);
|
|
147
|
-
border-radius: var(--uui-border-radius);
|
|
148
|
-
box-shadow: var(--uui-shadow-depth-3);
|
|
149
|
-
}
|
|
150
|
-
[role='option'] {
|
|
151
|
-
padding: var(--uui-size-space-2) var(--uui-size-space-3);
|
|
152
|
-
border-radius: var(--uui-border-radius);
|
|
153
|
-
cursor: pointer;
|
|
154
|
-
}
|
|
155
|
-
[role='option'] span {
|
|
156
|
-
color: var(--uui-color-text-alt);
|
|
157
|
-
}
|
|
158
|
-
[role='option'][aria-selected='true'],
|
|
159
|
-
[role='option']:hover {
|
|
160
|
-
background: var(--uui-color-surface-emphasis);
|
|
161
|
-
}
|
|
162
|
-
.more {
|
|
163
|
-
margin: var(--uui-size-space-1) var(--uui-size-space-3);
|
|
164
|
-
color: var(--uui-color-text-alt);
|
|
165
|
-
font-size: var(--uui-type-small-size);
|
|
166
|
-
}
|
|
167
63
|
`
|
|
168
64
|
}
|
|
169
65
|
|
package/plugin/settings-cards.js
CHANGED
|
@@ -177,7 +177,14 @@ const rank = (order, alias) => {
|
|
|
177
177
|
return at === -1 ? order.length : at
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
const STRUCTURE_TYPES = [
|
|
180
|
+
const STRUCTURE_TYPES = [
|
|
181
|
+
'document-type',
|
|
182
|
+
'document-blueprint',
|
|
183
|
+
'media-type',
|
|
184
|
+
'member-type',
|
|
185
|
+
'data-type',
|
|
186
|
+
'language',
|
|
187
|
+
]
|
|
181
188
|
const CODE_TYPES = ['partial-view', 'template', 'stylesheet', 'script']
|
|
182
189
|
|
|
183
190
|
/** The tree an editor for `entityType` sits beside, or undefined for none. */
|
|
@@ -31,7 +31,6 @@ import {
|
|
|
31
31
|
treeFor,
|
|
32
32
|
} from './settings-cards.js'
|
|
33
33
|
import './breadcrumb.js'
|
|
34
|
-
import './definition-tree.js'
|
|
35
34
|
import { readOnlyWords } from './definition-tree-model.js'
|
|
36
35
|
import './settings-card.js'
|
|
37
36
|
|
|
@@ -48,6 +47,25 @@ const emailStatus = async () => {
|
|
|
48
47
|
return response.json()
|
|
49
48
|
}
|
|
50
49
|
|
|
50
|
+
/** Where Umbraco's sections keep the sidebar's width, so every section shares one. */
|
|
51
|
+
const SPLIT_POSITION = 'umb-split-panel-position'
|
|
52
|
+
|
|
53
|
+
const savedPosition = () => {
|
|
54
|
+
try {
|
|
55
|
+
return localStorage.getItem(SPLIT_POSITION) ?? undefined
|
|
56
|
+
} catch {
|
|
57
|
+
return undefined
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const savePosition = (event) => {
|
|
62
|
+
try {
|
|
63
|
+
localStorage.setItem(SPLIT_POSITION, String(event.detail.position))
|
|
64
|
+
} catch {
|
|
65
|
+
// A browser that keeps nothing starts at the default width each time.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
51
69
|
const menuOf = (manifest, menu) => manifest.meta?.menus?.includes(menu) === true
|
|
52
70
|
|
|
53
71
|
/** Each tree, and the part of Settings that opens it. */
|
|
@@ -58,7 +76,6 @@ const TREE_SECTIONS = [
|
|
|
58
76
|
|
|
59
77
|
export class CromboloSettingsSectionElement extends UmbLitElement {
|
|
60
78
|
static properties = {
|
|
61
|
-
_mayForms: { state: true },
|
|
62
79
|
_routes: { state: true },
|
|
63
80
|
_sidebarApps: { state: true },
|
|
64
81
|
_tree: { state: true },
|
|
@@ -79,9 +96,6 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
|
|
|
79
96
|
super()
|
|
80
97
|
this.consumeContext(UMB_CURRENT_USER_CONTEXT, (user) => {
|
|
81
98
|
this.observe(user?.currentUser, (current) => {
|
|
82
|
-
this._mayForms =
|
|
83
|
-
current?.isAdmin === true ||
|
|
84
|
-
(current?.fallbackPermissions ?? []).includes('Crombolo.Form.Read')
|
|
85
99
|
this.#held = current?.allowedSections ?? []
|
|
86
100
|
this.#createRoutes()
|
|
87
101
|
})
|
|
@@ -267,7 +281,7 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
|
|
|
267
281
|
this.#showing(undefined, { title: this.#label(manifest) })
|
|
268
282
|
},
|
|
269
283
|
}))
|
|
270
|
-
// Forms
|
|
284
|
+
// Forms and Workflows are nodes in Structure, so its tree stays on screen beside them.
|
|
271
285
|
const forms = (path, tag, load) => ({
|
|
272
286
|
path,
|
|
273
287
|
component: async () => {
|
|
@@ -279,11 +293,12 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
|
|
|
279
293
|
this._routes = [
|
|
280
294
|
forms('forms/entries', 'crombolo-forms-entries', () => import('./forms-entries.js')),
|
|
281
295
|
forms('forms', 'crombolo-forms-overview', () => import('./forms-overview.js')),
|
|
296
|
+
forms('workflows', 'crombolo-workflow-designer', () => import('./workflow-designer.js')),
|
|
282
297
|
tree('structure'),
|
|
283
298
|
tree('code'),
|
|
284
299
|
// Umbraco's welcome, which this page replaces: an address people have.
|
|
285
300
|
{ path: 'dashboard/welcome', ...landing },
|
|
286
|
-
// Workflows
|
|
301
|
+
// Workflows were a Settings card, then beside forms (story 289): an address people have.
|
|
287
302
|
{
|
|
288
303
|
path: 'dashboard/workflows',
|
|
289
304
|
component: () => document.createElement('div'),
|
|
@@ -291,7 +306,7 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
|
|
|
291
306
|
history.replaceState(
|
|
292
307
|
null,
|
|
293
308
|
'',
|
|
294
|
-
new URL('section/
|
|
309
|
+
new URL('section/settings/workflows', document.baseURI).pathname,
|
|
295
310
|
)
|
|
296
311
|
},
|
|
297
312
|
},
|
|
@@ -321,7 +336,7 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
|
|
|
321
336
|
? `${section}/${c.path}`
|
|
322
337
|
: section,
|
|
323
338
|
}))
|
|
324
|
-
const main = html`<umb-section-main>
|
|
339
|
+
const main = html`<umb-section-main slot="end">
|
|
325
340
|
${
|
|
326
341
|
crumbs.length > 0
|
|
327
342
|
? html`<crombolo-breadcrumb class="crumbs" .items=${crumbs}></crombolo-breadcrumb>`
|
|
@@ -332,7 +347,13 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
|
|
|
332
347
|
// Both trees stay in the page, the one not in use hidden, as Umbraco's own
|
|
333
348
|
// Settings keeps its menus. A tree taken out and put back breaks: the trees
|
|
334
349
|
// share the section's expansion state, and a detached one still answers it.
|
|
335
|
-
|
|
350
|
+
// Out of the split's start slot, the sidebar stays in the page but takes no room.
|
|
351
|
+
return html`<umb-split-panel
|
|
352
|
+
lock="start"
|
|
353
|
+
snap="300px"
|
|
354
|
+
.position=${savedPosition() ?? 'var(--umb-split-panel-initial-position)'}
|
|
355
|
+
@position-changed=${savePosition}
|
|
356
|
+
><umb-section-sidebar slot=${shown ? 'start' : 'none'} ?hidden=${!shown}>
|
|
336
357
|
${
|
|
337
358
|
this._tree === 'structure' && this._readOnly
|
|
338
359
|
? html`<p class="read-only" role="status">
|
|
@@ -343,13 +364,8 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
|
|
|
343
364
|
${(this._sidebarApps ?? []).map(
|
|
344
365
|
(app) => html`<div class="tree" ?hidden=${app.alias !== shown}>${app.component}</div>`,
|
|
345
366
|
)}
|
|
346
|
-
${
|
|
347
|
-
this._tree === 'structure' && this._mayForms
|
|
348
|
-
? html`<crombolo-definition-tree kind="Forms"></crombolo-definition-tree>`
|
|
349
|
-
: nothing
|
|
350
|
-
}
|
|
351
367
|
</umb-section-sidebar>
|
|
352
|
-
${main}
|
|
368
|
+
${main}</umb-split-panel>`
|
|
353
369
|
}
|
|
354
370
|
|
|
355
371
|
static styles = [
|
|
@@ -360,8 +376,17 @@ export class CromboloSettingsSectionElement extends UmbLitElement {
|
|
|
360
376
|
height: 100%;
|
|
361
377
|
display: flex;
|
|
362
378
|
}
|
|
363
|
-
|
|
364
|
-
|
|
379
|
+
/* As Umbraco's own sections draw the split, so the width is the same in each. */
|
|
380
|
+
umb-split-panel {
|
|
381
|
+
--umb-split-panel-start-min-width: 200px;
|
|
382
|
+
--umb-split-panel-start-max-width: 400px;
|
|
383
|
+
--umb-split-panel-end-min-width: 600px;
|
|
384
|
+
--umb-split-panel-slot-overflow: visible;
|
|
385
|
+
}
|
|
386
|
+
@media only screen and (min-width: 800px) {
|
|
387
|
+
umb-split-panel {
|
|
388
|
+
--umb-split-panel-initial-position: 300px;
|
|
389
|
+
}
|
|
365
390
|
}
|
|
366
391
|
umb-section-sidebar[hidden],
|
|
367
392
|
.tree[hidden] {
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The panel a page's template is chosen in (`template-picker.js`): every
|
|
3
|
+
* component on disk in a tree of its folders, the first level open, with a
|
|
4
|
+
* search that narrows it by name. One the content type does not allow says so,
|
|
5
|
+
* and someone with Structure allows it beside it, which makes it a template
|
|
6
|
+
* first when nothing names it yet; it is then picked like the rest.
|
|
7
|
+
*/
|
|
8
|
+
import { DocumentTypeService } from '@umbraco-cms/backoffice/external/backend-api'
|
|
9
|
+
import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
10
|
+
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'
|
|
11
|
+
import { componentName, filterTree, templateTree, withAllowed } from './template-picker-model.js'
|
|
12
|
+
|
|
13
|
+
const base = () =>
|
|
14
|
+
`${(document.querySelector('base')?.getAttribute('href') ?? '/umbraco/').replace(/\/$/, '')}/crombolo/api/templates`
|
|
15
|
+
|
|
16
|
+
async function components() {
|
|
17
|
+
const response = await fetch(base(), { credentials: 'include' })
|
|
18
|
+
if (!response.ok) throw new Error(`templates responded ${response.status}`)
|
|
19
|
+
return (await response.json()).items
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The template a component is, made when nothing names it yet. */
|
|
23
|
+
async function templateOf(alias) {
|
|
24
|
+
const response = await fetch(base(), {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
credentials: 'include',
|
|
27
|
+
headers: { 'content-type': 'application/json' },
|
|
28
|
+
body: JSON.stringify({ alias }),
|
|
29
|
+
})
|
|
30
|
+
if (!response.ok) throw new Error(`templates responded ${response.status}`)
|
|
31
|
+
return (await response.json()).id
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Adds a template to a content type's allowed templates; the list of ids after. */
|
|
35
|
+
async function allowTemplate(documentTypeUnique, templateId) {
|
|
36
|
+
const { data: type } = await DocumentTypeService.getDocumentTypeById({
|
|
37
|
+
path: { id: documentTypeUnique },
|
|
38
|
+
})
|
|
39
|
+
const { id: _id, ...body } = type
|
|
40
|
+
const allowedTemplates = withAllowed(type.allowedTemplates, templateId)
|
|
41
|
+
await DocumentTypeService.putDocumentTypeById({
|
|
42
|
+
path: { id: documentTypeUnique },
|
|
43
|
+
body: { ...body, allowedTemplates },
|
|
44
|
+
})
|
|
45
|
+
return allowedTemplates.map((t) => t.id)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default class CromboloTemplatePickerModalElement extends UmbModalBaseElement {
|
|
49
|
+
static properties = {
|
|
50
|
+
_templates: { state: true },
|
|
51
|
+
_allowedIds: { state: true },
|
|
52
|
+
_query: { state: true },
|
|
53
|
+
_toggled: { state: true },
|
|
54
|
+
_busy: { state: true },
|
|
55
|
+
_problem: { state: true },
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
constructor() {
|
|
59
|
+
super()
|
|
60
|
+
this._query = ''
|
|
61
|
+
/** Folders opened or closed by hand, against the first level being open. */
|
|
62
|
+
this._toggled = new Set()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async connectedCallback() {
|
|
66
|
+
super.connectedCallback()
|
|
67
|
+
this._allowedIds = this.data?.allowedTemplateIds ?? []
|
|
68
|
+
try {
|
|
69
|
+
this._templates = (await components()).map((c) => ({
|
|
70
|
+
id: c.id,
|
|
71
|
+
alias: c.alias,
|
|
72
|
+
name: componentName(c.alias),
|
|
73
|
+
}))
|
|
74
|
+
} catch {
|
|
75
|
+
this._problem = 'The templates could not be listed.'
|
|
76
|
+
this._templates = []
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get #typeName() {
|
|
81
|
+
return this.data?.documentTypeName || 'this content type'
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#pick(template) {
|
|
85
|
+
this.value = { unique: template.id, allowedTemplateIds: this._allowedIds }
|
|
86
|
+
this._submitModal()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async #allow(template) {
|
|
90
|
+
this._busy = template.alias
|
|
91
|
+
this._problem = undefined
|
|
92
|
+
try {
|
|
93
|
+
const id = template.id ?? (await templateOf(template.alias))
|
|
94
|
+
this._templates = this._templates.map((t) => (t.alias === template.alias ? { ...t, id } : t))
|
|
95
|
+
this._allowedIds = await allowTemplate(this.data.documentTypeUnique, id)
|
|
96
|
+
} catch {
|
|
97
|
+
this._problem = `${template.name} could not be allowed for ${this.#typeName}.`
|
|
98
|
+
} finally {
|
|
99
|
+
this._busy = undefined
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#isOpen(folder, depth) {
|
|
104
|
+
if (this._query.trim()) return true
|
|
105
|
+
return (depth === 0) !== this._toggled.has(folder.path)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#toggle(folder) {
|
|
109
|
+
const toggled = new Set(this._toggled)
|
|
110
|
+
if (toggled.has(folder.path)) toggled.delete(folder.path)
|
|
111
|
+
else toggled.add(folder.path)
|
|
112
|
+
this._toggled = toggled
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#folder(folder, depth) {
|
|
116
|
+
const open = this.#isOpen(folder, depth)
|
|
117
|
+
return html`<li role="treeitem" aria-expanded=${open ? 'true' : 'false'}>
|
|
118
|
+
<button type="button" class="row folder" @click=${() => this.#toggle(folder)}>
|
|
119
|
+
<uui-symbol-expand ?open=${open}></uui-symbol-expand>
|
|
120
|
+
<umb-icon name="icon-folder"></umb-icon>${folder.name}
|
|
121
|
+
</button>
|
|
122
|
+
${open ? this.#branch(folder, depth + 1) : nothing}
|
|
123
|
+
</li>`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#branch(folder, depth) {
|
|
127
|
+
return html`<ul role="group">
|
|
128
|
+
${folder.folders.map((child) => this.#folder(child, depth))}
|
|
129
|
+
${folder.items.map((template) => this.#item(template))}
|
|
130
|
+
</ul>`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#item(template) {
|
|
134
|
+
const current = template.id !== null && template.id === this.data?.selected
|
|
135
|
+
if (template.allowed)
|
|
136
|
+
return html`<li role="treeitem">
|
|
137
|
+
<button
|
|
138
|
+
type="button"
|
|
139
|
+
class="row pick"
|
|
140
|
+
title=${template.alias}
|
|
141
|
+
aria-current=${current ? 'true' : 'false'}
|
|
142
|
+
@click=${() => this.#pick(template)}
|
|
143
|
+
>
|
|
144
|
+
<span class="spacer"></span><umb-icon name="icon-document-html"></umb-icon>${template.name}
|
|
145
|
+
</button>
|
|
146
|
+
</li>`
|
|
147
|
+
return html`<li role="treeitem" class="blocked">
|
|
148
|
+
<span class="row name" title=${template.alias}
|
|
149
|
+
><span class="spacer"></span><umb-icon name="icon-document-html"></umb-icon>${template.name}</span
|
|
150
|
+
>
|
|
151
|
+
<span class="why">Not allowed for ${this.#typeName}</span>
|
|
152
|
+
${
|
|
153
|
+
this.data?.mayAllow
|
|
154
|
+
? html`<uui-button
|
|
155
|
+
compact
|
|
156
|
+
look="secondary"
|
|
157
|
+
label=${`Allow ${template.name} for ${this.#typeName}`}
|
|
158
|
+
.state=${this._busy === template.alias ? 'waiting' : undefined}
|
|
159
|
+
?disabled=${this._busy !== undefined}
|
|
160
|
+
@click=${() => this.#allow(template)}
|
|
161
|
+
>Allow for ${this.#typeName}</uui-button
|
|
162
|
+
>`
|
|
163
|
+
: nothing
|
|
164
|
+
}
|
|
165
|
+
</li>`
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#tree() {
|
|
169
|
+
if (!this._templates) return html`<uui-loader></uui-loader>`
|
|
170
|
+
const shown = filterTree(templateTree(this._templates, this._allowedIds), this._query)
|
|
171
|
+
if (shown.folders.length === 0 && shown.items.length === 0)
|
|
172
|
+
return html`<p class="note">No template has that name.</p>`
|
|
173
|
+
return html`<ul role="tree" aria-label="Templates">
|
|
174
|
+
${shown.folders.map((folder) => this.#folder(folder, 0))}
|
|
175
|
+
${shown.items.map((template) => this.#item(template))}
|
|
176
|
+
</ul>`
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
render() {
|
|
180
|
+
const blocked = (this._templates ?? []).some(
|
|
181
|
+
(t) =>
|
|
182
|
+
t.id === null || !this._allowedIds.some((id) => id.toLowerCase() === t.id.toLowerCase()),
|
|
183
|
+
)
|
|
184
|
+
return html`<umb-body-layout headline="Choose a template">
|
|
185
|
+
<uui-box>
|
|
186
|
+
<uui-input
|
|
187
|
+
class="search"
|
|
188
|
+
label="Search templates"
|
|
189
|
+
placeholder="Search by name"
|
|
190
|
+
.value=${this._query}
|
|
191
|
+
@input=${(e) => {
|
|
192
|
+
this._query = e.target.value ?? ''
|
|
193
|
+
}}
|
|
194
|
+
>
|
|
195
|
+
<umb-icon name="icon-search" slot="prepend"></umb-icon>
|
|
196
|
+
</uui-input>
|
|
197
|
+
${this.#tree()}
|
|
198
|
+
${
|
|
199
|
+
blocked && !this.data?.mayAllow
|
|
200
|
+
? html`<p class="note" role="status">
|
|
201
|
+
Someone with access to Structure can allow more templates for ${this.#typeName}.
|
|
202
|
+
</p>`
|
|
203
|
+
: nothing
|
|
204
|
+
}
|
|
205
|
+
${this._problem ? html`<p role="alert">${this._problem}</p>` : nothing}
|
|
206
|
+
</uui-box>
|
|
207
|
+
<uui-button slot="actions" label="Close" @click=${() => this._rejectModal()}>Close</uui-button>
|
|
208
|
+
</umb-body-layout>`
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static styles = css`
|
|
212
|
+
.search {
|
|
213
|
+
width: 100%;
|
|
214
|
+
margin-bottom: var(--uui-size-space-4);
|
|
215
|
+
}
|
|
216
|
+
ul {
|
|
217
|
+
list-style: none;
|
|
218
|
+
margin: 0;
|
|
219
|
+
padding: 0;
|
|
220
|
+
}
|
|
221
|
+
ul ul {
|
|
222
|
+
padding-left: var(--uui-size-space-5);
|
|
223
|
+
}
|
|
224
|
+
li.blocked {
|
|
225
|
+
display: flex;
|
|
226
|
+
align-items: center;
|
|
227
|
+
gap: var(--uui-size-space-3);
|
|
228
|
+
}
|
|
229
|
+
.row {
|
|
230
|
+
display: flex;
|
|
231
|
+
align-items: center;
|
|
232
|
+
gap: var(--uui-size-space-2);
|
|
233
|
+
min-height: 2.2rem;
|
|
234
|
+
padding: 0 var(--uui-size-space-3);
|
|
235
|
+
border: 0;
|
|
236
|
+
border-radius: var(--uui-border-radius);
|
|
237
|
+
background: none;
|
|
238
|
+
color: inherit;
|
|
239
|
+
font: inherit;
|
|
240
|
+
text-align: left;
|
|
241
|
+
}
|
|
242
|
+
button.row {
|
|
243
|
+
width: 100%;
|
|
244
|
+
cursor: pointer;
|
|
245
|
+
}
|
|
246
|
+
button.row:hover,
|
|
247
|
+
.pick[aria-current='true'] {
|
|
248
|
+
background: var(--uui-color-surface-emphasis);
|
|
249
|
+
}
|
|
250
|
+
.pick[aria-current='true'] {
|
|
251
|
+
font-weight: 700;
|
|
252
|
+
}
|
|
253
|
+
.spacer {
|
|
254
|
+
display: inline-block;
|
|
255
|
+
width: 1em;
|
|
256
|
+
}
|
|
257
|
+
uui-symbol-expand {
|
|
258
|
+
width: 1em;
|
|
259
|
+
}
|
|
260
|
+
.blocked .name {
|
|
261
|
+
color: var(--uui-color-disabled-contrast);
|
|
262
|
+
}
|
|
263
|
+
.why,
|
|
264
|
+
.note {
|
|
265
|
+
color: var(--uui-color-text-alt);
|
|
266
|
+
font-size: var(--uui-type-small-size);
|
|
267
|
+
}
|
|
268
|
+
.why {
|
|
269
|
+
flex: 1;
|
|
270
|
+
}
|
|
271
|
+
`
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
customElements.define('crombolo-template-picker-modal', CromboloTemplatePickerModalElement)
|
|
275
|
+
|
|
276
|
+
export { CromboloTemplatePickerModalElement as element }
|