-
Notifications
You must be signed in to change notification settings - Fork 265
/
Copy pathclaim.component.ts
84 lines (75 loc) · 2.29 KB
/
claim.component.ts
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
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
import { JhiEventManager, JhiParseLinks, JhiPaginationUtil, JhiLanguageService, JhiAlertService } from 'ng-jhipster';
import { Claim } from './claim.model';
import { ClaimService } from './claim.service';
import { ITEMS_PER_PAGE, Principal, ResponseWrapper } from '../../shared';
import { PaginationConfig } from '../../core/config/uib-pagination.config';
@Component({
selector: 'jhi-claim',
templateUrl: './claim.component.html'
})
export class ClaimComponent implements OnInit, OnDestroy {
claims: Claim[];
currentAccount: any;
eventSubscriber: Subscription;
currentSearch: string;
constructor(
private claimService: ClaimService,
private alertService: JhiAlertService,
private eventManager: JhiEventManager,
private activatedRoute: ActivatedRoute,
private principal: Principal
) {
this.currentSearch = activatedRoute.snapshot.params['search'] ? activatedRoute.snapshot.params['search'] : '';
}
loadAll() {
if (this.currentSearch) {
this.claimService.search({
query: this.currentSearch,
}).subscribe(
(res: ResponseWrapper) => this.claims = res.json,
(res: ResponseWrapper) => this.onError(res.json)
);
return;
}
this.claimService.query().subscribe(
(res: ResponseWrapper) => {
this.claims = res.json;
this.currentSearch = '';
},
(res: ResponseWrapper) => this.onError(res.json)
);
}
search(query) {
if (!query) {
return this.clear();
}
this.currentSearch = query;
this.loadAll();
}
clear() {
this.currentSearch = '';
this.loadAll();
}
ngOnInit() {
this.loadAll();
this.principal.identity().then((account) => {
this.currentAccount = account;
});
this.registerChangeInClaims();
}
ngOnDestroy() {
this.eventManager.destroy(this.eventSubscriber);
}
trackId(index: number, item: Claim) {
return item.id;
}
registerChangeInClaims() {
this.eventSubscriber = this.eventManager.subscribe('claimListModification', (response) => this.loadAll());
}
private onError(error) {
this.alertService.error(error.message, null, null);
}
}