@@ -12,6 +12,7 @@ export const useChartStore = defineStore("chart", {
12
12
tables : { } ,
13
13
tablesColors :{ } ,
14
14
actualTables :{ } ,
15
+ tablesDict :{ } ,
15
16
refs : { } ,
16
17
grid : {
17
18
size : 100 ,
@@ -70,7 +71,12 @@ export const useChartStore = defineStore("chart", {
70
71
return state . ctm ;
71
72
} ,
72
73
getTables ( ) {
73
- return this . tables ;
74
+ const k = Object . keys ( this . tables )
75
+ let tbls = { } ;
76
+ for ( const k in this . tables ) {
77
+ tbls [ k ] = this . tables [ k ] [ Object . keys ( this . tables [ k ] ) [ 0 ] ]
78
+ }
79
+ return tbls ;
74
80
} ,
75
81
getRefs ( ) {
76
82
return this . refs ;
@@ -79,20 +85,71 @@ export const useChartStore = defineStore("chart", {
79
85
return this . tableGroups ;
80
86
} ,
81
87
getTable ( state ) {
82
- return ( tableId ) => {
83
- if ( ! ( tableId in state . tables ) )
84
- state . tables [ tableId ] = {
85
- x : 0 ,
86
- y : 0 ,
87
- width : 220 ,
88
- height : 32
89
- } ;
90
- return state . tables [ tableId ] ;
88
+ return ( tableId , schema , tablename ) => {
89
+
90
+ const tfn = `${ schema } .${ tablename } ` ;
91
+ if ( schema !== undefined && tablename !== undefined ) {
92
+ if ( tableId in state . tables ) {
93
+
94
+ if ( Object . keys ( state . tables [ tableId ] ) . includes ( 'width' ) ) {
95
+ const c = state . tables [ tableId ] ;
96
+ state . tables [ tableId ] = { } ;
97
+ state . tables [ tableId ] [ tfn ] = c
98
+
99
+ }
100
+ if ( ! ( tfn in state . tables [ tableId ] ) ) {
101
+ let founded = false ;
102
+ for ( const obj in state . tables ) {
103
+ if ( tfn in state . tables [ Number ( obj ) ] && obj != tableId ) {
104
+ state . tables [ tableId ] [ tfn ] = state . tables [ Number ( obj ) ] [ tfn ]
105
+ delete state . tables [ Number ( obj ) ] [ tfn ]
106
+ founded = true
107
+ }
108
+ }
109
+ if ( ! founded ) {
110
+
111
+ if ( Object . keys ( state . tables [ tableId ] ) . length > 0 ) {
112
+ if ( ! ( tfn in state . tables [ tableId ] ) ) {
113
+ const k = Object . keys ( state . tables [ tableId ] ) [ 0 ]
114
+ state . tables [ tableId ] [ tfn ] = state . tables [ tableId ] [ k ]
115
+ delete state . tables [ tableId ] [ k ]
116
+ }
117
+ } else {
118
+
119
+ state . tables [ tableId ] = { } ;
120
+ state . tables [ tableId ] [ tfn ] = {
121
+ x : 0 ,
122
+ y : 0 ,
123
+ width : 220 ,
124
+ height : 32
125
+ } ;
126
+ }
127
+ }
128
+ }
129
+ } else {
130
+ state . tables [ tableId ] = { }
131
+ state . tables [ tableId ] [ tfn ] = {
132
+ x : 0 ,
133
+ y : 0 ,
134
+ width : 220 ,
135
+ height : 32
136
+ } ;
137
+ }
138
+ }
139
+
140
+ if ( schema === undefined || tablename === undefined ) {
141
+
142
+ const k = Object . keys ( state . tables [ tableId ] ) [ 0 ]
143
+ return state . tables [ tableId ] [ k ] ;
144
+ } else {
145
+ return state . tables [ tableId ] [ tfn ]
146
+ }
147
+
91
148
} ;
92
149
} ,
93
150
getTableColor ( state ) {
94
151
return ( tablename , tableId , schema ) => {
95
- let tfn = `${ schema } .${ tablename } ` ;
152
+ const tfn = `${ schema } .${ tablename } ` ;
96
153
97
154
if ( tableId in state . tablesColors ) {
98
155
@@ -252,8 +309,60 @@ export const useChartStore = defineStore("chart", {
252
309
datetime :null
253
310
} ;
254
311
} ,
312
+ getTableV2 ( state , tableId , schema , tablename ) {
313
+ const tfn = `${ schema } .${ tablename } ` ;
314
+ if ( schema !== undefined && tablename !== undefined ) {
315
+ if ( tableId in state . tables ) {
316
+
317
+ if ( Object . keys ( state . tables [ tableId ] ) . includes ( 'width' ) ) {
318
+ const c = state . tables [ tableId ] ;
319
+ state . tables [ tableId ] = { } ;
320
+ state . tables [ tableId ] [ tfn ] = c
321
+
322
+ }
323
+ if ( ! ( tfn in state . tables [ tableId ] ) ) {
324
+ let founded = false ;
325
+ for ( const obj in state . tables ) {
326
+ if ( tfn in state . tables [ Number ( obj ) ] && obj != tableId ) {
327
+ state . tables [ tableId ] [ tfn ] = state . tables [ Number ( obj ) ] [ tfn ]
328
+ delete state . tables [ Number ( obj ) ] [ tfn ]
329
+ founded = true
330
+ }
331
+ }
332
+ if ( ! founded ) {
333
+
334
+ if ( Object . keys ( state . tables [ tableId ] ) . length > 0 ) {
335
+ if ( ! ( tfn in state . tables [ tableId ] ) ) {
336
+ const k = Object . keys ( state . tables [ tableId ] ) [ 0 ]
337
+ state . tables [ tableId ] [ tfn ] = state . tables [ tableId ] [ k ]
338
+ delete state . tables [ tableId ] [ k ]
339
+ }
340
+ } else {
341
+
342
+ state . tables [ tableId ] = { } ;
343
+ state . tables [ tableId ] [ tfn ] = {
344
+ x : 0 ,
345
+ y : 0 ,
346
+ width : 220 ,
347
+ height : 32
348
+ } ;
349
+ }
350
+ }
351
+ }
352
+ } else {
353
+ state . tables [ tableId ] = { }
354
+ state . tables [ tableId ] [ tfn ] = {
355
+ x : 0 ,
356
+ y : 0 ,
357
+ width : 220 ,
358
+ height : 32
359
+ } ;
360
+ }
361
+ }
362
+ } ,
255
363
loadDatabase ( database ) {
256
364
let tablesList = [ ] ;
365
+ let dict = { } ;
257
366
for ( const schema of database . schemas ) {
258
367
for ( const tableGroup of schema . tableGroups )
259
368
{
@@ -262,8 +371,12 @@ export const useChartStore = defineStore("chart", {
262
371
263
372
for ( const table of schema . tables )
264
373
{
265
- this . getTable ( table . id ) ;
374
+ this . getTable ( table . id , schema . name , table . name ) ;
266
375
this . getTableColor ( table . name , table . id , schema . name )
376
+ dict [ table . id ] = {
377
+ schema : schema . name ,
378
+ name : table . name
379
+ }
267
380
}
268
381
tablesList . push ( ...schema . tables . map ( ( x ) => x . id ) ) ;
269
382
@@ -274,22 +387,30 @@ export const useChartStore = defineStore("chart", {
274
387
console . log ( schema ) ;
275
388
}
276
389
277
-
278
390
this . $patch ( {
279
- actualTables :tablesList
391
+ actualTables :tablesList ,
392
+ tablesDict :dict
280
393
} )
281
394
this . loaded = true ;
282
395
} ,
283
396
load ( state ) {
284
- console . log ( Object . values ( this . actualTables ) )
397
+ console . log ( "state-> " , state , this . tablesDict )
285
398
for ( const tbl in state . tables ) {
286
399
if ( ! ( Object . values ( this . actualTables ) . includes ( Number ( tbl ) ) ) ) {
287
- delete state . tables [ tbl ]
288
- }
400
+ delete state . tables [ Number ( tbl ) ]
401
+ delete state . tablesColors [ Number ( tbl ) ]
402
+ } else {
403
+ if ( Object . keys ( state . tables [ Number ( tbl ) ] ) . includes ( 'width' ) ) {
404
+ this . getTableV2 ( state , tbl , this . tablesDict [ Number ( tbl ) ] . schema , this . tablesDict [ Number ( tbl ) ] . tablename )
405
+ }
406
+ }
289
407
}
408
+ console . log ( "state-> " , state , this . tablesDict )
290
409
this . $reset ( ) ;
291
410
this . $patch ( {
292
411
...state ,
412
+ actualTables :{ } ,
413
+ tablesDict :{ } ,
293
414
ctm : DOMMatrix . fromMatrix ( state . ctm ) ,
294
415
inverseCtm : DOMMatrix . fromMatrix ( state . inverseCtm ) . inverse ( )
295
416
} ) ;
@@ -322,8 +443,10 @@ export const useChartStore = defineStore("chart", {
322
443
} ) ;
323
444
} ,
324
445
updateTable ( tableId , newTable ) {
446
+ const k = Object . keys ( this . tables [ tableId ] ) [ 0 ] ;
447
+
325
448
this . $patch ( {
326
- tables :{ [ tableId ] : newTable }
449
+ tables :{ [ tableId ] : { [ k ] : newTable } }
327
450
} ) ;
328
451
} ,
329
452
updateRef ( refId , newRef ) {
0 commit comments