1
+
1
2
import { defineStore } from "pinia" ;
2
3
import { markRaw } from "vue" ;
3
4
@@ -10,6 +11,7 @@ export const useChartStore = defineStore("chart", {
10
11
tableGroups : { } ,
11
12
tables : { } ,
12
13
tablesColors :{ } ,
14
+ actualTables :{ } ,
13
15
refs : { } ,
14
16
grid : {
15
17
size : 100 ,
@@ -91,21 +93,62 @@ export const useChartStore = defineStore("chart", {
91
93
getTableColor ( state ) {
92
94
return ( tablename , tableId , schema ) => {
93
95
let tfn = `${ schema } .${ tablename } ` ;
94
- if ( ! ( tfn in state . tablesColors ) ) {
95
- state . tablesColors [ tfn ] = {
96
- color :null
97
- }
98
- }
99
- if ( tablename in state . tablesColors ) {
100
- state . tablesColors [ tfn ] = state . tablesColors [ tablename ] ;
101
- delete state . tablesColors [ tablename ] ;
102
- }
96
+
103
97
if ( tableId in state . tablesColors ) {
104
- state . tablesColors [ tfn ] = state . tablesColors [ tableId ] ;
105
- delete state . tablesColors [ tableId ] ;
106
- }
107
98
108
- return state . tablesColors [ tfn ] ;
99
+ if ( Object . keys ( state . tablesColors [ tableId ] ) . includes ( 'color' ) ) {
100
+ const c = state . tablesColors [ tableId ] . color ;
101
+ state . tablesColors [ tableId ] [ tfn ] = { color :c }
102
+ delete state . tablesColors [ tableId ] . color
103
+ }
104
+
105
+ if ( ! ( tfn in state . tablesColors [ tableId ] ) ) {
106
+ let founded = false ;
107
+ for ( const obj in state . tablesColors ) {
108
+ if ( tfn in state . tablesColors [ obj ] && obj != tableId ) {
109
+ state . tablesColors [ tableId ] [ tfn ] = state . tablesColors [ obj ] [ tfn ]
110
+ delete state . tablesColors [ obj ] [ tfn ]
111
+ founded = true
112
+ }
113
+ }
114
+ if ( ! founded ) {
115
+ if ( Object . keys ( state . tablesColors [ tableId ] ) . length > 0 ) {
116
+ if ( ! ( tfn in state . tablesColors [ tableId ] ) ) {
117
+ const k = Object . keys ( state . tablesColors [ tableId ] ) [ 0 ]
118
+ state . tablesColors [ tableId ] [ tfn ] = state . tablesColors [ tableId ] [ k ]
119
+ delete state . tablesColors [ tableId ] [ k ]
120
+ }
121
+ } else {
122
+ state . tablesColors [ tableId ] = { } ;
123
+ state . tablesColors [ tableId ] [ tfn ] = { color :null }
124
+ }
125
+ }
126
+ }
127
+ } else {
128
+
129
+ state . tablesColors [ tableId ] = { } ;
130
+ state . tablesColors [ tableId ] [ tfn ] = { color :null }
131
+
132
+ if ( tablename in state . tablesColors ) {
133
+ state . tablesColors [ tableId ] = { } ;
134
+ state . tablesColors [ tableId ] [ tfn ] = state . tablesColors [ tablename ] ;
135
+ delete state . tablesColors [ tablename ] ;
136
+ } else {
137
+ state . tablesColors [ tableId ] = { } ;
138
+ state . tablesColors [ tableId ] [ tfn ] = { color :null }
139
+ }
140
+
141
+ if ( tfn in state . tablesColors ) {
142
+ state . tablesColors [ tableId ] = { } ;
143
+ state . tablesColors [ tableId ] [ tfn ] = state . tablesColors [ tfn ]
144
+ delete state . tablesColors [ tfn ] ;
145
+ } else {
146
+ state . tablesColors [ tableId ] = { } ;
147
+ state . tablesColors [ tableId ] [ tfn ] = { color :null }
148
+ }
149
+
150
+ }
151
+ return state . tablesColors [ tableId ] [ tfn ] ;
109
152
} ;
110
153
} ,
111
154
getTableGroup ( state ) {
@@ -210,22 +253,40 @@ export const useChartStore = defineStore("chart", {
210
253
} ;
211
254
} ,
212
255
loadDatabase ( database ) {
213
- for ( const tableGroup of database . schemas [ 0 ] . tableGroups )
214
- {
215
- this . getTableGroup ( tableGroup . id ) ;
216
- }
217
- for ( const table of database . schemas [ 0 ] . tables )
218
- {
219
- this . getTable ( table . id ) ;
220
- }
221
- for ( const ref of database . schemas [ 0 ] . refs )
222
- {
223
- this . getRef ( ref . id ) ;
256
+ let tablesList = [ ] ;
257
+ for ( const schema of database . schemas ) {
258
+ for ( const tableGroup of schema . tableGroups )
259
+ {
260
+ this . getTableGroup ( tableGroup . id ) ;
261
+ }
262
+
263
+ for ( const table of schema . tables )
264
+ {
265
+ this . getTable ( table . id ) ;
266
+ this . getTableColor ( table . name , table . id , schema . name )
267
+ }
268
+ tablesList . push ( ...schema . tables . map ( ( x ) => x . id ) ) ;
269
+
270
+ for ( const ref of schema . refs )
271
+ {
272
+ this . getRef ( ref . id ) ;
273
+ }
274
+ console . log ( schema ) ;
224
275
}
225
- console . log ( database . schemas [ 0 ] ) ;
276
+
277
+
278
+ this . $patch ( {
279
+ actualTables :tablesList
280
+ } )
226
281
this . loaded = true ;
227
282
} ,
228
- load ( state ) {
283
+ load ( state ) {
284
+ console . log ( Object . values ( this . actualTables ) )
285
+ for ( const tbl in state . tables ) {
286
+ if ( ! ( Object . values ( this . actualTables ) . includes ( Number ( tbl ) ) ) ) {
287
+ delete state . tables [ tbl ]
288
+ }
289
+ }
229
290
this . $reset ( ) ;
230
291
this . $patch ( {
231
292
...state ,
@@ -257,7 +318,7 @@ export const useChartStore = defineStore("chart", {
257
318
updateTableColor ( tablename , id , color , schema ) {
258
319
let tfn = `${ schema } .${ tablename } ` ;
259
320
this . $patch ( {
260
- tablesColors :{ [ tfn ] : { 'color' : color } }
321
+ tablesColors :{ [ id ] : { [ tfn ] : { 'color' : color } } }
261
322
} ) ;
262
323
} ,
263
324
updateTable ( tableId , newTable ) {
0 commit comments