7
7
* This file is part of the OperatorFabric project.
8
8
*/
9
9
10
- import { Component , EventEmitter , Input , OnChanges , OnDestroy , Output , TemplateRef , ViewChild } from '@angular/core' ;
10
+ import {
11
+ Component ,
12
+ EventEmitter ,
13
+ Input ,
14
+ OnChanges ,
15
+ OnDestroy ,
16
+ OnInit ,
17
+ Output ,
18
+ TemplateRef ,
19
+ ViewChild
20
+ } from '@angular/core' ;
11
21
import { NgbModal , NgbModalOptions , NgbModalRef } from '@ng-bootstrap/ng-bootstrap' ;
12
22
import { Card } from '@ofModel/card.model' ;
13
23
import { MessageLevel } from '@ofModel/message.model' ;
@@ -38,10 +48,11 @@ import {CardTemplateGateway} from '@ofServices/templateGateway/CardTemplateGatew
38
48
standalone : true ,
39
49
imports : [ NgIf , TranslateModule , UserCardComponent , SpinnerComponent ]
40
50
} )
41
- export class CardActionsComponent implements OnChanges , OnDestroy {
51
+ export class CardActionsComponent implements OnInit , OnChanges , OnDestroy {
42
52
@Input ( ) card : Card ;
43
53
@Input ( ) cardState : State ;
44
54
@Input ( ) parentModalRef : NgbModalRef ;
55
+ @Input ( ) templateInitialized : EventEmitter < void > ;
45
56
46
57
@Output ( ) closeCardDetail : EventEmitter < boolean > = new EventEmitter < boolean > ( ) ;
47
58
@@ -62,21 +73,15 @@ export class CardActionsComponent implements OnChanges, OnDestroy {
62
73
private readonly router : Router
63
74
) { }
64
75
65
- ngOnChanges ( ) : void {
66
- // We need to register this function each time we have a change
67
- // as this change can trigger a rendering of the card which in turn
68
- // initialize the template gateway and unregister the function.
69
- // This initialization is done in the template rendering compornent
70
- // This is a temporary fix to avoid the issue
71
- //
72
- // TODO : find a better way to handle this as this solution works only because the ngOnchanges of
73
- // the card-actions component is called after the ngOnchanges of the template-rendering Component
74
- // which is not guaranteed to be the case in the future as it depends of angular change detection mechanism
75
- //
76
- CardTemplateGateway . registerFunctionToEditCard ( ( ) => {
77
- if ( this . doesTheUserHavePermissionToEditCard ( ) ) this . editCard ( ) ;
78
- } ) ;
76
+ ngOnInit ( ) : void {
77
+ this . templateInitialized . subscribe ( ( ) =>
78
+ CardTemplateGateway . registerFunctionToEditCard ( ( ) => {
79
+ if ( this . doesTheUserHavePermissionToEditCard ( ) ) this . editCard ( ) ;
80
+ } )
81
+ ) ;
82
+ }
79
83
84
+ ngOnChanges ( ) : void {
80
85
this . setButtonsVisibility ( ) ;
81
86
}
82
87
0 commit comments