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