1- import { Component , OnInit , Input , Output , EventEmitter , forwardRef , OnChanges } from '@angular/core' ;
1+ import { Component , OnInit , Input , Output , EventEmitter , forwardRef , OnChanges , OnDestroy } from '@angular/core' ;
22import { CommonModule } from '@angular/common' ;
33import { FormGroup , ReactiveFormsModule } from '@angular/forms' ;
44import { ReferenceComponent } from '../reference/reference.component' ;
55import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component' ;
6+ import { IdleDetectionService } from '../../../_services/idle-detection.service' ;
7+ import { ServerConfigService } from '../../../_services/server-config.service' ;
68
79@Component ( {
810 selector : 'app-assignment-card' ,
@@ -11,7 +13,7 @@ import { ComponentMapperComponent } from '../../../_bridge/component-mapper/comp
1113 standalone : true ,
1214 imports : [ CommonModule , ReactiveFormsModule , forwardRef ( ( ) => ComponentMapperComponent ) ]
1315} )
14- export class AssignmentCardComponent implements OnInit , OnChanges {
16+ export class AssignmentCardComponent implements OnInit , OnChanges , OnDestroy {
1517 @Input ( ) pConn$ : typeof PConnect ;
1618 @Input ( ) formGroup$ : FormGroup ;
1719 @Input ( ) arMainButtons$ : any [ ] ;
@@ -21,19 +23,44 @@ export class AssignmentCardComponent implements OnInit, OnChanges {
2123
2224 @Output ( ) actionButtonClick : EventEmitter < any > = new EventEmitter ( ) ;
2325
26+ constructor (
27+ private idleService : IdleDetectionService ,
28+ private scservice : ServerConfigService
29+ ) { }
30+
2431 ngOnInit ( ) : void {
25- // Children may contain 'reference' component, so we need to
26- // normalize them
32+ // Children may contain 'reference' component, so we need to normalize them
2733 this . arChildren$ = ReferenceComponent . normalizePConnArray ( this . arChildren$ ) ;
34+
35+ this . checkAndEnableAutoSave ( ) ;
2836 }
2937
3038 ngOnChanges ( ) {
31- // Children may contain 'reference' component, so we need to
32- // normalize them
39+ // Children may contain 'reference' component, so we need to normalize them
3340 this . arChildren$ = ReferenceComponent . normalizePConnArray ( this . arChildren$ ) ;
3441 }
3542
43+ ngOnDestroy ( ) {
44+ this . idleService . stopWatching ( ) ;
45+ }
46+
47+ async checkAndEnableAutoSave ( ) {
48+ const sdkConfig = await this . scservice . getSdkConfig ( ) ;
49+ const autoSave = sdkConfig . serverConfig . autoSave ;
50+
51+ if ( autoSave ) {
52+ this . idleService . startWatching ( ( ) => this . autoSave ( ) , autoSave ) ;
53+ }
54+ }
55+
3656 onActionButtonClick ( oData : any ) {
3757 this . actionButtonClick . emit ( oData ) ;
3858 }
59+
60+ autoSave ( ) {
61+ const context = this . pConn$ . getContextName ( ) ;
62+ if ( PCore . getFormUtils ( ) . isStateModified ( context ) ) {
63+ this . pConn$ . getActionsApi ( ) . saveAssignment ( context ) ;
64+ }
65+ }
3966}
0 commit comments