diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-add-item-dialog.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-add-item-dialog.component.ts index e83580e271..3920a19f1b 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-add-item-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-add-item-dialog.component.ts @@ -15,7 +15,7 @@ /// import { Component, Inject } from '@angular/core'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; import { Router } from '@angular/router'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; @@ -27,6 +27,10 @@ import { DialogService } from '@core/services/dialog.service'; import { TranslateService } from '@ngx-translate/core'; import { EntityId } from '@shared/models/id/entity-id'; import { IotHubActionsService } from './iot-hub-actions.service'; +import { + IotHubSelectCfEntityDialogData, + TbIotHubSelectCfEntityDialogComponent +} from './iot-hub-select-cf-entity-dialog.component'; export interface IotHubAddItemDialogData { itemType: ItemType; @@ -59,6 +63,7 @@ export class TbIotHubAddItemDialogComponent extends DialogComponent( + TbIotHubSelectCfEntityDialogComponent, { + panelClass: ['tb-dialog'], + disableClose: true, + autoFocus: false, + data: { itemName: item.name } + } + ).afterClosed().subscribe(entityId => { + if (entityId) { + this.installItem(item, { entityId }); + } + }); + return; + } + const installData = this.data.entityId ? { entityId: this.data.entityId } : undefined; + this.installItem(item, installData); + } + + private installItem(item: MpItemVersionView, installData?: { entityId: EntityId }): void { this.isInstalling = true; const versionId = item.id as string; - const installData = this.data.entityId ? { entityId: this.data.entityId } : undefined; this.iotHubApiService.installItemVersion(versionId, { ignoreLoading: true }, installData).subscribe({ next: (result) => { this.isInstalling = false; diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts index 44bc1ad4c8..94bc1c5610 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts @@ -29,6 +29,7 @@ import { TbDeviceInstallDialogComponent } from './device-install-dialog/device-i import { TbIotHubSearchComponent } from './iot-hub-search.component'; import { TbIotHubInstalledItemsTableComponent } from './iot-hub-installed-items-table.component'; import { TbIotHubInstalledItemsDialogComponent } from './iot-hub-installed-items-dialog.component'; +import { TbIotHubSelectCfEntityDialogComponent } from './iot-hub-select-cf-entity-dialog.component'; import { IotHubActionsService } from './iot-hub-actions.service'; @NgModule({ @@ -44,7 +45,8 @@ import { IotHubActionsService } from './iot-hub-actions.service'; TbDeviceInstallDialogComponent, TbIotHubSearchComponent, TbIotHubInstalledItemsTableComponent, - TbIotHubInstalledItemsDialogComponent + TbIotHubInstalledItemsDialogComponent, + TbIotHubSelectCfEntityDialogComponent ], imports: [ CommonModule, @@ -65,7 +67,8 @@ import { IotHubActionsService } from './iot-hub-actions.service'; TbDeviceInstallDialogComponent, TbIotHubSearchComponent, TbIotHubInstalledItemsTableComponent, - TbIotHubInstalledItemsDialogComponent + TbIotHubInstalledItemsDialogComponent, + TbIotHubSelectCfEntityDialogComponent ] }) export class IotHubComponentsModule { } diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts index b8e24f7d70..564c1e9b93 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts @@ -213,7 +213,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, switch (descriptor.type) { case 'WIDGET': return descriptor.widgetTypeId?.id; case 'DASHBOARD': return descriptor.dashboardId?.id; - case 'CALCULATED_FIELD': return descriptor.entityId?.id; + case 'CALCULATED_FIELD': return descriptor.calculatedFieldId?.id; case 'RULE_CHAIN': return descriptor.ruleChainId?.id; case 'DEVICE': return descriptor.dashboardId?.id ?? null; case 'SOLUTION_TEMPLATE': return descriptor.dashboardId?.id; @@ -226,7 +226,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, switch (descriptor.type) { case 'WIDGET': return EntityType.WIDGET_TYPE; case 'DASHBOARD': return EntityType.DASHBOARD; - case 'CALCULATED_FIELD': return descriptor.entityId?.entityType as EntityType; + case 'CALCULATED_FIELD': return EntityType.CALCULATED_FIELD; case 'RULE_CHAIN': return EntityType.RULE_CHAIN; case 'DEVICE': return descriptor.dashboardId ? EntityType.DASHBOARD : null; case 'SOLUTION_TEMPLATE': return EntityType.DASHBOARD; diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts index 4223a58554..10a8faba8e 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts @@ -212,8 +212,8 @@ export class TbIotHubItemDetailDialogComponent extends DialogComponent +
+

{{ 'iot-hub.install-confirm-title' | translate:{ name: data.itemName } }}

+

{{ 'iot-hub.select-entity-for-cf' | translate:{ name: data.itemName } }}

+ + +
+ + + + diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-select-cf-entity-dialog.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-select-cf-entity-dialog.component.ts new file mode 100644 index 0000000000..a4570ea52b --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-select-cf-entity-dialog.component.ts @@ -0,0 +1,61 @@ +/// +/// Copyright © 2016-2026 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 } from '@angular/core'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { Router } from '@angular/router'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { DialogComponent } from '@shared/components/dialog.component'; +import { EntityType } from '@shared/models/entity-type.models'; +import { EntityId } from '@shared/models/id/entity-id'; + +export interface IotHubSelectCfEntityDialogData { + itemName: string; +} + +@Component({ + selector: 'tb-iot-hub-select-cf-entity-dialog', + standalone: false, + templateUrl: './iot-hub-select-cf-entity-dialog.component.html', + styleUrls: ['./iot-hub-install-dialog.component.scss'] +}) +export class TbIotHubSelectCfEntityDialogComponent + extends DialogComponent { + + selectedEntityId: EntityId | null = null; + cfEntityTypes: EntityType[] = [EntityType.DEVICE, EntityType.ASSET, EntityType.DEVICE_PROFILE, EntityType.ASSET_PROFILE]; + defaultCfEntityType = EntityType.DEVICE_PROFILE; + + constructor( + protected store: Store, + protected router: Router, + protected dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: IotHubSelectCfEntityDialogData + ) { + super(store, router, dialogRef); + } + + cancel(): void { + this.dialogRef.close(null); + } + + confirm(): void { + if (this.selectedEntityId) { + this.dialogRef.close(this.selectedEntityId); + } + } +} diff --git a/ui-ngx/src/app/shared/models/entity-type.models.ts b/ui-ngx/src/app/shared/models/entity-type.models.ts index 4ee4674c75..614dd04878 100644 --- a/ui-ngx/src/app/shared/models/entity-type.models.ts +++ b/ui-ngx/src/app/shared/models/entity-type.models.ts @@ -694,7 +694,8 @@ export const baseDetailsPageByEntityType = new Map([ [EntityType.WIDGET_TYPE, '/resources/widgets-library/widget-types/details'], [EntityType.OAUTH2_CLIENT, '/security-settings/oauth2/clients/details'], [EntityType.DOMAIN, '/security-settings/oauth2/clients/details'], - [EntityType.MOBILE_APP, '/mobile-center/applications'] + [EntityType.MOBILE_APP, '/mobile-center/applications'], + [EntityType.CALCULATED_FIELD, '/calculatedFields'] ]); export interface EntitySubtype {