diff --git a/src/main/webapp/app/entities/customer/customer-detail.component.html b/src/main/webapp/app/entities/customer/customer-detail.component.html index 9586d033..54f26efa 100644 --- a/src/main/webapp/app/entities/customer/customer-detail.component.html +++ b/src/main/webapp/app/entities/customer/customer-detail.component.html @@ -26,6 +26,58 @@ class="btn btn-primary">   Edit + + + + + + + + + + + + + + + + + + + + +
ID Role Contact Customer
{{customerContact.id}}{{customerContact.role}} +
+ {{customerContact.contactEmail}} +
+
+
+ {{customerContact.customerPrefix}} +
+
+
+ + + +
+
diff --git a/src/main/webapp/app/entities/customer/customer-detail.component.ts b/src/main/webapp/app/entities/customer/customer-detail.component.ts index da1b94e3..f8603b3e 100644 --- a/src/main/webapp/app/entities/customer/customer-detail.component.ts +++ b/src/main/webapp/app/entities/customer/customer-detail.component.ts @@ -1,7 +1,15 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; +import { HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http'; +import { Subscription } from 'rxjs'; -import { ICustomer } from 'app/shared/model/customer.model'; +import { JhiEventManager, JhiParseLinks, JhiAlertService } from 'ng-jhipster'; + +import { Customer, ICustomer } from 'app/shared/model/customer.model'; +import { ICustomerContact } from 'app/shared/model/customer-contact.model'; +import { CustomerContactService } from 'app/entities/customer-contact'; +import { AccountService } from 'app/core'; +import { ITEMS_PER_PAGE } from 'app/shared'; @Component({ selector: 'jhi-customer-detail', @@ -10,11 +18,29 @@ import { ICustomer } from 'app/shared/model/customer.model'; export class CustomerDetailComponent implements OnInit { customer: ICustomer; - constructor(protected activatedRoute: ActivatedRoute) {} + contacts: CustomerPager; + + constructor( + protected activatedRoute: ActivatedRoute, + public jhiAlertService: JhiAlertService, + public parseLinks: JhiParseLinks, + public customerContactService: CustomerContactService + ) { + this.contacts = new CustomerPager(this); + this.contacts.customerContacts = []; + this.contacts.itemsPerPage = ITEMS_PER_PAGE; + this.contacts.page = 0; + this.contacts.links = { + last: 0 + }; + this.contacts.predicate = 'id'; + this.contacts.reverse = true; + } ngOnInit() { this.activatedRoute.data.subscribe(({ customer }) => { this.customer = customer; + this.contacts.reset(); }); } @@ -22,3 +48,67 @@ export class CustomerDetailComponent implements OnInit { window.history.back(); } } + +class CustomerPager { + constructor(private master: CustomerDetailComponent) {} + + customerContacts: ICustomerContact[]; + currentAccount: any; + eventSubscriber: Subscription; + itemsPerPage: number; + links: any; + page: any; + predicate: any; + reverse: any; + totalItems: number; + + loadAll() { + debugger; + this.master.customerContactService + .query({ + 'customerId.equals': this.master.customer.id, + page: this.page, + size: this.itemsPerPage, + sort: this.sort() + }) + .subscribe( + (res: HttpResponse) => this.paginateCustomerContacts(res.body, res.headers), + (res: HttpErrorResponse) => this.onError(res.message) + ); + } + + reset() { + this.page = 0; + this.customerContacts = []; + this.loadAll(); + } + + loadPage(page) { + this.page = page; + this.loadAll(); + } + + sort() { + const result = [this.predicate + ',' + (this.reverse ? 'asc' : 'desc')]; + if (this.predicate !== 'id') { + result.push('id'); + } + return result; + } + + trackId(index: number, item: ICustomerContact) { + return item.id; + } + + protected paginateCustomerContacts(data: ICustomerContact[], headers: HttpHeaders) { + this.links = this.master.parseLinks.parse(headers.get('link')); + this.totalItems = parseInt(headers.get('X-Total-Count'), 10); + for (let i = 0; i < data.length; i++) { + this.customerContacts.push(data[i]); + } + } + + protected onError(errorMessage: string) { + this.master.jhiAlertService.error(errorMessage, null, null); + } +}