@crombolo/backoffice-host 0.42.1 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,412 @@
1
+ /**
2
+ * The Content section's Overview (story 236), in place of Umbraco's news: the
3
+ * pages changed lately, how many are drafts or published, what people did, and
4
+ * a way to start a new page. Everything comes from `crombolo/api/overview`,
5
+ * already narrowed to what the signed-in user may see.
6
+ */
7
+ import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user'
8
+ import { UMB_DOCUMENT_CREATE_OPTIONS_MODAL } from '@umbraco-cms/backoffice/document'
9
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
10
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
11
+ import { umbOpenModal } from '@umbraco-cms/backoffice/modal'
12
+ import { activityLine, ago, avatarHue, firstName, initials, STATES } from './overview-format.js'
13
+
14
+ const base = () =>
15
+ (document.querySelector('base')?.getAttribute('href') ?? '/umbraco/').replace(/\/$/, '')
16
+
17
+ const LISTS = { recent: 'Recent content', drafts: 'Drafts', published: 'Published' }
18
+ const SHORT = 5
19
+ const LONG = 25
20
+
21
+ export default class CromboloOverviewDashboardElement extends UmbLitElement {
22
+ static properties = {
23
+ _name: { state: true },
24
+ _data: { state: true },
25
+ _list: { state: true },
26
+ _take: { state: true },
27
+ _skip: { state: true },
28
+ _error: { state: true },
29
+ }
30
+
31
+ constructor() {
32
+ super()
33
+ this._list = 'recent'
34
+ this._take = SHORT
35
+ this._skip = 0
36
+ this.consumeContext(UMB_CURRENT_USER_CONTEXT, (user) => {
37
+ this.observe(user?.currentUser, (current) => {
38
+ this._name = current?.name
39
+ })
40
+ })
41
+ }
42
+
43
+ connectedCallback() {
44
+ super.connectedCallback()
45
+ this.#load()
46
+ }
47
+
48
+ async #load() {
49
+ const query = new URLSearchParams({
50
+ list: this._list,
51
+ skip: String(this._skip),
52
+ take: String(this._take),
53
+ })
54
+ try {
55
+ const response = await fetch(`${base()}/crombolo/api/overview?${query}`, {
56
+ credentials: 'include',
57
+ headers: { accept: 'application/json' },
58
+ })
59
+ if (!response.ok) throw new Error(`overview responded ${response.status}`)
60
+ this._data = await response.json()
61
+ this._error = undefined
62
+ } catch {
63
+ this._error = 'The overview could not be loaded. Try again in a moment.'
64
+ }
65
+ }
66
+
67
+ #show(list, take = SHORT) {
68
+ this._list = list
69
+ this._take = take
70
+ this._skip = 0
71
+ this.#load()
72
+ }
73
+
74
+ #page(by) {
75
+ this._skip = Math.max(0, this._skip + by * this._take)
76
+ this.#load()
77
+ }
78
+
79
+ async #newPage() {
80
+ const under = this._data?.newPageUnder ?? null
81
+ await umbOpenModal(this, UMB_DOCUMENT_CREATE_OPTIONS_MODAL, {
82
+ data: {
83
+ parent: under
84
+ ? { unique: under, entityType: 'document' }
85
+ : { unique: null, entityType: 'document-root' },
86
+ documentType: null,
87
+ },
88
+ }).catch(() => undefined)
89
+ }
90
+
91
+ render() {
92
+ const name = firstName(this._name)
93
+ return html`
94
+ <header>
95
+ <h1>Overview</h1>
96
+ <p>${name ? `Welcome back, ${name}. ` : ''}Here’s what’s happening in Crombolo.</p>
97
+ </header>
98
+ ${this._error ? html`<uui-box><p class="error">${this._error}</p></uui-box>` : nothing}
99
+ <div class="grid">
100
+ <div class="main">
101
+ ${this.#renderPages()}
102
+ <button class="new" type="button" @click=${() => this.#newPage()}>
103
+ <span>
104
+ <strong>New content</strong>
105
+ <small>Create a new page</small>
106
+ </span>
107
+ <uui-icon name="icon-add"></uui-icon>
108
+ </button>
109
+ </div>
110
+ <div class="side">${this.#renderStats()} ${this.#renderActivity()}</div>
111
+ </div>
112
+ `
113
+ }
114
+
115
+ #renderPages() {
116
+ const pages = this._data?.pages
117
+ const expanded = this._take === LONG
118
+ return html`<uui-box>
119
+ <div class="box-head" slot="header">
120
+ <span class="headline">${LISTS[this._list]}</span>
121
+ ${
122
+ this._list !== 'recent' || expanded
123
+ ? html`<button class="link" type="button" @click=${() => this.#show('recent')}>
124
+ Back to recent
125
+ </button>`
126
+ : html`<button class="link" type="button" @click=${() => this.#show('recent', LONG)}>
127
+ View all ›
128
+ </button>`
129
+ }
130
+ </div>
131
+ ${
132
+ !pages
133
+ ? html`<uui-loader></uui-loader>`
134
+ : pages.items.length === 0
135
+ ? html`<p class="empty">${this.#emptyText()}</p>`
136
+ : html`<table>
137
+ <thead>
138
+ <tr><th>Title</th><th>Type</th><th>Status</th><th>Updated</th><th>Author</th></tr>
139
+ </thead>
140
+ <tbody>
141
+ ${pages.items.map(
142
+ (p) => html`<tr>
143
+ <td>
144
+ <span class="title">
145
+ <uui-icon name="icon-document"></uui-icon>
146
+ <a href=${`${base()}/section/content/workspace/document/edit/${p.key}`}>${p.name}</a>
147
+ </span>
148
+ </td>
149
+ <td><span class="pill">${p.type}</span></td>
150
+ <td><span class="state ${p.state}">${STATES[p.state] ?? p.state}</span></td>
151
+ <td class="muted">${ago(p.updated)}</td>
152
+ <td>
153
+ ${
154
+ p.author
155
+ ? html`<span class="avatar hue-${avatarHue(p.author)}" title=${p.author}>${initials(p.author)}</span>`
156
+ : nothing
157
+ }
158
+ </td>
159
+ </tr>`,
160
+ )}
161
+ </tbody>
162
+ </table>`
163
+ }
164
+ ${
165
+ pages && this._take === LONG && pages.total > LONG
166
+ ? html`<div class="pager">
167
+ <uui-button label="Newer" ?disabled=${this._skip === 0} @click=${() => this.#page(-1)}></uui-button>
168
+ <span class="muted">${this._skip + 1}–${Math.min(this._skip + LONG, pages.total)} of ${pages.total}</span>
169
+ <uui-button label="Older" ?disabled=${this._skip + LONG >= pages.total} @click=${() => this.#page(1)}></uui-button>
170
+ </div>`
171
+ : nothing
172
+ }
173
+ </uui-box>`
174
+ }
175
+
176
+ #emptyText() {
177
+ if (this._list === 'drafts') return 'No drafts: every page you can see is published.'
178
+ if (this._list === 'published') return 'Nothing is published yet.'
179
+ return 'No pages created yet'
180
+ }
181
+
182
+ #renderStats() {
183
+ const counts = this._data?.counts
184
+ const stat = (list, icon, label, count) => html`<div class="stat">
185
+ <span class="stat-icon ${list}"><uui-icon name=${icon}></uui-icon></span>
186
+ <strong>${count ?? '–'}</strong>
187
+ <span>${label}</span>
188
+ <button class="link" type="button" @click=${() => this.#show(list, LONG)}>
189
+ View ${label.toLowerCase()} ›
190
+ </button>
191
+ </div>`
192
+ return html`<uui-box headline="Quick stats">
193
+ <div class="stats">
194
+ ${stat('drafts', 'icon-edit', 'Drafts', counts?.drafts)}
195
+ ${stat('published', 'icon-check', 'Published', counts?.published)}
196
+ </div>
197
+ </uui-box>`
198
+ }
199
+
200
+ #renderActivity() {
201
+ const activity = this._data?.activity
202
+ return html`<uui-box>
203
+ <div class="box-head" slot="header">
204
+ <span class="headline">Activity</span>
205
+ ${
206
+ this._data?.mayReadAudit
207
+ ? html`<a class="link" href=${`${base()}/section/settings/dashboard/audit-log`}>View all ›</a>`
208
+ : nothing
209
+ }
210
+ </div>
211
+ ${
212
+ !activity
213
+ ? html`<uui-loader></uui-loader>`
214
+ : activity.length === 0
215
+ ? html`<p class="empty">No recent activity</p>`
216
+ : html`<ul class="feed">
217
+ ${activity.map(
218
+ (a) => html`<li>
219
+ <span class="feed-icon ${a.action.includes('ublish') ? 'publish' : ''}">
220
+ <uui-icon name="icon-document"></uui-icon>
221
+ </span>
222
+ <a href=${`${base()}/section/content/workspace/document/edit/${a.key}`}>${activityLine(a)}</a>
223
+ <span class="muted when">${ago(a.when)}</span>
224
+ </li>`,
225
+ )}
226
+ </ul>`
227
+ }
228
+ </uui-box>`
229
+ }
230
+
231
+ static styles = css`
232
+ :host {
233
+ display: block;
234
+ padding: var(--uui-size-layout-1);
235
+ max-width: 1400px;
236
+ }
237
+ header h1 {
238
+ margin: 0 0 var(--uui-size-space-3);
239
+ font-size: 2rem;
240
+ line-height: 1.15;
241
+ font-weight: 800;
242
+ letter-spacing: -0.02em;
243
+ }
244
+ header p {
245
+ margin: 0 0 var(--uui-size-layout-1);
246
+ color: var(--uui-color-text-alt);
247
+ }
248
+ uui-box {
249
+ box-shadow: var(--crombolo-card-shadow, none);
250
+ --uui-box-border-radius: 12px;
251
+ }
252
+ .grid {
253
+ display: grid;
254
+ grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
255
+ gap: var(--uui-size-layout-1);
256
+ align-items: start;
257
+ }
258
+ @media (max-width: 1000px) {
259
+ .grid { grid-template-columns: minmax(0, 1fr); }
260
+ }
261
+ .main, .side {
262
+ display: flex;
263
+ flex-direction: column;
264
+ gap: var(--uui-size-layout-1);
265
+ }
266
+ .box-head {
267
+ display: flex;
268
+ justify-content: space-between;
269
+ align-items: center;
270
+ width: 100%;
271
+ }
272
+ .headline { font-weight: 700; font-size: var(--uui-type-h5-size, 1rem); }
273
+ .link {
274
+ background: none;
275
+ border: 0;
276
+ padding: 0;
277
+ font: inherit;
278
+ color: var(--uui-color-interactive-emphasis);
279
+ cursor: pointer;
280
+ text-decoration: none;
281
+ }
282
+ .link:hover { text-decoration: underline; }
283
+ table { width: 100%; border-collapse: collapse; }
284
+ th {
285
+ text-align: left;
286
+ font-weight: 400;
287
+ color: var(--uui-color-text-alt);
288
+ padding: var(--uui-size-space-3) var(--uui-size-space-3);
289
+ border-bottom: 1px solid var(--uui-color-border);
290
+ }
291
+ td {
292
+ padding: var(--uui-size-space-4) var(--uui-size-space-3);
293
+ border-bottom: 1px solid var(--uui-color-border);
294
+ vertical-align: middle;
295
+ }
296
+ tr:last-child td { border-bottom: 0; }
297
+ .title { display: flex; gap: var(--uui-size-space-3); align-items: center; }
298
+ .title a { color: inherit; text-decoration: none; }
299
+ .title a:hover { text-decoration: underline; }
300
+ .pill {
301
+ background: var(--crombolo-terracotta-tint, var(--uui-color-surface-alt));
302
+ border-radius: var(--uui-border-radius);
303
+ padding: var(--uui-size-space-1) var(--uui-size-space-3);
304
+ white-space: nowrap;
305
+ }
306
+ .state { white-space: nowrap; }
307
+ .state::before {
308
+ content: '';
309
+ display: inline-block;
310
+ width: 0.6em;
311
+ height: 0.6em;
312
+ border-radius: 50%;
313
+ margin-right: var(--uui-size-space-2);
314
+ background: var(--uui-color-positive);
315
+ }
316
+ .state.draft::before { background: var(--uui-color-warning); }
317
+ .state.changed::before { background: var(--uui-color-warning-emphasis, var(--uui-color-warning)); }
318
+ .muted { color: var(--uui-color-text-alt); white-space: nowrap; }
319
+ .avatar {
320
+ display: inline-grid;
321
+ place-items: center;
322
+ width: 2.2em;
323
+ height: 2.2em;
324
+ border-radius: 50%;
325
+ background: var(--uui-color-surface-alt);
326
+ color: #54321f;
327
+ font-size: 0.85em;
328
+ font-weight: 700;
329
+ }
330
+ /* Soft colours, dark ink on each: the same in light and dark. */
331
+ .avatar.hue-0 { background: #f6dccf; }
332
+ .avatar.hue-1 { background: #dcebdc; }
333
+ .avatar.hue-2 { background: #ece0f3; }
334
+ .avatar.hue-3 { background: #f7e8c6; }
335
+ .avatar.hue-4 { background: #d9e8f2; }
336
+ .avatar.hue-5 { background: #f3dbe2; }
337
+ .pager {
338
+ display: flex;
339
+ justify-content: space-between;
340
+ align-items: center;
341
+ padding-top: var(--uui-size-space-4);
342
+ }
343
+ .empty { color: var(--uui-color-text-alt); margin: 0; }
344
+ .error { color: var(--uui-color-danger); margin: 0; }
345
+ .new {
346
+ display: flex;
347
+ justify-content: space-between;
348
+ align-items: center;
349
+ width: 100%;
350
+ padding: var(--uui-size-layout-1);
351
+ border: 0;
352
+ border-radius: var(--uui-border-radius);
353
+ background: var(--uui-color-selected);
354
+ color: var(--uui-color-selected-contrast);
355
+ font: inherit;
356
+ text-align: left;
357
+ cursor: pointer;
358
+ }
359
+ .new:hover { filter: brightness(1.05); }
360
+ .new strong { display: block; font-size: 1.3em; }
361
+ .new uui-icon {
362
+ font-size: 1.4em;
363
+ background: var(--uui-color-surface);
364
+ color: var(--uui-color-selected);
365
+ border-radius: 50%;
366
+ padding: var(--uui-size-space-3);
367
+ }
368
+ .stats {
369
+ display: grid;
370
+ grid-template-columns: 1fr 1fr;
371
+ gap: var(--uui-size-space-4);
372
+ }
373
+ .stat {
374
+ display: flex;
375
+ flex-direction: column;
376
+ gap: var(--uui-size-space-2);
377
+ border: 1px solid var(--uui-color-border);
378
+ border-radius: var(--uui-border-radius);
379
+ padding: var(--uui-size-space-5);
380
+ }
381
+ .stat strong { font-size: 2em; line-height: 1; }
382
+ .stat .link { text-align: left; margin-top: var(--uui-size-space-3); }
383
+ .stat-icon, .feed-icon {
384
+ display: inline-grid;
385
+ place-items: center;
386
+ width: 2.4em;
387
+ height: 2.4em;
388
+ border-radius: 50%;
389
+ background: color-mix(in srgb, var(--uui-color-interactive-emphasis) 14%, transparent);
390
+ color: var(--uui-color-interactive-emphasis);
391
+ }
392
+ .stat-icon.published, .feed-icon.publish {
393
+ background: color-mix(in srgb, var(--uui-color-positive) 14%, transparent);
394
+ color: var(--uui-color-positive);
395
+ }
396
+ .feed { list-style: none; margin: 0; padding: 0; }
397
+ .feed li {
398
+ display: grid;
399
+ grid-template-columns: auto 1fr auto;
400
+ gap: var(--uui-size-space-4);
401
+ align-items: center;
402
+ padding: var(--uui-size-space-4) 0;
403
+ border-bottom: 1px solid var(--uui-color-border);
404
+ }
405
+ .feed li:last-child { border-bottom: 0; }
406
+ .feed a { color: inherit; text-decoration: none; }
407
+ .feed a:hover { text-decoration: underline; }
408
+ .feed-icon { border-radius: var(--uui-border-radius); }
409
+ `
410
+ }
411
+
412
+ customElements.define('crombolo-overview-dashboard', CromboloOverviewDashboardElement)
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The Overview's words (story 236): a page's state, how long ago, initials for
3
+ * an avatar, and a line for each activity. Pure, so the unit tests read it.
4
+ */
5
+
6
+ export const STATES = {
7
+ published: 'Published',
8
+ changed: 'Changes not published',
9
+ draft: 'Draft',
10
+ }
11
+
12
+ const VERBS = {
13
+ Create: 'created %',
14
+ Save: 'saved %',
15
+ CreateAndPublish: 'created and published %',
16
+ SaveAndPublish: 'published %',
17
+ Publish: 'published %',
18
+ PublishWithDescendants: 'published % and the pages below it',
19
+ Unpublish: 'unpublished %',
20
+ Trash: 'moved % to the recycle bin',
21
+ Restore: 'restored %',
22
+ Move: 'moved %',
23
+ Copy: 'copied %',
24
+ Revert: 'rolled back %',
25
+ }
26
+
27
+ /** The first word of a name, for the greeting. */
28
+ export const firstName = (name) =>
29
+ String(name ?? '')
30
+ .trim()
31
+ .split(/\s+/)[0] ?? ''
32
+
33
+ /** Up to two initials. */
34
+ export function initials(name) {
35
+ const words = String(name ?? '')
36
+ .trim()
37
+ .split(/\s+/)
38
+ .filter(Boolean)
39
+ if (words.length === 0) return '?'
40
+ const first = words[0]?.[0] ?? ''
41
+ const last = words.length > 1 ? (words[words.length - 1]?.[0] ?? '') : ''
42
+ return `${first}${last}`.toUpperCase()
43
+ }
44
+
45
+ /** "just now", "5m ago", "2h ago", "3d ago", then the date. */
46
+ export function ago(when, now = new Date()) {
47
+ const then = new Date(when)
48
+ const seconds = Math.max(0, (now.getTime() - then.getTime()) / 1000)
49
+ if (seconds < 60) return 'just now'
50
+ if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`
51
+ if (seconds < 86_400) return `${Math.floor(seconds / 3600)}h ago`
52
+ if (seconds < 7 * 86_400) return `${Math.floor(seconds / 86_400)}d ago`
53
+ return then.toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' })
54
+ }
55
+
56
+ /** "You published "Home"" or "Jordan Wu saved "About"". */
57
+ export function activityLine(entry) {
58
+ const who = entry.mine ? 'You' : entry.who || 'Someone'
59
+ const verb = VERBS[entry.action] ?? `${entry.action.toLowerCase()} %`
60
+ return `${who} ${verb.replace('%', `“${entry.name}”`)}`
61
+ }
62
+
63
+ /** How many soft colours an avatar can take; `avatarHue` picks one per name. */
64
+ export const AVATAR_HUES = 6
65
+
66
+ /** The same name always gets the same colour, so a person is recognisable down a list. */
67
+ export function avatarHue(name) {
68
+ let hash = 0
69
+ for (const char of String(name ?? '')) hash = (hash * 31 + char.codePointAt(0)) >>> 0
70
+ return hash % AVATAR_HUES
71
+ }
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Search & sharing",
4
4
  "id": "Crombolo.Seo",
5
- "version": "0.42.1",
5
+ "version": "0.44.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,57 @@
1
+ /**
2
+ * One card on the Settings landing page (story 234): a link headed by its title
3
+ * on a dark band, with what it opens beneath.
4
+ */
5
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
6
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
7
+
8
+ export class CromboloSettingsCardElement extends UmbLitElement {
9
+ static properties = { href: {}, heading: {}, description: {} }
10
+
11
+ render() {
12
+ return html`<a href=${this.href}>
13
+ <strong>${this.heading}</strong>
14
+ ${this.description ? html`<span>${this.description}</span>` : nothing}
15
+ </a>`
16
+ }
17
+
18
+ static styles = css`
19
+ :host {
20
+ display: block;
21
+ }
22
+ a {
23
+ display: flex;
24
+ flex-direction: column;
25
+ height: 100%;
26
+ box-sizing: border-box;
27
+ overflow: hidden;
28
+ background: var(--uui-color-surface);
29
+ border: 1px solid var(--uui-color-border);
30
+ border-radius: 12px;
31
+ box-shadow: var(--crombolo-card-shadow, none);
32
+ color: var(--uui-color-text);
33
+ text-decoration: none;
34
+ }
35
+ a:hover,
36
+ a:focus-visible {
37
+ border-color: var(--uui-color-interactive-emphasis);
38
+ }
39
+ a:focus-visible {
40
+ outline: 2px solid var(--uui-color-focus);
41
+ outline-offset: 2px;
42
+ }
43
+ strong {
44
+ padding: var(--uui-size-space-4) var(--uui-size-space-5);
45
+ background: var(--crombolo-card-header-background, var(--uui-color-header-surface));
46
+ color: var(--crombolo-card-header-text, var(--uui-color-header-contrast-emphasis));
47
+ font-weight: 700;
48
+ }
49
+ span {
50
+ padding: var(--uui-size-space-4) var(--uui-size-space-5) var(--uui-size-space-5);
51
+ color: var(--uui-color-text-alt);
52
+ font-size: var(--uui-type-small-size);
53
+ }
54
+ `
55
+ }
56
+
57
+ customElements.define('crombolo-settings-card', CromboloSettingsCardElement)