1
- import { Component , Input , OnInit } from "@angular/core" ;
2
1
import {
3
- SortValues ,
4
- StructureCommon ,
2
+ Component ,
3
+ Input ,
4
+ OnDestroy ,
5
+ OnInit ,
6
+ TemplateRef ,
7
+ ViewChild ,
8
+ } from "@angular/core" ;
9
+ import {
5
10
USER_FONCTION_LABELS ,
6
11
UserFonction ,
12
+ SortValues ,
13
+ StructureCommon ,
7
14
UserStructureRole ,
8
15
} from "@domifa/common" ;
9
- import { Subscription } from "rxjs" ;
16
+
17
+ import { Subject , Subscription } from "rxjs" ;
10
18
import {
11
19
StructureService ,
12
20
UserStructureWithSecurity ,
13
21
} from "../../services/structure.service" ;
14
22
import { environment } from "../../../../../environments/environment" ;
15
23
import { subMonths } from "date-fns" ;
24
+ import { NgbModal , NgbModalRef } from "@ng-bootstrap/ng-bootstrap" ;
16
25
17
26
@Component ( {
18
27
selector : "app-users" ,
19
28
templateUrl : "./users.component.html" ,
20
29
styleUrl : "./users.component.css" ,
21
30
} )
22
- export class UsersComponent implements OnInit {
31
+ export class UsersComponent implements OnInit , OnDestroy {
23
32
public users : UserStructureWithSecurity [ ] = [ ] ;
24
33
public sortValue : SortValues = "asc" ;
25
34
public currentKey = "id" ;
26
35
public twoMonthsAgo = subMonths ( new Date ( ) , 2 ) ;
27
-
36
+ public reloadUsers = new Subject < void > ( ) ;
28
37
public readonly frontendUrl = environment . frontendUrl ;
29
38
public readonly USER_FONCTION = UserFonction ;
30
39
public readonly _USER_FONCTION_LABELS = USER_FONCTION_LABELS ;
@@ -34,14 +43,31 @@ export class UsersComponent implements OnInit {
34
43
simple : "Instructeur" ,
35
44
facteur : "Facteur" ,
36
45
} ;
37
-
38
46
@Input ( { required : true } ) public structure : StructureCommon ;
39
47
private subscription = new Subscription ( ) ;
40
48
public searching = true ;
49
+ @ViewChild ( "confirmPasswordReinit" , { static : true } )
50
+ public confirmPasswordReinit ! : TemplateRef < NgbModalRef > ;
41
51
42
- constructor ( private readonly structureService : StructureService ) { }
52
+ public userForPasswordReinit ?: UserStructureWithSecurity ;
53
+ constructor (
54
+ private readonly structureService : StructureService ,
55
+ private readonly modalService : NgbModal
56
+ ) { }
43
57
44
58
ngOnInit ( ) : void {
59
+ this . loadUsers ( ) ;
60
+
61
+ // Subscribe to reloadUsers subject to reload the list when triggered
62
+ this . subscription . add (
63
+ this . reloadUsers . subscribe ( ( ) => {
64
+ this . loadUsers ( ) ;
65
+ } )
66
+ ) ;
67
+ }
68
+
69
+ private loadUsers ( ) : void {
70
+ this . searching = true ;
45
71
this . subscription . add (
46
72
this . structureService . getUsers ( this . structure . id ) . subscribe ( ( users ) => {
47
73
this . users = users . map ( ( user ) => {
@@ -50,7 +76,31 @@ export class UsersComponent implements OnInit {
50
76
}
51
77
return user ;
52
78
} ) ;
79
+ this . searching = false ;
53
80
} )
54
81
) ;
55
82
}
83
+
84
+ public openConfirmationModdal ( user : UserStructureWithSecurity ) : void {
85
+ this . userForPasswordReinit = user ;
86
+ this . modalService . open ( this . confirmPasswordReinit , {
87
+ size : "s" ,
88
+ centered : true ,
89
+ } ) ;
90
+ }
91
+
92
+ public doResetPassword ( email : string ) : void {
93
+ if ( ! email ) return ;
94
+ this . subscription . add (
95
+ this . structureService
96
+ . resetStructureAdminPassword ( email )
97
+ . subscribe ( ( ) => this . reloadUsers . next ( ) )
98
+ ) ;
99
+
100
+ this . modalService . dismissAll ( ) ;
101
+ }
102
+
103
+ ngOnDestroy ( ) : void {
104
+ this . subscription . unsubscribe ( ) ;
105
+ }
56
106
}
0 commit comments