1
|
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
|
2
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
3
|
import { UserAutoComplete } from 'src/app/shared/models/response/user-autocomplete.interface';
|
4
|
import { UsersService } from 'src/app/shared/services/roles-users-management/user.service';
|
5
|
import { ErrorHandlingService } from 'src/app/shared/services/error-handling/error-handling.service';
|
6
|
import { ApiService } from '.././../../../shared/services/api.service';
|
7
|
|
8
|
@Component({
|
9
|
selector: 'app-search-user',
|
10
|
templateUrl: './search-user.component.html',
|
11
|
styleUrls: ['./search-user.component.scss']
|
12
|
})
|
13
|
export class SearchUserComponent implements OnInit {
|
14
|
searchCriteriaForm: FormGroup;
|
15
|
userSuggestions: string[];
|
16
|
userSuggestion: UserAutoComplete[];
|
17
|
|
18
|
constructor(
|
19
|
private fb: FormBuilder,
|
20
|
private errorHandlingService: ErrorHandlingService,
|
21
|
private userservice: UsersService
|
22
|
) { }
|
23
|
|
24
|
ngOnInit(): void {
|
25
|
this.searchCriteriaForm = this.fb.group({
|
26
|
userCode: [null],
|
27
|
name: [null],
|
28
|
surname: [null],
|
29
|
email: [null],
|
30
|
status: [null]
|
31
|
});
|
32
|
}
|
33
|
|
34
|
autoSuggestUserCode(event) {
|
35
|
if (!event.query || event.query.length < 3) {
|
36
|
this.userSuggestions = [];
|
37
|
return;
|
38
|
}
|
39
|
this.userservice.getUserCodeAutoComplete(event.query).subscribe(
|
40
|
(values: UserAutoComplete[]) => {
|
41
|
let temp: string[] = [];
|
42
|
this.userSuggestion = values;
|
43
|
values.map(val => temp.push(val.id));
|
44
|
this.userSuggestions = temp
|
45
|
},
|
46
|
err => this.errorHandlingService.showHttpResponseError(err)
|
47
|
);
|
48
|
}
|
49
|
|
50
|
autoSuggestName(event) {
|
51
|
if (!event.query || event.query.length < 3) {
|
52
|
this.userSuggestions = [];
|
53
|
return;
|
54
|
}
|
55
|
this.userservice.getUserNameAutocomplete(event.query).subscribe(
|
56
|
(values: UserAutoComplete[]) => {
|
57
|
let temp: string[] = [];
|
58
|
this.userSuggestion = values;
|
59
|
values.map(val => temp.push(val.name));
|
60
|
this.userSuggestions = temp
|
61
|
},
|
62
|
err => this.errorHandlingService.showHttpResponseError(err)
|
63
|
);
|
64
|
}
|
65
|
|
66
|
autoSuggestSurname(event) {
|
67
|
if (!event.query || event.query.length < 3) {
|
68
|
this.userSuggestions = [];
|
69
|
return;
|
70
|
}
|
71
|
this.userservice.getUserSurnameAutoComplete(event.query).subscribe(
|
72
|
(values: UserAutoComplete[]) => {
|
73
|
let temp: string[] = [];
|
74
|
this.userSuggestion = values;
|
75
|
values.map(val => temp.push(val.surname));
|
76
|
this.userSuggestions = temp
|
77
|
},
|
78
|
err => this.errorHandlingService.showHttpResponseError(err)
|
79
|
);
|
80
|
}
|
81
|
|
82
|
autoSuggestEmail(event) {
|
83
|
if (!event.query || event.query.length < 3) {
|
84
|
this.userSuggestions = [];
|
85
|
return;
|
86
|
}
|
87
|
this.userservice.getUserEmailAutoComplete(event.query).subscribe(
|
88
|
(values: UserAutoComplete[]) => {
|
89
|
let temp: string[] = [];
|
90
|
this.userSuggestion = values;
|
91
|
values.map(val => temp.push(val.email));
|
92
|
this.userSuggestions = temp
|
93
|
},
|
94
|
err => this.errorHandlingService.showHttpResponseError(err)
|
95
|
);
|
96
|
}
|
97
|
|
98
|
resetForm() {
|
99
|
this.searchCriteriaForm.reset();
|
100
|
}
|
101
|
|
102
|
|
103
|
|
104
|
}
|