@@ -21,46 +21,35 @@ import { AlignmentObject } from '../shared/types/model/AlignmentObject';
21
21
import { AlignmentConnection } from '../shared/types/model/AlignmentConnection' ;
22
22
import { Zone } from '../shared/types/enums/Zone' ;
23
23
import { ObjectiveState } from '../shared/types/enums/ObjectiveState' ;
24
+ import { RefreshDataService } from '../shared/services/refresh-data.service' ;
24
25
25
26
@Component ( {
26
27
selector : 'app-diagram' ,
27
28
templateUrl : './diagram.component.html' ,
28
29
styleUrl : './diagram.component.scss' ,
29
30
} )
30
31
export class DiagramComponent implements AfterViewInit , OnDestroy {
31
- private alignmentData$ : Subject < AlignmentLists > = new Subject < AlignmentLists > ( ) ;
32
+ @Input ( )
33
+ public alignmentData$ : Subject < AlignmentLists > = new Subject < AlignmentLists > ( ) ;
32
34
cy ! : cytoscape . Core ;
33
35
diagramData : any [ ] = [ ] ;
34
36
alignmentDataCache : AlignmentLists | null = null ;
37
+ reloadRequired : boolean | null | undefined = false ;
35
38
36
39
constructor (
37
40
private keyResultService : KeyresultService ,
41
+ private refreshDataService : RefreshDataService ,
38
42
private router : Router ,
39
43
) { }
40
44
41
- @Input ( )
42
- get alignmentData ( ) : Subject < AlignmentLists > {
43
- return this . alignmentData$ ;
44
- }
45
-
46
- set alignmentData ( alignmentData : AlignmentLists ) {
47
- this . alignmentData$ . next ( alignmentData ) ;
48
- }
49
-
50
45
ngAfterViewInit ( ) : void {
51
- this . alignmentData . subscribe ( ( alignmentData : AlignmentLists ) : void => {
52
- let lastAlignmentItem : AlignmentObject =
53
- alignmentData . alignmentObjectDtoList [ alignmentData . alignmentObjectDtoList . length - 1 ] ;
54
-
55
- const diagramReloadRequired : boolean =
56
- lastAlignmentItem ?. objectTitle === 'reload'
57
- ? lastAlignmentItem ?. objectType === 'true'
58
- : JSON . stringify ( this . alignmentDataCache ) !== JSON . stringify ( alignmentData ) ;
46
+ this . refreshDataService . reloadAlignmentSubject . subscribe ( ( value : boolean | null | undefined ) : void => {
47
+ this . reloadRequired = value ;
48
+ } ) ;
59
49
60
- if ( diagramReloadRequired ) {
61
- if ( lastAlignmentItem ?. objectTitle === 'reload' ) {
62
- alignmentData . alignmentObjectDtoList . pop ( ) ;
63
- }
50
+ this . alignmentData$ . subscribe ( ( alignmentData : AlignmentLists ) : void => {
51
+ if ( this . reloadRequired == true || JSON . stringify ( this . alignmentDataCache ) !== JSON . stringify ( alignmentData ) ) {
52
+ this . reloadRequired = undefined ;
64
53
this . alignmentDataCache = alignmentData ;
65
54
this . diagramData = [ ] ;
66
55
this . cleanUpDiagram ( ) ;
@@ -71,7 +60,8 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {
71
60
72
61
ngOnDestroy ( ) : void {
73
62
this . cleanUpDiagram ( ) ;
74
- this . alignmentData . unsubscribe ( ) ;
63
+ this . alignmentData$ . unsubscribe ( ) ;
64
+ this . refreshDataService . reloadAlignmentSubject . unsubscribe ( ) ;
75
65
}
76
66
77
67
generateDiagram ( ) : void {
@@ -187,8 +177,8 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {
187
177
}
188
178
} ) ;
189
179
190
- zip ( observableArray ) . subscribe ( ( ) => {
191
- this . generateConnections ( alignmentData , diagramElements ) ;
180
+ zip ( observableArray ) . subscribe ( async ( ) => {
181
+ await this . generateConnections ( alignmentData , diagramElements ) ;
192
182
} ) ;
193
183
}
194
184
@@ -223,7 +213,7 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {
223
213
} ;
224
214
}
225
215
226
- generateConnections ( alignmentData : AlignmentLists , diagramElements : any [ ] ) : void {
216
+ async generateConnections ( alignmentData : AlignmentLists , diagramElements : any [ ] ) {
227
217
let edges : any [ ] = [ ] ;
228
218
alignmentData . alignmentConnectionDtoList . forEach ( ( alignmentConnection : AlignmentConnection ) => {
229
219
let edge = {
@@ -238,7 +228,10 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {
238
228
edges . push ( edge ) ;
239
229
} ) ;
240
230
this . diagramData = diagramElements . concat ( edges ) ;
241
- this . generateDiagram ( ) ;
231
+
232
+ // Sometimes the DOM Element #cy is not ready when cytoscape tries to generate the diagram
233
+ // To avoid this, we use here a setTimeout()
234
+ setTimeout ( ( ) => this . generateDiagram ( ) , 0 ) ;
242
235
}
243
236
244
237
generateObjectiveSVG ( title : string , teamName : string , state : string ) : string {
0 commit comments