76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
|
|
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
|
||
|
|
import {
|
||
|
|
UmbDocumentItemRepository,
|
||
|
|
UmbDocumentSearchRepository,
|
||
|
|
UmbDocumentTreeRepository,
|
||
|
|
type UmbDocumentSearchRequestArgs,
|
||
|
|
} from '@umbraco-cms/backoffice/document';
|
||
|
|
import { UMB_DOCUMENT_TYPE_ENTITY_TYPE } from '@umbraco-cms/backoffice/document-type';
|
||
|
|
import type {
|
||
|
|
UmbPickerSearchableDataSource,
|
||
|
|
UmbPickerTreeDataSource,
|
||
|
|
} from '@umbraco-cms/backoffice/picker-data-source';
|
||
|
|
import type { UmbSearchRequestArgs } from '@umbraco-cms/backoffice/search';
|
||
|
|
import type {
|
||
|
|
UmbTreeAncestorsOfRequestArgs,
|
||
|
|
UmbTreeChildrenOfRequestArgs,
|
||
|
|
UmbTreeRootItemsRequestArgs,
|
||
|
|
} from '@umbraco-cms/backoffice/tree';
|
||
|
|
import { getConfigValue, type UmbConfigCollectionModel } from '@umbraco-cms/backoffice/utils';
|
||
|
|
|
||
|
|
export class ExampleDocumentPickerPropertyEditorDataSource
|
||
|
|
extends UmbControllerBase
|
||
|
|
implements UmbPickerTreeDataSource, UmbPickerSearchableDataSource
|
||
|
|
{
|
||
|
|
#tree = new UmbDocumentTreeRepository(this);
|
||
|
|
#item = new UmbDocumentItemRepository(this);
|
||
|
|
#search = new UmbDocumentSearchRepository(this);
|
||
|
|
#config: UmbConfigCollectionModel = [];
|
||
|
|
|
||
|
|
setConfig(config: UmbConfigCollectionModel) {
|
||
|
|
// TODO: add examples for all config options
|
||
|
|
this.#config = config;
|
||
|
|
}
|
||
|
|
|
||
|
|
getConfig(): UmbConfigCollectionModel {
|
||
|
|
return this.#config;
|
||
|
|
}
|
||
|
|
|
||
|
|
requestTreeRoot() {
|
||
|
|
return this.#tree.requestTreeRoot();
|
||
|
|
}
|
||
|
|
|
||
|
|
requestTreeRootItems(args: UmbTreeRootItemsRequestArgs) {
|
||
|
|
return this.#tree.requestTreeRootItems(args);
|
||
|
|
}
|
||
|
|
|
||
|
|
requestTreeItemsOf(args: UmbTreeChildrenOfRequestArgs) {
|
||
|
|
return this.#tree.requestTreeItemsOf(args);
|
||
|
|
}
|
||
|
|
|
||
|
|
requestTreeItemAncestors(args: UmbTreeAncestorsOfRequestArgs) {
|
||
|
|
return this.#tree.requestTreeItemAncestors(args);
|
||
|
|
}
|
||
|
|
|
||
|
|
requestItems(uniques: Array<string>) {
|
||
|
|
return this.#item.requestItems(uniques);
|
||
|
|
}
|
||
|
|
|
||
|
|
search(args: UmbSearchRequestArgs) {
|
||
|
|
const filterString = getConfigValue<string>(this.#config, 'filter');
|
||
|
|
const filterArray = filterString ? filterString.split(',') : [];
|
||
|
|
const allowedContentTypes: UmbDocumentSearchRequestArgs['allowedContentTypes'] = filterArray.map(
|
||
|
|
(unique: string) => ({
|
||
|
|
entityType: UMB_DOCUMENT_TYPE_ENTITY_TYPE,
|
||
|
|
unique,
|
||
|
|
}),
|
||
|
|
);
|
||
|
|
|
||
|
|
const combinedArgs: UmbDocumentSearchRequestArgs = { ...args, allowedContentTypes };
|
||
|
|
|
||
|
|
return this.#search.search(combinedArgs);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export { ExampleDocumentPickerPropertyEditorDataSource as api };
|