diff --git a/src/main/webapp/app/entities/customer-contact/customer-contact-table.component.html b/src/main/webapp/app/entities/customer-contact/customer-contact-table.component.html new file mode 100644 index 00000000..ac4d18d6 --- /dev/null +++ b/src/main/webapp/app/entities/customer-contact/customer-contact-table.component.html @@ -0,0 +1,66 @@ +
+

+ Customer Contacts + +

+ +
+
+ + + + + + + + + + + + + + + + + + + +
ID Role Contact Customer
{{customerContact.id}}{{customerContact.role}} + + + + +
+ + + +
+
+
+
diff --git a/src/main/webapp/app/entities/customer-contact/customer-contact-table.component.ts b/src/main/webapp/app/entities/customer-contact/customer-contact-table.component.ts new file mode 100644 index 00000000..7ed7d125 --- /dev/null +++ b/src/main/webapp/app/entities/customer-contact/customer-contact-table.component.ts @@ -0,0 +1,111 @@ +import { Component, Input, OnInit, OnDestroy } from '@angular/core'; +import { HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http'; +import { Subscription } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { JhiEventManager, JhiParseLinks, JhiAlertService } from 'ng-jhipster'; + +import { ICustomerContact } from 'app/shared/model/customer-contact.model'; +import { AccountService } from 'app/core'; + +import { ITEMS_PER_PAGE } from 'app/shared'; +import { CustomerContactService } from './customer-contact.service'; + +@Component({ + selector: 'jhi-customer-contact-table', + templateUrl: './customer-contact-table.component.html' +}) +export class CustomerContactTableComponent implements OnInit, OnDestroy { + customerContacts: ICustomerContact[]; + currentAccount: any; + eventSubscriber: Subscription; + itemsPerPage: number; + links: any; + page: any; + predicate: any; + reverse: any; + totalItems: number; + + @Input('customer') public customerId: number; + + constructor( + protected customerContactService: CustomerContactService, + protected jhiAlertService: JhiAlertService, + protected eventManager: JhiEventManager, + protected parseLinks: JhiParseLinks, + protected accountService: AccountService + ) { + this.customerContacts = []; + this.itemsPerPage = ITEMS_PER_PAGE; + this.page = 0; + this.links = { + last: 0 + }; + this.predicate = 'id'; + this.reverse = true; + } + + loadAll() { + this.customerContactService + .query({ + 'customerId.equals': this.customerId, + 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(); + } + + ngOnInit() { + this.loadAll(); + this.accountService.identity().then(account => { + this.currentAccount = account; + }); + this.registerChangeInCustomerContacts(); + } + + ngOnDestroy() { + this.eventManager.destroy(this.eventSubscriber); + } + + trackId(index: number, item: ICustomerContact) { + return item.id; + } + + registerChangeInCustomerContacts() { + this.eventSubscriber = this.eventManager.subscribe('customerContactListModification', response => this.reset()); + } + + sort() { + const result = [this.predicate + ',' + (this.reverse ? 'asc' : 'desc')]; + if (this.predicate !== 'id') { + result.push('id'); + } + return result; + } + + protected paginateCustomerContacts(data: ICustomerContact[], headers: HttpHeaders) { + this.links = this.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.jhiAlertService.error(errorMessage, null, null); + } +} diff --git a/src/main/webapp/app/entities/customer-contact/customer-contact.module.ts b/src/main/webapp/app/entities/customer-contact/customer-contact.module.ts index 4be5e7cf..078a3fed 100644 --- a/src/main/webapp/app/entities/customer-contact/customer-contact.module.ts +++ b/src/main/webapp/app/entities/customer-contact/customer-contact.module.ts @@ -6,6 +6,7 @@ import { JhiLanguageHelper } from 'app/core'; import { HsadminNgSharedModule } from 'app/shared'; import { CustomerContactComponent, + CustomerContactTableComponent, CustomerContactDetailComponent, CustomerContactUpdateComponent, CustomerContactDeletePopupComponent, @@ -18,8 +19,10 @@ const ENTITY_STATES = [...customerContactRoute, ...customerContactPopupRoute]; @NgModule({ imports: [HsadminNgSharedModule, RouterModule.forChild(ENTITY_STATES)], + exports: [CustomerContactTableComponent], declarations: [ CustomerContactComponent, + CustomerContactTableComponent, CustomerContactDetailComponent, CustomerContactUpdateComponent, CustomerContactDeleteDialogComponent, @@ -27,6 +30,7 @@ const ENTITY_STATES = [...customerContactRoute, ...customerContactPopupRoute]; ], entryComponents: [ CustomerContactComponent, + CustomerContactTableComponent, CustomerContactUpdateComponent, CustomerContactDeleteDialogComponent, CustomerContactDeletePopupComponent diff --git a/src/main/webapp/app/entities/customer-contact/index.ts b/src/main/webapp/app/entities/customer-contact/index.ts index 9e0cbba0..efc43a1f 100644 --- a/src/main/webapp/app/entities/customer-contact/index.ts +++ b/src/main/webapp/app/entities/customer-contact/index.ts @@ -1,4 +1,5 @@ export * from './customer-contact.service'; +export * from './customer-contact-table.component'; export * from './customer-contact-update.component'; export * from './customer-contact-delete-dialog.component'; export * from './customer-contact-detail.component'; 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 54f26efa..f8e979bc 100644 --- a/src/main/webapp/app/entities/customer/customer-detail.component.html +++ b/src/main/webapp/app/entities/customer/customer-detail.component.html @@ -27,57 +27,11 @@   Edit - - - - - - - - - - - - - - - - - - - -
ID Role Contact Customer
{{customerContact.id}}{{customerContact.role}} - - - - -
- - - -
-
+
+

Related Entities

+ +
+ 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 f8603b3e..fb2b04a7 100644 --- a/src/main/webapp/app/entities/customer/customer-detail.component.ts +++ b/src/main/webapp/app/entities/customer/customer-detail.component.ts @@ -1,15 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http'; -import { Subscription } from 'rxjs'; -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'; +import { ICustomer } from 'app/shared/model/customer.model'; +import { CustomerContactTableComponent } from 'app/entities/customer-contact'; @Component({ selector: 'jhi-customer-detail', @@ -18,29 +11,11 @@ import { ITEMS_PER_PAGE } from 'app/shared'; export class CustomerDetailComponent implements OnInit { customer: ICustomer; - 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; - } + constructor(protected activatedRoute: ActivatedRoute, protected customerContactTableComponent: CustomerContactTableComponent) {} ngOnInit() { this.activatedRoute.data.subscribe(({ customer }) => { this.customer = customer; - this.contacts.reset(); }); } @@ -48,67 +23,3 @@ 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); - } -} diff --git a/src/main/webapp/app/entities/customer/customer.module.ts b/src/main/webapp/app/entities/customer/customer.module.ts index 8d50348c..429782ab 100644 --- a/src/main/webapp/app/entities/customer/customer.module.ts +++ b/src/main/webapp/app/entities/customer/customer.module.ts @@ -3,6 +3,8 @@ import { RouterModule } from '@angular/router'; import { JhiLanguageService } from 'ng-jhipster'; import { JhiLanguageHelper } from 'app/core'; +import { HsadminNgCustomerContactModule } from 'app/entities/customer-contact/customer-contact.module'; + import { HsadminNgSharedModule } from 'app/shared'; import { CustomerComponent, @@ -17,7 +19,7 @@ import { const ENTITY_STATES = [...customerRoute, ...customerPopupRoute]; @NgModule({ - imports: [HsadminNgSharedModule, RouterModule.forChild(ENTITY_STATES)], + imports: [HsadminNgSharedModule, RouterModule.forChild(ENTITY_STATES), HsadminNgCustomerContactModule], declarations: [ CustomerComponent, CustomerDetailComponent,