diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index ba46193b34..e8d7ff0234 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -805,14 +805,28 @@ export class EntityService { case EntityType.DEVICE: const device: Device = { name: entityData.name, - type: entityData.type + type: entityData.type, + label: entityData.label, + additionalInfo: { + description: entityData.description + } }; + if (entityData.gateway !== null) { + device.additionalInfo = { + ...device.additionalInfo, + gateway: entityData.gateway + }; + } saveEntityObservable = this.deviceService.saveDevice(device, config); break; case EntityType.ASSET: const asset: Asset = { name: entityData.name, - type: entityData.type + type: entityData.type, + label: entityData.label, + additionalInfo: { + description: entityData.description + } }; saveEntityObservable = this.assetService.saveAsset(asset, config); break; @@ -839,7 +853,31 @@ export class EntityService { } return findEntityObservable.pipe( mergeMap((entity) => { - return this.saveEntityData(entity.id, entityData, config).pipe( + const tasks: Observable[] = []; + const result: Device | Asset = entity as (Device | Asset); + const additionalInfo = result.additionalInfo || {}; + if(result.label !== entityData.label || + result.type !== entityData.type || + additionalInfo.description !== entityData.description || + (result.id.entityType === EntityType.DEVICE && (additionalInfo.gateway !== entityData.gateway)) ) { + result.label = entityData.label; + result.type = entityData.type; + result.additionalInfo = additionalInfo; + result.additionalInfo.description = entityData.description; + if (result.id.entityType === EntityType.DEVICE) { + result.additionalInfo.gateway = entityData.gateway; + } + switch (result.id.entityType) { + case EntityType.DEVICE: + tasks.push(this.deviceService.saveDevice(result, config)); + break; + case EntityType.ASSET: + tasks.push(this.assetService.saveAsset(result, config)); + break; + } + } + tasks.push(this.saveEntityData(entity.id, entityData, config)); + return forkJoin(tasks).pipe( map(() => { return { update: { entity: 1 } } as ImportEntitiesResultInfo; }), diff --git a/ui-ngx/src/app/modules/home/components/import-export/import-dialog-csv.component.ts b/ui-ngx/src/app/modules/home/components/import-export/import-dialog-csv.component.ts index 500ba662c5..7897d24feb 100644 --- a/ui-ngx/src/app/modules/home/components/import-export/import-dialog-csv.component.ts +++ b/ui-ngx/src/app/modules/home/components/import-export/import-dialog-csv.component.ts @@ -168,7 +168,7 @@ export class ImportDialogCsvComponent extends DialogComponent {{ 'import.column-key' | translate }} + *ngIf="isColumnTypeDiffers(column.type)"> column.type === ImportEntityColumnType.name) > -1; const isSelectType = this.columns.findIndex((column) => column.type === ImportEntityColumnType.type) > -1; + const isSelectLabel = this.columns.findIndex((column) => column.type === ImportEntityColumnType.label) > -1; const isSelectCredentials = this.columns.findIndex((column) => column.type === ImportEntityColumnType.accessToken) > -1; + const isSelectGateway = this.columns.findIndex((column) => column.type === ImportEntityColumnType.isGateway) > -1; + const isSelectDescription = this.columns.findIndex((column) => column.type === ImportEntityColumnType.description) > -1; const hasInvalidColumn = this.columns.findIndex((column) => !this.columnValid(column)) > -1; this.valid = isSelectName && isSelectType && !hasInvalidColumn; this.columnTypes.find((columnType) => columnType.value === ImportEntityColumnType.name).disabled = isSelectName; this.columnTypes.find((columnType) => columnType.value === ImportEntityColumnType.type).disabled = isSelectType; + this.columnTypes.find((columnType) => columnType.value === ImportEntityColumnType.label).disabled = isSelectLabel; + this.columnTypes.find((columnType) => columnType.value === ImportEntityColumnType.isGateway).disabled = isSelectGateway; + this.columnTypes.find((columnType) => columnType.value === ImportEntityColumnType.description).disabled = isSelectDescription; + const accessTokenColumnType = this.columnTypes.find((columnType) => columnType.value === ImportEntityColumnType.accessToken); if (accessTokenColumnType) { accessTokenColumnType.disabled = isSelectCredentials; @@ -127,6 +137,15 @@ export class TableColumnsAssignmentComponent implements OnInit, ControlValueAcce } } + public isColumnTypeDiffers(columnType: ImportEntityColumnType): boolean { + return columnType !== ImportEntityColumnType.name && + columnType !== ImportEntityColumnType.type && + columnType !== ImportEntityColumnType.label && + columnType !== ImportEntityColumnType.accessToken && + columnType !== ImportEntityColumnType.isGateway && + columnType !== ImportEntityColumnType.description; + } + private columnValid(column: CsvColumnParam): boolean { if (!importEntityObjectColumns.includes(column.type)) { return column.key && column.key.trim().length > 0; diff --git a/ui-ngx/src/app/modules/home/pages/asset/asset.component.html b/ui-ngx/src/app/modules/home/pages/asset/asset.component.html index baf0155272..1ac34a2407 100644 --- a/ui-ngx/src/app/modules/home/pages/asset/asset.component.html +++ b/ui-ngx/src/app/modules/home/pages/asset/asset.component.html @@ -77,6 +77,10 @@ [entityType]="entityType.ASSET" > + + asset.label + +
asset.description diff --git a/ui-ngx/src/app/modules/home/pages/asset/asset.component.ts b/ui-ngx/src/app/modules/home/pages/asset/asset.component.ts index 01b67e62d2..46e8da5798 100644 --- a/ui-ngx/src/app/modules/home/pages/asset/asset.component.ts +++ b/ui-ngx/src/app/modules/home/pages/asset/asset.component.ts @@ -64,6 +64,7 @@ export class AssetComponent extends EntityComponent { { name: [entity ? entity.name : '', [Validators.required]], type: [entity ? entity.type : null, [Validators.required]], + label: [entity ? entity.label : ''], additionalInfo: this.fb.group( { description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''], @@ -76,6 +77,7 @@ export class AssetComponent extends EntityComponent { updateForm(entity: AssetInfo) { this.entityForm.patchValue({name: entity.name}); this.entityForm.patchValue({type: entity.type}); + this.entityForm.patchValue({label: entity.label}); this.entityForm.patchValue({additionalInfo: {description: entity.additionalInfo ? entity.additionalInfo.description : ''}}); } diff --git a/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts index 036aa19490..2ef473a9c6 100644 --- a/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts @@ -57,6 +57,7 @@ import { AssetTableHeaderComponent } from '@modules/home/pages/asset/asset-table import { AssetId } from '@app/shared/models/id/asset-id'; import { AssetTabsComponent } from '@home/pages/asset/asset-tabs.component'; import { HomeDialogsService } from '@home/dialogs/home-dialogs.service'; +import { DeviceInfo } from '@shared/models/device.models'; @Injectable() export class AssetsTableConfigResolver implements Resolve> { @@ -146,12 +147,13 @@ export class AssetsTableConfigResolver implements Resolve> { const columns: Array> = [ new DateEntityTableColumn('createdTime', 'asset.created-time', this.datePipe, '150px'), - new EntityTableColumn('name', 'asset.name', '33%'), - new EntityTableColumn('type', 'asset.asset-type', '33%'), + new EntityTableColumn('name', 'asset.name', '25%'), + new EntityTableColumn('type', 'asset.asset-type', '25%'), + new EntityTableColumn('label', 'asset.label', '25%'), ]; if (assetScope === 'tenant') { columns.push( - new EntityTableColumn('customerTitle', 'customer.customer', '33%'), + new EntityTableColumn('customerTitle', 'customer.customer', '25%'), new EntityTableColumn('customerIsPublic', 'asset.public', '60px', entity => { return checkBoxCell(entity.customerIsPublic); diff --git a/ui-ngx/src/app/shared/models/asset.models.ts b/ui-ngx/src/app/shared/models/asset.models.ts index 4b6cea4383..21610eae76 100644 --- a/ui-ngx/src/app/shared/models/asset.models.ts +++ b/ui-ngx/src/app/shared/models/asset.models.ts @@ -26,6 +26,7 @@ export interface Asset extends BaseData { customerId?: CustomerId; name: string; type: string; + label: string; additionalInfo?: any; } diff --git a/ui-ngx/src/app/shared/models/device.models.ts b/ui-ngx/src/app/shared/models/device.models.ts index 945dc9db5d..ef527eb33c 100644 --- a/ui-ngx/src/app/shared/models/device.models.ts +++ b/ui-ngx/src/app/shared/models/device.models.ts @@ -26,7 +26,7 @@ export interface Device extends BaseData { customerId?: CustomerId; name: string; type: string; - label?: string; + label: string; additionalInfo?: any; } diff --git a/ui-ngx/src/app/shared/models/entity.models.ts b/ui-ngx/src/app/shared/models/entity.models.ts index 988f071fc6..eb3fc2d387 100644 --- a/ui-ngx/src/app/shared/models/entity.models.ts +++ b/ui-ngx/src/app/shared/models/entity.models.ts @@ -31,6 +31,9 @@ export interface EntityInfo { export interface ImportEntityData { name: string; type: string; + label: string; + gateway: boolean; + description: string; accessToken: string; attributes: { server: AttributeData[],