1
1
import { EMPTY } from 'rxjs' ;
2
- import { ChangeDetectorRef } from '@angular/core' ;
3
2
import { ToastrService } from 'ngx-toastr' ;
4
3
import { ApiService } from '../api.service' ;
5
- import { UntypedFormArray , UntypedFormBuilder , UntypedFormControl , Validators } from '@angular/forms' ;
6
- import { Component , OnInit , AfterContentChecked } from '@angular/core' ;
4
+ import { FormArray , FormBuilder , FormControl , Validators , FormRecord } from '@angular/forms' ;
5
+ import { Component , OnInit } from '@angular/core' ;
7
6
import { concat , Observable , Subscription } from 'rxjs' ;
8
7
import { tap } from 'rxjs/operators' ;
9
8
import { NgbModal } from "@ng-bootstrap/ng-bootstrap" ;
@@ -14,30 +13,24 @@ import {QualityProfilesComponent} from "./quality-profiles.component";
14
13
templateUrl : './settings.component.html' ,
15
14
styleUrls : [ './settings.component.css' ]
16
15
} )
17
- export class SettingsComponent implements OnInit , AfterContentChecked {
16
+ export class SettingsComponent implements OnInit {
18
17
public users : any [ ] ;
19
- public form ;
18
+ public form : FormRecord < any > ;
20
19
public isSaving = false ;
21
20
public isLoading = false ;
22
- public isVeryingJackettIndexers = false ;
21
+ public isVerifyingJackettIndexers = false ;
23
22
public isLoadingUsers = false ;
24
23
public gitCommit = '' ;
25
24
public authenticateOpenSubtitles$ : Subscription ;
26
25
27
26
constructor (
28
27
public apiService : ApiService ,
29
28
public toastr : ToastrService ,
30
- public fb : UntypedFormBuilder ,
31
- public changeDectorRef : ChangeDetectorRef ,
29
+ public fb : FormBuilder ,
32
30
public modalService : NgbModal ,
33
31
) {
34
32
}
35
33
36
- ngAfterContentChecked ( ) {
37
- // handles form "required" dynamically changing after lifecycle check
38
- this . changeDectorRef . detectChanges ( ) ;
39
- }
40
-
41
34
ngOnInit ( ) {
42
35
const settings = this . apiService . settings || { } ;
43
36
this . form = this . fb . group ( {
@@ -60,7 +53,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
60
53
'exclusions' : [ settings [ 'keyword_search_filters' ] ? Object . keys ( settings [ 'keyword_search_filters' ] ) : [ ] ] ,
61
54
'enable_video_detection' : [ settings [ 'enable_video_detection' ] , Validators . required ] ,
62
55
'language' : [ settings [ 'language' ] , Validators . required ] ,
63
- 'users' : new UntypedFormArray ( [ ] ) ,
56
+ 'users' : new FormArray ( [ ] ) ,
64
57
'apprise_notification_url' : [ settings [ 'apprise_notification_url' ] ] ,
65
58
'preferred_media_category' : [ settings [ 'preferred_media_category' ] , Validators . required ] ,
66
59
'stuck_download_handling_enabled' : [ settings [ 'stuck_download_handling_enabled' ] , Validators . required ] ,
@@ -76,9 +69,9 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
76
69
password : '' ,
77
70
} ;
78
71
Object . keys ( user ) . forEach ( ( key ) => {
79
- controls [ key ] = new UntypedFormControl ( user [ key ] ) ;
72
+ controls [ key ] = new FormControl ( user [ key ] ) ;
80
73
} ) ;
81
- this . form . get ( ' users' ) . insert ( 0 , this . fb . group ( controls ) ) ;
74
+ this . form . controls . users . insert ( 0 , this . fb . group ( controls ) ) ;
82
75
} ) ;
83
76
} , ( error ) => {
84
77
this . toastr . error ( 'An unknown error occurred loading users' ) ;
@@ -97,7 +90,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
97
90
}
98
91
99
92
public hasExclusions ( ) : boolean {
100
- const exclusions = this . form . get ( ' exclusions' ) . value ;
93
+ const exclusions = this . form . controls . exclusions . value ;
101
94
return exclusions && exclusions . length ;
102
95
}
103
96
@@ -126,7 +119,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
126
119
}
127
120
128
121
public addUser ( ) {
129
- this . form . get ( ' users' ) . push ( this . fb . group ( {
122
+ this . form . controls . users . push ( this . fb . group ( {
130
123
username : [ '' , Validators . required ] ,
131
124
password : [ '' , Validators . required ] ,
132
125
can_immediately_watch_movies : [ false ] ,
@@ -136,7 +129,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
136
129
137
130
public saveUser ( index : number ) {
138
131
139
- const userControl = this . form . get ( ' users' ) . controls [ index ] ;
132
+ const userControl = this . form . controls . users . controls [ index ] ;
140
133
if ( ! userControl . valid ) {
141
134
this . toastr . error ( 'Please supply all required fields for this user' ) ;
142
135
return ;
@@ -157,7 +150,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
157
150
this . apiService . createUser ( userControl . value . username , userControl . value . password ) . subscribe (
158
151
( data ) => {
159
152
this . toastr . success ( `Added ${ userControl . value . username } ` ) ;
160
- this . form . get ( ' users' ) . at ( index ) . addControl ( 'id' , new UntypedFormControl ( data . id ) ) ;
153
+ this . form . controls . users . at ( index ) . addControl ( 'id' , new FormControl ( data . id ) ) ;
161
154
} ,
162
155
( error ) => {
163
156
this . toastr . error ( `An unknown error occurred adding user ${ userControl . value . username } ` ) ;
@@ -168,11 +161,11 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
168
161
}
169
162
170
163
public removeUser ( index : number ) {
171
- const userControl = this . form . get ( ' users' ) . controls [ index ] ;
164
+ const userControl = this . form . controls . users . controls [ index ] ;
172
165
this . apiService . deleteUser ( userControl . value . id ) . subscribe (
173
166
( data ) => {
174
167
this . toastr . success ( `Successfully deleted ${ userControl . value . username } ` ) ;
175
- this . form . get ( ' users' ) . removeAt ( index ) ;
168
+ this . form . controls . users . removeAt ( index ) ;
176
169
} ,
177
170
( error ) => {
178
171
this . toastr . error ( `An unknown error occurred deleting user ${ userControl . value . username } ` ) ;
@@ -182,7 +175,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
182
175
}
183
176
184
177
public canDeleteUser ( index : number ) {
185
- const userControl = this . form . get ( ' users' ) . controls [ index ] ;
178
+ const userControl = this . form . controls . users . controls [ index ] ;
186
179
return userControl . get ( 'id' ) && this . apiService . user . id !== userControl . get ( 'id' ) . value ;
187
180
}
188
181
@@ -375,7 +368,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
375
368
}
376
369
377
370
protected _verifyJackettIndexers ( ) {
378
- this . isVeryingJackettIndexers = true ;
371
+ this . isVerifyingJackettIndexers = true ;
379
372
this . apiService . verifyJackettIndexers ( ) . subscribe (
380
373
( data : any [ ] ) => {
381
374
const failedIndexers = data . filter ( ( indexer : any ) => {
@@ -388,11 +381,11 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
388
381
} else {
389
382
this . toastr . success ( 'All indexers were successful' ) ;
390
383
}
391
- this . isVeryingJackettIndexers = false ;
384
+ this . isVerifyingJackettIndexers = false ;
392
385
} ,
393
386
( error ) => {
394
387
this . toastr . error ( 'An unknown error occurred verifying jackett indexers' ) ;
395
- this . isVeryingJackettIndexers = false ;
388
+ this . isVerifyingJackettIndexers = false ;
396
389
} ,
397
390
) ;
398
391
}
0 commit comments