Compare commits

...

4 Commits

Author SHA1 Message Date
Michael Hoennig
346d350c6f experimentelles extrahieren von customer-contact.table (noch nicht korrekt) 2019-04-08 10:57:55 +02:00
Michael Hoennig
1b852707b7 separate customer-contact-table.component - routing still wrong 2019-04-05 10:16:07 +02:00
Michael Hoennig
dfa6bd2bed spike for isOwnedByLoginUser 2019-04-03 18:32:10 +02:00
Michael Hoennig
39b9a1a7dc spike for master-detail with customer and contact 2019-04-03 16:27:26 +02:00
10 changed files with 221 additions and 9 deletions

View File

@ -65,7 +65,13 @@ public class ContactQueryService extends QueryService<Contact> {
log.debug("find by criteria : {}, page: {}", criteria, page);
final Specification<Contact> specification = createSpecification(criteria);
return contactRepository.findAll(specification, page)
.map(contactMapper::toDto);
.map(contactMapper::toDto)
.map((dto) -> determineAccessRights(dto));
}
private ContactDTO determineAccessRights(ContactDTO dto) {
dto.setOwnedByLoginUser(dto.getLastName().startsWith("Owner"));
return dto;
}
/**

View File

@ -1,4 +1,5 @@
package org.hostsharing.hsadminng.service.dto;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Objects;
@ -8,6 +9,8 @@ import java.util.Objects;
*/
public class ContactDTO implements Serializable {
private boolean isOwnedByLoginUser;
private Long id;
@NotNull
@ -22,7 +25,6 @@ public class ContactDTO implements Serializable {
@Size(max = 80)
private String email;
public Long getId() {
return id;
}
@ -85,4 +87,12 @@ public class ContactDTO implements Serializable {
", email='" + getEmail() + "'" +
"}";
}
public boolean isOwnedByLoginUser() {
return isOwnedByLoginUser;
}
public void setOwnedByLoginUser(boolean ownedByLoginUser) {
isOwnedByLoginUser = ownedByLoginUser;
}
}

View File

@ -0,0 +1,61 @@
<div>
<jhi-alert></jhi-alert>
<br/>
<div class="table-responsive" *ngIf="customerContacts">
<table class="table table-striped">
<thead>
<tr jhiSort [(predicate)]="predicate" [(ascending)]="reverse" [callback]="reset.bind(this)">
<th jhiSortBy="id"><span jhiTranslate="global.field.id">ID</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="role"><span jhiTranslate="hsadminNgApp.customerContact.role">Role</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="contactEmail"><span jhiTranslate="hsadminNgApp.customerContact.contact">Contact</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="customerPrefix" *ngIf="!customerId"><span jhiTranslate="hsadminNgApp.customerContact.customer">Customer</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th>
<button id="jh-create-entity" class="btn btn-primary float-right jh-create-entity create-customer-contact" [routerLink]="['/customer-contact/new']">
<fa-icon [icon]="'plus'" [title]="'hsadminNgApp.customerContact.home.createLabel' | translate"></fa-icon>
</button>
</th>
</tr>
</thead>
<tbody infinite-scroll (scrolled)="loadPage(page + 1)" [infiniteScrollDisabled]="page >= links['last']" [infiniteScrollDistance]="0">
<tr *ngFor="let customerContact of customerContacts ;trackBy: trackId">
<td><a [routerLink]="['/customer-contact', customerContact.id, 'view' ]">{{customerContact.id}}</a></td>
<td jhiTranslate="{{'hsadminNgApp.CustomerContactRole.' + customerContact.role}}">{{customerContact.role}}</td>
<td>
<div *ngIf="customerContact.contactId">
<a [routerLink]="['/contact', customerContact.contactId , 'view' ]" >{{customerContact.contactEmail}}</a>
</div>
</td>
<td *ngIf="!customerId">
<div *ngIf="customerContact.customerId">
<a [routerLink]="['/customer', customerContact.customerId , 'view' ]" >{{customerContact.customerPrefix}}</a>
</div>
</td>
<td class="text-right">
<div class="btn-group flex-btn-group-container">
<button type="submit"
[routerLink]="['/customer-contact', customerContact.id, 'view' ]"
class="btn btn-info btn-sm">
<fa-icon [icon]="'eye'" [title]="'entity.action.view' | translate"></fa-icon>
<span *ngIf="!customerId" class="d-none d-md-inline" jhiTranslate="entity.action.view">View</span>
</button>
<button type="submit"
[routerLink]="['/customer-contact', customerContact.id, 'edit']"
class="btn btn-primary btn-sm">
<fa-icon [icon]="'pencil-alt'" [title]="'entity.action.edit' | translate"></fa-icon>
<span *ngIf="!customerId" class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
</button>
<button type="submit"
[routerLink]="['/', 'customer-contact', { outlets: { popup: customerContact.id + '/delete'} }]"
replaceUrl="true"
queryParamsHandling="merge"
class="btn btn-danger btn-sm">
<fa-icon [icon]="'times'" [title]="'entity.action.delete' | translate"></fa-icon>
<span *ngIf="!customerId" class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span>
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>

View File

@ -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<ICustomerContact[]>) => 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);
}
}

