set default filter trough constructor
This commit is contained in:
@@ -51,6 +51,7 @@ export class UmbDefaultCollectionContext<
|
||||
public readonly view = new UmbCollectionViewManager(this);
|
||||
|
||||
#defaultViewAlias: string;
|
||||
#defaultFilter: Partial<FilterModelType>;
|
||||
|
||||
#initResolver?: () => void;
|
||||
#initialized = false;
|
||||
@@ -59,10 +60,11 @@ export class UmbDefaultCollectionContext<
|
||||
this.#initialized ? resolve() : (this.#initResolver = resolve);
|
||||
});
|
||||
|
||||
constructor(host: UmbControllerHost, defaultViewAlias: string) {
|
||||
constructor(host: UmbControllerHost, defaultViewAlias: string, defaultFilter: Partial<FilterModelType> = {}) {
|
||||
super(host, UMB_DEFAULT_COLLECTION_CONTEXT);
|
||||
|
||||
this.#defaultViewAlias = defaultViewAlias;
|
||||
this.#defaultFilter = defaultFilter;
|
||||
|
||||
this.pagination.addEventListener(UmbChangeEvent.TYPE, this.#onPageChange);
|
||||
}
|
||||
@@ -79,6 +81,7 @@ export class UmbDefaultCollectionContext<
|
||||
}
|
||||
|
||||
this.#filter.setValue({
|
||||
...this.#defaultFilter,
|
||||
...this.#config,
|
||||
...this.#filter.getValue(),
|
||||
skip: 0,
|
||||
|
||||
@@ -7,65 +7,69 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbDirectionModel } from '@umbraco-cms/backoffice/models';
|
||||
import { UmbArrayState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
|
||||
|
||||
const orderByOptions: Array<UmbUserOrderByOption> = [
|
||||
{
|
||||
unique: 'nameAscending',
|
||||
label: '#user_sortNameAscending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.NAME,
|
||||
orderDirection: UmbDirectionModel.ASCENDING,
|
||||
},
|
||||
},
|
||||
{
|
||||
unique: 'nameDescending',
|
||||
label: '#user_sortNameDescending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.NAME,
|
||||
orderDirection: UmbDirectionModel.DESCENDING,
|
||||
},
|
||||
},
|
||||
{
|
||||
unique: 'createDateDescending',
|
||||
label: '#user_sortCreateDateDescending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.CREATE_DATE,
|
||||
orderDirection: UmbDirectionModel.DESCENDING,
|
||||
},
|
||||
},
|
||||
{
|
||||
unique: 'createDateAscending',
|
||||
label: '#user_sortCreateDateAscending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.CREATE_DATE,
|
||||
orderDirection: UmbDirectionModel.ASCENDING,
|
||||
},
|
||||
},
|
||||
{
|
||||
unique: 'lastLoginDateDescending',
|
||||
label: '#user_sortLastLoginDateDescending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.LAST_LOGIN_DATE,
|
||||
orderDirection: UmbDirectionModel.DESCENDING,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export class UmbUserCollectionContext extends UmbDefaultCollectionContext<
|
||||
UmbUserDetailModel,
|
||||
UmbUserCollectionFilterModel
|
||||
> {
|
||||
#orderByOptions = new UmbArrayState<UmbUserOrderByOption>(
|
||||
[
|
||||
{
|
||||
unique: 'nameAscending',
|
||||
label: '#user_sortNameAscending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.NAME,
|
||||
orderDirection: UmbDirectionModel.ASCENDING,
|
||||
},
|
||||
},
|
||||
{
|
||||
unique: 'nameDescending',
|
||||
label: '#user_sortNameDescending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.NAME,
|
||||
orderDirection: UmbDirectionModel.DESCENDING,
|
||||
},
|
||||
},
|
||||
{
|
||||
unique: 'createDateDescending',
|
||||
label: '#user_sortCreateDateDescending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.CREATE_DATE,
|
||||
orderDirection: UmbDirectionModel.DESCENDING,
|
||||
},
|
||||
},
|
||||
{
|
||||
unique: 'createDateAscending',
|
||||
label: '#user_sortCreateDateAscending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.CREATE_DATE,
|
||||
orderDirection: UmbDirectionModel.ASCENDING,
|
||||
},
|
||||
},
|
||||
{
|
||||
unique: 'lastLoginDateDescending',
|
||||
label: '#user_sortLastLoginDateDescending',
|
||||
config: {
|
||||
orderBy: UmbUserOrderByModel.LAST_LOGIN_DATE,
|
||||
orderDirection: UmbDirectionModel.DESCENDING,
|
||||
},
|
||||
},
|
||||
],
|
||||
(x) => x.label,
|
||||
);
|
||||
#orderByOptions = new UmbArrayState<UmbUserOrderByOption>([], (x) => x.label);
|
||||
orderByOptions = this.#orderByOptions.asObservable();
|
||||
|
||||
#activeOrderByOption = new UmbStringState<string | undefined>(undefined);
|
||||
activeOrderByOption = this.#activeOrderByOption.asObservable();
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host, UMB_COLLECTION_VIEW_USER_GRID);
|
||||
// init default orderBy option
|
||||
const defaultOrderByOption = this.#orderByOptions.getValue()[0];
|
||||
this.setActiveOrderByOption(defaultOrderByOption.unique);
|
||||
const firstOption: UmbUserOrderByOption = orderByOptions[0];
|
||||
|
||||
super(host, UMB_COLLECTION_VIEW_USER_GRID, {
|
||||
orderBy: firstOption.config.orderBy,
|
||||
orderDirection: firstOption.config.orderDirection,
|
||||
});
|
||||
|
||||
this.#orderByOptions.setValue(orderByOptions);
|
||||
this.#activeOrderByOption.setValue(firstOption.unique);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,8 +84,6 @@ export class UmbUserCollectionContext extends UmbDefaultCollectionContext<
|
||||
this.setFilter({ orderBy: option?.config.orderBy, orderDirection: option?.config.orderDirection });
|
||||
}
|
||||
|
||||
getActiveOrderByOption() {}
|
||||
|
||||
/**
|
||||
* Sets the state filter for the collection and refreshes the collection.
|
||||
* @param {Array<UmbUserStateFilterModel>} selection
|
||||
|
||||
Reference in New Issue
Block a user