diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts b/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts index d8e53c2b85..af4bff4ddd 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts @@ -58,11 +58,7 @@ import { isObject } from '@core/utils'; import { EntityDebugSettingsService } from '@home/components/entity/debug/entity-debug-settings.service'; import { DatePipe } from '@angular/common'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; -import { - TbIotHubAddItemDialogComponent, - IotHubAddItemDialogData, - IotHubAddItemDialogResult -} from '@home/components/iot-hub/iot-hub-add-item-dialog.component'; +import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; export class CalculatedFieldsTableConfig extends EntityTableConfig { @@ -83,6 +79,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig { + this.iotHubActions.addItem(ItemType.CALCULATED_FIELD, { entityId: this.entityId }).subscribe(result => { if (result?.descriptor) { this.updateData(); } diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table.component.ts b/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table.component.ts index 741e9851e1..1ffe3e4310 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table.component.ts @@ -34,6 +34,7 @@ import { CalculatedFieldsTableConfig } from '@home/components/calculated-fields/ import { CalculatedFieldsService } from '@core/http/calculated-fields.service'; import { ImportExportService } from '@shared/import-export/import-export.service'; import { EntityDebugSettingsService } from '@home/components/entity/debug/entity-debug-settings.service'; +import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; import { DatePipe } from '@angular/common'; @Component({ @@ -63,6 +64,7 @@ export class CalculatedFieldsTableComponent { private renderer: Renderer2, private importExportService: ImportExportService, private entityDebugSettingsService: EntityDebugSettingsService, + private iotHubActions: IotHubActionsService, private destroyRef: DestroyRef) { effect(() => { @@ -79,6 +81,7 @@ export class CalculatedFieldsTableComponent { this.entityName(), this.importExportService, this.entityDebugSettingsService, + this.iotHubActions, ); this.cd.markForCheck(); } diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts index dfa3b421a2..07d4f9cfc0 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts @@ -22,6 +22,8 @@ import { MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; +import { EntityId } from '@shared/models/id/entity-id'; +import { TbIotHubAddItemDialogComponent, IotHubAddItemDialogData, IotHubAddItemDialogResult } from './iot-hub-add-item-dialog.component'; import { TbIotHubItemDetailDialogComponent, IotHubItemDetailDialogData, IotHubItemDetailDialogMode } from './iot-hub-item-detail-dialog.component'; import { TbIotHubInstallDialogComponent, IotHubInstallDialogData } from './iot-hub-install-dialog.component'; import { TbIotHubUpdateDialogComponent, IotHubUpdateDialogData } from './iot-hub-update-dialog.component'; @@ -44,6 +46,19 @@ export class IotHubActionsService { }).afterClosed(); } + addItem(itemType: ItemType, options?: { itemSubType?: string; entityId?: EntityId }): Observable { + return this.dialog.open(TbIotHubAddItemDialogComponent, { + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], + disableClose: true, + autoFocus: false, + data: { + itemType, + itemSubType: options?.itemSubType, + entityId: options?.entityId + } as IotHubAddItemDialogData + }).afterClosed(); + } + installItem(item: MpItemVersionView): Observable { if (item.type === ItemType.DEVICE) { return this.installDevice(item); diff --git a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts index ce2e947d03..e62ea12143 100644 --- a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts @@ -78,11 +78,7 @@ import { EntityAliasesDialogData } from '@home/components/alias/entity-aliases-dialog.component'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; -import { - TbIotHubAddItemDialogComponent, - IotHubAddItemDialogData, - IotHubAddItemDialogResult -} from '@home/components/iot-hub/iot-hub-add-item-dialog.component'; +import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; @Injectable() export class DashboardsTableConfigResolver { @@ -96,6 +92,7 @@ export class DashboardsTableConfigResolver { private dialogService: DialogService, private homeDialogs: HomeDialogsService, private importExport: ImportExportService, + private iotHubActions: IotHubActionsService, private translate: TranslateService, private datePipe: DatePipe, private router: Router, @@ -401,15 +398,7 @@ export class DashboardsTableConfigResolver { } addDashboardFromIotHub(_$event: Event) { - const dialogRef = this.dialog.open(TbIotHubAddItemDialogComponent, { - panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], - disableClose: true, - autoFocus: false, - data: { - itemType: ItemType.DASHBOARD - } as IotHubAddItemDialogData - }); - dialogRef.afterClosed().subscribe((result: IotHubAddItemDialogResult) => { + this.iotHubActions.addItem(ItemType.DASHBOARD).subscribe(result => { if (result?.descriptor?.type === 'DASHBOARD' && result.descriptor.dashboardId?.id) { this.router.navigateByUrl(`dashboards/${result.descriptor.dashboardId.id}`); } diff --git a/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts index 1c1fffa546..f711b24d8f 100644 --- a/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts @@ -85,11 +85,7 @@ import { } from '@home/pages/device/device-check-connectivity-dialog.component'; import { EntityId } from '@shared/models/id/entity-id'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; -import { - TbIotHubAddItemDialogComponent, - IotHubAddItemDialogData, - IotHubAddItemDialogResult -} from '@home/components/iot-hub/iot-hub-add-item-dialog.component'; +import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; interface DevicePageQueryParams extends PageQueryParam { deviceProfileId?: string; @@ -113,7 +109,8 @@ export class DevicesTableConfigResolver { private translate: TranslateService, private datePipe: DatePipe, private router: Router, - private dialog: MatDialog) { + private dialog: MatDialog, + private iotHubActions: IotHubActionsService) { this.config.entityType = EntityType.DEVICE; this.config.entityComponent = DeviceComponent; @@ -463,15 +460,7 @@ export class DevicesTableConfigResolver { } addDeviceFromIotHub() { - const dialogRef = this.dialog.open(TbIotHubAddItemDialogComponent, { - panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], - disableClose: true, - autoFocus: false, - data: { - itemType: ItemType.DEVICE - } as IotHubAddItemDialogData - }); - dialogRef.afterClosed().subscribe((result: IotHubAddItemDialogResult) => { + this.iotHubActions.addItem(ItemType.DEVICE).subscribe(result => { if (result?.descriptor) { this.config.updateData(); } diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts index 7a4a69da0b..43a7c91b53 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts @@ -50,11 +50,7 @@ import { PageLink } from '@shared/models/page/page-link'; import { Edge } from '@shared/models/edge.models'; import { mergeMap } from 'rxjs/operators'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; -import { - TbIotHubAddItemDialogComponent, - IotHubAddItemDialogData, - IotHubAddItemDialogResult -} from '@home/components/iot-hub/iot-hub-add-item-dialog.component'; +import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; import { PageData } from '@shared/models/page/page-data'; import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe'; @@ -69,6 +65,7 @@ export class RuleChainsTableConfigResolver { private importExport: ImportExportService, private itembuffer: ItemBufferService, private edgeService: EdgeService, + private iotHubActions: IotHubActionsService, private translate: TranslateService, private datePipe: DatePipe, private router: Router, @@ -303,16 +300,7 @@ export class RuleChainsTableConfigResolver { addRuleChainFromIotHub() { const ruleChainScope = this.config.componentsData.ruleChainScope; const ruleChainType = ruleChainScope === 'edges' ? 'EDGE' : 'CORE'; - const dialogRef = this.dialog.open(TbIotHubAddItemDialogComponent, { - panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], - disableClose: true, - autoFocus: false, - data: { - itemType: ItemType.RULE_CHAIN, - itemSubType: ruleChainType - } as IotHubAddItemDialogData - }); - dialogRef.afterClosed().subscribe((result: IotHubAddItemDialogResult) => { + this.iotHubActions.addItem(ItemType.RULE_CHAIN, { itemSubType: ruleChainType }).subscribe(result => { if (result?.descriptor?.type === 'RULE_CHAIN' && result.descriptor.ruleChainId?.id) { const ruleChainId = result.descriptor.ruleChainId.id; if (ruleChainScope === 'edges') { diff --git a/ui-ngx/src/app/modules/home/pages/widget/widget-types-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/widget/widget-types-table-config.resolver.ts index ef49ec05fe..c4152106df 100644 --- a/ui-ngx/src/app/modules/home/pages/widget/widget-types-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/widget/widget-types-table-config.resolver.ts @@ -48,11 +48,7 @@ import { WidgetTypeTabsComponent } from '@home/pages/widget/widget-type-tabs.com import { SelectWidgetTypeDialogComponent } from '@home/pages/widget/select-widget-type-dialog.component'; import { MatDialog } from '@angular/material/dialog'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; -import { - TbIotHubAddItemDialogComponent, - IotHubAddItemDialogData, - IotHubAddItemDialogResult -} from '@home/components/iot-hub/iot-hub-add-item-dialog.component'; +import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; @Injectable() export class WidgetTypesTableConfigResolver { @@ -66,7 +62,8 @@ export class WidgetTypesTableConfigResolver { private translate: TranslateService, private importExport: ImportExportService, private datePipe: DatePipe, - private router: Router) { + private router: Router, + private iotHubActions: IotHubActionsService) { this.config.entityType = EntityType.WIDGETS_BUNDLE; this.config.entityComponent = WidgetTypeComponent; @@ -196,15 +193,7 @@ export class WidgetTypesTableConfigResolver { } addWidgetFromIotHub() { - const dialogRef = this.dialog.open(TbIotHubAddItemDialogComponent, { - panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], - disableClose: true, - autoFocus: false, - data: { - itemType: ItemType.WIDGET - } as IotHubAddItemDialogData - }); - dialogRef.afterClosed().subscribe((result: IotHubAddItemDialogResult) => { + this.iotHubActions.addItem(ItemType.WIDGET).subscribe(result => { if (result?.descriptor) { this.config.updateData(); }