add entity action base class + methods on repo

This commit is contained in:
Mads Rasmussen
2023-02-03 14:03:31 +01:00
parent b803b87579
commit ff4ccd44d6
20 changed files with 188 additions and 150 deletions

View File

@@ -8,5 +8,5 @@ export interface ManifestTree extends ManifestBase {
export interface MetaTree {
storeAlias?: string;
repository?: UmbRepositoryFactory;
repository?: UmbRepositoryFactory<any>;
}

View File

@@ -7,6 +7,7 @@ import {
PagedEntityTreeItem,
ProblemDetails,
} from '@umbraco-cms/backend-api';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
import { UmbTreeRepository } from 'libs/repository/tree-repository.interface';
import { Observable } from 'rxjs';
@@ -158,8 +159,6 @@ export interface DataSourceResponse<T = undefined> {
data?: T;
error?: ProblemDetails;
}
// TODO; figure out why we can't add UmbControllerHostInterface as host type
export interface UmbRepositoryFactory {
new (host: any): UmbTreeRepository;
export interface UmbRepositoryFactory<T> {
new (host: UmbControllerHostInterface): T;
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbCopyDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbCopyDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('copy');
async execute() {
await this.repository.copy();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbCreateDocumentBlueprintEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbCreateDocumentBlueprintEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('Blueprint');
async execute() {
await this.repository.createBlueprint();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbCreateDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbCreateDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('create');
alert('open create dialog');
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbDocumentCultureAndHostnamesEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbDocumentCultureAndHostnamesEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('culture and hostnames');
async execute() {
await this.repository.setCultureAndHostnames();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbMoveDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbMoveDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('move');
async execute() {
await this.repository.move();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbDocumentPermissionsEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbDocumentPermissionsEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('Permissions');
async execute() {
await this.repository.setPermissions();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbDocumentPublicAccessEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbDocumentPublicAccessEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('public access');
async execute() {
await this.repository.setPublicAccess();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbPublishDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbPublishDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('publish');
async execute() {
await this.repository.publish();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbRollbackDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbRollbackDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('Rollback');
async execute() {
await this.repository.rollback();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbSaveAndPreviewDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbSaveAndPreviewDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('save and preview');
async execute() {
await this.repository.saveAndPreview();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbSaveAndPublishDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbSaveAndPublishDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('save and publish');
async execute() {
await this.repository.saveAndPublish();
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbSaveAndScheduleDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbSaveAndScheduleDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('save and schedule');
async execute() {
await this.repository.saveAndSchedule();
}
}

View File

@@ -2,20 +2,16 @@ 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 {
#host: UmbControllerHostInterface;
#key: string;
#documentRepository: UmbDocumentRepository;
export class UmbSaveDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
#workspaceContext?: UmbDocumentWorkspaceContext;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
this.#documentRepository = new UmbDocumentRepository(this.#host); // TODO: make repository injectable
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
// TODO: add context token for workspace
new UmbContextConsumerController(this.#host, 'umbWorkspaceContext', (instance: UmbDocumentWorkspaceContext) => {
new UmbContextConsumerController(this.host, 'umbWorkspaceContext', (instance: UmbDocumentWorkspaceContext) => {
this.#workspaceContext = instance;
});
}
@@ -29,6 +25,6 @@ export class UmbSaveDocumentEntityAction {
const document = this.#workspaceContext.getData();
// TODO: handle errors
if (!document) return;
this.#documentRepository.saveDetail(document);
this.repository.saveDetail(document);
}
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbSortChildrenOfDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbSortChildrenOfDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('Sort');
async execute() {
await this.repository.sortChildrenOf();
}
}

View File

@@ -1,26 +1,22 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbContextConsumerController } from '@umbraco-cms/context-api';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
import { UmbModalService, UMB_MODAL_SERVICE_CONTEXT_TOKEN } from '@umbraco-cms/modal';
export class UmbTrashDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
export class UmbTrashDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
#modalService?: UmbModalService;
#documentRepository: UmbDocumentRepository;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
this.#documentRepository = new UmbDocumentRepository(this.#host); // TODO: make repository injectable
super(host, UmbDocumentRepository, key);
new UmbContextConsumerController(this.#host, UMB_MODAL_SERVICE_CONTEXT_TOKEN, (instance) => {
new UmbContextConsumerController(this.host, UMB_MODAL_SERVICE_CONTEXT_TOKEN, (instance) => {
this.#modalService = instance;
});
}
async execute() {
const { data } = await this.#documentRepository.requestTreeItems([this.#key]);
const { data } = await this.repository.requestTreeItems([this.unique]);
if (data) {
const item = data[0];
@@ -34,7 +30,7 @@ export class UmbTrashDocumentEntityAction {
modalHandler?.onClose().then(({ confirmed }) => {
if (confirmed) {
this.#documentRepository.delete(this.#key);
this.repository.delete(this.unique);
}
});
}

View File

@@ -1,15 +1,13 @@
import { UmbDocumentRepository } from '../repository/document.repository';
import { UmbEntityActionBase } from '../../../shared/components/entity-action';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbUnpublishDocumentEntityAction {
#host: UmbControllerHostInterface;
#key: string;
constructor(host: UmbControllerHostInterface, key: string) {
this.#host = host;
this.#key = key;
export class UmbUnpublishDocumentEntityAction extends UmbEntityActionBase<UmbDocumentRepository> {
constructor(host: UmbControllerHostInterface, unique: string) {
super(host, UmbDocumentRepository, unique);
}
execute() {
alert('unpublish');
async execute() {
await this.repository.unpublish();
}
}

View File

@@ -215,4 +215,59 @@ export class UmbDocumentRepository implements UmbTreeRepository, UmbDetailReposi
return { error };
}
// Listing all currently known methods we need to implement:
// these currently only covers posting data
// TODO: find a good way to split these
async saveAndPublish() {
alert('save and publish');
}
async saveAndPreview() {
alert('save and preview');
}
async saveAndSchedule() {
alert('save and schedule');
}
async createBlueprint() {
alert('create document blueprint');
}
async move() {
alert('move');
}
async copy() {
alert('copy');
}
async sortChildrenOf() {
alert('sort');
}
async setCultureAndHostnames() {
alert('set culture and hostnames');
}
async setPermissions() {
alert('set permissions');
}
async setPublicAccess() {
alert('set public access');
}
async publish() {
alert('publish');
}
async unpublish() {
alert('unpublish');
}
async rollback() {
alert('rollback');
}
}

View File

@@ -0,0 +1,20 @@
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
import type { UmbRepositoryFactory } from '@umbraco-cms/models';
export interface UmbEntityAction<T> {
unique: string;
repository: T;
execute(): Promise<void>;
}
export class UmbEntityActionBase<T> {
host: UmbControllerHostInterface;
unique: string;
repository: T;
constructor(host: UmbControllerHostInterface, repository: UmbRepositoryFactory<T>, unique: string) {
this.host = host;
this.unique = unique;
this.repository = new repository(this.host);
}
}