@@ -7,6 +7,8 @@ import type {
7
7
UmbDocumentBlueprintVariantModel ,
8
8
UmbDocumentBlueprintVariantOptionModel ,
9
9
} from '../types.js' ;
10
+ import { sortVariants } from '../utils.js' ;
11
+ import { UMB_CREATE_DOCUMENT_BLUEPRINT_WORKSPACE_PATH_PATTERN } from '../paths.js' ;
10
12
import { UMB_DOCUMENT_BLUEPRINT_WORKSPACE_ALIAS } from './manifests.js' ;
11
13
import {
12
14
appendToFrozenArray ,
@@ -17,6 +19,7 @@ import {
17
19
import {
18
20
UmbSubmittableWorkspaceContextBase ,
19
21
UmbWorkspaceIsNewRedirectController ,
22
+ UmbWorkspaceIsNewRedirectControllerAlias ,
20
23
UmbWorkspaceSplitViewManager ,
21
24
} from '@umbraco-cms/backoffice/workspace' ;
22
25
import { UmbContentTypeStructureManager } from '@umbraco-cms/backoffice/content-type' ;
@@ -35,8 +38,15 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
35
38
import type { UmbLanguageDetailModel } from '@umbraco-cms/backoffice/language' ;
36
39
import { UmbContentWorkspaceDataManager , type UmbContentWorkspaceContext } from '@umbraco-cms/backoffice/content' ;
37
40
import { UmbReadOnlyVariantStateManager } from '@umbraco-cms/backoffice/utils' ;
38
- import { UMB_DOCUMENT_DETAIL_MODEL_VARIANT_SCAFFOLD } from '@umbraco-cms/backoffice/document' ;
41
+ import {
42
+ UMB_DOCUMENT_COLLECTION_ALIAS ,
43
+ UMB_DOCUMENT_DETAIL_MODEL_VARIANT_SCAFFOLD ,
44
+ UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN ,
45
+ } from '@umbraco-cms/backoffice/document' ;
39
46
import { UmbDataTypeItemRepositoryManager } from '@umbraco-cms/backoffice/data-type' ;
47
+ import { Observable , map } from '@umbraco-cms/backoffice/external/rxjs' ;
48
+ import { UmbEntityContext , type UmbEntityModel } from '@umbraco-cms/backoffice/entity' ;
49
+ import { UMB_SETTINGS_SECTION_PATH } from '@umbraco-cms/backoffice/settings' ;
40
50
41
51
type EntityModel = UmbDocumentBlueprintDetailModel ;
42
52
@@ -119,27 +129,46 @@ export class UmbDocumentBlueprintWorkspaceContext
119
129
}
120
130
return [ ] ;
121
131
} ,
122
- ) ;
132
+ ) . pipe ( map ( ( results ) => results . sort ( sortVariants ) ) ) ;
133
+
134
+ // TODO: this should be set up for all entity workspace contexts in a base class
135
+ #entityContext = new UmbEntityContext ( this ) ;
123
136
124
137
constructor ( host : UmbControllerHost ) {
125
138
super ( host , UMB_DOCUMENT_BLUEPRINT_WORKSPACE_ALIAS ) ;
126
139
127
- this . observe ( this . contentTypeUnique , ( unique ) => this . structure . loadType ( unique ) ) ;
128
-
129
- this . observe ( this . variesByCulture , ( varies ) => {
130
- this . #data. setVariesByCulture ( varies ) ;
131
- this . #variesByCulture = varies ;
132
- } ) ;
133
- this . observe ( this . variesBySegment , ( varies ) => {
134
- this . #data. setVariesBySegment ( varies ) ;
135
- this . #variesBySegment = varies ;
136
- } ) ;
137
- this . observe ( this . varies , ( varies ) => ( this . #varies = varies ) ) ;
138
-
139
- this . observe ( this . structure . contentTypeDataTypeUniques , ( dataTypeUniques : Array < string > ) => {
140
- this . #dataTypeItemManager. setUniques ( dataTypeUniques ) ;
141
- } ) ;
142
-
140
+ this . observe ( this . contentTypeUnique , ( unique ) => this . structure . loadType ( unique ) , null ) ;
141
+ this . observe (
142
+ this . varies ,
143
+ ( varies ) => {
144
+ this . #data. setVaries ( varies ) ;
145
+ this . #varies = varies ;
146
+ } ,
147
+ null ,
148
+ ) ;
149
+ this . observe (
150
+ this . variesByCulture ,
151
+ ( varies ) => {
152
+ this . #data. setVariesByCulture ( varies ) ;
153
+ this . #variesByCulture = varies ;
154
+ } ,
155
+ null ,
156
+ ) ;
157
+ this . observe (
158
+ this . variesBySegment ,
159
+ ( varies ) => {
160
+ this . #data. setVariesBySegment ( varies ) ;
161
+ this . #variesBySegment = varies ;
162
+ } ,
163
+ null ,
164
+ ) ;
165
+ this . observe (
166
+ this . structure . contentTypeDataTypeUniques ,
167
+ ( dataTypeUniques : Array < string > ) => {
168
+ this . #dataTypeItemManager. setUniques ( dataTypeUniques ) ;
169
+ } ,
170
+ null ,
171
+ ) ;
143
172
this . observe ( this . #dataTypeItemManager. items , ( dataTypes ) => {
144
173
// Make a map of the data type unique and editorAlias:
145
174
this . #dataTypeSchemaAliasMap = new Map (
@@ -148,14 +177,15 @@ export class UmbDocumentBlueprintWorkspaceContext
148
177
} ) ,
149
178
) ;
150
179
} ) ;
180
+
151
181
this . loadLanguages ( ) ;
152
182
153
183
this . routes . setRoutes ( [
154
184
{
155
- path : 'create/parent/:entityType/:parentUnique/:documentTypeUnique' ,
185
+ path : UMB_CREATE_DOCUMENT_BLUEPRINT_WORKSPACE_PATH_PATTERN . toString ( ) ,
156
186
component : ( ) => import ( './document-blueprint-workspace-editor.element.js' ) ,
157
187
setup : async ( _component , info ) => {
158
- const parentEntityType = info . match . params . entityType ;
188
+ const parentEntityType = info . match . params . parentEntityType ;
159
189
const parentUnique = info . match . params . parentUnique === 'null' ? null : info . match . params . parentUnique ;
160
190
const documentTypeUnique = info . match . params . documentTypeUnique ;
161
191
this . create ( { entityType : parentEntityType , unique : parentUnique } , documentTypeUnique ) ;
@@ -168,10 +198,10 @@ export class UmbDocumentBlueprintWorkspaceContext
168
198
} ,
169
199
} ,
170
200
{
171
- path : 'edit/:unique' ,
201
+ path : UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN . toString ( ) ,
172
202
component : ( ) => import ( './document-blueprint-workspace-editor.element.js' ) ,
173
203
setup : ( _component , info ) => {
174
- this . removeUmbControllerByAlias ( 'isNewRedirectController' ) ;
204
+ this . removeUmbControllerByAlias ( UmbWorkspaceIsNewRedirectControllerAlias ) ;
175
205
const unique = info . match . params . unique ;
176
206
this . load ( unique ) ;
177
207
} ,
@@ -181,8 +211,7 @@ export class UmbDocumentBlueprintWorkspaceContext
181
211
182
212
override resetState ( ) {
183
213
super . resetState ( ) ;
184
- this . #data. setPersisted ( undefined ) ;
185
- this . #data. setCurrent ( undefined ) ;
214
+ this . #data. clear ( ) ;
186
215
}
187
216
188
217
async loadLanguages ( ) {
@@ -194,42 +223,50 @@ export class UmbDocumentBlueprintWorkspaceContext
194
223
async load ( unique : string ) {
195
224
this . resetState ( ) ;
196
225
this . #getDataPromise = this . repository . requestByUnique ( unique ) ;
197
- const { data, asObservable } = await this . repository . requestByUnique ( unique ) ;
226
+ type GetDataType = Awaited < ReturnType < UmbDocumentBlueprintDetailRepository [ 'requestByUnique' ] > > ;
227
+ const { data, asObservable } = ( await this . #getDataPromise) as GetDataType ;
198
228
199
229
if ( data ) {
230
+ this . #entityContext. setEntityType ( UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE ) ;
231
+ this . #entityContext. setUnique ( unique ) ;
200
232
this . setIsNew ( false ) ;
201
233
this . #data. setPersisted ( data ) ;
202
234
this . #data. setCurrent ( data ) ;
203
235
}
204
236
205
- if ( asObservable ) {
206
- this . observe ( asObservable ( ) , ( entity ) => this . #onStoreChange( entity ) , 'UmbDocumentBlueprintStoreObserver' ) ;
207
- }
237
+ this . observe ( asObservable ( ) , ( entity ) => this . #onStoreChange( entity ) , 'UmbDocumentBlueprintStoreObserver' ) ;
208
238
}
209
239
210
240
#onStoreChange( entity : EntityModel | undefined ) {
211
241
if ( ! entity ) {
212
242
//TODO: This solution is alright for now. But reconsider when we introduce signal-r
213
- history . pushState ( null , '' , 'section/document-blueprint' ) ;
243
+ history . pushState ( null , '' , UMB_SETTINGS_SECTION_PATH ) ;
214
244
}
215
245
}
216
246
217
- async create ( parent : { entityType : string ; unique : string | null } , documentTypeUnique : string ) {
247
+ async create ( parent : UmbEntityModel , documentTypeUnique : string ) {
218
248
this . resetState ( ) ;
219
249
this . #parent. setValue ( parent ) ;
220
250
221
- const { data } = await this . repository . createScaffold ( {
251
+ this . #getDataPromise = this . repository . createScaffold ( {
222
252
documentType : { unique : documentTypeUnique , collection : null } ,
223
253
} ) ;
224
254
255
+ const { data } = await this . #getDataPromise;
225
256
if ( ! data ) return undefined ;
226
257
258
+ this . #entityContext. setEntityType ( UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE ) ;
259
+ this . #entityContext. setUnique ( data . unique ) ;
227
260
this . setIsNew ( true ) ;
228
261
this . #data. setPersisted ( undefined ) ;
229
262
this . #data. setCurrent ( data ) ;
230
263
return data ;
231
264
}
232
265
266
+ getCollectionAlias ( ) {
267
+ return UMB_DOCUMENT_COLLECTION_ALIAS ;
268
+ }
269
+
233
270
getData ( ) {
234
271
return this . #data. getCurrent ( ) ;
235
272
}
@@ -294,7 +331,10 @@ export class UmbDocumentBlueprintWorkspaceContext
294
331
* @returns {Promise<Observable<ReturnType | undefined> | undefined> }
295
332
* @description Get an Observable for the value of this property.
296
333
*/
297
- async propertyValueByAlias < PropertyValueType = unknown > ( propertyAlias : string , variantId ?: UmbVariantId ) {
334
+ async propertyValueByAlias < PropertyValueType = unknown > (
335
+ propertyAlias : string ,
336
+ variantId ?: UmbVariantId ,
337
+ ) : Promise < Observable < PropertyValueType | undefined > | undefined > {
298
338
return this . #data. createObservablePartOfCurrent (
299
339
( data ) =>
300
340
data ?. values ?. find ( ( x ) => x ?. alias === propertyAlias && ( variantId ? variantId . compare ( x as any ) : true ) )
0 commit comments