-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.component.ts
More file actions
105 lines (94 loc) · 3.31 KB
/
app.component.ts
File metadata and controls
105 lines (94 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
import { Component, ViewContainerRef } from "@angular/core";
import { OnInit } from "@angular/core";
import { PostService } from "./services/post.service";
import { debuglog } from "util";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { Customer, CustomerTransaction, Post } from "./model/post.model";
import { NotFoundError } from "./error-handling/not-found-error";
import { BadInputError } from "./error-handling/bad-input-error";
import { AppError } from "./error-handling/app-error";
import { ToastsManager } from "ng2-toastr/ng2-toastr";
import { BrowserModule } from "@angular/platform-browser";
import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
posts: Post[];
post: Post = new Post();
customer: Customer[];
customerDetails: Customer;
customerTransactionDetails: CustomerTransaction[]=[];
emailValidationForm: FormGroup;
customerDisplay: Customer[];
constructor(
private services: PostService,
vcr: ViewContainerRef, private formBuilder:FormBuilder
) {
}
ngOnInit() {
this.emailValidationForm = this.formBuilder.group({
email: ['', [Validators.required]]
});
this.emailValidationForm.valueChanges.subscribe((data) => {
this.displayFilter(data);
});
this.services.getAll().subscribe((response: Customer[]) => {
// this.posts = response;
this.customer = response;
this.customerDisplay = response;
});
}
displayFilter(data) {
if (this.customer && this.customer.length > 0) {
this.customerDisplay = this.transform(this.customer,data.email);
} else {
this.customerDisplay = this.customer;
}
}
transform(items: any[], searchText: string): any[] {
if (!items) {
return [];
}
if (!searchText) {
return items;
}
searchText = searchText.toLowerCase();
return items.filter(it => {
return it.CustomerFirstName.toLowerCase().includes(searchText);
});
}
// logValidationErrors(group: FormGroup = this.parent): void {
// Object.keys(group.controls).forEach((key: string) => {
// const abstractControl = group.get(key);
// this.formErrors[key] = '';
// if (abstractControl && !abstractControl.valid &&
// (abstractControl.touched || abstractControl.dirty || abstractControl.value !== '')) {
// const messages = this.validationMessages[key];
// for (const errorKey in abstractControl.errors) {
// if (errorKey) {
// this.formErrors[key] = messages[errorKey] + ' ';
// }
// }
// }
// if (abstractControl instanceof FormGroup) {
// this.logValidationErrors(abstractControl);
// }
// });
// }
// private _filter(value: string): StreetType[] {
// if (value && value.length >= 3) {
// const filterValue = this._normalizeValue(value);
// return this.streetTypeData.filter(streetType => this._normalizeValue(streetType.name).includes(filterValue));
// } else {
// return [];
// }
// }
getCustomerDetails(customerId: number) {
this.services.getCustomerDetails(customerId).subscribe((response) => {
this.customerTransactionDetails = response;
})
}
}