From d583c9ec47fe344a57545fe3b05d58e2add8ded0 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 3 Apr 2019 09:53:29 +0200 Subject: [PATCH 1/4] generate some Customer sample data for context="sample-data" --- src/main/resources/config/application-dev.yml | 2 +- .../20190403083735_added_entity_Customer.xml | 12 ++++++++++++ .../config/liquibase/sample-data/customers.csv | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/config/liquibase/sample-data/customers.csv diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml index f128d896..502ea108 100644 --- a/src/main/resources/config/application-dev.yml +++ b/src/main/resources/config/application-dev.yml @@ -57,7 +57,7 @@ spring: hibernate.cache.use_query_cache: false hibernate.generate_statistics: true liquibase: - contexts: dev + contexts: dev,sample-data mail: host: localhost port: 25 diff --git a/src/main/resources/config/liquibase/changelog/20190403083735_added_entity_Customer.xml b/src/main/resources/config/liquibase/changelog/20190403083735_added_entity_Customer.xml index 8b6f2eb3..40af35bc 100644 --- a/src/main/resources/config/liquibase/changelog/20190403083735_added_entity_Customer.xml +++ b/src/main/resources/config/liquibase/changelog/20190403083735_added_entity_Customer.xml @@ -33,5 +33,17 @@ + + + + + + + + + diff --git a/src/main/resources/config/liquibase/sample-data/customers.csv b/src/main/resources/config/liquibase/sample-data/customers.csv new file mode 100644 index 00000000..7981d1a8 --- /dev/null +++ b/src/main/resources/config/liquibase/sample-data/customers.csv @@ -0,0 +1,7 @@ +id;jhi_number;prefix +1;10001;aaa +2;10002;bbb +3;10003;ccc +4;10004;ddd +5;10098;abc +6;10099;bca From 301f5facd4dfea1400061707c55847842ed121e2 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 3 Apr 2019 11:53:36 +0200 Subject: [PATCH 2/4] filter Customer table --- .../entities/customer/customer.component.html | 6 ++++ .../entities/customer/customer.component.ts | 36 +++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/app/entities/customer/customer.component.html b/src/main/webapp/app/entities/customer/customer.component.html index 02824bee..d1c745cf 100644 --- a/src/main/webapp/app/entities/customer/customer.component.html +++ b/src/main/webapp/app/entities/customer/customer.component.html @@ -19,6 +19,12 @@ Prefix + + + + + + diff --git a/src/main/webapp/app/entities/customer/customer.component.ts b/src/main/webapp/app/entities/customer/customer.component.ts index a1d3ce51..b277ea6a 100644 --- a/src/main/webapp/app/entities/customer/customer.component.ts +++ b/src/main/webapp/app/entities/customer/customer.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; import { HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http'; -import { Subscription } from 'rxjs'; -import { filter, map } from 'rxjs/operators'; +import { Subscription, Subject } from 'rxjs'; +import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; import { JhiEventManager, JhiParseLinks, JhiAlertService } from 'ng-jhipster'; import { ICustomer } from 'app/shared/model/customer.model'; @@ -24,6 +24,9 @@ export class CustomerComponent implements OnInit, OnDestroy { predicate: any; reverse: any; totalItems: number; + filterValue: any; + filterValueChanged = new Subject(); + subscription: Subscription; constructor( protected customerService: CustomerService, @@ -40,11 +43,25 @@ export class CustomerComponent implements OnInit, OnDestroy { }; this.predicate = 'id'; this.reverse = true; + this.resetFilter(); + } + + resetFilter() { + this.filterValue = { + number: null, + prefix: null + }; + this.loadAll(); } loadAll() { + let criteria = { + ...(this.filterValue.number && { 'number.equals': this.filterValue.number }), + ...(this.filterValue.prefix && { 'prefix.contains': this.filterValue.prefix }) + }; this.customerService .query({ + ...criteria, page: this.page, size: this.itemsPerPage, sort: this.sort() @@ -55,6 +72,10 @@ export class CustomerComponent implements OnInit, OnDestroy { ); } + filter($event) { + this.filterValueChanged.next($event.target.value); + } + reset() { this.page = 0; this.customers = []; @@ -72,6 +93,15 @@ export class CustomerComponent implements OnInit, OnDestroy { this.currentAccount = account; }); this.registerChangeInCustomers(); + + this.subscription = this.filterValueChanged + .pipe( + debounceTime(500), + distinctUntilChanged((previous: any, current: any) => previous === current) + ) + .subscribe(() => { + this.loadAll(); + }); } ngOnDestroy() { @@ -97,6 +127,8 @@ export class CustomerComponent implements OnInit, OnDestroy { protected paginateCustomers(data: ICustomer[], headers: HttpHeaders) { this.links = this.parseLinks.parse(headers.get('link')); this.totalItems = parseInt(headers.get('X-Total-Count'), 10); + this.page = 0; + this.customers = []; for (let i = 0; i < data.length; i++) { this.customers.push(data[i]); } From d379043a4bd8784f548b619e0d238f9c8e15e33a Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 3 Apr 2019 13:40:13 +0200 Subject: [PATCH 3/4] sample data for contact and customer-contact --- src/main/jdl/customer.jdl | 1 - src/main/resources/.h2.server.properties | 1 + .../20190403083736_added_entity_Contact.xml | 13 +++++++++++++ .../20190403083737_added_entity_CustomerContact.xml | 13 +++++++++++++ .../config/liquibase/sample-data/contacts.csv | 6 ++++++ .../liquibase/sample-data/customer-contacts.csv | 8 ++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/config/liquibase/sample-data/contacts.csv create mode 100644 src/main/resources/config/liquibase/sample-data/customer-contacts.csv diff --git a/src/main/jdl/customer.jdl b/src/main/jdl/customer.jdl index 707076ea..d840ff5f 100644 --- a/src/main/jdl/customer.jdl +++ b/src/main/jdl/customer.jdl @@ -14,7 +14,6 @@ entity Contact { email String required maxlength(80) } - enum CustomerContactRole { CONTRACTUAL, TECHNICAL, diff --git a/src/main/resources/.h2.server.properties b/src/main/resources/.h2.server.properties index 085caa6d..909b4938 100644 --- a/src/main/resources/.h2.server.properties +++ b/src/main/resources/.h2.server.properties @@ -1,4 +1,5 @@ #H2 Server Properties +#Wed Apr 03 13:36:25 CEST 2019 0=JHipster H2 (Memory)|org.h2.Driver|jdbc\:h2\:mem\:hsadminng|hsadminNg webAllowOthers=true webPort=8082 diff --git a/src/main/resources/config/liquibase/changelog/20190403083736_added_entity_Contact.xml b/src/main/resources/config/liquibase/changelog/20190403083736_added_entity_Contact.xml index da4e0b9d..62bef1eb 100644 --- a/src/main/resources/config/liquibase/changelog/20190403083736_added_entity_Contact.xml +++ b/src/main/resources/config/liquibase/changelog/20190403083736_added_entity_Contact.xml @@ -37,5 +37,18 @@ + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20190403083737_added_entity_CustomerContact.xml b/src/main/resources/config/liquibase/changelog/20190403083737_added_entity_CustomerContact.xml index f9e6013b..eb08e6ae 100644 --- a/src/main/resources/config/liquibase/changelog/20190403083737_added_entity_CustomerContact.xml +++ b/src/main/resources/config/liquibase/changelog/20190403083737_added_entity_CustomerContact.xml @@ -37,5 +37,18 @@ + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/sample-data/contacts.csv b/src/main/resources/config/liquibase/sample-data/contacts.csv new file mode 100644 index 00000000..f1983b54 --- /dev/null +++ b/src/main/resources/config/liquibase/sample-data/contacts.csv @@ -0,0 +1,6 @@ +id;first_name;last_name;email +1;Paule;Müller;paule.mueller@example.com +2;Helma;Schmidt;helma.schmidt@example.com +3;Vidi;Vitt;vidi.vitt@example.com +4;Saskia;Balder;saskia@balder.example.com + diff --git a/src/main/resources/config/liquibase/sample-data/customer-contacts.csv b/src/main/resources/config/liquibase/sample-data/customer-contacts.csv new file mode 100644 index 00000000..dbc269ad --- /dev/null +++ b/src/main/resources/config/liquibase/sample-data/customer-contacts.csv @@ -0,0 +1,8 @@ +id;customer_id;jhi_role;contact_id +1;1;CONTRACTUAL;1 +2;1;TECHNICAL;1 +3;1;FINANCIAL;1 +4;2;CONTRACTUAL;1 +5;2;TECHNICAL;2 +6;2;FINANCIAL;3 + From 38244767d70a38c80407d054a157fb5cabdbdcee Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 3 Apr 2019 13:47:26 +0200 Subject: [PATCH 4/4] fix code style violation (let -> const) --- src/main/webapp/app/entities/customer/customer.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/app/entities/customer/customer.component.ts b/src/main/webapp/app/entities/customer/customer.component.ts index b277ea6a..bd1f3e49 100644 --- a/src/main/webapp/app/entities/customer/customer.component.ts +++ b/src/main/webapp/app/entities/customer/customer.component.ts @@ -55,7 +55,7 @@ export class CustomerComponent implements OnInit, OnDestroy { } loadAll() { - let criteria = { + const criteria = { ...(this.filterValue.number && { 'number.equals': this.filterValue.number }), ...(this.filterValue.prefix && { 'prefix.contains': this.filterValue.prefix }) };