Browse Source

feat(iot-hub): prompt for parent entity when adding a CALCULATED_FIELD

- TbIotHubSelectCfEntityDialogComponent: small reusable dialog mirroring
  the install dialog's select-entity state (Title + select-entity-for-cf
  description + tb-entity-select over DEVICE/ASSET/DEVICE_PROFILE/
  ASSET_PROFILE, default DEVICE_PROFILE).
- TbIotHubAddItemDialogComponent.onAddItem: when itemType ===
  CALCULATED_FIELD and no parent entityId is supplied, open the new
  dialog and pass the chosen EntityId into installItemVersion.
  installItem() extracted as a shared helper.
- Open-installed-CF flow now uses the descriptor's calculatedFieldId +
  EntityType.CALCULATED_FIELD (in installed-items-table and detail
  dialog), and registers /calculatedFields in baseDetailsPageByEntityType
  so the link resolves.
pull/15548/head
Igor Kulikov 5 months ago
parent
commit
6b21f1772c
  1. 28
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-add-item-dialog.component.ts
  2. 7
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts
  3. 4
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts
  4. 4
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts
  5. 35
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-select-cf-entity-dialog.component.html
  6. 61
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-select-cf-entity-dialog.component.ts
  7. 3
      ui-ngx/src/app/shared/models/entity-type.models.ts

28
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<TbIotHubAddI
private translate: TranslateService,
private iotHubApiService: IotHubApiService,
private dialogService: DialogService,
private dialog: MatDialog,
private iotHubActions: IotHubActionsService
) {
super(store, router, dialogRef);
@ -77,9 +82,28 @@ export class TbIotHubAddItemDialogComponent extends DialogComponent<TbIotHubAddI
this.installDeviceItem(item);
return;
}
if (this.itemType === ItemType.CALCULATED_FIELD && !this.data.entityId) {
this.dialog.open<TbIotHubSelectCfEntityDialogComponent, IotHubSelectCfEntityDialogData, EntityId | null>(
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;

7
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 { }

4
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;

4
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<TbIotHubI
case 'WIDGET': entityId = descriptor.widgetTypeId?.id; entityType = EntityType.WIDGET_TYPE; break;
case 'DASHBOARD': entityId = descriptor.dashboardId?.id; entityType = EntityType.DASHBOARD; break;
case 'CALCULATED_FIELD':
entityId = descriptor.entityId?.id;
entityType = descriptor.entityId?.entityType as EntityType;
entityId = descriptor.calculatedFieldId?.id;
entityType = EntityType.CALCULATED_FIELD;
break;
case 'RULE_CHAIN': entityId = descriptor.ruleChainId?.id; entityType = EntityType.RULE_CHAIN; break;
case 'SOLUTION_TEMPLATE': entityId = descriptor.dashboardId?.id; entityType = EntityType.DASHBOARD; break;

35
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-select-cf-entity-dialog.component.html

@ -0,0 +1,35 @@
<!--
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.
-->
<div class="flex flex-col gap-5 p-6">
<h2 class="tb-iot-hub-install-title">{{ 'iot-hub.install-confirm-title' | translate:{ name: data.itemName } }}</h2>
<p class="tb-iot-hub-install-desc">{{ 'iot-hub.select-entity-for-cf' | translate:{ name: data.itemName } }}</p>
<tb-entity-select
[(ngModel)]="selectedEntityId"
[allowedEntityTypes]="cfEntityTypes"
[defaultEntityType]="defaultCfEntityType"
[filterAllowedEntityTypes]="false"
appearance="outline"
required>
</tb-entity-select>
</div>
<mat-dialog-actions align="end">
<button mat-button (click)="cancel()">{{ 'action.cancel' | translate }}</button>
<button mat-flat-button color="primary" [disabled]="!selectedEntityId" (click)="confirm()">
{{ 'iot-hub.install' | translate }}
</button>
</mat-dialog-actions>

61
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<TbIotHubSelectCfEntityDialogComponent, EntityId | null> {
selectedEntityId: EntityId | null = null;
cfEntityTypes: EntityType[] = [EntityType.DEVICE, EntityType.ASSET, EntityType.DEVICE_PROFILE, EntityType.ASSET_PROFILE];
defaultCfEntityType = EntityType.DEVICE_PROFILE;
constructor(
protected store: Store<AppState>,
protected router: Router,
protected dialogRef: MatDialogRef<TbIotHubSelectCfEntityDialogComponent, EntityId | null>,
@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);
}
}
}

3
ui-ngx/src/app/shared/models/entity-type.models.ts

@ -694,7 +694,8 @@ export const baseDetailsPageByEntityType = new Map<EntityType, string>([
[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 {

Loading…
Cancel
Save