Skip to content

Commit 93129b6

Browse files
authored
Merge pull request #260 from lcnetdev/redo-default-library
Redo default library
2 parents e94c75a + 26eaa2d commit 93129b6

File tree

2 files changed

+124
-50
lines changed

2 files changed

+124
-50
lines changed

src/stores/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const useConfigStore = defineStore('config', {
77

88
versionMajor: 0,
99
versionMinor: 18,
10-
versionPatch: 12,
10+
versionPatch: 13,
1111

1212
regionUrls: {
1313

src/stores/profile.js

+123-49
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import utilsExport from '@/lib/utils_export';
1313
// import utilsMisc from '@/lib/utils_misc';
1414

1515
import shortCodesOverrides from "@/lib/shortCodesOverrides.json"
16-
16+
import defaultComponents from "@/lib/defaults/default_components.json"
1717

1818
import utilsProfile from '../lib/utils_profile'
1919

@@ -231,12 +231,11 @@ export const useProfileStore = defineStore('profile', {
231231
},
232232

233233

234-
/** Groups the library components into a array ready to render
234+
/** Groups the library components into a array ready to render
235235
*
236236
* @return {array}
237237
*/
238-
returnComponentLibrary: (state) => {
239-
238+
returnComponentLibrary: (state) => {
240239
// limit to the current profiles being used
241240
// console.log(state.activeProfile)
242241
// console.log(state.componentLibrary)
@@ -246,10 +245,8 @@ export const useProfileStore = defineStore('profile', {
246245
// }
247246
let results = []
248247
for (let key in state.activeProfile.rt){
249-
250248
// ther are components saved for this profile
251249
if (state.componentLibrary.profiles[key]){
252-
253250
let groups = {}
254251
let groupsOrder = []
255252
// loop through all the components sorted by position order
@@ -264,98 +261,170 @@ export const useProfileStore = defineStore('profile', {
264261
if (groupsOrder.indexOf(group.groupId)==-1){
265262
groupsOrder.push(group.groupId)
266263
}
267-
268264
}
269265
}
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]})
272267
}
273268

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+
}
274290
}
275291

276292
// now go through and see if there are the the same group being used in multiple profiles if so
277293
// that means they have cross profile components (2 fields in Work 1 in instance for exmaple)
278294

279295

280296
let groupsCount = {}
297+
let groupsCountDefault = {}
281298
for (let profileComponents of results){
299+
300+
let type = profileComponents.type
301+
282302
for (let groupKey in profileComponents.groups){
283303
if (profileComponents.groups[groupKey].groupId !== null){
284304
for (let groupItem of profileComponents.groups[groupKey]){
305+
let group = groupsCount
306+
if (type == 'default'){
307+
group = groupsCountDefault
308+
}
285309
if (groupItem.groupId !== null){
286-
if (!groupsCount[groupItem.groupId]){
287-
groupsCount[groupItem.groupId]=[]
310+
if (!group[groupItem.groupId]){
311+
group[groupItem.groupId]=[]
288312
}
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)
291315
}
292316
}
293317
}
294-
295318
}
296319
}
297320
}
298321

299322
let groupsToMerge = []
323+
let groupsToMergeDefault = []
300324
for (let groupKey in groupsCount){
301325
if (groupsCount[groupKey].length>1){
302326
groupsToMerge.push(groupKey)
303327
}
304328
}
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)
312332
}
333+
}
313334

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+
}
315345

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+
}
317356

357+
// put them into the multi profile
358+
multiProfile.groups[groupName] = tmpGroupComponents
359+
multiProfile.groupsOrder.push(groupName)
318360

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();
327367

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+
}
339370
}
340371
}
341-
342-
372+
results.push(multiProfile)
343373
}
344374

375+
return results
376+
}
345377

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)
347382

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
348411

412+
return val
413+
}
414+
defaultObj.groupsOrder.sort(sortFn)
349415

416+
results.push(defaultObj)
350417
}
418+
351419
// remove any empty ones that may have shifted fully into the multi profile
352420
results = results.filter((g) => {return (g.groupsOrder.length>0)})
353421

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+
})
355427
return results
356-
357-
358-
359428
},
360429

361430

@@ -5177,6 +5246,11 @@ export const useProfileStore = defineStore('profile', {
51775246
*
51785247
*/
51795248
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+
}
51805254
for (let key in this.componentLibrary.profiles){
51815255
for (let group of this.componentLibrary.profiles[key].groups){
51825256
if (group.id == id){

0 commit comments

Comments
 (0)