View File

@ -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

View File

@ -30,7 +30,7 @@ export class CustomerContactResolve implements Resolve<ICustomerContact> {
export const customerContactRoute: Routes = [
{
path: '',
path: '/customer-contact',
component: CustomerContactComponent,
data: {
authorities: ['ROLE_USER'],
@ -39,7 +39,7 @@ export const customerContactRoute: Routes = [
canActivate: [UserRouteAccessService]
},
{
path: ':id/view',
path: '/customer-contact/:id/view',
component: CustomerContactDetailComponent,
resolve: {
customerContact: CustomerContactResolve
@ -51,7 +51,7 @@ export const customerContactRoute: Routes = [
canActivate: [UserRouteAccessService]
},
{
path: 'new',
path: '/customer-contact/new',
component: CustomerContactUpdateComponent,
resolve: {
customerContact: CustomerContactResolve
@ -63,7 +63,7 @@ export const customerContactRoute: Routes = [
canActivate: [UserRouteAccessService]
},
{
path: ':id/edit',
path: '/customer-contact/:id/edit',
component: CustomerContactUpdateComponent,
resolve: {
customerContact: CustomerContactResolve

View File

@ -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';

View File

@ -26,6 +26,18 @@
class="btn btn-primary">
<fa-icon [icon]="'pencil-alt'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.edit"> Edit</span>
</button>
<hr/>
<jhi-customer-contact-table [customer]="customer.id"></jhi-customer-contact-table>
<!--
<hs-table referenceKey="customer" [referenceValue]="customer.id">
<hs-table-column field="role"
contactEmail
customerPrefix
</hs-table>
-->
<hr/>
</div>
</div>
</div>

View File

@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ICustomer } from 'app/shared/model/customer.model';
import { CustomerContactTableComponent } from 'app/entities/customer-contact';
@Component({
selector: 'jhi-customer-detail',
@ -10,7 +11,7 @@ import { ICustomer } from 'app/shared/model/customer.model';
export class CustomerDetailComponent implements OnInit {
customer: ICustomer;
constructor(protected activatedRoute: ActivatedRoute) {}
constructor(protected activatedRoute: ActivatedRoute, protected customerContactTableComponent: CustomerContactTableComponent) {}
ngOnInit() {
this.activatedRoute.data.subscribe(({ customer }) => {

View File

@ -3,7 +3,10 @@ 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 { CustomerContactTableComponent } from 'app/entities/customer-contact';
import {
CustomerComponent,
CustomerDetailComponent,
@ -17,7 +20,7 @@ import {
const ENTITY_STATES = [...customerRoute, ...customerPopupRoute];
@NgModule({
imports: [HsadminNgSharedModule, RouterModule.forChild(ENTITY_STATES)],
imports: [HsadminNgSharedModule, RouterModule.forChild(ENTITY_STATES), HsadminNgCustomerContactModule],
declarations: [
CustomerComponent,
CustomerDetailComponent,
@ -26,7 +29,10 @@ const ENTITY_STATES = [...customerRoute, ...customerPopupRoute];
CustomerDeletePopupComponent
],
entryComponents: [CustomerComponent, CustomerUpdateComponent, CustomerDeleteDialogComponent, CustomerDeletePopupComponent],
providers: [{ provide: JhiLanguageService, useClass: JhiLanguageService }],
providers: [
{ provide: JhiLanguageService, useClass: JhiLanguageService },
{ provide: CustomerContactTableComponent, useClass: CustomerContactTableComponent }
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class HsadminNgCustomerModule {