Skip to content

Commit c84b00c

Browse files
committed
add media type folder workspace
1 parent 1036ae7 commit c84b00c

File tree

8 files changed

+178
-0
lines changed

8 files changed

+178
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './repository/index.js';
2+
export * from './workspace/index.js';

src/packages/media/media-types/tree/folder/manifests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { UMB_MEDIA_TYPE_FOLDER_ENTITY_TYPE } from '../../entity.js';
22
import { UMB_MEDIA_TYPE_FOLDER_REPOSITORY_ALIAS } from './repository/constants.js';
33
import { manifests as repositoryManifests } from './repository/manifests.js';
4+
import { manifests as workspaceManifests } from './workspace/manifests.js';
45

56
export const manifests: Array<UmbExtensionManifest> = [
67
{
@@ -24,4 +25,5 @@ export const manifests: Array<UmbExtensionManifest> = [
2425
},
2526
},
2627
...repositoryManifests,
28+
...workspaceManifests,
2729
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const UMB_MEDIA_TYPE_FOLDER_WORKSPACE_ALIAS = 'Umb.Workspace.MediaType.Folder';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './constants.js';
2+
export * from './media-type-folder.workspace.context-token.js';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { UMB_MEDIA_TYPE_FOLDER_ENTITY_TYPE } from '../../../entity.js';
2+
import { UMB_MEDIA_TYPE_FOLDER_WORKSPACE_ALIAS } from './constants.js';
3+
import { UmbSubmitWorkspaceAction } from '@umbraco-cms/backoffice/workspace';
4+
5+
export const manifests: Array<UmbExtensionManifest> = [
6+
{
7+
type: 'workspace',
8+
kind: 'routable',
9+
alias: UMB_MEDIA_TYPE_FOLDER_WORKSPACE_ALIAS,
10+
name: 'Media Type Folder Workspace',
11+
api: () => import('./media-type-folder-workspace.context.js'),
12+
meta: {
13+
entityType: UMB_MEDIA_TYPE_FOLDER_ENTITY_TYPE,
14+
},
15+
},
16+
{
17+
type: 'workspaceAction',
18+
kind: 'default',
19+
alias: 'Umb.WorkspaceAction.MediaType.Folder.Save',
20+
name: 'Save Media Type Folder Workspace Action',
21+
api: UmbSubmitWorkspaceAction,
22+
meta: {
23+
label: '#buttons_save',
24+
look: 'primary',
25+
color: 'positive',
26+
},
27+
conditions: [
28+
{
29+
alias: 'Umb.Condition.WorkspaceAlias',
30+
match: UMB_MEDIA_TYPE_FOLDER_WORKSPACE_ALIAS,
31+
},
32+
],
33+
},
34+
];
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { UMB_MEDIA_TYPE_FOLDER_WORKSPACE_ALIAS } from './constants.js';
2+
import { UMB_MEDIA_TYPE_FOLDER_WORKSPACE_CONTEXT } from './media-type-folder.workspace.context-token.js';
3+
import { css, html, customElement, state } from '@umbraco-cms/backoffice/external/lit';
4+
import type { UUIInputElement } from '@umbraco-cms/backoffice/external/uui';
5+
import { UUIInputEvent } from '@umbraco-cms/backoffice/external/uui';
6+
import { umbFocus, UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
7+
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
8+
import { umbBindToValidation } from '@umbraco-cms/backoffice/validation';
9+
10+
const elementName = 'umb-media-type-folder-workspace-editor';
11+
@customElement(elementName)
12+
export class UmbMediaTypeFolderWorkspaceEditorElement extends UmbLitElement {
13+
@state()
14+
private _name = '';
15+
16+
#workspaceContext?: typeof UMB_MEDIA_TYPE_FOLDER_WORKSPACE_CONTEXT.TYPE;
17+
18+
constructor() {
19+
super();
20+
21+
this.consumeContext(UMB_MEDIA_TYPE_FOLDER_WORKSPACE_CONTEXT, (workspaceContext) => {
22+
this.#workspaceContext = workspaceContext;
23+
this.#observeName();
24+
});
25+
}
26+
27+
#observeName() {
28+
if (!this.#workspaceContext) return;
29+
this.observe(this.#workspaceContext.name, (name) => {
30+
if (name !== this._name) {
31+
this._name = name ?? '';
32+
}
33+
});
34+
}
35+
36+
#handleInput(event: UUIInputEvent) {
37+
if (event instanceof UUIInputEvent) {
38+
const target = event.composedPath()[0] as UUIInputElement;
39+
40+
if (typeof target?.value === 'string') {
41+
this.#workspaceContext?.setName(target.value);
42+
}
43+
}
44+
}
45+
46+
override render() {
47+
return html`<umb-workspace-editor alias=${UMB_MEDIA_TYPE_FOLDER_WORKSPACE_ALIAS}>
48+
<uui-input
49+
slot="header"
50+
id="nameInput"
51+
.value=${this._name ?? ''}
52+
@input="${this.#handleInput}"
53+
required
54+
${umbBindToValidation(this, `$.name`, this._name)}
55+
${umbFocus()}></uui-input>
56+
</umb-workspace-editor>`;
57+
}
58+
59+
static override styles = [
60+
UmbTextStyles,
61+
css`
62+
#nameInput {
63+
flex: 1 1 auto;
64+
}
65+
`,
66+
];
67+
}
68+
69+
export { UmbMediaTypeFolderWorkspaceEditorElement as element };
70+
71+
declare global {
72+
interface HTMLElementTagNameMap {
73+
[elementName]: UmbMediaTypeFolderWorkspaceEditorElement;
74+
}
75+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { UMB_MEDIA_TYPE_FOLDER_ENTITY_TYPE } from '../../../entity.js';
2+
import { UMB_MEDIA_TYPE_FOLDER_REPOSITORY_ALIAS, type UmbMediaTypeFolderRepository } from '../repository/index.js';
3+
import { UMB_MEDIA_TYPE_FOLDER_WORKSPACE_ALIAS } from './constants.js';
4+
import { UmbMediaTypeFolderWorkspaceEditorElement } from './media-type-folder-editor.element.js';
5+
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
6+
import {
7+
UmbEntityDetailWorkspaceContextBase,
8+
type UmbRoutableWorkspaceContext,
9+
type UmbSubmittableWorkspaceContext,
10+
} from '@umbraco-cms/backoffice/workspace';
11+
import type { IRoutingInfo, PageComponent } from '@umbraco-cms/backoffice/router';
12+
import type { UmbFolderModel } from '@umbraco-cms/backoffice/tree';
13+
14+
export class UmbMediaTypeFolderWorkspaceContext
15+
extends UmbEntityDetailWorkspaceContextBase<UmbFolderModel, UmbMediaTypeFolderRepository>
16+
implements UmbSubmittableWorkspaceContext, UmbRoutableWorkspaceContext
17+
{
18+
public readonly name = this._data.createObservablePartOfCurrent((data) => data?.name);
19+
20+
constructor(host: UmbControllerHost) {
21+
super(host, {
22+
workspaceAlias: UMB_MEDIA_TYPE_FOLDER_WORKSPACE_ALIAS,
23+
entityType: UMB_MEDIA_TYPE_FOLDER_ENTITY_TYPE,
24+
detailRepositoryAlias: UMB_MEDIA_TYPE_FOLDER_REPOSITORY_ALIAS,
25+
});
26+
27+
this.routes.setRoutes([
28+
{
29+
path: 'edit/:unique',
30+
component: UmbMediaTypeFolderWorkspaceEditorElement,
31+
setup: (component: PageComponent, info: IRoutingInfo) => {
32+
const unique = info.match.params.unique;
33+
this.load(unique);
34+
},
35+
},
36+
]);
37+
}
38+
39+
/**
40+
* @description Set the name of the script
41+
* @param {string} value
42+
* @memberof UmbScriptWorkspaceContext
43+
*/
44+
public setName(value: string) {
45+
this._data.updateCurrent({ name: value });
46+
}
47+
}
48+
49+
export { UmbMediaTypeFolderWorkspaceContext as api };
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { UMB_MEDIA_TYPE_FOLDER_ENTITY_TYPE } from '../../../entity.js';
2+
import type { UmbMediaTypeFolderWorkspaceContext } from './media-type-folder-workspace.context.js';
3+
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
4+
import type { UmbWorkspaceContext } from '@umbraco-cms/backoffice/workspace';
5+
6+
export const UMB_MEDIA_TYPE_FOLDER_WORKSPACE_CONTEXT = new UmbContextToken<
7+
UmbWorkspaceContext,
8+
UmbMediaTypeFolderWorkspaceContext
9+
>(
10+
'UmbWorkspaceContext',
11+
undefined,
12+
(context): context is UmbMediaTypeFolderWorkspaceContext =>
13+
context.getEntityType?.() === UMB_MEDIA_TYPE_FOLDER_ENTITY_TYPE,
14+
);

0 commit comments

Comments
 (0)