Skip to content

Commit 2020c9e

Browse files
committed
register script folder workspace
1 parent c6d9a0c commit 2020c9e

File tree

7 files changed

+131
-0
lines changed

7 files changed

+131
-0
lines changed

src/packages/templating/scripts/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_SCRIPT_FOLDER_ENTITY_TYPE } from '../../entity.js';
22
import { UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS } from './repository/index.js';
33
import { manifests as repositoryManifests } from './repository/manifests.js';
4+
import { manifests as workspaceManifests } from './workspace/manifests.js';
45

56
export const UMB_DELETE_SCRIPT_FOLDER_ENTITY_ACTION_ALIAS = 'Umb.EntityAction.Script.Folder.Delete';
67

@@ -16,4 +17,5 @@ export const manifests: Array<UmbExtensionManifest> = [
1617
},
1718
},
1819
...repositoryManifests,
20+
...workspaceManifests,
1921
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const UMB_SCRIPT_FOLDER_WORKSPACE_ALIAS = 'Umb.Workspace.Script.Folder';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './constants.js';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { UMB_SCRIPT_FOLDER_ENTITY_TYPE } from '../../../entity.js';
2+
import { UMB_SCRIPT_FOLDER_WORKSPACE_ALIAS } from './constants.js';
3+
4+
export const manifests: Array<UmbExtensionManifest> = [
5+
{
6+
type: 'workspace',
7+
kind: 'routable',
8+
alias: UMB_SCRIPT_FOLDER_WORKSPACE_ALIAS,
9+
name: 'Script Folder Workspace',
10+
api: () => import('./script-type-folder-workspace.context.js'),
11+
meta: {
12+
entityType: UMB_SCRIPT_FOLDER_ENTITY_TYPE,
13+
},
14+
},
15+
];
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { UMB_SCRIPT_FOLDER_WORKSPACE_ALIAS } from './constants.js';
2+
import { UMB_SCRIPT_FOLDER_WORKSPACE_CONTEXT } from './script-type-folder.workspace.context-token.js';
3+
import { css, html, customElement, state } from '@umbraco-cms/backoffice/external/lit';
4+
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
5+
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
6+
7+
const elementName = 'umb-script-folder-workspace-editor';
8+
@customElement(elementName)
9+
export class UmbScriptFolderWorkspaceEditorElement extends UmbLitElement {
10+
@state()
11+
private _name = '';
12+
13+
#workspaceContext?: typeof UMB_SCRIPT_FOLDER_WORKSPACE_CONTEXT.TYPE;
14+
15+
constructor() {
16+
super();
17+
18+
this.consumeContext(UMB_SCRIPT_FOLDER_WORKSPACE_CONTEXT, (workspaceContext) => {
19+
this.#workspaceContext = workspaceContext;
20+
this.#observeName();
21+
});
22+
}
23+
24+
#observeName() {
25+
if (!this.#workspaceContext) return;
26+
this.observe(this.#workspaceContext.name, (name) => {
27+
if (name !== this._name) {
28+
this._name = name ?? '';
29+
}
30+
});
31+
}
32+
33+
override render() {
34+
return html`<umb-workspace-editor headline=${this._name} alias=${UMB_SCRIPT_FOLDER_WORKSPACE_ALIAS}>
35+
</umb-workspace-editor>`;
36+
}
37+
38+
static override styles = [UmbTextStyles, css``];
39+
}
40+
41+
export { UmbScriptFolderWorkspaceEditorElement as element };
42+
43+
declare global {
44+
interface HTMLElementTagNameMap {
45+
[elementName]: UmbScriptFolderWorkspaceEditorElement;
46+
}
47+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS, type UmbScriptFolderRepository } from '../repository/index.js';
2+
import { UMB_SCRIPT_FOLDER_ENTITY_TYPE } from '../../../entity.js';
3+
import { UMB_SCRIPT_FOLDER_WORKSPACE_ALIAS } from './constants.js';
4+
import { UmbScriptFolderWorkspaceEditorElement } from './script-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 UmbScriptFolderWorkspaceContext
15+
extends UmbEntityDetailWorkspaceContextBase<UmbFolderModel, UmbScriptFolderRepository>
16+
implements UmbSubmittableWorkspaceContext, UmbRoutableWorkspaceContext
17+
{
18+
public readonly data = this._data.current;
19+
public readonly unique = this._data.createObservablePartOfCurrent((data) => data?.unique);
20+
public readonly entityType = this._data.createObservablePartOfCurrent((data) => data?.entityType);
21+
public readonly name = this._data.createObservablePartOfCurrent((data) => data?.name);
22+
23+
constructor(host: UmbControllerHost) {
24+
super(host, {
25+
workspaceAlias: UMB_SCRIPT_FOLDER_WORKSPACE_ALIAS,
26+
entityType: UMB_SCRIPT_FOLDER_ENTITY_TYPE,
27+
detailRepositoryAlias: UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS,
28+
});
29+
30+
this.routes.setRoutes([
31+
{
32+
path: 'edit/:unique',
33+
component: UmbScriptFolderWorkspaceEditorElement,
34+
setup: (component: PageComponent, info: IRoutingInfo) => {
35+
const unique = info.match.params.unique;
36+
this.load(unique);
37+
},
38+
},
39+
]);
40+
}
41+
42+
/**
43+
* @description Set the name of the script
44+
* @param {string} value
45+
* @memberof UmbScriptWorkspaceContext
46+
*/
47+
public setName(value: string) {
48+
this._data.updateCurrent({ name: value });
49+
}
50+
}
51+
52+
export { UmbScriptFolderWorkspaceContext as api };
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { UMB_SCRIPT_FOLDER_ENTITY_TYPE } from '../../../entity.js';
2+
import type { UmbScriptFolderWorkspaceContext } from './script-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_SCRIPT_FOLDER_WORKSPACE_CONTEXT = new UmbContextToken<
7+
UmbWorkspaceContext,
8+
UmbScriptFolderWorkspaceContext
9+
>(
10+
'UmbWorkspaceContext',
11+
undefined,
12+
(context): context is UmbScriptFolderWorkspaceContext => context.getEntityType?.() === UMB_SCRIPT_FOLDER_ENTITY_TYPE,
13+
);

0 commit comments

Comments
 (0)