1
|
import { Component, Input, OnInit } from '@angular/core';
|
2
|
import { FormBuilder } from '@angular/forms';
|
3
|
import { IPowerClient } from 'src/app/shared/models/ipower-client.interface';
|
4
|
import { SearchSystemException} from 'src/app/shared/models/request/search-system-exceptions.interface';
|
5
|
import { IpowerClientsService } from 'src/app/shared/services/administration/ipower-clients.service';
|
6
|
|
7
|
@Component({
|
8
|
selector: 'app-application-level-form',
|
9
|
templateUrl: './application-level-form.component.html',
|
10
|
styleUrls: ['./application-level-form.component.scss']
|
11
|
})
|
12
|
export class ApplicationLevelFormComponent implements OnInit {
|
13
|
|
14
|
iPowerClientNameSuggestions: any;
|
15
|
iPowerClientCodeSuggestions: any;
|
16
|
private iPowerClientSuggestions: IPowerClient[];
|
17
|
private selectedIPowerClient: IPowerClient;
|
18
|
|
19
|
searchCriteriaForm = this.fb.group({
|
20
|
processId: [null],
|
21
|
clientId: [null],
|
22
|
clientName: [null],
|
23
|
jobName: [null],
|
24
|
dmsFileCode: [null],
|
25
|
dateFrom: [null],
|
26
|
dateTo: [null],
|
27
|
});
|
28
|
|
29
|
constructor(private fb: FormBuilder, private iPowerClientsService: IpowerClientsService) { }
|
30
|
|
31
|
|
32
|
|
33
|
ngOnInit(): void {
|
34
|
}
|
35
|
|
36
|
public formValue(): SearchSystemException {
|
37
|
let formValue: SearchSystemException = {
|
38
|
processId: this.searchCriteriaForm.get('processId').value,
|
39
|
clientId: this.searchCriteriaForm.get('clientId').value,
|
40
|
jobName: this.searchCriteriaForm.get('jobName').value,
|
41
|
dmsFileCode: this.searchCriteriaForm.get('dmsFileCode').value,
|
42
|
dateFrom: this.searchCriteriaForm.get('dateFrom').value,
|
43
|
dateTo: this.searchCriteriaForm.get('dateTo').value
|
44
|
};
|
45
|
|
46
|
formValue.dateFrom = new Date(Date.UTC(formValue.dateFrom?.getFullYear(), formValue.dateFrom?.getMonth(), formValue.dateFrom?.getDate()));
|
47
|
formValue.dateTo = new Date(Date.UTC(formValue.dateTo?.getFullYear(), formValue.dateTo?.getMonth(),formValue.dateTo?.getDate() + 1));
|
48
|
formValue.dateTo?.setMilliseconds(formValue.dateTo?.getMilliseconds() -1);
|
49
|
|
50
|
|
51
|
return formValue;
|
52
|
}
|
53
|
|
54
|
/*
|
55
|
* Auto-suggest & Auto-complete IPower Client
|
56
|
*/
|
57
|
autosuggestIPowerClientName(event): void {
|
58
|
|
59
|
if (!event.query || event.query.length < 3) {
|
60
|
this.iPowerClientNameSuggestions = [];
|
61
|
return;
|
62
|
}
|
63
|
|
64
|
this.iPowerClientsService.getClientsByNameOnly(event.query).subscribe(
|
65
|
(values: IPowerClient[]) => {
|
66
|
this.iPowerClientSuggestions = values;
|
67
|
|
68
|
const temp: string[] = [];
|
69
|
values.map(val => temp.push(val.name));
|
70
|
this.iPowerClientNameSuggestions = temp;
|
71
|
},
|
72
|
err => console.error(err) // TODO: Handle this via a Messaging Service
|
73
|
);
|
74
|
}
|
75
|
|
76
|
autosuggestIPowerClientCode(event): void {
|
77
|
|
78
|
if (event.query.length < 3) {
|
79
|
this.iPowerClientCodeSuggestions = [];
|
80
|
return;
|
81
|
}
|
82
|
|
83
|
this.iPowerClientsService.getClientsByCodeOnly(event.query).subscribe(
|
84
|
(values: IPowerClient[]) => {
|
85
|
this.iPowerClientSuggestions = values;
|
86
|
|
87
|
const temp: string[] = [];
|
88
|
values.map(val => temp.push(val.clientCode));
|
89
|
this.iPowerClientCodeSuggestions = temp;
|
90
|
},
|
91
|
err => console.error(err)
|
92
|
);
|
93
|
}
|
94
|
|
95
|
iPowerClientNameSelected(name: string): void {
|
96
|
this.selectedIPowerClient = this.iPowerClientSuggestions.find(client => client.name === name);
|
97
|
this.searchCriteriaForm.get('clientId').patchValue(this.selectedIPowerClient ? this.selectedIPowerClient.clientCode : '');
|
98
|
this.searchCriteriaForm.updateValueAndValidity();
|
99
|
}
|
100
|
|
101
|
iPowerClientCodeSelected(code: string): void {
|
102
|
this.selectedIPowerClient = this.iPowerClientSuggestions.find(client => client.clientCode === code);
|
103
|
this.searchCriteriaForm.get('clientName').patchValue(this.selectedIPowerClient ? this.selectedIPowerClient.name : '');
|
104
|
this.searchCriteriaForm.updateValueAndValidity();
|
105
|
}
|
106
|
|
107
|
resetForm() {
|
108
|
this.searchCriteriaForm.reset();
|
109
|
}
|
110
|
|
111
|
}
|