@@ -13,7 +13,7 @@ import utilsExport from '@/lib/utils_export';
13
13
// import utilsMisc from '@/lib/utils_misc';
14
14
15
15
import shortCodesOverrides from "@/lib/shortCodesOverrides.json"
16
-
16
+ import defaultComponents from "@/lib/defaults/default_components.json"
17
17
18
18
import utilsProfile from '../lib/utils_profile'
19
19
@@ -231,12 +231,11 @@ export const useProfileStore = defineStore('profile', {
231
231
} ,
232
232
233
233
234
- /** Groups the library components into a array ready to render
234
+ /** Groups the library components into a array ready to render
235
235
*
236
236
* @return {array }
237
237
*/
238
- returnComponentLibrary : ( state ) => {
239
-
238
+ returnComponentLibrary : ( state ) => {
240
239
// limit to the current profiles being used
241
240
// console.log(state.activeProfile)
242
241
// console.log(state.componentLibrary)
@@ -246,10 +245,8 @@ export const useProfileStore = defineStore('profile', {
246
245
// }
247
246
let results = [ ]
248
247
for ( let key in state . activeProfile . rt ) {
249
-
250
248
// ther are components saved for this profile
251
249
if ( state . componentLibrary . profiles [ key ] ) {
252
-
253
250
let groups = { }
254
251
let groupsOrder = [ ]
255
252
// loop through all the components sorted by position order
@@ -264,98 +261,170 @@ export const useProfileStore = defineStore('profile', {
264
261
if ( groupsOrder . indexOf ( group . groupId ) == - 1 ) {
265
262
groupsOrder . push ( group . groupId )
266
263
}
267
-
268
264
}
269
265
}
270
-
271
- results . push ( { groups :groups , groupsOrder :groupsOrder , profileId : key , label : key . split ( ":" ) . slice ( - 1 ) [ 0 ] } )
266
+ results . push ( { groups :groups , groupsOrder :groupsOrder , profileId : key , label : key . split ( ":" ) . slice ( - 1 ) [ 0 ] } )
272
267
}
273
268
269
+ if ( usePreferenceStore ( ) . returnValue ( '--b-edit-main-splitpane-properties-show-defaults' ) ) {
270
+ let groups = { }
271
+ let groupsOrder = [ ]
272
+ for ( let dKey in defaultComponents . DefaultComponentLibrary . profiles ) {
273
+ if ( dKey . includes ( key ) ) {
274
+ for ( let group of defaultComponents . DefaultComponentLibrary . profiles [ dKey ] . groups . sort ( ( { position :a } , { position :b } ) => a - b ) ) {
275
+ if ( group . groupId === null ) {
276
+ groups [ group . id ] = [ group ]
277
+ groupsOrder . push ( group . id )
278
+ } else {
279
+ if ( ! groups [ group . groupId ] ) { groups [ group . groupId ] = [ ] }
280
+ groups [ group . groupId ] . push ( group )
281
+ if ( groupsOrder . indexOf ( group . groupId ) == - 1 ) {
282
+ groupsOrder . push ( group . groupId )
283
+ }
284
+ }
285
+ }
286
+ results . push ( { type : "default" , groups :groups , groupsOrder :groupsOrder , profileId : dKey , label : key . split ( ":" ) . slice ( - 1 ) [ 0 ] } )
287
+ }
288
+ }
289
+ }
274
290
}
275
291
276
292
// now go through and see if there are the the same group being used in multiple profiles if so
277
293
// that means they have cross profile components (2 fields in Work 1 in instance for exmaple)
278
294
279
295
280
296
let groupsCount = { }
297
+ let groupsCountDefault = { }
281
298
for ( let profileComponents of results ) {
299
+
300
+ let type = profileComponents . type
301
+
282
302
for ( let groupKey in profileComponents . groups ) {
283
303
if ( profileComponents . groups [ groupKey ] . groupId !== null ) {
284
304
for ( let groupItem of profileComponents . groups [ groupKey ] ) {
305
+ let group = groupsCount
306
+ if ( type == 'default' ) {
307
+ group = groupsCountDefault
308
+ }
285
309
if ( groupItem . groupId !== null ) {
286
- if ( ! groupsCount [ groupItem . groupId ] ) {
287
- groupsCount [ groupItem . groupId ] = [ ]
310
+ if ( ! group [ groupItem . groupId ] ) {
311
+ group [ groupItem . groupId ] = [ ]
288
312
}
289
- if ( groupsCount [ groupItem . groupId ] . indexOf ( groupItem . structure . parentId ) == - 1 ) {
290
- groupsCount [ groupItem . groupId ] . push ( groupItem . structure . parentId )
313
+ if ( group [ groupItem . groupId ] . indexOf ( groupItem . structure . parentId ) == - 1 ) {
314
+ group [ groupItem . groupId ] . push ( groupItem . structure . parentId )
291
315
}
292
316
}
293
317
}
294
-
295
318
}
296
319
}
297
320
}
298
321
299
322
let groupsToMerge = [ ]
323
+ let groupsToMergeDefault = [ ]
300
324
for ( let groupKey in groupsCount ) {
301
325
if ( groupsCount [ groupKey ] . length > 1 ) {
302
326
groupsToMerge . push ( groupKey )
303
327
}
304
328
}
305
- if ( groupsToMerge . length > 0 ) {
306
- // we have to MERGE
307
- let multiProfile = {
308
- groups : { } ,
309
- groupsOrder : [ ] ,
310
- label : 'Multi' ,
311
- profileId : 'Multi'
329
+ for ( let groupKey in groupsCountDefault ) {
330
+ if ( groupsCountDefault [ groupKey ] . length > 1 ) {
331
+ groupsToMergeDefault . push ( groupKey )
312
332
}
333
+ }
313
334
314
- for ( let groupName of groupsToMerge ) {
335
+ let mergeComponents = function ( results , groupsToMerge , title ) {
336
+ if ( groupsToMerge . length > 0 ) {
337
+ // we have to MERGE
338
+ let multiProfile = {
339
+ groups : { } ,
340
+ groupsOrder : [ ] ,
341
+ label : title ,
342
+ profileId : title ,
343
+ type : title . includes ( "Default" ) ? 'default' : null
344
+ }
315
345
316
- let tmpGroupComponents = [ ]
346
+ for ( let groupName of groupsToMerge ) {
347
+ let tmpGroupComponents = [ ]
348
+ // remove them from the orginal group/profile and them to the multi profile
349
+ for ( let profileComponents of results ) {
350
+ if ( profileComponents . groups [ groupName ] ) {
351
+ tmpGroupComponents = tmpGroupComponents . concat ( JSON . parse ( JSON . stringify ( profileComponents . groups [ groupName ] ) ) )
352
+ delete profileComponents . groups [ groupName ]
353
+ }
354
+ profileComponents . groupsOrder = profileComponents . groupsOrder . filter ( ( v ) => { return ( v !== groupName ) } )
355
+ }
317
356
357
+ // put them into the multi profile
358
+ multiProfile . groups [ groupName ] = tmpGroupComponents
359
+ multiProfile . groupsOrder . push ( groupName )
318
360
319
- // remove them from the orginal group/profile and them to the multi profile
320
- for ( let profileComponents of results ) {
321
- if ( profileComponents . groups [ groupName ] ) {
322
- tmpGroupComponents = tmpGroupComponents . concat ( JSON . parse ( JSON . stringify ( profileComponents . groups [ groupName ] ) ) )
323
- delete profileComponents . groups [ groupName ]
324
- }
325
- profileComponents . groupsOrder = profileComponents . groupsOrder . filter ( ( v ) => { return ( v !== groupName ) } )
326
- }
361
+ // add a label to denote if the individual component is a work or instance whatever component.
362
+ for ( let groupKey in multiProfile . groups ) {
363
+ for ( let component of multiProfile . groups [ groupKey ] ) {
364
+ if ( component . label . indexOf ( "(i)" ) > - 1 ) { continue }
365
+ if ( component . label . indexOf ( "(w)" ) > - 1 ) { continue }
366
+ let initial = component . structure . parentId . split ( ':' ) . slice ( - 1 ) [ 0 ] . charAt ( 0 ) . toLowerCase ( ) ;
327
367
328
- // put them into the multi profile
329
- multiProfile . groups [ groupName ] = tmpGroupComponents
330
- multiProfile . groupsOrder . push ( groupName )
331
-
332
- // add a label to denote if the individual component is a work or instance whatever component.
333
- for ( let groupKey in multiProfile . groups ) {
334
- for ( let component of multiProfile . groups [ groupKey ] ) {
335
- if ( component . label . indexOf ( "(i)" ) > - 1 ) { continue }
336
- if ( component . label . indexOf ( "(w)" ) > - 1 ) { continue }
337
- let initial = component . structure . parentId . split ( ':' ) . slice ( - 1 ) [ 0 ] . charAt ( 0 ) . toLowerCase ( ) ;
338
- component . label = `(${ initial } ) ${ component . label } `
368
+ component . label = `(${ initial } ) ${ component . label } `
369
+ }
339
370
}
340
371
}
341
-
342
-
372
+ results . push ( multiProfile )
343
373
}
344
374
375
+ return results
376
+ }
345
377
346
- results . push ( multiProfile )
378
+ let r = mergeComponents ( results , groupsToMerge , 'Multi' )
379
+ results . concat ( r )
380
+ r = mergeComponents ( results , groupsToMergeDefault , 'Multi Default' )
381
+ results . concat ( r )
347
382
383
+ //merge the defaults into 1 list
384
+ if ( usePreferenceStore ( ) . returnValue ( '--b-edit-main-splitpane-properties-show-defaults' ) ) {
385
+ let defaultIdx = [ ]
386
+ let defaults = [ ]
387
+ let defaultObj = { type : "default" , groups :{ } , groupsOrder :[ ] , profileId : 'defaults' , label : 'Defaults' }
388
+ // Get the defaults
389
+ for ( let item in results ) {
390
+ if ( results [ item ] . type == 'default' ) {
391
+ defaultIdx . push ( Number ( item ) )
392
+ defaults . push ( results [ item ] )
393
+ }
394
+ }
395
+ //merge into 1
396
+ for ( let item of defaults ) {
397
+ defaultObj . groups = Object . assign ( { } , defaultObj . groups , item . groups )
398
+ defaultObj . groupsOrder = defaultObj . groupsOrder . concat ( item . groupsOrder )
399
+ }
400
+ //rebuild results
401
+ for ( let i = results . length - 1 ; i >= 0 ; i -- ) {
402
+ if ( defaultIdx . includes ( i ) ) {
403
+ results . splice ( i , 1 )
404
+ }
405
+ }
406
+ let sortFn = function ( a , b ) {
407
+ let targetA = ! defaultObj . groups [ a ] [ 0 ] . label . startsWith ( "(" ) ? defaultObj . groups [ a ] [ 0 ] . label : a
408
+ let targetB = ! defaultObj . groups [ b ] [ 0 ] . label . startsWith ( "(" ) ? defaultObj . groups [ b ] [ 0 ] . label : b
409
+
410
+ let val = targetA < targetB ? - 1 : targetA > targetB ? 1 : 0
348
411
412
+ return val
413
+ }
414
+ defaultObj . groupsOrder . sort ( sortFn )
349
415
416
+ results . push ( defaultObj )
350
417
}
418
+
351
419
// remove any empty ones that may have shifted fully into the multi profile
352
420
results = results . filter ( ( g ) => { return ( g . groupsOrder . length > 0 ) } )
353
421
354
-
422
+ results = results . sort ( ( a , b ) => {
423
+ if ( ! a . type || a . type == null ) { return - 1 }
424
+ if ( ! b . type || b . type == null ) { return 1 }
425
+ return ( a . type < b . type ) ? 1 : ( a . type > b . type ) ? - 1 : 0
426
+ } )
355
427
return results
356
-
357
-
358
-
359
428
} ,
360
429
361
430
@@ -5177,6 +5246,11 @@ export const useProfileStore = defineStore('profile', {
5177
5246
*
5178
5247
*/
5179
5248
addFromComponentLibrary ( id ) {
5249
+ let defaultLibrary = null
5250
+ if ( usePreferenceStore ( ) . returnValue ( '--b-edit-main-splitpane-properties-show-defaults' ) ) {
5251
+ defaultLibrary = defaultComponents . DefaultComponentLibrary . profiles
5252
+ this . componentLibrary . profiles = Object . assign ( { } , this . componentLibrary . profiles , defaultLibrary )
5253
+ }
5180
5254
for ( let key in this . componentLibrary . profiles ) {
5181
5255
for ( let group of this . componentLibrary . profiles [ key ] . groups ) {
5182
5256
if ( group . id == id ) {
0 commit comments