From 3e9b097d8bb1434ff5f6c059d121064e3b8db108 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 3 Feb 2023 22:31:42 +0100 Subject: [PATCH] add workspace actions to document + add default element for a workspace action --- .../workspace-action.models.ts | 13 ++-- .../libs/models/index.ts | 5 ++ .../document-types/workspace/manifests.ts | 3 +- .../documents/entity-actions/manifests.ts | 48 ++------------- .../entity-actions/save-and-preview.action.ts | 13 ---- .../entity-actions/save-and-publish.action.ts | 13 ---- .../save-and-schedule.action.ts | 13 ---- .../documents/entity-actions/save.action.ts | 30 ---------- .../actions/save-and-preview.action.ts | 13 ++++ .../actions/save-and-publish.action.ts | 13 ++++ .../actions/save-and-schedule.action.ts | 13 ++++ .../workspace/actions/save.action.ts | 21 +++++++ .../documents/workspace/manifests.ts | 47 ++++++++++----- .../media/media/workspace/manifests.ts | 3 +- .../data-types/workspace/manifests.ts | 3 +- .../language/language-workspace.element.ts | 2 +- .../languages/workspace/language/manifests.ts | 3 +- .../src/backoffice/shared/components/index.ts | 6 ++ .../workspace/workspace-action/index.ts | 15 +++++ .../workspace-action-node-save.element.ts | 0 .../workspace-action.element.ts | 59 +++++++++++++++++++ .../workspace-layout.element.ts | 4 +- .../workspace/user-group-workspace.element.ts | 8 +-- .../users/users/workspace/manifests.ts | 3 +- 24 files changed, 205 insertions(+), 146 deletions(-) delete mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-preview.action.ts delete mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-publish.action.ts delete mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-schedule.action.ts delete mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save.action.ts create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-preview.action.ts create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-publish.action.ts create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-schedule.action.ts create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save.action.ts create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/index.ts rename src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/{actions => workspace-action}/save/workspace-action-node-save.element.ts (100%) create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/workspace-action.element.ts diff --git a/src/Umbraco.Web.UI.Client/libs/extensions-registry/workspace-action.models.ts b/src/Umbraco.Web.UI.Client/libs/extensions-registry/workspace-action.models.ts index a7ec0f8f5a..d37e5b53eb 100644 --- a/src/Umbraco.Web.UI.Client/libs/extensions-registry/workspace-action.models.ts +++ b/src/Umbraco.Web.UI.Client/libs/extensions-registry/workspace-action.models.ts @@ -1,14 +1,15 @@ -import type { InterfaceColor, InterfaceLook } from '@umbraco-ui/uui-base/lib/types/index' +import type { InterfaceColor, InterfaceLook } from '@umbraco-ui/uui-base/lib/types/index'; import type { ManifestElement } from './models'; export interface ManifestWorkspaceAction extends ManifestElement { type: 'workspaceAction'; - meta: MetaEditorAction; + meta: MetaWorkspaceAction; } -export interface MetaEditorAction { +export interface MetaWorkspaceAction { workspaces: Array; - label?: string, //TODO: Use or implement additional label-key - look?: InterfaceLook, - color?: InterfaceColor, + label?: string; //TODO: Use or implement additional label-key + look?: InterfaceLook; + color?: InterfaceColor; + api: any; //TODO: Implement UmbEntityAction } diff --git a/src/Umbraco.Web.UI.Client/libs/models/index.ts b/src/Umbraco.Web.UI.Client/libs/models/index.ts index fcf4400f8f..85cb4f5486 100644 --- a/src/Umbraco.Web.UI.Client/libs/models/index.ts +++ b/src/Umbraco.Web.UI.Client/libs/models/index.ts @@ -6,6 +6,7 @@ import { FolderTreeItem, ProblemDetails, } from '@umbraco-cms/backend-api'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; // Extension Manifests export * from '@umbraco-cms/extensions-registry'; @@ -157,3 +158,7 @@ export interface DataSourceResponse { data?: T; error?: ProblemDetails; } + +export interface UmbRepositoryFactory { + new (host: UmbControllerHostInterface): T; +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/manifests.ts index 39ef3c38ec..82229b33e1 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/manifests.ts @@ -31,7 +31,8 @@ const workspaceActions: Array = [ type: 'workspaceAction', alias: 'Umb.WorkspaceAction.DocumentType.Save', name: 'Save Document Type Workspace Action', - loader: () => import('../../../shared/components/workspace/actions/save/workspace-action-node-save.element'), + loader: () => + import('../../../shared/components/workspace/workspace-action/save/workspace-action-node-save.element'), meta: { workspaces: ['Umb.Workspace.DocumentType'], look: 'primary', diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/manifests.ts index 36048f90bb..8f110c456c 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/manifests.ts @@ -1,6 +1,6 @@ import { UmbCreateDocumentEntityAction } from './create.action'; import { UmbPublishDocumentEntityAction } from './publish.action'; -import { UmbSaveDocumentEntityAction } from './save.action'; +import { UmbSaveDocumentWorkspaceAction } from '../workspace/actions/save.action'; import { UmbCopyDocumentEntityAction } from './copy.action'; import { UmbDocumentCultureAndHostnamesEntityAction } from './culture-and-hostnames.action'; import { UmbMoveDocumentEntityAction } from './move.action'; @@ -9,10 +9,10 @@ import { UmbSortChildrenOfDocumentEntityAction } from './sort-children-of.action import { UmbCreateDocumentBlueprintEntityAction } from './create-blueprint.action'; import { UmbDocumentPublicAccessEntityAction } from './public-access.action'; import { UmbDocumentPermissionsEntityAction } from './permissions.action'; -import { UmbSaveAndPublishDocumentEntityAction } from './save-and-publish.action'; +import { UmbSaveAndPublishDocumentWorkspaceAction } from '../workspace/actions/save-and-publish.action'; import { UmbUnpublishDocumentEntityAction } from './unpublish.action'; -import { UmbSaveAndPreviewDocumentEntityAction } from './save-and-preview.action'; -import { UmbSaveAndScheduleDocumentEntityAction } from './save-and-schedule.action'; +import { UmbSaveAndPreviewDocumentWorkspaceAction } from '../workspace/actions/save-and-preview.action'; +import { UmbSaveAndScheduleDocumentWorkspaceAction } from '../workspace/actions/save-and-schedule.action'; import { UmbRollbackDocumentEntityAction } from './rollback.action'; import { ManifestEntityAction } from '@umbraco-cms/extensions-registry'; @@ -172,46 +172,6 @@ const entityActions: Array = [ api: UmbRollbackDocumentEntityAction, }, }, - { - type: 'entityAction', - alias: 'Umb.EntityAction.Document.Save', - name: 'Save Document Entity Action', - meta: { - entityType, - label: 'Save', - api: UmbSaveDocumentEntityAction, - }, - }, - { - type: 'entityAction', - alias: 'Umb.EntityAction.Document.SaveAndPublish', - name: 'Save And Publish Document Entity Action', - meta: { - entityType, - label: 'Save And Publish', - api: UmbSaveAndPublishDocumentEntityAction, - }, - }, - { - type: 'entityAction', - alias: 'Umb.EntityAction.Document.SaveAndPreview', - name: 'Unpublish Document Entity Action', - meta: { - entityType, - label: 'Save And Preview', - api: UmbSaveAndPreviewDocumentEntityAction, - }, - }, - { - type: 'entityAction', - alias: 'Umb.EntityAction.Document.SaveAndSchedule', - name: 'Save And Schedule Document Entity Action', - meta: { - entityType, - label: 'Save And Schedule', - api: UmbSaveAndScheduleDocumentEntityAction, - }, - }, ]; export const manifests = [...entityActions]; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-preview.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-preview.action.ts deleted file mode 100644 index d44216350b..0000000000 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-preview.action.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { UmbDocumentRepository } from '../repository/document.repository'; -import { UmbEntityActionBase } from '../../../shared/components/entity-action'; -import { UmbControllerHostInterface } from '@umbraco-cms/controller'; - -export class UmbSaveAndPreviewDocumentEntityAction extends UmbEntityActionBase { - constructor(host: UmbControllerHostInterface, unique: string) { - super(host, UmbDocumentRepository, unique); - } - - async execute() { - await this.repository.saveAndPreview(); - } -} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-publish.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-publish.action.ts deleted file mode 100644 index 58de17d829..0000000000 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-publish.action.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { UmbDocumentRepository } from '../repository/document.repository'; -import { UmbEntityActionBase } from '../../../shared/components/entity-action'; -import { UmbControllerHostInterface } from '@umbraco-cms/controller'; - -export class UmbSaveAndPublishDocumentEntityAction extends UmbEntityActionBase { - constructor(host: UmbControllerHostInterface, unique: string) { - super(host, UmbDocumentRepository, unique); - } - - async execute() { - await this.repository.saveAndPublish(); - } -} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-schedule.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-schedule.action.ts deleted file mode 100644 index b18db77126..0000000000 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save-and-schedule.action.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { UmbDocumentRepository } from '../repository/document.repository'; -import { UmbEntityActionBase } from '../../../shared/components/entity-action'; -import { UmbControllerHostInterface } from '@umbraco-cms/controller'; - -export class UmbSaveAndScheduleDocumentEntityAction extends UmbEntityActionBase { - constructor(host: UmbControllerHostInterface, unique: string) { - super(host, UmbDocumentRepository, unique); - } - - async execute() { - await this.repository.saveAndSchedule(); - } -} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save.action.ts deleted file mode 100644 index 115d5a86d3..0000000000 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/entity-actions/save.action.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { UmbDocumentRepository } from '../repository/document.repository'; -import { UmbDocumentWorkspaceContext } from '../workspace/document-workspace.context'; -import { UmbContextConsumerController } from '@umbraco-cms/context-api'; -import { UmbControllerHostInterface } from '@umbraco-cms/controller'; -import { UmbEntityActionBase } from 'src/backoffice/shared/components/entity-action'; - -export class UmbSaveDocumentEntityAction extends UmbEntityActionBase { - #workspaceContext?: UmbDocumentWorkspaceContext; - - constructor(host: UmbControllerHostInterface, unique: string) { - super(host, UmbDocumentRepository, unique); - - // TODO: add context token for workspace - new UmbContextConsumerController(this.host, 'umbWorkspaceContext', (instance: UmbDocumentWorkspaceContext) => { - this.#workspaceContext = instance; - }); - } - - async execute() { - if (!this.#workspaceContext) { - alert('the actions doesnt work here'); - return; - } - // TODO: it doesn't get the updated value - const document = this.#workspaceContext.getData(); - // TODO: handle errors - if (!document) return; - this.repository.saveDetail(document); - } -} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-preview.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-preview.action.ts new file mode 100644 index 0000000000..7a56c11c65 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-preview.action.ts @@ -0,0 +1,13 @@ +import { UmbDocumentRepository } from '../../repository/document.repository'; +import { UmbEntityActionBase } from '../../../../shared/components/entity-action'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; + +export class UmbSaveAndPreviewDocumentWorkspaceAction extends UmbEntityActionBase { + constructor(host: UmbControllerHostInterface, unique: string) { + super(host, UmbDocumentRepository, unique); + } + + async execute() { + await this.repository.saveAndPreview(); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-publish.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-publish.action.ts new file mode 100644 index 0000000000..feeebf2ac6 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-publish.action.ts @@ -0,0 +1,13 @@ +import { UmbDocumentRepository } from '../../repository/document.repository'; +import { UmbEntityActionBase } from '../../../../shared/components/entity-action'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; + +export class UmbSaveAndPublishDocumentWorkspaceAction extends UmbEntityActionBase { + constructor(host: UmbControllerHostInterface, unique: string) { + super(host, UmbDocumentRepository, unique); + } + + async execute() { + await this.repository.saveAndPublish(); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-schedule.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-schedule.action.ts new file mode 100644 index 0000000000..26f99261a2 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save-and-schedule.action.ts @@ -0,0 +1,13 @@ +import { UmbDocumentRepository } from '../../repository/document.repository'; +import { UmbEntityActionBase } from '../../../../shared/components/entity-action'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; + +export class UmbSaveAndScheduleDocumentWorkspaceAction extends UmbEntityActionBase { + constructor(host: UmbControllerHostInterface, unique: string) { + super(host, UmbDocumentRepository, unique); + } + + async execute() { + await this.repository.saveAndSchedule(); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save.action.ts new file mode 100644 index 0000000000..9d0feefe6f --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/actions/save.action.ts @@ -0,0 +1,21 @@ +import { UmbDocumentRepository } from '../../repository/document.repository'; +import { UmbDocumentWorkspaceContext } from '../document-workspace.context'; +import { UmbWorkspaceAction } from '../../../../shared/components/workspace/workspace-action'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; + +export class UmbSaveDocumentWorkspaceAction extends UmbWorkspaceAction { + #workspaceContext?: UmbDocumentWorkspaceContext; + + constructor(host: UmbControllerHostInterface, unique: string) { + super(host, UmbDocumentRepository, unique); + } + + async execute() { + if (!this.workspaceContext) return; + // TODO: it doesn't get the updated value + const document = this.workspaceContext.getData(); + // TODO: handle errors + if (!document) return; + this.repository.saveDetail(document); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/manifests.ts index 0c58e5719b..17a5e43c14 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/manifests.ts @@ -1,5 +1,14 @@ import { DOCUMENT_REPOSITORY_ALIAS } from '../repository/manifests'; -import type { ManifestWorkspace, ManifestWorkspaceAction, ManifestWorkspaceView, ManifestWorkspaceViewCollection } from '@umbraco-cms/models'; +import type { + ManifestWorkspace, + ManifestWorkspaceAction, + ManifestWorkspaceView, + ManifestWorkspaceViewCollection, +} from '@umbraco-cms/models'; +import { UmbSaveAndPublishDocumentWorkspaceAction } from './actions/save-and-publish.action'; +import { UmbSaveDocumentWorkspaceAction } from './actions/save.action'; +import { UmbSaveAndPreviewDocumentWorkspaceAction } from './actions/save-and-preview.action'; +import { UmbSaveAndScheduleDocumentWorkspaceAction } from './actions/save-and-schedule.action'; const workspace: ManifestWorkspace = { type: 'workspace', @@ -54,7 +63,7 @@ const workspaceViewCollections: Array = [ pathname: 'collection', icon: 'umb:grid', entityType: 'document', - repositoryAlias: DOCUMENT_REPOSITORY_ALIAS + repositoryAlias: DOCUMENT_REPOSITORY_ALIAS, }, }, ]; @@ -62,35 +71,45 @@ const workspaceViewCollections: Array = [ const workspaceActions: Array = [ { type: 'workspaceAction', - alias: 'Umb.WorkspaceAction.Document.SaveAndPreview', - name: 'Save Document Workspace Action', - loader: () => import('src/backoffice/shared/components/workspace/actions/save/workspace-action-node-save.element'), + alias: 'Umb.WorkspaceAction.Document.SaveAndPublish', + name: 'Save And Publish Document Workspace Action', meta: { workspaces: ['Umb.Workspace.Document'], - label: 'Save and preview', + label: 'Save And Publish', + look: 'primary', + color: 'positive', + api: UmbSaveAndPublishDocumentWorkspaceAction, }, }, { type: 'workspaceAction', alias: 'Umb.WorkspaceAction.Document.Save', name: 'Save Document Workspace Action', - loader: () => import('src/backoffice/shared/components/workspace/actions/save/workspace-action-node-save.element'), meta: { workspaces: ['Umb.Workspace.Document'], - look: 'secondary', label: 'Save', + look: 'secondary', + api: UmbSaveDocumentWorkspaceAction, }, }, { type: 'workspaceAction', - alias: 'Umb.WorkspaceAction.Document.SaveAndPublish', - name: 'Save Document Workspace Action', - loader: () => import('src/backoffice/shared/components/workspace/actions/save/workspace-action-node-save.element'), + alias: 'Umb.WorkspaceAction.Document.SaveAndPreview', + name: 'Save And Preview Document Workspace Action', meta: { workspaces: ['Umb.Workspace.Document'], - label: 'Save and publish', - look: 'primary', - color: 'positive', + label: 'Save And Preview', + api: UmbSaveAndPreviewDocumentWorkspaceAction, + }, + }, + { + type: 'workspaceAction', + alias: 'Umb.WorkspaceAction.Document.SaveAndSchedule', + name: 'Save And Schedule Document Workspace Action', + meta: { + workspaces: ['Umb.Workspace.Document'], + label: 'Save And Schedule', + api: UmbSaveAndScheduleDocumentWorkspaceAction, }, }, ]; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/media/media/workspace/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/media/media/workspace/manifests.ts index dbdbe34146..33615dd9ae 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/media/media/workspace/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/media/media/workspace/manifests.ts @@ -69,7 +69,8 @@ const workspaceActions: Array = [ type: 'workspaceAction', alias: 'Umb.WorkspaceAction.Media.Save', name: 'Save Media Workspace Action', - loader: () => import('src/backoffice/shared/components/workspace/actions/save/workspace-action-node-save.element'), + loader: () => + import('src/backoffice/shared/components/workspace/workspace-action/save/workspace-action-node-save.element'), meta: { workspaces: ['Umb.Workspace.Media'], look: 'primary', diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/workspace/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/workspace/manifests.ts index e8c420106b..952199ab0b 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/workspace/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/workspace/manifests.ts @@ -44,7 +44,8 @@ const workspaceActions: Array = [ type: 'workspaceAction', alias: 'Umb.WorkspaceAction.DataType.Save', name: 'Save Data Type Workspace Action', - loader: () => import('src/backoffice/shared/components/workspace/actions/save/workspace-action-node-save.element'), + loader: () => + import('src/backoffice/shared/components/workspace/workspace-action/save/workspace-action-node-save.element'), meta: { workspaces: ['Umb.Workspace.DataType'], look: 'primary', diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/language-workspace.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/language-workspace.element.ts index 20a4af6d39..40b42eddbb 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/language-workspace.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/language-workspace.element.ts @@ -6,7 +6,7 @@ import { UmbLanguageStoreItemType } from '../../language.store'; import { UmbWorkspaceEntityElement } from '../../../../shared/components/workspace/workspace-entity-element.interface'; import { UmbWorkspaceLanguageContext } from './language-workspace.context'; import { UmbLitElement } from '@umbraco-cms/element'; -import '../../../../shared/components/workspace/actions/save/workspace-action-node-save.element.ts'; +import '../../../../shared/components/workspace/workspace-action/save/workspace-action-node-save.element.ts'; @customElement('umb-language-workspace') export class UmbLanguageWorkspaceElement extends UmbLitElement implements UmbWorkspaceEntityElement { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/manifests.ts index 285d60cc7a..1c686ba026 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/manifests.ts @@ -15,7 +15,8 @@ const workspaceActions: Array = [ type: 'workspaceAction', alias: 'Umb.WorkspaceAction.Language.Save', name: 'Save Language Workspace Action', - loader: () => import('../../../../shared/components/workspace/actions/save/workspace-action-node-save.element'), + loader: () => + import('../../../../shared/components/workspace/workspace-action/save/workspace-action-node-save.element'), meta: { workspaces: ['Umb.Workspace.Language'], look: 'primary', diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/index.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/index.ts index aebac0b705..122ae87df6 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/index.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/index.ts @@ -3,16 +3,22 @@ import './backoffice-frame/backoffice-header.element'; import './backoffice-frame/backoffice-main.element'; import './backoffice-frame/backoffice-modal-container.element'; import './backoffice-frame/backoffice-notification-container.element'; + import './ref-property-editor-ui/ref-property-editor-ui.element'; import './content-property/content-property.element'; import './table/table.element'; import './code-block/code-block.element'; import './extension-slot/extension-slot.element'; + import './workspace/workspace-layout/workspace-layout.element'; +import './workspace/workspace-action/workspace-action.element'; + import './section/section-main/section-main.element'; import './section/section-sidebar/section-sidebar.element'; import './section/section.element'; + import './tree/tree.element'; + import './workspace/workspace-content/workspace-content.element'; import './workspace/workspace-action-menu/workspace-action-menu.element'; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/index.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/index.ts new file mode 100644 index 0000000000..42e0494605 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/index.ts @@ -0,0 +1,15 @@ +import { UmbEntityActionBase } from '../../entity-action'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; +import type { UmbRepositoryFactory } from '@umbraco-cms/models'; +import { UmbContextConsumerController } from '@umbraco-cms/context-api'; + +export class UmbWorkspaceAction extends UmbEntityActionBase { + workspaceContext: any; + constructor(host: UmbControllerHostInterface, repository: UmbRepositoryFactory, unique: string) { + super(host, repository, unique); + + new UmbContextConsumerController(this.host, 'umbWorkspaceContext', (instance) => { + this.workspaceContext = instance; + }); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/actions/save/workspace-action-node-save.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/save/workspace-action-node-save.element.ts similarity index 100% rename from src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/actions/save/workspace-action-node-save.element.ts rename to src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/save/workspace-action-node-save.element.ts diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/workspace-action.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/workspace-action.element.ts new file mode 100644 index 0000000000..3cae7ba75b --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-action/workspace-action.element.ts @@ -0,0 +1,59 @@ +import { css, html } from 'lit'; +import { customElement, property, state } from 'lit/decorators.js'; +import { UUITextStyles } from '@umbraco-ui/uui-css/lib'; +import type { UUIButtonState } from '@umbraco-ui/uui'; +import { UmbLitElement } from '@umbraco-cms/element'; +import type { ManifestWorkspaceAction } from '@umbraco-cms/models'; + +@customElement('umb-workspace-action') +export class UmbWorkspaceActionElement extends UmbLitElement { + static styles = [UUITextStyles, css``]; + + @state() + private _buttonState?: UUIButtonState; + + private _manifest?: ManifestWorkspaceAction; + @property({ type: Object, attribute: false }) + public get manifest() { + return this._manifest; + } + public set manifest(value: ManifestWorkspaceAction | undefined) { + if (!value) return; + const oldValue = this._manifest; + this._manifest = value; + if (oldValue !== this._manifest) { + this.#createApi(); + this.requestUpdate('manifest', oldValue); + } + } + + #createApi() { + if (!this._manifest?.meta.api) return; + this.#api = new this._manifest.meta.api(this); + } + + #api: any; + + private async _onClick() { + await this.#api.execute(); + } + + render() { + return html` + + `; + } +} + +export default UmbWorkspaceActionElement; + +declare global { + interface HTMLElementTagNameMap { + 'umb-workspace-action': UmbWorkspaceActionElement; + } +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-layout/workspace-layout.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-layout/workspace-layout.element.ts index 6986763e9d..f2cfdf468e 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-layout/workspace-layout.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-layout/workspace-layout.element.ts @@ -163,8 +163,8 @@ export class UmbWorkspaceLayout extends UmbLitElement { - extension.meta.workspaces.includes(this.alias)}> + .filter=${(extension: ManifestWorkspaceAction) => extension.meta.workspaces.includes(this.alias)} + default-element="umb-workspace-action"> `; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/workspace/user-group-workspace.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/workspace/user-group-workspace.element.ts index fea60878ce..3a04cbc4e5 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/workspace/user-group-workspace.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/workspace/user-group-workspace.element.ts @@ -186,8 +186,6 @@ export class UmbUserGroupWorkspaceElement extends UmbLitElement implements UmbWo private _userStore?: UmbUserStore; - - private _workspaceContext: UmbWorkspaceUserGroupContext = new UmbWorkspaceUserGroupContext(this); @state() @@ -225,7 +223,8 @@ export class UmbUserGroupWorkspaceElement extends UmbLitElement implements UmbWo type: 'workspaceAction', alias: 'Umb.WorkspaceAction.UserGroup.Save', name: 'Save User Group Workspace Action', - loader: () => import('../../../shared/components/workspace/actions/save/workspace-action-node-save.element'), + loader: () => + import('../../../shared/components/workspace/workspace-action/save/workspace-action-node-save.element'), meta: { workspaces: ['Umb.Workspace.UserGroup'], look: 'primary', @@ -263,7 +262,6 @@ export class UmbUserGroupWorkspaceElement extends UmbLitElement implements UmbWo //this._workspaceContext.setUsers(); } - private _updatePermission(permission: { name: string; description: string; value: boolean }) { if (!this._workspaceContext) return; @@ -294,7 +292,7 @@ export class UmbUserGroupWorkspaceElement extends UmbLitElement implements UmbWo } private _updateSections(value: string[]) { - console.log("To be done"); + console.log('To be done'); //this._workspaceContext.setSections(value); } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/users/users/workspace/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/users/users/workspace/manifests.ts index fd2d64379c..566eed14f1 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/users/users/workspace/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/users/users/workspace/manifests.ts @@ -16,7 +16,8 @@ const workspaceActions: Array = [ type: 'workspaceAction', alias: 'Umb.WorkspaceAction.User.Save', name: 'Save User Workspace Action', - loader: () => import('src/backoffice/shared/components/workspace/actions/save/workspace-action-node-save.element'), + loader: () => + import('src/backoffice/shared/components/workspace/workspace-action/save/workspace-action-node-save.element'), meta: { workspaces: ['Umb.Workspace.User'], look: 'primary',