2019-08-15 14:48:14 +03:00
|
|
|
///
|
2020-02-20 10:26:43 +02:00
|
|
|
/// Copyright © 2016-2020 The Thingsboard Authors
|
2019-08-15 14:48:14 +03:00
|
|
|
///
|
|
|
|
|
/// 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 {
|
|
|
|
|
DateEntityTableColumn,
|
|
|
|
|
EntityTableColumn,
|
|
|
|
|
EntityTableConfig
|
2019-08-21 18:18:46 +03:00
|
|
|
} from '@home/models/entity/entities-table-config.models';
|
2019-08-15 14:48:14 +03:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
|
import { DatePipe } from '@angular/common';
|
2020-04-02 11:01:13 +03:00
|
|
|
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
|
2019-08-21 18:18:46 +03:00
|
|
|
import { EntityAction } from '@home/models/entity/entity-component.models';
|
2020-04-02 11:01:13 +03:00
|
|
|
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';
|
2019-08-22 13:34:15 +03:00
|
|
|
import { CustomerTabsComponent } from '@home/pages/customer/customer-tabs.component';
|
2019-08-15 14:48:14 +03:00
|
|
|
|
|
|
|
|
@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;
|
2019-08-22 13:34:15 +03:00
|
|
|
this.config.entityTabsComponent = CustomerTabsComponent;
|
2019-08-15 14:48:14 +03:00
|
|
|
this.config.entityTranslations = entityTypeTranslations.get(EntityType.CUSTOMER);
|
|
|
|
|
this.config.entityResources = entityTypeResources.get(EntityType.CUSTOMER);
|
|
|
|
|
|
|
|
|
|
this.config.columns.push(
|
2020-04-02 11:01:13 +03:00
|
|
|
new DateEntityTableColumn<Customer>('createdTime', 'common.created-time', this.datePipe, '150px'),
|
2020-01-24 19:05:41 +02:00
|
|
|
new EntityTableColumn<Customer>('title', 'customer.title', '25%'),
|
|
|
|
|
new EntityTableColumn<Customer>('email', 'contact.email', '25%'),
|
|
|
|
|
new EntityTableColumn<Customer>('country', 'contact.country', '25%'),
|
|
|
|
|
new EntityTableColumn<Customer>('city', 'contact.city', '25%')
|
2019-08-15 14:48:14 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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)
|
2019-08-15 20:39:56 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('customer.manage-customer-assets'),
|
|
|
|
|
nameFunction: (customer) => {
|
|
|
|
|
return customer.additionalInfo && customer.additionalInfo.isPublic
|
|
|
|
|
? this.translate.instant('customer.manage-public-assets')
|
|
|
|
|
: this.translate.instant('customer.manage-customer-assets');
|
|
|
|
|
},
|
|
|
|
|
icon: 'domain',
|
|
|
|
|
isEnabled: (customer) => true,
|
|
|
|
|
onAction: ($event, entity) => this.manageCustomerAssets($event, entity)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('customer.manage-customer-devices'),
|
|
|
|
|
nameFunction: (customer) => {
|
|
|
|
|
return customer.additionalInfo && customer.additionalInfo.isPublic
|
|
|
|
|
? this.translate.instant('customer.manage-public-devices')
|
|
|
|
|
: this.translate.instant('customer.manage-customer-devices');
|
|
|
|
|
},
|
|
|
|
|
icon: 'devices_other',
|
|
|
|
|
isEnabled: (customer) => true,
|
|
|
|
|
onAction: ($event, entity) => this.manageCustomerDevices($event, entity)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('customer.manage-customer-dashboards'),
|
|
|
|
|
nameFunction: (customer) => {
|
|
|
|
|
return customer.additionalInfo && customer.additionalInfo.isPublic
|
|
|
|
|
? this.translate.instant('customer.manage-public-dashboards')
|
|
|
|
|
: this.translate.instant('customer.manage-customer-dashboards');
|
|
|
|
|
},
|
|
|
|
|
icon: 'dashboard',
|
|
|
|
|
isEnabled: (customer) => true,
|
|
|
|
|
onAction: ($event, entity) => this.manageCustomerDashboards($event, entity)
|
2019-08-15 14:48:14 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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);
|
2019-08-15 20:39:56 +03:00
|
|
|
this.config.deleteEnabled = (customer) => customer && (!customer.additionalInfo || !customer.additionalInfo.isPublic);
|
|
|
|
|
this.config.entitySelectionEnabled = (customer) => customer && (!customer.additionalInfo || !customer.additionalInfo.isPublic);
|
|
|
|
|
this.config.detailsReadonly = (customer) => customer && customer.additionalInfo && customer.additionalInfo.isPublic;
|
2019-08-15 14:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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`);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 20:39:56 +03:00
|
|
|
manageCustomerAssets($event: Event, customer: Customer) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.router.navigateByUrl(`customers/${customer.id.id}/assets`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
manageCustomerDevices($event: Event, customer: Customer) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.router.navigateByUrl(`customers/${customer.id.id}/devices`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
manageCustomerDashboards($event: Event, customer: Customer) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.router.navigateByUrl(`customers/${customer.id.id}/dashboards`);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 14:48:14 +03:00
|
|
|
onCustomerAction(action: EntityAction<Customer>): boolean {
|
|
|
|
|
switch (action.action) {
|
|
|
|
|
case 'manageUsers':
|
|
|
|
|
this.manageCustomerUsers(action.event, action.entity);
|
|
|
|
|
return true;
|
2019-08-20 20:42:48 +03:00
|
|
|
case 'manageAssets':
|
|
|
|
|
this.manageCustomerAssets(action.event, action.entity);
|
|
|
|
|
return true;
|
|
|
|
|
case 'manageDevices':
|
|
|
|
|
this.manageCustomerDevices(action.event, action.entity);
|
|
|
|
|
return true;
|
|
|
|
|
case 'manageDashboards':
|
|
|
|
|
this.manageCustomerDashboards(action.event, action.entity);
|
|
|
|
|
return true;
|
2019-08-15 14:48:14 +03:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|