diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/manifests.ts index 4800606d69..5b3646bd34 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/manifests.ts @@ -12,6 +12,7 @@ import { manifests as duplicateManifests } from './duplicate/manifests.js'; import { manifests as moveManifests } from './move-to/manifests.js'; import { manifests as publicAccessManifests } from './public-access/manifests.js'; import { manifests as sortChildrenOfManifests } from './sort-children-of/manifests.js'; +import { manifests as notificationManifests } from './notifications/manifests.js'; import type { ManifestEntityAction, ManifestTypes } from '@umbraco-cms/backoffice/extension-registry'; import { @@ -143,4 +144,5 @@ export const manifests: Array = [ ...publicAccessManifests, ...sortChildrenOfManifests, ...entityActions, + ...notificationManifests, ]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/document-notifications-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/document-notifications-modal.element.ts new file mode 100644 index 0000000000..6c9c6aba57 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/document-notifications-modal.element.ts @@ -0,0 +1,64 @@ +import type { + UmbDocumentNotificationsModalData, + UmbDocumentNotificationsModalValue, +} from './document-notifications-modal.token.js'; +import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity'; +import { css, customElement, html } from '@umbraco-cms/backoffice/external/lit'; +import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'; +import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; + +@customElement('umb-document-notifications-modal') +export class UmbDocumentNotificationsModalElement extends UmbModalBaseElement< + UmbDocumentNotificationsModalData, + UmbDocumentNotificationsModalValue +> { + #unique?: UmbEntityUnique; + + constructor() { + super(); + this.#unique = this.data?.unique; + } + + override render() { + return html` + + + ${this.#unique} + + + + + + + + + + + + + + + + + + + `; + } + + static override styles = [ + UmbTextStyles, + css` + uui-toggle { + display: block; + } + `, + ]; +} + +export default UmbDocumentNotificationsModalElement; + +declare global { + interface HTMLElementTagNameMap { + 'umb-document-notifications-modal': UmbDocumentNotificationsModalElement; + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/document-notifications-modal.token.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/document-notifications-modal.token.ts new file mode 100644 index 0000000000..16bf13836e --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/document-notifications-modal.token.ts @@ -0,0 +1,18 @@ +import { UMB_DOCUMENT_NOTIFICATIONS_MODAL_ALIAS } from './manifests.js'; +import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity'; +import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; + +export interface UmbDocumentNotificationsModalData { + unique: UmbEntityUnique; +} +export interface UmbDocumentNotificationsModalValue {} + +export const UMB_DOCUMENT_NOTIFICATIONS_MODAL = new UmbModalToken< + UmbDocumentNotificationsModalData, + UmbDocumentNotificationsModalValue +>(UMB_DOCUMENT_NOTIFICATIONS_MODAL_ALIAS, { + modal: { + type: 'sidebar', + size: 'small', + }, +}); diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/document-notifications.action.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/document-notifications.action.ts new file mode 100644 index 0000000000..ba0398e90a --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/document-notifications.action.ts @@ -0,0 +1,20 @@ +import { UMB_DOCUMENT_NOTIFICATIONS_MODAL } from './document-notifications-modal.token.js'; +import type { UmbEntityActionArgs } from '@umbraco-cms/backoffice/entity-action'; +import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; +import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; +import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; + +export class UmbDocumentNotificationsEntityAction extends UmbEntityActionBase { + constructor(host: UmbControllerHost, args: UmbEntityActionArgs) { + super(host, args); + } + + override async execute() { + const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT); + const modalContext = modalManager.open(this, UMB_DOCUMENT_NOTIFICATIONS_MODAL, { + data: { unique: this.args.unique }, + }); + await modalContext.onSubmit(); + } +} +export default UmbDocumentNotificationsEntityAction; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/index.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/index.ts new file mode 100644 index 0000000000..b1641ba97e --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/index.ts @@ -0,0 +1,2 @@ +export * from './document-notifications-modal.token.js'; +export * from './repository/index.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/manifests.ts new file mode 100644 index 0000000000..854920739b --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/manifests.ts @@ -0,0 +1,27 @@ +import { UMB_DOCUMENT_ENTITY_TYPE } from '../../entity.js'; +import { manifests as repositoryManifests } from './repository/manifests.js'; +import type { ManifestEntityAction, ManifestTypes } from '@umbraco-cms/backoffice/extension-registry'; + +export const UMB_DOCUMENT_NOTIFICATIONS_MODAL_ALIAS = 'Umb.Modal.DocumentNotifications'; + +const actionManifest: ManifestEntityAction = { + type: 'entityAction', + kind: 'default', + alias: 'Umb.EntityAction.Document.Notifications', + name: 'Notifications', + api: () => import('./document-notifications.action.js'), + forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE], + meta: { + icon: 'icon-megaphone', + label: '#notifications_notifications', + }, +}; + +const modalManifest: ManifestTypes = { + type: 'modal', + alias: UMB_DOCUMENT_NOTIFICATIONS_MODAL_ALIAS, + name: 'Document Notifications Modal', + js: () => import('./document-notifications-modal.element.js'), +}; + +export const manifests = [actionManifest, modalManifest, ...repositoryManifests]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/document-notifications.repository.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/document-notifications.repository.ts new file mode 100644 index 0000000000..9b79298de1 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/document-notifications.repository.ts @@ -0,0 +1,44 @@ +import { UmbDocumentNotificationsServerDataSource } from './document-notifications.server.data.js'; +import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; +import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; +import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification'; +import type { UmbApi } from '@umbraco-cms/backoffice/extension-api'; +import type { UpdateDocumentNotificationsRequestModel } from '@umbraco-cms/backoffice/external/backend-api'; + +export class UmbDocumentNotificationsRepository extends UmbControllerBase implements UmbApi { + #dataSource = new UmbDocumentNotificationsServerDataSource(this); + + #notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE; + + constructor(host: UmbControllerHost) { + super(host); + + this.consumeContext(UMB_NOTIFICATION_CONTEXT, (instance) => { + this.#notificationContext = instance; + }); + } + + async readNotifications(unique: string) { + if (!unique) throw new Error('Unique is missing'); + + const { data, error } = await this.#dataSource.read(unique); + if (!error) { + return { data }; + } + return { error }; + } + + async updateNotifications(unique: string, data: UpdateDocumentNotificationsRequestModel) { + if (!unique) throw new Error('Unique is missing'); + if (!data) throw new Error('Data is missing'); + + const { error } = await this.#dataSource.update(unique, data); + if (!error) { + const notification = { data: { message: `Notification settings saved` } }; + this.#notificationContext?.peek('positive', notification); + } + return { error }; + } +} + +export { UmbDocumentNotificationsRepository as api }; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/document-notifications.server.data.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/document-notifications.server.data.ts new file mode 100644 index 0000000000..7ee5f2bce7 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/document-notifications.server.data.ts @@ -0,0 +1,46 @@ +import { DocumentService } from '@umbraco-cms/backoffice/external/backend-api'; +import type { UpdateDocumentNotificationsRequestModel } from '@umbraco-cms/backoffice/external/backend-api'; +import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; +import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources'; + +/** + * A data source for the Document Culture and Hostnames that fetches data from the server + * @class UmbDocumentNotificationsServerDataSource + * @implements {RepositoryDetailDataSource} + */ +export class UmbDocumentNotificationsServerDataSource { + #host: UmbControllerHost; + + /** + * Creates an instance of UmbDocumentNotificationsServerDataSource. + * @param {UmbControllerHost} host - The controller host for this controller to be appended to + * @memberof UmbDocumentNotificationsServerDataSource + */ + constructor(host: UmbControllerHost) { + this.#host = host; + } + + /** + * Fetches the Culture and Hostnames for the given Document unique + * @param {string} unique + * @memberof UmbDocumentNotificationsServerDataSource + */ + async read(unique: string) { + if (!unique) throw new Error('Unique is missing'); + return tryExecuteAndNotify(this.#host, DocumentService.getDocumentByIdNotifications({ id: unique })); + } + + /** + * Updates Culture and Hostnames for the given Document unique + * @param {string} unique + * @param {UpdateDocumentNotificationsRequestModel} data + * @memberof UmbDocumentNotificationsServerDataSource + */ + async update(unique: string, data: UpdateDocumentNotificationsRequestModel) { + if (!unique) throw new Error('Unique is missing'); + return tryExecuteAndNotify( + this.#host, + DocumentService.putDocumentByIdNotifications({ id: unique, requestBody: data }), + ); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/index.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/index.ts new file mode 100644 index 0000000000..6b1e01d108 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/index.ts @@ -0,0 +1,2 @@ +export { UmbDocumentNotificationsRepository } from './document-notifications.repository.js'; +export { UMB_DOCUMENT_NOTIFICATIONS_REPOSITORY_ALIAS } from './manifests.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/manifests.ts new file mode 100644 index 0000000000..2296083714 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/notifications/repository/manifests.ts @@ -0,0 +1,12 @@ +import type { ManifestRepository, ManifestTypes } from '@umbraco-cms/backoffice/extension-registry'; + +export const UMB_DOCUMENT_NOTIFICATIONS_REPOSITORY_ALIAS = 'Umb.Repository.Document.Notifications'; + +const repository: ManifestRepository = { + type: 'repository', + alias: UMB_DOCUMENT_NOTIFICATIONS_REPOSITORY_ALIAS, + name: 'Document Notifications Repository', + api: () => import('./document-notifications.repository.js'), +}; + +export const manifests: Array = [repository]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/modals/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/modals/manifests.ts index 520453ed02..ff2a6d087e 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/modals/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/modals/manifests.ts @@ -6,6 +6,7 @@ export const UMB_DOCUMENT_PUBLISH_MODAL_ALIAS = 'Umb.Modal.DocumentPublish'; export const UMB_DOCUMENT_UNPUBLISH_MODAL_ALIAS = 'Umb.Modal.DocumentUnpublish'; export const UMB_DOCUMENT_SCHEDULE_MODAL_ALIAS = 'Umb.Modal.DocumentSchedule'; export const UMB_DOCUMENT_PUBLISH_WITH_DESCENDANTS_MODAL_ALIAS = 'Umb.Modal.DocumentPublishWithDescendants'; +export const UMB_DOCUMENT_NOTIFICATIONS_MODAL_ALIAS = 'Umb.Modal.DocumentNotifications'; const modals: Array = [ {