@@ -6,6 +6,9 @@ import { BehaviorSubject } from 'rxjs';
6
6
import { Location } from '@angular/common' ;
7
7
import { Router } from '@angular/router' ;
8
8
import { User } from 'src/app/domain/user' ;
9
+ import { Country } from 'src/app/domain/country' ;
10
+ import { FormGroup , FormBuilder , Validators , FormControl } from '@angular/forms' ;
11
+ import { DateValidation } from 'src/app/modules/validations/date.validation' ;
9
12
10
13
@Component ( {
11
14
selector : 'users-edit' ,
@@ -16,26 +19,58 @@ import { User } from 'src/app/domain/user';
16
19
export class UsersEditComponent {
17
20
@ViewChild ( 'panel' ) panel : ElementRef ;
18
21
19
- public user = new BehaviorSubject < User > ( null ) ;
22
+ public visible = new BehaviorSubject < Boolean > ( false ) ;
23
+ public form : FormGroup ;
24
+ public user : User = new User ;
25
+ public countries : Country [ ] = [ ] ;
20
26
public faTimes : IconDefinition = faTimes ;
21
27
22
- constructor ( private renderer : Renderer2 ,
23
- private location : Location ,
24
- private router : Router ) {
28
+ constructor (
29
+ private formBuilder : FormBuilder ,
30
+ private renderer : Renderer2 ,
31
+ private location : Location ,
32
+ private router : Router ) {
25
33
26
- this . user . subscribe ( ( user : User ) => {
27
- if ( user ) {
28
- this . renderer . addClass ( document . body , 'overflow' ) ;
29
- this . renderer . setProperty ( this . panel . nativeElement , 'scrollTop' , '0' ) ;
30
- this . location . go ( this . router . url . split ( '/' ) [ 1 ] + '/' + user . Id ) ;
31
- } else {
32
- this . renderer . removeClass ( document . body , 'overflow' ) ;
33
- this . location . go ( this . router . url . split ( '/' ) [ 1 ] ) ;
34
- }
35
- } ) ;
34
+ this . visible . subscribe ( ( visible : Boolean ) => {
35
+ if ( visible ) {
36
+ this . form = this . formBuilder . group ( {
37
+ Name : this . formBuilder . control ( {
38
+ value : this . user . Name ,
39
+ disabled : false
40
+ } , [ Validators . required ] ) ,
41
+ Email : this . formBuilder . control ( {
42
+ value : this . user . Email ,
43
+ disabled : false ,
44
+ } , [ Validators . required , Validators . email ] ) ,
45
+ Document : this . formBuilder . control ( {
46
+ value : this . user . Document ,
47
+ disabled : true
48
+ } , [ Validators . required , Validators . minLength ( 6 ) ] ) ,
49
+ Birthdate : this . formBuilder . control ( {
50
+ value : this . user . Birthdate
51
+ } , [ Validators . required , Validators . pattern ( DateValidation ) ] ) ,
52
+ Country : this . formBuilder . control ( {
53
+ value : this . user . Country
54
+ } , [ Validators . required ] ) ,
55
+ Profile : this . formBuilder . control ( {
56
+ value : this . user . Profile
57
+ } , [ Validators . required ] ) ,
58
+ Active : this . formBuilder . control ( {
59
+ value : this . user . Active
60
+ } ) ,
61
+ } ) ;
62
+
63
+ this . renderer . addClass ( document . body , 'overflow' ) ;
64
+ this . renderer . setProperty ( this . panel . nativeElement , 'scrollTop' , '0' ) ;
65
+ this . location . go ( this . router . url . split ( '/' ) [ 1 ] + '/' + this . user . Id ) ;
66
+ } else {
67
+ this . renderer . removeClass ( document . body , 'overflow' ) ;
68
+ this . location . go ( this . router . url . split ( '/' ) [ 1 ] ) ;
69
+ }
70
+ } ) ;
36
71
}
37
72
38
73
close ( ) {
39
- this . user . next ( null ) ;
74
+ this . visible . next ( false ) ;
40
75
}
41
76
}
0 commit comments