Merge pull request #12123 from vvlladd28/improvement/custom-translate/description

Add support custom translate for entity description columns
This commit is contained in:
Igor Kulikov 2024-11-29 17:56:50 +02:00 committed by GitHub
commit 2e5989fa94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 20 deletions

View File

@ -28,13 +28,12 @@ import { DatePipe } from '@angular/common';
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
import { EntityAction } from '@home/models/entity/entity-component.models';
import { DialogService } from '@core/services/dialog.service';
import { MatDialog } from '@angular/material/dialog';
import { ImportExportService } from '@shared/import-export/import-export.service';
import { HomeDialogsService } from '@home/dialogs/home-dialogs.service';
import { AssetProfile } from '@shared/models/asset.models';
import { AssetProfileService } from '@core/http/asset-profile.service';
import { AssetProfileComponent } from '@home/components/profile/asset-profile.component';
import { AssetProfileTabsComponent } from './asset-profile-tabs.component';
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
@Injectable()
export class AssetProfilesTableConfigResolver {
@ -43,12 +42,11 @@ export class AssetProfilesTableConfigResolver {
constructor(private assetProfileService: AssetProfileService,
private importExport: ImportExportService,
private homeDialogs: HomeDialogsService,
private translate: TranslateService,
private datePipe: DatePipe,
private dialogService: DialogService,
private router: Router,
private dialog: MatDialog) {
private customTranslate: CustomTranslatePipe) {
this.config.entityType = EntityType.ASSET_PROFILE;
this.config.entityComponent = AssetProfileComponent;
@ -61,7 +59,8 @@ export class AssetProfilesTableConfigResolver {
this.config.columns.push(
new DateEntityTableColumn<AssetProfile>('createdTime', 'common.created-time', this.datePipe, '150px'),
new EntityTableColumn<AssetProfile>('name', 'asset-profile.name', '50%'),
new EntityTableColumn<AssetProfile>('description', 'asset-profile.description', '50%'),
new EntityTableColumn<AssetProfile>('description', 'asset-profile.description', '50%',
entity => this.customTranslate.transform(entity.description || '')),
new EntityTableColumn<AssetProfile>('isDefault', 'asset-profile.default', '60px',
entity => {
return checkBoxCell(entity.default);

View File

@ -42,7 +42,7 @@ import {
AddDeviceProfileDialogData
} from '@home/components/profile/add-device-profile-dialog.component';
import { ImportExportService } from '@shared/import-export/import-export.service';
import { HomeDialogsService } from '@home/dialogs/home-dialogs.service';
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
@Injectable()
export class DeviceProfilesTableConfigResolver {
@ -51,12 +51,12 @@ export class DeviceProfilesTableConfigResolver {
constructor(private deviceProfileService: DeviceProfileService,
private importExport: ImportExportService,
private homeDialogs: HomeDialogsService,
private translate: TranslateService,
private datePipe: DatePipe,
private dialogService: DialogService,
private router: Router,
private dialog: MatDialog) {
private dialog: MatDialog,
private customTranslate: CustomTranslatePipe) {
this.config.entityType = EntityType.DEVICE_PROFILE;
this.config.entityComponent = DeviceProfileComponent;
@ -77,7 +77,8 @@ export class DeviceProfilesTableConfigResolver {
new EntityTableColumn<DeviceProfile>('transportType', 'device-profile.transport-type', '20%', (deviceProfile) => {
return this.translate.instant(deviceTransportTypeTranslationMap.get(deviceProfile.transportType));
}),
new EntityTableColumn<DeviceProfile>('description', 'device-profile.description', '40%'),
new EntityTableColumn<DeviceProfile>('description', 'device-profile.description', '40%',
entity => this.customTranslate.transform(entity.description || '')),
new EntityTableColumn<DeviceProfile>('isDefault', 'device-profile.default', '60px',
entity => {
return checkBoxCell(entity.default);

View File

@ -35,6 +35,7 @@ import { RecipientTableHeaderComponent } from '@home/pages/notification/recipien
import { ActivatedRouteSnapshot } from '@angular/router';
import { Injectable } from '@angular/core';
import { DatePipe } from '@angular/common';
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
@Injectable()
export class RecipientTableConfigResolver {
@ -44,7 +45,8 @@ export class RecipientTableConfigResolver {
constructor(private notificationService: NotificationService,
private translate: TranslateService,
private dialog: MatDialog,
private datePipe: DatePipe) {
private datePipe: DatePipe,
private customTranslate: CustomTranslatePipe) {
this.config.entityType = EntityType.NOTIFICATION_TARGET;
this.config.detailsPanelEnabled = false;
@ -82,7 +84,7 @@ export class RecipientTableConfigResolver {
(target) => this.translate.instant(NotificationTargetTypeTranslationMap.get(target.configuration.type)),
() => ({}), false),
new EntityTableColumn<NotificationTarget>('configuration.description', 'notification.description', '60%',
(target) => target.configuration.description || '',
(target) => this.customTranslate.transform(target.configuration.description || ''),
() => ({}), false)
);
}

View File

@ -35,6 +35,7 @@ import {
import { ActivatedRouteSnapshot } from '@angular/router';
import { Injectable } from '@angular/core';
import { DatePipe } from '@angular/common';
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
@Injectable()
export class RuleTableConfigResolver {
@ -44,7 +45,8 @@ export class RuleTableConfigResolver {
constructor(private notificationService: NotificationService,
private translate: TranslateService,
private dialog: MatDialog,
private datePipe: DatePipe) {
private datePipe: DatePipe,
private customTranslate: CustomTranslatePipe) {
this.config.entityType = EntityType.NOTIFICATION_RULE;
this.config.detailsPanelEnabled = false;
@ -81,7 +83,7 @@ export class RuleTableConfigResolver {
(rule) => this.translate.instant(TriggerTypeTranslationMap.get(rule.triggerType)) || '',
() => ({}), true),
new EntityTableColumn<NotificationRule>('additionalConfig.description', 'notification.description', '30%',
(target) => target.additionalConfig?.description || '',
(target) => this.customTranslate.transform(target.additionalConfig?.description || ''),
() => ({}), false)
);
}

View File

@ -50,13 +50,12 @@ import { PageLink } from '@shared/models/page/page-link';
import { Edge } from '@shared/models/edge.models';
import { mergeMap } from 'rxjs/operators';
import { PageData } from '@shared/models/page/page-data';
import { HomeDialogsService } from '@home/dialogs/home-dialogs.service';
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
@Injectable()
export class RuleChainsTableConfigResolver {
private readonly config: EntityTableConfig<RuleChain> = new EntityTableConfig<RuleChain>();
private edge: Edge;
constructor(private ruleChainService: RuleChainService,
private dialogService: DialogService,
@ -64,10 +63,10 @@ export class RuleChainsTableConfigResolver {
private importExport: ImportExportService,
private itembuffer: ItemBufferService,
private edgeService: EdgeService,
private homeDialogs: HomeDialogsService,
private translate: TranslateService,
private datePipe: DatePipe,
private router: Router) {
private router: Router,
private customTranslate: CustomTranslatePipe) {
this.config.entityType = EntityType.RULE_CHAIN;
this.config.entityComponent = RuleChainComponent;
this.config.entityTabsComponent = RuleChainTabsComponent;
@ -128,7 +127,9 @@ export class RuleChainsTableConfigResolver {
columns.push(
new DateEntityTableColumn<RuleChain>('createdTime', 'common.created-time', this.datePipe, '150px'),
new EntityTableColumn<RuleChain>('name', 'rulechain.name', '50%'),
new EntityTableColumn<RuleChain>('description', 'rulechain.description', '50%', entity => entity.additionalInfo?.description ?? '')
new EntityTableColumn<RuleChain>('description', 'rulechain.description', '50%',
entity => this.customTranslate.transform(entity.additionalInfo?.description || ''),
() => ({}), false)
);
if (ruleChainScope === 'tenant' || ruleChainScope === 'edge') {
columns.push(

View File

@ -33,6 +33,7 @@ import { TenantProfileComponent } from '@home/components/profile/tenant-profile.
import { TenantProfileTabsComponent } from './tenant-profile-tabs.component';
import { DialogService } from '@core/services/dialog.service';
import { ImportExportService } from '@shared/import-export/import-export.service';
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
@Injectable()
export class TenantProfilesTableConfigResolver {
@ -44,7 +45,8 @@ export class TenantProfilesTableConfigResolver {
private translate: TranslateService,
private datePipe: DatePipe,
private router: Router,
private dialogService: DialogService) {
private dialogService: DialogService,
private customTranslate: CustomTranslatePipe) {
this.config.entityType = EntityType.TENANT_PROFILE;
this.config.entityComponent = TenantProfileComponent;
@ -55,7 +57,8 @@ export class TenantProfilesTableConfigResolver {
this.config.columns.push(
new DateEntityTableColumn<TenantProfile>('createdTime', 'common.created-time', this.datePipe, '150px'),
new EntityTableColumn<TenantProfile>('name', 'tenant-profile.name', '40%'),
new EntityTableColumn<TenantProfile>('description', 'tenant-profile.description', '60%'),
new EntityTableColumn<TenantProfile>('description', 'tenant-profile.description', '60%',
entity => this.customTranslate.transform(entity.description || '')),
new EntityTableColumn<TenantProfile>('isDefault', 'tenant-profile.default', '60px',
entity => {
return checkBoxCell(entity.default);