11import { Component , OnInit } from '@angular/core' ;
2- import { UntypedFormBuilder , UntypedFormGroup , UntypedFormArray , AbstractControl } from '@angular/forms' ;
2+ import { FormBuilder , FormGroup , FormArray , FormControl , AbstractControl } from '@angular/forms' ;
33import { SettingsService } from '../../service/settings/settings.service' ;
44import { GithubService , GithubReleaseInfo } from 'src/app/service/settings/github.service' ;
55import { LoaderService } from 'src/app/service/loader/data-loader.service' ;
@@ -27,6 +27,14 @@ interface RemoteReleaseCheck {
2727 latestCheckError : string | null ;
2828}
2929
30+ interface ProgressDefinitionForm {
31+ pid : FormControl < number > ;
32+ key : FormControl < string > ;
33+ score : FormControl < number > ;
34+ definition : FormControl < string > ;
35+ mandatory ?: FormControl < boolean > ;
36+ }
37+
3038@Component ( {
3139 selector : 'app-settings' ,
3240 templateUrl : './settings.component.html' ,
@@ -38,7 +46,9 @@ export class SettingsComponent implements OnInit {
3846 dataStoreMaxLevel ! : number ;
3947 selectedMaxLevel ! : number ;
4048 selectedMaxLevelCaption : String = '' ;
41- progressDefinitionsForm ! : UntypedFormGroup ;
49+ progressDefinitionsForm ! : FormGroup < {
50+ definitions : FormArray < FormGroup < ProgressDefinitionForm > > ;
51+ } > ;
4252 tempProgressDefinitions : ProgressDefinitions = { } ;
4353 editingProgressDefinitions : boolean = false ;
4454 remoteReleaseCheck : RemoteReleaseCheck = {
@@ -72,7 +82,7 @@ export class SettingsComponent implements OnInit {
7282 constructor (
7383 private loader : LoaderService ,
7484 private settings : SettingsService ,
75- private formBuilder : UntypedFormBuilder ,
85+ private formBuilder : FormBuilder ,
7686 public modal : ModalMessageComponent ,
7787 private githubService : GithubService
7888 ) { }
@@ -203,17 +213,17 @@ export class SettingsComponent implements OnInit {
203213 // === Progress Definitions ===
204214 private initProgressDefinitionsForm ( ) : void {
205215 this . progressDefinitionsForm = this . formBuilder . group ( {
206- definitions : this . formBuilder . array ( [ ] ) ,
216+ definitions : this . formBuilder . array < FormGroup < ProgressDefinitionForm > > ( [ ] ) ,
207217 } ) ;
208218 }
209219
210- get definitionsFormArray ( ) : UntypedFormArray {
211- return this . progressDefinitionsForm . get ( ' definitions' ) as UntypedFormArray ;
220+ get definitionsFormArray ( ) : FormArray < FormGroup < ProgressDefinitionForm > > {
221+ return this . progressDefinitionsForm . controls . definitions ;
212222 }
213223
214224 // Return the FormGroup for a specific index in the definitions FormArray.
215- getDefinitionGroup ( index : number ) : UntypedFormGroup {
216- return this . definitionsFormArray . at ( index ) as UntypedFormGroup ;
225+ getDefinitionGroup ( index : number ) : FormGroup < ProgressDefinitionForm > {
226+ return this . definitionsFormArray . at ( index ) ;
217227 }
218228
219229 private updateProgressDefinitionsForm ( ) : void {
@@ -226,8 +236,8 @@ export class SettingsComponent implements OnInit {
226236 key : [ key ] ,
227237 score : [ progDef . score * 100 ] ,
228238 definition : [ progDef . definition ] ,
229- mandatory : progDef . score == 1 || progDef . score == 0 ,
230- } )
239+ mandatory : [ progDef . score == 1 || progDef . score == 0 ] ,
240+ } ) as unknown as FormGroup < ProgressDefinitionForm >
231241 ) ;
232242 } ) ;
233243 }
@@ -244,7 +254,7 @@ export class SettingsComponent implements OnInit {
244254 key : [ '' ] ,
245255 score : [ score ] ,
246256 definition : [ '' ] ,
247- } )
257+ } ) as unknown as FormGroup < ProgressDefinitionForm >
248258 ) ;
249259 }
250260
@@ -273,11 +283,11 @@ export class SettingsComponent implements OnInit {
273283 const renamedItems : Array < { originalKey : string ; newKey : string ; pid : number } > = [ ] ;
274284
275285 this . definitionsFormArray . controls . forEach ( control => {
276- const formGroup = control as UntypedFormGroup ;
277- const pid = formGroup . get ( ' pid' ) ? .value ;
278- const key = formGroup . get ( ' key' ) ? .value ;
279- const score = formGroup . get ( ' score' ) ? .value / 100 ; // Convert from percentage back to decimal
280- const definition = formGroup . get ( ' definition' ) ? .value ;
286+ const formGroup = control ;
287+ const pid = formGroup . controls . pid . value ;
288+ const key = formGroup . controls . key . value ;
289+ const score = formGroup . controls . score . value / 100 ; // Convert from percentage back to decimal
290+ const definition = formGroup . controls . definition . value ;
281291
282292 if ( key && key . trim ( ) ) {
283293 // Only add if key is not empty
@@ -336,7 +346,7 @@ export class SettingsComponent implements OnInit {
336346 }
337347
338348 getFormGroupValue ( control : AbstractControl , field : string ) : any {
339- return ( control as UntypedFormGroup ) . get ( field ) ?. value ;
349+ return ( control as FormGroup ) . get ( field ) ?. value ;
340350 }
341351
342352 /**
0 commit comments