reuse tree repository base
This commit is contained in:
@@ -1,29 +1,14 @@
|
||||
import { UmbStylesheetTreeServerDataSource } from './stylesheet-tree.server.data-source.js';
|
||||
import { UMB_STYLESHEET_TREE_STORE_CONTEXT_TOKEN, UmbStylesheetTreeStore } from './stylesheet-tree.store.js';
|
||||
import { FileSystemTreeItemPresentationModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
import { UmbFileSystemTreeRootModel, UmbTreeRepository } from '@umbraco-cms/backoffice/tree';
|
||||
import { UMB_STYLESHEET_TREE_STORE_CONTEXT_TOKEN } from './stylesheet-tree.store.js';
|
||||
import { UmbEntityTreeRepositoryBase } from '@umbraco-cms/backoffice/tree';
|
||||
import { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
|
||||
export class UmbStylesheetTreeRepository
|
||||
extends UmbRepositoryBase
|
||||
implements UmbTreeRepository<FileSystemTreeItemPresentationModel, UmbFileSystemTreeRootModel>
|
||||
{
|
||||
#init;
|
||||
#treeDataSource;
|
||||
#treeStore?: UmbStylesheetTreeStore;
|
||||
|
||||
export class UmbStylesheetTreeRepository extends UmbEntityTreeRepositoryBase<any, any> {
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
this.#treeDataSource = new UmbStylesheetTreeServerDataSource(this);
|
||||
|
||||
this.#init = this.consumeContext(UMB_STYLESHEET_TREE_STORE_CONTEXT_TOKEN, (instance) => {
|
||||
this.#treeStore = instance;
|
||||
}).asPromise();
|
||||
super(host, UmbStylesheetTreeServerDataSource, UMB_STYLESHEET_TREE_STORE_CONTEXT_TOKEN);
|
||||
}
|
||||
async requestTreeRoot() {
|
||||
await this.#init;
|
||||
|
||||
async requestTreeRoot() {
|
||||
const data = {
|
||||
path: null,
|
||||
type: 'stylesheet-root',
|
||||
@@ -34,40 +19,4 @@ export class UmbStylesheetTreeRepository
|
||||
|
||||
return { data };
|
||||
}
|
||||
|
||||
async requestRootTreeItems() {
|
||||
await this.#init;
|
||||
|
||||
const { data, error } = await this.#treeDataSource.getRootItems();
|
||||
|
||||
if (data) {
|
||||
this.#treeStore?.appendItems(data.items);
|
||||
}
|
||||
|
||||
return { data, error, asObservable: () => this.#treeStore!.rootItems };
|
||||
}
|
||||
|
||||
async requestTreeItemsOf(path: string | null) {
|
||||
if (path === undefined) throw new Error('Cannot request tree item with missing path');
|
||||
await this.#init;
|
||||
|
||||
const { data, error } = await this.#treeDataSource.getChildrenOf(path);
|
||||
|
||||
if (data) {
|
||||
this.#treeStore!.appendItems(data.items);
|
||||
}
|
||||
|
||||
return { data, error, asObservable: () => this.#treeStore!.childrenOf(path) };
|
||||
}
|
||||
|
||||
async rootTreeItems() {
|
||||
await this.#init;
|
||||
return this.#treeStore!.rootItems;
|
||||
}
|
||||
|
||||
async treeItemsOf(parentPath: string | null) {
|
||||
if (!parentPath) throw new Error('Parent Path is missing');
|
||||
await this.#init;
|
||||
return this.#treeStore!.childrenOf(parentPath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user