1- import { Component , OnInit } from '@angular/core' ;
1+ import { Component , OnInit , ChangeDetectorRef } from '@angular/core' ;
22import { AdminUpdateConfigService , ConfigFile } from './admin-update-config.service' ;
33import { Observable } from 'rxjs' ;
44import { NotificationsService } from '../../shared/notifications/notifications.service' ;
@@ -46,30 +46,32 @@ export class AdminUpdateConfigComponent implements OnInit {
4646 constructor (
4747 private configService : AdminUpdateConfigService ,
4848 private notificationsService : NotificationsService ,
49- private translateService : TranslateService
49+ private translateService : TranslateService ,
50+ private cdr : ChangeDetectorRef
5051 ) { }
5152
5253 ngOnInit ( ) : void {
5354 this . loadConfigFiles ( ) ;
5455 }
5556
5657 /**
57- * Load available config files from /config/config-be/
58+ * Load available config files
5859 */
5960 loadConfigFiles ( ) : void {
6061 this . loading = true ;
6162 this . configService . getConfigFiles ( ) . subscribe ( {
6263 next : ( files ) => {
6364 this . configFiles = files ;
6465 this . loading = false ;
66+ this . cdr . detectChanges ( ) ; // Force change detection
6567 } ,
6668 error : ( error ) => {
67-
6869 this . loading = false ;
6970 this . notificationsService . error (
7071 this . translateService . instant ( 'admin.update-config.error.load-files.title' ) ,
7172 this . translateService . instant ( 'admin.update-config.error.load-files.message' )
7273 ) ;
74+ this . cdr . detectChanges ( ) ; // Force change detection
7375 }
7476 } ) ;
7577 }
@@ -82,10 +84,12 @@ export class AdminUpdateConfigComponent implements OnInit {
8284 this . selectedFile = null ;
8385 this . fileContent = '' ;
8486 this . originalContent = '' ;
87+ this . cdr . detectChanges ( ) ; // Force change detection when clearing selection
8588 return ;
8689 }
8790
8891 this . selectedFile = file ;
92+ this . cdr . detectChanges ( ) ; // Force change detection when file is selected
8993 this . loadFileContent ( file . fileName ) ;
9094 }
9195
@@ -94,17 +98,23 @@ export class AdminUpdateConfigComponent implements OnInit {
9498 */
9599 loadFileContent ( filename : string ) : void {
96100 this . loading = true ;
101+ this . cdr . detectChanges ( ) ; // Force change detection to show loading spinner
97102
98103 // Instant subscription - no delays!
99104 this . configService . getConfigFileContent ( filename ) . subscribe ( {
100105 next : ( content ) => {
101106 this . fileContent = content ;
102107 this . originalContent = content ;
103108 this . loading = false ;
109+ this . cdr . detectChanges ( ) ; // Force change detection to hide loading spinner
104110 } ,
105111 error : ( error ) => {
106112 this . loading = false ;
107- this . notificationsService . error ( 'Load Failed' , `Could not load ${ filename } ` ) ;
113+ this . notificationsService . error (
114+ this . translateService . instant ( 'admin.update-config.error.load-content.title' ) ,
115+ this . translateService . instant ( 'admin.update-config.error.load-content.message' , { fileName : filename } )
116+ ) ;
117+ this . cdr . detectChanges ( ) ; // Force change detection on error
108118 }
109119 } ) ;
110120 }
@@ -117,33 +127,36 @@ export class AdminUpdateConfigComponent implements OnInit {
117127 }
118128
119129 /**
120- * Save the current config file to /config/config-be/
130+ * Save the current config file
121131 */
122132 saveFile ( ) : void {
123133 if ( ! this . selectedFile || this . saving ) {
124134 return ;
125135 }
126136
127137 this . saving = true ;
138+ this . cdr . detectChanges ( ) ; // Force change detection to show saving state
128139
129140 this . configService . saveConfigFile ( this . selectedFile . fileName , this . fileContent ) . subscribe ( {
130141 next : ( result ) => {
131142 this . saving = false ;
132143 this . originalContent = this . fileContent ;
133144
134145 this . notificationsService . success (
135- 'File Saved Successfully!' ,
136- ` ${ this . selectedFile ?. fileName } has been updated successfully`
146+ this . translateService . instant ( 'admin.update-config.success.save.title' ) ,
147+ this . translateService . instant ( 'admin.update-config.success.save.message' , { fileName : this . selectedFile ?. fileName } )
137148 ) ;
138149
139150 this . loadConfigFiles ( ) ;
151+ this . cdr . detectChanges ( ) ; // Force change detection after save
140152 } ,
141153 error : ( error ) => {
142154 this . saving = false ;
143155 this . notificationsService . error (
144- 'Save Failed' ,
145- `Could not save ${ this . selectedFile ?. fileName } `
156+ this . translateService . instant ( 'admin.update-config.error.save.title' ) ,
157+ this . translateService . instant ( 'admin.update-config.error. save.message' , { fileName : this . selectedFile ?. fileName } )
146158 ) ;
159+ this . cdr . detectChanges ( ) ; // Force change detection on error
147160 }
148161 } ) ;
149162 }
@@ -156,14 +169,15 @@ export class AdminUpdateConfigComponent implements OnInit {
156169 }
157170
158171 /**
159- * Reset to original file (reload from config/config-be/)
172+ * Reset to original file
160173 */
161174 resetToOriginalFile ( ) : void {
162175 if ( ! this . selectedFile ) {
163176 return ;
164177 }
165178
166179 this . loading = true ;
180+ this . cdr . detectChanges ( ) ; // Force change detection to show loading state
167181
168182 this . configService . reloadOriginalContent ( this . selectedFile . fileName ) . subscribe ( {
169183 next : ( originalContent ) => {
@@ -172,13 +186,18 @@ export class AdminUpdateConfigComponent implements OnInit {
172186 this . loading = false ;
173187
174188 this . notificationsService . success (
175- 'File Reloaded!' ,
176- `Reloaded ${ this . selectedFile ?. fileName } from server`
189+ this . translateService . instant ( 'admin.update-config.success.reload.title' ) ,
190+ this . translateService . instant ( 'admin.update-config.success.reload.message' , { fileName : this . selectedFile ?. fileName } )
177191 ) ;
192+ this . cdr . detectChanges ( ) ; // Force change detection after reload
178193 } ,
179194 error : ( error ) => {
180195 this . loading = false ;
181- this . notificationsService . error ( 'Reload Failed' , 'Could not reload original file' ) ;
196+ this . notificationsService . error (
197+ this . translateService . instant ( 'admin.update-config.error.reload.title' ) ,
198+ this . translateService . instant ( 'admin.update-config.error.reload.message' )
199+ ) ;
200+ this . cdr . detectChanges ( ) ; // Force change detection on error
182201 }
183202 } ) ;
184203 }
0 commit comments