21 changed files with 853 additions and 77 deletions
@ -0,0 +1,57 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2019 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<form #assignToCustomerForm="ngForm" [formGroup]="assignToCustomerFormGroup" (ngSubmit)="assign()"> |
||||
|
<mat-toolbar fxLayout="row" color="primary"> |
||||
|
<h2>{{ assignToCustomerTitle | translate }}</h2> |
||||
|
<span fxFlex></span> |
||||
|
<button mat-button mat-icon-button |
||||
|
(click)="cancel()" |
||||
|
type="button"> |
||||
|
<mat-icon class="material-icons">close</mat-icon> |
||||
|
</button> |
||||
|
</mat-toolbar> |
||||
|
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> |
||||
|
</mat-progress-bar> |
||||
|
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div> |
||||
|
<div mat-dialog-content> |
||||
|
<fieldset [disabled]="isLoading$ | async"> |
||||
|
<span>{{ assignToCustomerText | translate }}</span> |
||||
|
<tb-entity-autocomplete |
||||
|
formControlName="customerId" |
||||
|
required |
||||
|
[entityType]="entityType.CUSTOMER"> |
||||
|
</tb-entity-autocomplete> |
||||
|
</fieldset> |
||||
|
</div> |
||||
|
<div mat-dialog-actions fxLayout="row"> |
||||
|
<span fxFlex></span> |
||||
|
<button mat-button mat-raised-button color="primary" |
||||
|
type="submit" |
||||
|
[disabled]="(isLoading$ | async) || assignToCustomerForm.invalid |
||||
|
|| !assignToCustomerForm.dirty"> |
||||
|
{{ 'action.assign' | translate }} |
||||
|
</button> |
||||
|
<button mat-button color="primary" |
||||
|
style="margin-right: 20px;" |
||||
|
type="button" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="cancel()" cdkFocusInitial> |
||||
|
{{ 'action.cancel' | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
</form> |
||||
@ -0,0 +1,117 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {Component, Inject, OnInit, SkipSelf} from '@angular/core'; |
||||
|
import {ErrorStateMatcher, MAT_DIALOG_DATA, MatDialogRef} from '@angular/material'; |
||||
|
import {PageComponent} from '@shared/components/page.component'; |
||||
|
import {Store} from '@ngrx/store'; |
||||
|
import {AppState} from '@core/core.state'; |
||||
|
import {FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators} from '@angular/forms'; |
||||
|
import {DeviceService} from '@core/http/device.service'; |
||||
|
import {EntityId} from '@shared/models/id/entity-id'; |
||||
|
import {EntityType} from '@shared/models/entity-type.models'; |
||||
|
import {forkJoin, Observable} from 'rxjs'; |
||||
|
|
||||
|
export interface AssignToCustomerDialogData { |
||||
|
entityIds: Array<EntityId>; |
||||
|
entityType: EntityType; |
||||
|
} |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-assign-to-customer-dialog', |
||||
|
templateUrl: './assign-to-customer-dialog.component.html', |
||||
|
providers: [{provide: ErrorStateMatcher, useExisting: AssignToCustomerDialogComponent}], |
||||
|
styleUrls: [] |
||||
|
}) |
||||
|
export class AssignToCustomerDialogComponent extends PageComponent implements OnInit, ErrorStateMatcher { |
||||
|
|
||||
|
assignToCustomerFormGroup: FormGroup; |
||||
|
|
||||
|
submitted = false; |
||||
|
|
||||
|
entityType = EntityType; |
||||
|
|
||||
|
assignToCustomerTitle: string; |
||||
|
assignToCustomerText: string; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
@Inject(MAT_DIALOG_DATA) public data: AssignToCustomerDialogData, |
||||
|
private deviceService: DeviceService, |
||||
|
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
||||
|
public dialogRef: MatDialogRef<AssignToCustomerDialogComponent, boolean>, |
||||
|
public fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.assignToCustomerFormGroup = this.fb.group({ |
||||
|
customerId: [null, [Validators.required]] |
||||
|
}); |
||||
|
switch (this.data.entityType) { |
||||
|
case EntityType.DEVICE: |
||||
|
this.assignToCustomerTitle = 'device.assign-device-to-customer'; |
||||
|
this.assignToCustomerText = 'device.assign-to-customer-text'; |
||||
|
break; |
||||
|
case EntityType.ASSET: |
||||
|
// TODO:
|
||||
|
break; |
||||
|
case EntityType.ENTITY_VIEW: |
||||
|
// TODO:
|
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { |
||||
|
const originalErrorState = this.errorStateMatcher.isErrorState(control, form); |
||||
|
const customErrorState = !!(control && control.invalid && this.submitted); |
||||
|
return originalErrorState || customErrorState; |
||||
|
} |
||||
|
|
||||
|
cancel(): void { |
||||
|
this.dialogRef.close(false); |
||||
|
} |
||||
|
|
||||
|
assign(): void { |
||||
|
this.submitted = true; |
||||
|
const customerId: string = this.assignToCustomerFormGroup.get('customerId').value; |
||||
|
const tasks: Observable<any>[] = []; |
||||
|
this.data.entityIds.forEach( |
||||
|
(entityId) => { |
||||
|
tasks.push(this.getAssignToCustomerTask(customerId, entityId.id)); |
||||
|
} |
||||
|
); |
||||
|
forkJoin(tasks).subscribe( |
||||
|
() => { |
||||
|
this.dialogRef.close(true); |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
private getAssignToCustomerTask(customerId: string, entityId: string): Observable<any> { |
||||
|
switch (this.data.entityType) { |
||||
|
case EntityType.DEVICE: |
||||
|
return this.deviceService.assignDeviceToCustomer(customerId, entityId); |
||||
|
break; |
||||
|
case EntityType.ASSET: |
||||
|
// TODO:
|
||||
|
break; |
||||
|
case EntityType.ENTITY_VIEW: |
||||
|
// TODO:
|
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { NgModule } from '@angular/core'; |
||||
|
import { CommonModule } from '@angular/common'; |
||||
|
import { SharedModule } from '@app/shared/shared.module'; |
||||
|
import {AssignToCustomerDialogComponent} from '@modules/home/dialogs/assign-to-customer-dialog.component'; |
||||
|
|
||||
|
@NgModule({ |
||||
|
entryComponents: [ |
||||
|
AssignToCustomerDialogComponent |
||||
|
], |
||||
|
declarations: |
||||
|
[ |
||||
|
AssignToCustomerDialogComponent |
||||
|
], |
||||
|
imports: [ |
||||
|
CommonModule, |
||||
|
SharedModule |
||||
|
], |
||||
|
exports: [ |
||||
|
AssignToCustomerDialogComponent |
||||
|
] |
||||
|
}) |
||||
|
export class HomeDialogsModule { } |
||||
@ -0,0 +1,72 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import {NgModule} from '@angular/core'; |
||||
|
import {RouterModule, Routes} from '@angular/router'; |
||||
|
|
||||
|
import {EntitiesTableComponent} from '@shared/components/entity/entities-table.component'; |
||||
|
import {Authority} from '@shared/models/authority.enum'; |
||||
|
import {UsersTableConfigResolver} from '../user/users-table-config.resolver'; |
||||
|
import {CustomersTableConfigResolver} from './customers-table-config.resolver'; |
||||
|
|
||||
|
const routes: Routes = [ |
||||
|
{ |
||||
|
path: 'customers', |
||||
|
data: { |
||||
|
breadcrumb: { |
||||
|
label: 'customer.customers', |
||||
|
icon: 'supervisor_account' |
||||
|
} |
||||
|
}, |
||||
|
children: [ |
||||
|
{ |
||||
|
path: '', |
||||
|
component: EntitiesTableComponent, |
||||
|
data: { |
||||
|
auth: [Authority.TENANT_ADMIN], |
||||
|
title: 'customer.customers' |
||||
|
}, |
||||
|
resolve: { |
||||
|
entitiesTableConfig: CustomersTableConfigResolver |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
path: ':customerId/users', |
||||
|
component: EntitiesTableComponent, |
||||
|
data: { |
||||
|
auth: [Authority.TENANT_ADMIN], |
||||
|
title: 'user.customer-users', |
||||
|
breadcrumb: { |
||||
|
label: 'user.customer-users', |
||||
|
icon: 'account_circle' |
||||
|
} |
||||
|
}, |
||||
|
resolve: { |
||||
|
entitiesTableConfig: UsersTableConfigResolver |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
]; |
||||
|
|
||||
|
@NgModule({ |
||||
|
imports: [RouterModule.forChild(routes)], |
||||
|
exports: [RouterModule], |
||||
|
providers: [ |
||||
|
CustomersTableConfigResolver |
||||
|
] |
||||
|
}) |
||||
|
export class CustomerRoutingModule { } |
||||
@ -0,0 +1,79 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2019 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<div class="tb-details-buttons"> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'manageUsers')" |
||||
|
[fxShow]="!isEdit && !isPublic"> |
||||
|
{{'customer.manage-users' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'manageAssets')" |
||||
|
[fxShow]="!isEdit"> |
||||
|
{{'customer.manage-assets' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'manageDevices')" |
||||
|
[fxShow]="!isEdit"> |
||||
|
{{'customer.manage-devices' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'manageDashboards')" |
||||
|
[fxShow]="!isEdit"> |
||||
|
{{'customer.manage-dashboards' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button color="primary" |
||||
|
[disabled]="(isLoading$ | async)" |
||||
|
(click)="onEntityAction($event, 'delete')" |
||||
|
[fxShow]="!hideDelete() && !isEdit && !isPublic"> |
||||
|
{{'customer.delete' | translate }} |
||||
|
</button> |
||||
|
<div fxLayout="row"> |
||||
|
<button mat-raised-button |
||||
|
ngxClipboard |
||||
|
(cbOnSuccess)="onCustomerIdCopied($event)" |
||||
|
[cbContent]="entity?.id?.id" |
||||
|
[fxShow]="!isEdit"> |
||||
|
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> |
||||
|
<span translate>customer.copyId</span> |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="mat-padding" fxLayout="column"> |
||||
|
<form #entityNgForm="ngForm" [formGroup]="entityForm"> |
||||
|
<fieldset [fxShow]="!isPublic" [disabled]="(isLoading$ | async) || !isEdit"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>customer.title</mat-label> |
||||
|
<input matInput formControlName="title" required/> |
||||
|
<mat-error *ngIf="entityForm.get('title').hasError('required')"> |
||||
|
{{ 'customer.title-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<div formGroupName="additionalInfo" fxLayout="column"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>customer.description</mat-label> |
||||
|
<textarea matInput formControlName="description" rows="2"></textarea> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<tb-contact [parentForm]="entityForm" [isEdit]="isEdit"></tb-contact> |
||||
|
</fieldset> |
||||
|
</form> |
||||
|
</div> |
||||
@ -0,0 +1,79 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { Component } from '@angular/core'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
||||
|
import { Customer } from '@shared/models/customer.model'; |
||||
|
import { ContactBasedComponent } from '@shared/components/entity/contact-based.component'; |
||||
|
import {Tenant} from '@app/shared/models/tenant.model'; |
||||
|
import {ActionNotificationShow} from '@app/core/notification/notification.actions'; |
||||
|
import {TranslateService} from '@ngx-translate/core'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-customer', |
||||
|
templateUrl: './customer.component.html' |
||||
|
}) |
||||
|
export class CustomerComponent extends ContactBasedComponent<Customer> { |
||||
|
|
||||
|
isPublic = false; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected translate: TranslateService, |
||||
|
protected fb: FormBuilder) { |
||||
|
super(store, fb); |
||||
|
} |
||||
|
|
||||
|
hideDelete() { |
||||
|
if (this.entitiesTableConfig) { |
||||
|
return !this.entitiesTableConfig.deleteEnabled(this.entity); |
||||
|
} else { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
buildEntityForm(entity: Customer): FormGroup { |
||||
|
return this.fb.group( |
||||
|
{ |
||||
|
title: [entity ? entity.title : '', [Validators.required]], |
||||
|
additionalInfo: this.fb.group( |
||||
|
{ |
||||
|
description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''] |
||||
|
} |
||||
|
) |
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
updateEntityForm(entity: Customer) { |
||||
|
this.isPublic = entity.additionalInfo && entity.additionalInfo.isPublic; |
||||
|
this.entityForm.patchValue({title: entity.title}); |
||||
|
this.entityForm.patchValue({additionalInfo: {description: entity.additionalInfo ? entity.additionalInfo.description : ''}}); |
||||
|
} |
||||
|
|
||||
|
onCustomerIdCopied(event) { |
||||
|
this.store.dispatch(new ActionNotificationShow( |
||||
|
{ |
||||
|
message: this.translate.instant('customer.idCopiedMessage'), |
||||
|
type: 'success', |
||||
|
duration: 750, |
||||
|
verticalPosition: 'bottom', |
||||
|
horizontalPosition: 'right' |
||||
|
})); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { NgModule } from '@angular/core'; |
||||
|
import { CommonModule } from '@angular/common'; |
||||
|
import { SharedModule } from '@shared/shared.module'; |
||||
|
import {CustomerComponent} from '@modules/home/pages/customer/customer.component'; |
||||
|
import {CustomerRoutingModule} from './customer-routing.module'; |
||||
|
|
||||
|
@NgModule({ |
||||
|
entryComponents: [ |
||||
|
CustomerComponent |
||||
|
], |
||||
|
declarations: [ |
||||
|
CustomerComponent |
||||
|
], |
||||
|
imports: [ |
||||
|
CommonModule, |
||||
|
SharedModule, |
||||
|
CustomerRoutingModule |
||||
|
] |
||||
|
}) |
||||
|
export class CustomerModule { } |
||||
@ -0,0 +1,105 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { Injectable } from '@angular/core'; |
||||
|
|
||||
|
import { Resolve, Router } from '@angular/router'; |
||||
|
|
||||
|
import { Tenant } from '@shared/models/tenant.model'; |
||||
|
import { |
||||
|
DateEntityTableColumn, |
||||
|
EntityTableColumn, |
||||
|
EntityTableConfig |
||||
|
} from '@shared/components/entity/entities-table-config.models'; |
||||
|
import { TranslateService } from '@ngx-translate/core'; |
||||
|
import { DatePipe } from '@angular/common'; |
||||
|
import { |
||||
|
EntityType, |
||||
|
entityTypeResources, |
||||
|
entityTypeTranslations |
||||
|
} from '@shared/models/entity-type.models'; |
||||
|
import { EntityAction } from '@shared/components/entity/entity-component.models'; |
||||
|
import {Customer} from '@app/shared/models/customer.model'; |
||||
|
import {CustomerService} from '@app/core/http/customer.service'; |
||||
|
import {CustomerComponent} from '@modules/home/pages/customer/customer.component'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class CustomersTableConfigResolver implements Resolve<EntityTableConfig<Customer>> { |
||||
|
|
||||
|
private readonly config: EntityTableConfig<Customer> = new EntityTableConfig<Customer>(); |
||||
|
|
||||
|
constructor(private customerService: CustomerService, |
||||
|
private translate: TranslateService, |
||||
|
private datePipe: DatePipe, |
||||
|
private router: Router) { |
||||
|
|
||||
|
this.config.entityType = EntityType.CUSTOMER; |
||||
|
this.config.entityComponent = CustomerComponent; |
||||
|
this.config.entityTranslations = entityTypeTranslations.get(EntityType.CUSTOMER); |
||||
|
this.config.entityResources = entityTypeResources.get(EntityType.CUSTOMER); |
||||
|
|
||||
|
this.config.columns.push( |
||||
|
new DateEntityTableColumn<Customer>('createdTime', 'customer.created-time', this.datePipe, '150px'), |
||||
|
new EntityTableColumn<Customer>('title', 'customer.title'), |
||||
|
new EntityTableColumn<Customer>('email', 'contact.email'), |
||||
|
new EntityTableColumn<Customer>('country', 'contact.country'), |
||||
|
new EntityTableColumn<Customer>('city', 'contact.city') |
||||
|
); |
||||
|
|
||||
|
this.config.cellActionDescriptors.push( |
||||
|
{ |
||||
|
name: this.translate.instant('customer.manage-customer-users'), |
||||
|
icon: 'account_circle', |
||||
|
isEnabled: (customer) => !customer.additionalInfo || !customer.additionalInfo.isPublic, |
||||
|
onAction: ($event, entity) => this.manageCustomerUsers($event, entity) |
||||
|
} |
||||
|
); |
||||
|
|
||||
|
this.config.deleteEntityTitle = customer => this.translate.instant('customer.delete-customer-title', { customerTitle: customer.title }); |
||||
|
this.config.deleteEntityContent = () => this.translate.instant('customer.delete-customer-text'); |
||||
|
this.config.deleteEntitiesTitle = count => this.translate.instant('customer.delete-customers-title', {count}); |
||||
|
this.config.deleteEntitiesContent = () => this.translate.instant('customer.delete-customers-text'); |
||||
|
|
||||
|
this.config.entitiesFetchFunction = pageLink => this.customerService.getCustomers(pageLink); |
||||
|
this.config.loadEntity = id => this.customerService.getCustomer(id.id); |
||||
|
this.config.saveEntity = customer => this.customerService.saveCustomer(customer); |
||||
|
this.config.deleteEntity = id => this.customerService.deleteCustomer(id.id); |
||||
|
this.config.onEntityAction = action => this.onCustomerAction(action); |
||||
|
} |
||||
|
|
||||
|
resolve(): EntityTableConfig<Customer> { |
||||
|
this.config.tableTitle = this.translate.instant('customer.customers'); |
||||
|
|
||||
|
return this.config; |
||||
|
} |
||||
|
|
||||
|
manageCustomerUsers($event: Event, customer: Customer) { |
||||
|
if ($event) { |
||||
|
$event.stopPropagation(); |
||||
|
} |
||||
|
this.router.navigateByUrl(`customers/${customer.id.id}/users`); |
||||
|
} |
||||
|
|
||||
|
onCustomerAction(action: EntityAction<Customer>): boolean { |
||||
|
switch (action.action) { |
||||
|
case 'manageUsers': |
||||
|
this.manageCustomerUsers(action.event, action.entity); |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue