use abstract class for stylesheet
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { manifests as repositoryManifests } from './repository/manifests.js';
|
||||
import { manifests as navigationManifests } from './navigation/manifests.js';
|
||||
import { manifests as menuManifests } from './menu/manifests.js';
|
||||
import { manifests as treeManifests } from './tree/manifests.js';
|
||||
import { manifests as workspaceManifests } from './workspace/manifests.js';
|
||||
import { manifests as entityActionManifests } from './entity-actions/manifests.js';
|
||||
@@ -7,7 +7,7 @@ import { manifests as componentManifests } from './components/manifests.js';
|
||||
|
||||
export const manifests = [
|
||||
...repositoryManifests,
|
||||
...navigationManifests,
|
||||
...menuManifests,
|
||||
...treeManifests,
|
||||
...workspaceManifests,
|
||||
...entityActionManifests,
|
||||
|
||||
@@ -15,9 +15,9 @@ export const manifests = [
|
||||
},
|
||||
{
|
||||
type: 'workspaceContext',
|
||||
name: 'Stylesheet Navigation Structure Workspace Context',
|
||||
alias: 'Umb.Context.Stylesheet.NavigationStructure',
|
||||
api: () => import('./stylesheet-navigation-structure.context.js'),
|
||||
name: 'Stylesheet Menu Structure Workspace Context',
|
||||
alias: 'Umb.Context.Stylesheet.Menu.Structure',
|
||||
api: () => import('./stylesheet-menu-structure.context.js'),
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.WorkspaceAlias',
|
||||
@@ -0,0 +1,11 @@
|
||||
import { UMB_STYLESHEET_TREE_REPOSITORY_ALIAS } from '../tree/index.js';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbMenuTreeStructureWorkspaceContextBase } from '@umbraco-cms/backoffice/menu';
|
||||
|
||||
export class UmbStylesheetMenuStructureWorkspaceContext extends UmbMenuTreeStructureWorkspaceContextBase {
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host, { treeRepositoryAlias: UMB_STYLESHEET_TREE_REPOSITORY_ALIAS });
|
||||
}
|
||||
}
|
||||
|
||||
export default UmbStylesheetMenuStructureWorkspaceContext;
|
||||
@@ -1,5 +0,0 @@
|
||||
import type { UmbStylesheetNavigationStructureWorkspaceContext } from './stylesheet-navigation-structure.context.js';
|
||||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
|
||||
export const UMB_STYLESHEET_NAVIGATION_STRUCTURE_WORKSPACE_CONTEXT =
|
||||
new UmbContextToken<UmbStylesheetNavigationStructureWorkspaceContext>('UmbNavigationStructureWorkspaceContext');
|
||||
@@ -1,54 +0,0 @@
|
||||
import { UmbStylesheetTreeRepository } from '../tree/index.js';
|
||||
import { UMB_STYLESHEET_NAVIGATION_STRUCTURE_WORKSPACE_CONTEXT } from './stylesheet-navigation-structure.context-token.js';
|
||||
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
|
||||
|
||||
import { UMB_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/workspace';
|
||||
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
|
||||
interface UmbStructureItemModel {
|
||||
unique: string | null;
|
||||
entityType: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export class UmbStylesheetNavigationStructureWorkspaceContext extends UmbContextBase<UmbStylesheetNavigationStructureWorkspaceContext> {
|
||||
#workspaceContext?: any;
|
||||
#treeRepository = new UmbStylesheetTreeRepository(this);
|
||||
|
||||
#structure = new UmbArrayState<UmbStructureItemModel>([], (x) => x.unique);
|
||||
public readonly structure = this.#structure.asObservable();
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host, UMB_STYLESHEET_NAVIGATION_STRUCTURE_WORKSPACE_CONTEXT);
|
||||
|
||||
this.consumeContext(UMB_WORKSPACE_CONTEXT, (instance) => {
|
||||
this.#workspaceContext = instance;
|
||||
this.#requestStructure();
|
||||
});
|
||||
}
|
||||
|
||||
async #requestStructure() {
|
||||
const isNew = this.#workspaceContext?.getIsNew();
|
||||
const uniqueObservable = isNew ? this.#workspaceContext?.parentUnique : this.#workspaceContext?.unique;
|
||||
|
||||
const unique = (await this.observe(uniqueObservable, () => {})?.asPromise()) as string;
|
||||
if (!unique) throw new Error('Unique is not available');
|
||||
|
||||
const { data } = await this.#treeRepository.requestTreeItemAncestors({ descendantUnique: unique });
|
||||
|
||||
if (data) {
|
||||
const structureItems = data.map((ancestor) => {
|
||||
return {
|
||||
unique: ancestor.unique,
|
||||
entityType: ancestor.entityType,
|
||||
name: ancestor.name,
|
||||
};
|
||||
});
|
||||
|
||||
this.#structure.setValue(structureItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default UmbStylesheetNavigationStructureWorkspaceContext;
|
||||
Reference in New Issue
Block a user