1
1
import { XGraph } from 'graph_class' ;
2
2
import { StateHandler } from 'states_handler' ;
3
- import { FlowchartHandler } from 'flowchart_handler' ;
3
+ // import { FlowchartHandler } from 'flowchart_handler';
4
4
import { $GF , GFLog } from 'globals_class' ;
5
5
import { GFEvents } from 'flowcharting_base' ;
6
6
import { GFDrawio } from 'drawio_base' ;
@@ -71,8 +71,6 @@ export class Flowchart {
71
71
}
72
72
73
73
change ( ) {
74
- const funcName = 'change' ;
75
- GFLog . debug ( `${ this . constructor . name } .${ funcName } () : ${ this . uid } ` ) ;
76
74
this . change_xgraph ( ) ;
77
75
this . events . emit ( 'flowchart_changed' , this ) ;
78
76
}
@@ -142,10 +140,7 @@ export class Flowchart {
142
140
}
143
141
this . data . csv = value ;
144
142
}
145
- if ( this . xgraph ) {
146
- this . xgraph . source = this . getResolvedSource ( ) ;
147
143
this . change ( ) ;
148
- }
149
144
}
150
145
get source ( ) {
151
146
return this . data . type === 'csv' ? this . data . csv : this . data . xml ;
@@ -157,10 +152,7 @@ export class Flowchart {
157
152
return ;
158
153
}
159
154
this . data . download = value ;
160
- if ( value && this . xgraph ) {
161
- this . xgraph . source = this . getResolvedSource ( ) ;
162
- }
163
- this . change ( ) ;
155
+ this . change ( ) ;
164
156
}
165
157
get download ( ) {
166
158
return this . data . download ;
@@ -352,8 +344,8 @@ export class Flowchart {
352
344
static getDefaultData ( ) : gf . TFlowchartData {
353
345
return {
354
346
name : 'Main' ,
355
- xml : FlowchartHandler . getDefaultDioGraph ( ) ,
356
- csv : FlowchartHandler . getDefaultCsvGraph ( ) ,
347
+ xml : '' ,
348
+ csv : '' ,
357
349
download : false ,
358
350
type : 'xml' ,
359
351
url : 'http://<YourUrl>/<Your XML/drawio file/api>' ,
@@ -379,6 +371,9 @@ export class Flowchart {
379
371
}
380
372
381
373
init_stateHandler ( ) : this {
374
+ if ( this . stateHandler ) {
375
+ this . stateHandler . free ( )
376
+ }
382
377
if ( this . xgraph ) {
383
378
this . stateHandler = new StateHandler ( this . $gf , this . xgraph ) ;
384
379
}
@@ -391,31 +386,30 @@ export class Flowchart {
391
386
* @return {this }
392
387
* @memberof Flowchart
393
388
*/
394
- init_xgraph ( ) : this {
389
+ async init_xgraph ( ) {
395
390
const $GF = this . $gf ;
396
391
try {
397
- const content = this . getResolvedSource ( ) ;
398
- if ( this . xgraph !== undefined ) {
399
- this . xgraph . free ( ) ;
400
- }
401
- this . xgraph = new XGraph ( this . $gf , this . container , this . data . type , content ) ;
402
- this . xgraph . events . connect ( 'graph_changed' , this , this . _on_xgraph_graph_changed . bind ( this ) ) ;
392
+ return this . resolveSource ( ) . then ( ( content ) => {
393
+ if ( this . xgraph !== undefined ) {
394
+ this . xgraph . free ( ) ;
395
+ }
396
+ this . xgraph = new XGraph ( this . $gf , this . container , this . data . type , content ) ;
397
+ this . xgraph . events . connect ( 'graph_changed' , this , this . _on_flowchart_graph_changed . bind ( this ) ) ;
398
+ this . update_graph ( ) ;
399
+ this . events . emit ( 'graph_changed' , this . xgraph ) ;
400
+ } ) ;
403
401
} catch ( error ) {
404
402
$GF . notify ( 'Unable to initialize graph' , 'error' ) ;
405
403
GFLog . error ( 'Unable to initialize graph' , error ) ;
406
404
}
407
- return this ;
405
+ return ;
408
406
}
409
407
410
408
change_xgraph ( ) : this {
411
409
const $GF = this . $gf ;
412
410
try {
413
411
// const content = this.getResolvedSource();
414
412
this . init_xgraph ( ) ;
415
- // if (content !== undefined && content !== null) {
416
- this . xgraph ?. change ( ) ;
417
- this . update_graph ( ) ;
418
- // this.xgraph?.update();
419
413
$GF . clearNotify ( ) ;
420
414
} catch ( error ) {
421
415
$GF . notify ( 'Unable to initialize graph' , 'error' ) ;
@@ -693,23 +687,35 @@ export class Flowchart {
693
687
* @returns
694
688
* @memberof Flowchart
695
689
*/
696
- getResolvedSource ( replaceVarBool = true ) : string {
690
+ async resolveSource ( replaceVarBool = true ) : Promise < string > {
697
691
const $GF = this . $gf ;
698
- let content : string | null = '' ;
692
+ let content = '' ;
699
693
if ( this . download ) {
700
694
const url = $GF . resolveVars ( this . data . url ) ;
701
695
$GF . notify ( `Loading content definition for ${ this . data . name } ` , 'info' ) ;
702
- content = this . loadContent ( url ) ;
696
+ content = await GFDrawio . loadFile ( url ) ;
703
697
$GF . clearNotify ( ) ;
704
698
if ( content !== null ) {
705
699
if ( replaceVarBool ) {
706
700
content = $GF . resolveVars ( content ) ;
707
701
}
708
702
}
709
703
} else {
704
+ if ( ! this . source || this . source . length === 0 ) {
705
+ content = await GFDrawio . getTemplate ( this . type ) ;
706
+ if ( this . type === 'xml' ) {
707
+ this . data . xml = content ;
708
+ } ;
709
+ if ( this . type === 'csv' ) {
710
+ this . data . csv = content ;
711
+ } ;
712
+ }
713
+ if ( GFDrawio . isEncoded ( content ) ) {
714
+ content = GFDrawio . decode ( content ) ;
715
+ }
710
716
content = $GF . resolveVars ( this . source ) ;
711
717
}
712
- return content === null ? '' : content ;
718
+ return content ;
713
719
}
714
720
715
721
/**
@@ -720,9 +726,9 @@ export class Flowchart {
720
726
* @memberof Flowchart
721
727
*/
722
728
//TODO : Transform to fetch
723
- loadContent ( url : string ) : string | null {
724
- return $GF . utils . $loadFile ( url ) ;
725
- }
729
+ // loadContent(url: string): string | null {
730
+ // return $GF.utils.$loadFile(url);
731
+ // }
726
732
727
733
/**
728
734
* Apply xml to graph
@@ -817,11 +823,12 @@ export class Flowchart {
817
823
//###########################################################################
818
824
//### EVENTS
819
825
//###########################################################################
820
- private _on_xgraph_graph_changed ( ) {
826
+ private _on_flowchart_graph_changed ( ) {
821
827
_log ( '📬' , this . constructor . name , '_on_flowchart_graph_changed' ) ;
822
828
if ( this . xgraph ) {
823
- this . stateHandler ?. setXGraph ( this . xgraph ) ;
824
- this . stateHandler ?. init ( ) ;
829
+ this . init_stateHandler ( ) ;
830
+ // this.stateHandler?.setXGraph(this.xgraph);
831
+ // this.stateHandler?.init();
825
832
}
826
833
}
827
834
0 commit comments