Browse Source

Add addItem method to IotHubActionsService, refactor all callers

- New addItem(itemType, options?) method opens add item dialog via service
- Options: optional itemSubType and entityId
- Refactored dashboards, rule chains, devices, widget types, calculated fields
  to use iotHubActions.addItem() instead of opening dialog directly
- Removed direct TbIotHubAddItemDialogComponent imports from all table configs
- All table configs now inject IotHubActionsService
pull/15508/head
Igor Kulikov 6 months ago
parent
commit
41a8b8aee7
  1. 18
      ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts
  2. 3
      ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table.component.ts
  3. 15
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts
  4. 17
      ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts
  5. 19
      ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts
  6. 18
      ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts
  7. 19
      ui-ngx/src/app/modules/home/pages/widget/widget-types-table-config.resolver.ts

18
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 { EntityDebugSettingsService } from '@home/components/entity/debug/entity-debug-settings.service';
import { DatePipe } from '@angular/common'; import { DatePipe } from '@angular/common';
import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
TbIotHubAddItemDialogComponent,
IotHubAddItemDialogData,
IotHubAddItemDialogResult
} from '@home/components/iot-hub/iot-hub-add-item-dialog.component';
export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedField> { export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedField> {
@ -83,6 +79,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
public entityName: string, public entityName: string,
private importExportService: ImportExportService, private importExportService: ImportExportService,
private entityDebugSettingsService: EntityDebugSettingsService, private entityDebugSettingsService: EntityDebugSettingsService,
private iotHubActions: IotHubActionsService,
) { ) {
super(); super();
this.tableTitle = this.translate.instant('entity.type-calculated-fields'); this.tableTitle = this.translate.instant('entity.type-calculated-fields');
@ -256,16 +253,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
} }
private addCalculatedFieldFromIotHub(): void { private addCalculatedFieldFromIotHub(): void {
const dialogRef = this.dialog.open(TbIotHubAddItemDialogComponent, { this.iotHubActions.addItem(ItemType.CALCULATED_FIELD, { entityId: this.entityId }).subscribe(result => {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: true,
autoFocus: false,
data: {
itemType: ItemType.CALCULATED_FIELD,
entityId: this.entityId
} as IotHubAddItemDialogData
});
dialogRef.afterClosed().subscribe((result: IotHubAddItemDialogResult) => {
if (result?.descriptor) { if (result?.descriptor) {
this.updateData(); this.updateData();
} }

3
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 { CalculatedFieldsService } from '@core/http/calculated-fields.service';
import { ImportExportService } from '@shared/import-export/import-export.service'; import { ImportExportService } from '@shared/import-export/import-export.service';
import { EntityDebugSettingsService } from '@home/components/entity/debug/entity-debug-settings.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'; import { DatePipe } from '@angular/common';
@Component({ @Component({
@ -63,6 +64,7 @@ export class CalculatedFieldsTableComponent {
private renderer: Renderer2, private renderer: Renderer2,
private importExportService: ImportExportService, private importExportService: ImportExportService,
private entityDebugSettingsService: EntityDebugSettingsService, private entityDebugSettingsService: EntityDebugSettingsService,
private iotHubActions: IotHubActionsService,
private destroyRef: DestroyRef) { private destroyRef: DestroyRef) {
effect(() => { effect(() => {
@ -79,6 +81,7 @@ export class CalculatedFieldsTableComponent {
this.entityName(), this.entityName(),
this.importExportService, this.importExportService,
this.entityDebugSettingsService, this.entityDebugSettingsService,
this.iotHubActions,
); );
this.cd.markForCheck(); this.cd.markForCheck();
} }

15
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 { ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service'; 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 { TbIotHubItemDetailDialogComponent, IotHubItemDetailDialogData, IotHubItemDetailDialogMode } from './iot-hub-item-detail-dialog.component';
import { TbIotHubInstallDialogComponent, IotHubInstallDialogData } from './iot-hub-install-dialog.component'; import { TbIotHubInstallDialogComponent, IotHubInstallDialogData } from './iot-hub-install-dialog.component';
import { TbIotHubUpdateDialogComponent, IotHubUpdateDialogData } from './iot-hub-update-dialog.component'; import { TbIotHubUpdateDialogComponent, IotHubUpdateDialogData } from './iot-hub-update-dialog.component';
@ -44,6 +46,19 @@ export class IotHubActionsService {
}).afterClosed(); }).afterClosed();
} }
addItem(itemType: ItemType, options?: { itemSubType?: string; entityId?: EntityId }): Observable<IotHubAddItemDialogResult> {
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<string> { installItem(item: MpItemVersionView): Observable<string> {
if (item.type === ItemType.DEVICE) { if (item.type === ItemType.DEVICE) {
return this.installDevice(item); return this.installDevice(item);

17
ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts

@ -78,11 +78,7 @@ import {
EntityAliasesDialogData EntityAliasesDialogData
} from '@home/components/alias/entity-aliases-dialog.component'; } from '@home/components/alias/entity-aliases-dialog.component';
import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
TbIotHubAddItemDialogComponent,
IotHubAddItemDialogData,
IotHubAddItemDialogResult
} from '@home/components/iot-hub/iot-hub-add-item-dialog.component';
@Injectable() @Injectable()
export class DashboardsTableConfigResolver { export class DashboardsTableConfigResolver {
@ -96,6 +92,7 @@ export class DashboardsTableConfigResolver {
private dialogService: DialogService, private dialogService: DialogService,
private homeDialogs: HomeDialogsService, private homeDialogs: HomeDialogsService,
private importExport: ImportExportService, private importExport: ImportExportService,
private iotHubActions: IotHubActionsService,
private translate: TranslateService, private translate: TranslateService,
private datePipe: DatePipe, private datePipe: DatePipe,
private router: Router, private router: Router,
@ -401,15 +398,7 @@ export class DashboardsTableConfigResolver {
} }
addDashboardFromIotHub(_$event: Event) { addDashboardFromIotHub(_$event: Event) {
const dialogRef = this.dialog.open(TbIotHubAddItemDialogComponent, { this.iotHubActions.addItem(ItemType.DASHBOARD).subscribe(result => {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: true,
autoFocus: false,
data: {
itemType: ItemType.DASHBOARD
} as IotHubAddItemDialogData
});
dialogRef.afterClosed().subscribe((result: IotHubAddItemDialogResult) => {
if (result?.descriptor?.type === 'DASHBOARD' && result.descriptor.dashboardId?.id) { if (result?.descriptor?.type === 'DASHBOARD' && result.descriptor.dashboardId?.id) {
this.router.navigateByUrl(`dashboards/${result.descriptor.dashboardId.id}`); this.router.navigateByUrl(`dashboards/${result.descriptor.dashboardId.id}`);
} }

19
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'; } from '@home/pages/device/device-check-connectivity-dialog.component';
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
TbIotHubAddItemDialogComponent,
IotHubAddItemDialogData,
IotHubAddItemDialogResult
} from '@home/components/iot-hub/iot-hub-add-item-dialog.component';
interface DevicePageQueryParams extends PageQueryParam { interface DevicePageQueryParams extends PageQueryParam {
deviceProfileId?: string; deviceProfileId?: string;
@ -113,7 +109,8 @@ export class DevicesTableConfigResolver {
private translate: TranslateService, private translate: TranslateService,
private datePipe: DatePipe, private datePipe: DatePipe,
private router: Router, private router: Router,
private dialog: MatDialog) { private dialog: MatDialog,
private iotHubActions: IotHubActionsService) {
this.config.entityType = EntityType.DEVICE; this.config.entityType = EntityType.DEVICE;
this.config.entityComponent = DeviceComponent; this.config.entityComponent = DeviceComponent;
@ -463,15 +460,7 @@ export class DevicesTableConfigResolver {
} }
addDeviceFromIotHub() { addDeviceFromIotHub() {
const dialogRef = this.dialog.open(TbIotHubAddItemDialogComponent, { this.iotHubActions.addItem(ItemType.DEVICE).subscribe(result => {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: true,
autoFocus: false,
data: {
itemType: ItemType.DEVICE
} as IotHubAddItemDialogData
});
dialogRef.afterClosed().subscribe((result: IotHubAddItemDialogResult) => {
if (result?.descriptor) { if (result?.descriptor) {
this.config.updateData(); this.config.updateData();
} }

18
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 { Edge } from '@shared/models/edge.models';
import { mergeMap } from 'rxjs/operators'; import { mergeMap } from 'rxjs/operators';
import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
TbIotHubAddItemDialogComponent,
IotHubAddItemDialogData,
IotHubAddItemDialogResult
} from '@home/components/iot-hub/iot-hub-add-item-dialog.component';
import { PageData } from '@shared/models/page/page-data'; import { PageData } from '@shared/models/page/page-data';
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe'; import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
@ -69,6 +65,7 @@ export class RuleChainsTableConfigResolver {
private importExport: ImportExportService, private importExport: ImportExportService,
private itembuffer: ItemBufferService, private itembuffer: ItemBufferService,
private edgeService: EdgeService, private edgeService: EdgeService,
private iotHubActions: IotHubActionsService,
private translate: TranslateService, private translate: TranslateService,
private datePipe: DatePipe, private datePipe: DatePipe,
private router: Router, private router: Router,
@ -303,16 +300,7 @@ export class RuleChainsTableConfigResolver {
addRuleChainFromIotHub() { addRuleChainFromIotHub() {
const ruleChainScope = this.config.componentsData.ruleChainScope; const ruleChainScope = this.config.componentsData.ruleChainScope;
const ruleChainType = ruleChainScope === 'edges' ? 'EDGE' : 'CORE'; const ruleChainType = ruleChainScope === 'edges' ? 'EDGE' : 'CORE';
const dialogRef = this.dialog.open(TbIotHubAddItemDialogComponent, { this.iotHubActions.addItem(ItemType.RULE_CHAIN, { itemSubType: ruleChainType }).subscribe(result => {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: true,
autoFocus: false,
data: {
itemType: ItemType.RULE_CHAIN,
itemSubType: ruleChainType
} as IotHubAddItemDialogData
});
dialogRef.afterClosed().subscribe((result: IotHubAddItemDialogResult) => {
if (result?.descriptor?.type === 'RULE_CHAIN' && result.descriptor.ruleChainId?.id) { if (result?.descriptor?.type === 'RULE_CHAIN' && result.descriptor.ruleChainId?.id) {
const ruleChainId = result.descriptor.ruleChainId.id; const ruleChainId = result.descriptor.ruleChainId.id;
if (ruleChainScope === 'edges') { if (ruleChainScope === 'edges') {

19
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 { SelectWidgetTypeDialogComponent } from '@home/pages/widget/select-widget-type-dialog.component';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
TbIotHubAddItemDialogComponent,
IotHubAddItemDialogData,
IotHubAddItemDialogResult
} from '@home/components/iot-hub/iot-hub-add-item-dialog.component';
@Injectable() @Injectable()
export class WidgetTypesTableConfigResolver { export class WidgetTypesTableConfigResolver {
@ -66,7 +62,8 @@ export class WidgetTypesTableConfigResolver {
private translate: TranslateService, private translate: TranslateService,
private importExport: ImportExportService, private importExport: ImportExportService,
private datePipe: DatePipe, private datePipe: DatePipe,
private router: Router) { private router: Router,
private iotHubActions: IotHubActionsService) {
this.config.entityType = EntityType.WIDGETS_BUNDLE; this.config.entityType = EntityType.WIDGETS_BUNDLE;
this.config.entityComponent = WidgetTypeComponent; this.config.entityComponent = WidgetTypeComponent;
@ -196,15 +193,7 @@ export class WidgetTypesTableConfigResolver {
} }
addWidgetFromIotHub() { addWidgetFromIotHub() {
const dialogRef = this.dialog.open(TbIotHubAddItemDialogComponent, { this.iotHubActions.addItem(ItemType.WIDGET).subscribe(result => {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: true,
autoFocus: false,
data: {
itemType: ItemType.WIDGET
} as IotHubAddItemDialogData
});
dialogRef.afterClosed().subscribe((result: IotHubAddItemDialogResult) => {
if (result?.descriptor) { if (result?.descriptor) {
this.config.updateData(); this.config.updateData();
} }

Loading…
Cancel
Save