enable and disable bulk actions

This commit is contained in:
Jesper Møller Jensen
2023-05-17 17:31:00 +12:00
parent 2fa7ff7cc9
commit 534a490328
5 changed files with 27 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
import { html } from 'lit';
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import type { UmbUserGroupRepository } from '../../repository/user-group.repository';
import { UmbEntityBulkActionBase } from '@umbraco-cms/backoffice/entity-action';
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api';
import { UmbModalContext, UMB_MODAL_CONTEXT_TOKEN, UMB_CONFIRM_MODAL } from '@umbraco-cms/backoffice/modal';

View File

@@ -2,6 +2,7 @@ import { UUITextStyles } from '@umbraco-ui/uui-css';
import { css, html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { UUIBooleanInputEvent, UUICheckboxElement, UUIRadioGroupElement, UUIRadioGroupEvent } from '@umbraco-ui/uui';
import { UmbLitElement } from '@umbraco-cms/internal/lit-element';
import { UmbDropdownElement } from '../../../core/components/dropdown/dropdown.element';
import { UmbUserCollectionContext } from './user-collection.context';
import { UMB_COLLECTION_CONTEXT_TOKEN } from '@umbraco-cms/backoffice/collection';
@@ -11,13 +12,12 @@ import {
UMB_MODAL_CONTEXT_TOKEN,
UmbModalContext,
} from '@umbraco-cms/backoffice/modal';
import { UmbLitElement } from '@umbraco-cms/internal/lit-element';
import { UserOrderModel, UserStateModel } from '@umbraco-cms/backoffice/backend-api';
@customElement('umb-user-collection-header')
export class UmbUserCollectionHeaderElement extends UmbLitElement {
@state()
private _isCloud = true; //NOTE: Used to show either invite or create user buttons and views.
private _isCloud = false; //NOTE: Used to show either invite or create user buttons and views.
@state()
private _stateFilterOptions: Array<UserStateModel> = Object.values(UserStateModel);

View File

@@ -1,8 +1,9 @@
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { html } from 'lit';
import { UmbUserRepository } from '../../repository/user.repository';
import { UmbEntityBulkActionBase } from '@umbraco-cms/backoffice/entity-action';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api';
import { UmbModalContext, UMB_MODAL_CONTEXT_TOKEN } from '@umbraco-cms/backoffice/modal';
import { UmbModalContext, UMB_MODAL_CONTEXT_TOKEN, UMB_CONFIRM_MODAL } from '@umbraco-cms/backoffice/modal';
export class UmbUserDeleteEntityBulkAction extends UmbEntityBulkActionBase<UmbUserRepository> {
#modalContext?: UmbModalContext;
@@ -16,7 +17,22 @@ export class UmbUserDeleteEntityBulkAction extends UmbEntityBulkActionBase<UmbUs
}
async execute() {
//TODO: we need bulk actions on the server
alert('Bulk delete is not implemented yet');
if (!this.#modalContext || this.selection.length === 0) return;
const modalHandler = this.#modalContext.open(UMB_CONFIRM_MODAL, {
color: 'danger',
headline: `Delete users?`,
content: html`Are you sure you want to delete selected users?`,
confirmLabel: 'Delete',
});
await modalHandler.onSubmit();
//TODO: How should we handle bulk actions? right now we send a request per item we want to change.
//TODO: For now we have to reload the page to see the update
for (let index = 0; index < this.selection.length; index++) {
const element = this.selection[index];
await this.repository?.delete(element);
}
}
}

View File

@@ -1,6 +1,6 @@
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbUserRepository } from '../../repository/user.repository';
import { UmbEntityBulkActionBase } from '@umbraco-cms/backoffice/entity-action';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
export class UmbDisableUserEntityBulkAction extends UmbEntityBulkActionBase<UmbUserRepository> {
constructor(host: UmbControllerHostElement, repositoryAlias: string, selection: Array<string>) {
@@ -8,7 +8,6 @@ export class UmbDisableUserEntityBulkAction extends UmbEntityBulkActionBase<UmbU
}
async execute() {
//TODO: Implement
alert('Bulk disable is not implemented yet');
await this.repository?.disable(this.selection);
}
}

View File

@@ -1,6 +1,6 @@
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbUserRepository } from '../../repository/user.repository';
import { UmbEntityBulkActionBase } from '@umbraco-cms/backoffice/entity-action';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
export class UmbEnableUserEntityBulkAction extends UmbEntityBulkActionBase<UmbUserRepository> {
constructor(host: UmbControllerHostElement, repositoryAlias: string, selection: Array<string>) {
@@ -8,7 +8,6 @@ export class UmbEnableUserEntityBulkAction extends UmbEntityBulkActionBase<UmbUs
}
async execute() {
//TODO: Implement
alert('Bulk enable is not implemented yet');
await this.repository?.enable(this.selection);
}
}