update entity actions
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { UmbDocumentPublishingRepository } from '../../repository/index.js';
|
||||
import { UmbPublishDocumentEntityAction } from '../../entity-actions/publish.action.js';
|
||||
import type { UmbDocumentVariantOptionModel } from '../../types.js';
|
||||
import { umbPickDocumentVariantModal } from '../../modals/index.js';
|
||||
import { UMB_DOCUMENT_PUBLISH_MODAL } from '../../modals/index.js';
|
||||
import { UMB_DOCUMENT_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UmbEntityBulkActionBase } from '@umbraco-cms/backoffice/entity-bulk-action';
|
||||
import { UmbLanguageCollectionRepository } from '@umbraco-cms/backoffice/language';
|
||||
import { UMB_APP_LANGUAGE_CONTEXT, UmbLanguageCollectionRepository } from '@umbraco-cms/backoffice/language';
|
||||
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
|
||||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
|
||||
|
||||
export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<object> {
|
||||
async execute() {
|
||||
@@ -30,12 +31,39 @@ export class UmbDocumentPublishEntityBulkAction extends UmbEntityBulkActionBase<
|
||||
segment: null,
|
||||
}));
|
||||
|
||||
const selectedVariants = await umbPickDocumentVariantModal(this, { type: 'publish', options });
|
||||
// Figure out the default selections
|
||||
// TODO: Missing features to pre-select the variant that fits with the variant-id of the tree/collection? (Again only relevant if the action is executed from a Tree or Collection) [NL]
|
||||
const selection: Array<string> = [];
|
||||
const context = await this.getContext(UMB_APP_LANGUAGE_CONTEXT);
|
||||
const appCulture = context.getAppCulture();
|
||||
// If the app language is one of the options, select it by default:
|
||||
if (appCulture && options.some((o) => o.unique === appCulture)) {
|
||||
selection.push(new UmbVariantId(appCulture, null).toString());
|
||||
}
|
||||
|
||||
const modalManagerContext = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
|
||||
const result = await modalManagerContext
|
||||
.open(this, UMB_DOCUMENT_PUBLISH_MODAL, {
|
||||
data: {
|
||||
options,
|
||||
},
|
||||
value: { selection },
|
||||
})
|
||||
.onSubmit()
|
||||
.catch(() => undefined);
|
||||
|
||||
if (!result?.selection.length) return;
|
||||
|
||||
const variantIds = result?.selection.map((x) => UmbVariantId.FromString(x)) ?? [];
|
||||
|
||||
const repository = new UmbDocumentPublishingRepository(this._host);
|
||||
|
||||
if (selectedVariants.length) {
|
||||
if (variantIds.length) {
|
||||
for (const unique of this.selection) {
|
||||
await repository.publish(unique, selectedVariants);
|
||||
await repository.publish(
|
||||
unique,
|
||||
variantIds.map((variantId) => ({ variantId })),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { UmbUnpublishDocumentEntityAction } from '../../entity-actions/unpublish.action.js';
|
||||
import { UMB_DOCUMENT_ENTITY_TYPE } from '../../entity.js';
|
||||
import { umbPickDocumentVariantModal } from '../../modals/index.js';
|
||||
import { UmbDocumentPublishingRepository } from '../../repository/index.js';
|
||||
import type { UmbDocumentVariantOptionModel } from '../../types.js';
|
||||
import { UmbEntityBulkActionBase } from '@umbraco-cms/backoffice/entity-bulk-action';
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
export * from './document-variant-language-picker.element.js';
|
||||
export * from './pick-document-variant-modal.controller.js';
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import type { UmbDocumentVariantOptionModel } from '../../types.js';
|
||||
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
|
||||
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
|
||||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
|
||||
export interface UmbPickDocumentVariantModalArgs {
|
||||
type: UmbDocumentVariantPickerModalType;
|
||||
options: Array<UmbDocumentVariantOptionModel>;
|
||||
selected?: Array<UmbVariantId>;
|
||||
}
|
||||
|
||||
export class UmbPickDocumentVariantModalController extends UmbControllerBase {
|
||||
async open(args: UmbPickDocumentVariantModalArgs): Promise<UmbVariantId[]> {
|
||||
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
|
||||
const selected = args.selected ?? [];
|
||||
|
||||
const modalData: UmbDocumentVariantPickerModalData = {
|
||||
type: args.type,
|
||||
options: args.options,
|
||||
};
|
||||
|
||||
if (modalData.options.length === 0) {
|
||||
// TODO: What do to when there is no options? [NL]
|
||||
}
|
||||
|
||||
const modal = modalManager.open(this, UMB_DOCUMENT_LANGUAGE_PICKER_MODAL, {
|
||||
data: modalData,
|
||||
// We need to turn the selected variant ids into strings for them to be serializable to the value state, in other words the value of a modal cannot hold class instances:
|
||||
// Make selection unique by filtering out duplicates:
|
||||
value: { selection: selected.map((x) => x.toString()).filter((v, i, a) => a.indexOf(v) === i) ?? [] },
|
||||
});
|
||||
|
||||
const p = modal.onSubmit();
|
||||
p.catch(() => this.destroy());
|
||||
const result = await p;
|
||||
|
||||
// This is a one time off, so we can destroy our selfs.
|
||||
this.destroy();
|
||||
|
||||
// Map back into UmbVariantId instances:
|
||||
return result?.selection.map((x) => UmbVariantId.FromString(x)) ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
export function umbPickDocumentVariantModal(host: UmbControllerHost, args: UmbPickDocumentVariantModalArgs) {
|
||||
return new UmbPickDocumentVariantModalController(host).open(args);
|
||||
}
|
||||
Reference in New Issue
Block a user