diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/repository/sources/stylesheet.server.data.ts b/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/repository/sources/stylesheet.server.data.ts index 4419399142..bc82863011 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/repository/sources/stylesheet.server.data.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/repository/sources/stylesheet.server.data.ts @@ -32,7 +32,7 @@ export class UmbStylesheetServerDataSource implements UmbDataSource> { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/repository/stylesheet.repository.ts b/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/repository/stylesheet.repository.ts index f21b6e2067..9d64f38445 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/repository/stylesheet.repository.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/repository/stylesheet.repository.ts @@ -1,5 +1,6 @@ import { UmbStylesheetTreeStore, UMB_STYLESHEET_TREE_STORE_CONTEXT_TOKEN } from './stylesheet.tree.store'; import { UmbStylesheetTreeServerDataSource } from './sources/stylesheet.tree.server.data'; +import { UmbStylesheetServerDataSource } from './sources/stylesheet.server.data'; import { UmbControllerHostInterface } from '@umbraco-cms/backoffice/controller'; import { UmbNotificationContext, UMB_NOTIFICATION_CONTEXT_TOKEN } from '@umbraco-cms/backoffice/notification'; import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api'; @@ -12,8 +13,9 @@ import { export class UmbStylesheetRepository implements UmbTreeRepository { - #host: UmbControllerHostInterface; - #treeDataSource: UmbStylesheetTreeServerDataSource; + #host; + #dataSource; + #treeDataSource; #treeStore?: UmbStylesheetTreeStore; #notificationContext?: UmbNotificationContext; #initResolver?: () => void; @@ -21,7 +23,9 @@ export class UmbStylesheetRepository constructor(host: UmbControllerHostInterface) { this.#host = host; + // TODO: figure out how spin up get the correct data source + this.#dataSource = new UmbStylesheetServerDataSource(this.#host); this.#treeDataSource = new UmbStylesheetTreeServerDataSource(this.#host); new UmbContextConsumerController(this.#host, UMB_STYLESHEET_TREE_STORE_CONTEXT_TOKEN, (instance) => { @@ -95,4 +99,12 @@ export class UmbStylesheetRepository await this.#init; return this.#treeStore!.items(paths); } + + // DETAILS + async requestByPath(path: string) { + if (!path) throw new Error('Path is missing'); + await this.#init; + const { data, error } = await this.#dataSource.get(path); + return { data, error }; + } } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/workspace/stylesheet-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/workspace/stylesheet-workspace.context.ts index 324422e1eb..e3be06cf52 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/workspace/stylesheet-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/templating/stylesheets/workspace/stylesheet-workspace.context.ts @@ -1,39 +1,42 @@ import { UmbWorkspaceContext } from '../../../shared/components/workspace/workspace-context/workspace-context'; import { UmbStylesheetRepository } from '../repository/stylesheet.repository'; +import { StylesheetDetails } from '..'; import { UmbControllerHostInterface } from '@umbraco-cms/backoffice/controller'; import { UmbWorkspaceContextInterface } from '@umbraco-cms/backoffice/workspace'; +import { ObjectState } from '@umbraco-cms/backoffice/observable-api'; export class UmbStylesheetWorkspaceContext extends UmbWorkspaceContext implements UmbWorkspaceContextInterface { + #data = new ObjectState(undefined); + data = this.#data.asObservable(); + constructor(host: UmbControllerHostInterface) { super(host, new UmbStylesheetRepository(host)); } - /* getEntityType(): string { return 'stylesheet'; } - getEntityKey() { - return '1234'; - } - getData() { - return 'fake' as unknown as MemberDetails; + return this.#data.getValue(); } - async save() { - console.log('save'); + getEntityKey() { + return this.getData()?.path || ''; } async load(path: string) { - console.log('load', path); + const { data } = await this.repository.requestByPath(path); + if (data) { + this.setIsNew(false); + this.#data.update(data); + } } public destroy(): void { - console.log('destroy'); + this.#data.complete(); } - */ }