Newer
Older
import { Component, OnInit } from '@angular/core';
import { SignaturesContentService } from '../../service/signatures.service';
import { NotificationService } from '../../service/notification.service';
import { HttpClient } from '@angular/common/http';
import { MatDialog } from '@angular/material';
import { map, finalize } from 'rxjs/operators';
import { ActivatedRoute, Router } from '@angular/router';
import { ConfirmComponent } from '../../plugins/confirm.component';
import { TranslateService } from '@ngx-translate/core';
export interface Ldap {
id: string;
label: string;
description: string;
}
@Component({
selector: 'app-administration-ldap',
templateUrl: 'ldap.component.html',
styleUrls: ['../administration.scss', 'ldap.component.scss'],
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
})
export class LdapComponent implements OnInit {
creationMode: boolean = true;
loading: boolean = true;
ldap: Ldap;
ldapClone: Ldap;
title: string = '';
constructor(public http: HttpClient, private translate: TranslateService, private route: ActivatedRoute, private router: Router, public signaturesService: SignaturesContentService, public notificationService: NotificationService, public dialog: MatDialog) {
}
ngOnInit(): void {
this.route.params.subscribe((params: any) => {
if (params['id'] === undefined) {
this.creationMode = true;
this.title = this.translate.instant('lang.ldapCreation');
this.ldap = {
id: '',
label: '',
description: ''
};
this.loading = false;
} else {
this.creationMode = false;
this.http.get('../rest/ldaps/' + params['id'])
.pipe(
map((data: any) => data.ldap),
finalize(() => this.loading = false)
)
.subscribe({
next: data => {
this.ldap = data;
this.ldapClone = JSON.parse(JSON.stringify(this.ldap));
this.title = this.ldap.label;
},
});
}
});
}
canValidate() {
if (JSON.stringify(this.ldap) === JSON.stringify(this.ldapClone)) {
return false;
} else {
return true;
}
}
onSubmit() {
if (this.creationMode) {
this.createLdap();
} else {
this.modifyLdap();
}
}
modifyLdap() {
this.loading = true;
this.http.put('../rest/ldaps/' + this.ldap.id, this.ldap)
.pipe(
finalize(() => this.loading = false)
)
.subscribe({
next: () => {
this.router.navigate(['/administration/ldaps']);
this.notificationService.success('lang.ldapUpdated');
},
});
}
createLdap() {
this.loading = true;
this.http.post('../rest/ldaps', this.ldap)
.pipe(
finalize(() => this.loading = false)
)
.subscribe({
next: () => {
this.router.navigate(['/administration/ldaps']);
this.notificationService.success('lang.ldapAdded');
},
});
}
delete() {
const dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false });
dialogRef.afterClosed().subscribe(result => {
if (result === 'yes') {
this.loading = true;
this.http.delete('../rest/ldaps/' + this.ldap.id)
.pipe(
finalize(() => this.loading = false)
)
.subscribe({
next: () => {
this.router.navigate(['/administration/ldaps']);
this.notificationService.success('lang.ldapDeleted');
},
});
}
});
}
cancel() {
this.router.navigate(['/administration/ldaps']);
}
}