Browse Source

feat(iot-hub): add "Add from IoT Hub" action to alarm rules table

- Inject IotHubActionsService into AlarmRulesTableConfig (and the
  surrounding alarm-rules table component + AlarmRulesTableConfig
  resolver) and register a third header action descriptor — "Add
  from IoT Hub" (icon: hub) — that calls
  iotHubActions.addItem(ItemType.ALARM_RULE, { entityId }) and
  refreshes the table on a successful install.
- Extend TbIotHubAddItemDialogComponent so the same
  TbIotHubSelectCfEntityDialogComponent prompt is reused when an
  ALARM_RULE install is launched without a preselected entityId,
  not just for CALCULATED_FIELD installs.
pull/15540/head
Igor Kulikov 4 months ago
parent
commit
bed6caa8bf
  1. 17
      ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts
  2. 5
      ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table.component.ts
  3. 2
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-add-item-dialog.component.ts
  4. 3
      ui-ngx/src/app/modules/home/pages/alarm/alarm-routing.module.ts

17
ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts

@ -70,6 +70,8 @@ import { AlarmRulesTabsComponent } from '@home/pages/alarm/alarm-rules-tabs.comp
import { Router } from '@angular/router';
import { EntityAction } from '@home/models/entity/entity-component.models';
import { AlarmRulesComponent } from '@home/components/alarm-rules/alarm-rules.component';
import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
export type AlarmRuleTableEntity = CalculatedFieldAlarmRule | CalculatedFieldAlarmRuleInfo;
@ -97,6 +99,7 @@ export class AlarmRulesTableConfig extends EntityTableConfig<AlarmRuleTableEntit
private entityDebugSettingsService: EntityDebugSettingsService,
private utilsService: UtilsService,
private router: Router,
private iotHubActions: IotHubActionsService,
public pageMode: boolean = false,
) {
super();
@ -150,6 +153,12 @@ export class AlarmRulesTableConfig extends EntityTableConfig<AlarmRuleTableEntit
icon: 'file_upload',
isEnabled: () => true,
onAction: () => this.importCalculatedField()
},
{
name: this.translate.instant('iot-hub.add-from-iot-hub'),
icon: 'hub',
isEnabled: () => true,
onAction: () => this.addAlarmRuleFromIotHub()
}
];
@ -333,6 +342,14 @@ export class AlarmRulesTableConfig extends EntityTableConfig<AlarmRuleTableEntit
this.importExportService.exportCalculatedField(calculatedField.id.id);
}
private addAlarmRuleFromIotHub(): void {
this.iotHubActions.addItem(ItemType.ALARM_RULE, { entityId: this.entityId }).subscribe(result => {
if (result?.descriptor) {
this.updateData();
}
});
}
private importCalculatedField(): void {
this.importExportService.openCalculatedFieldImportDialog('alarm-rule.import', 'alarm-rule.file')
.pipe(

5
ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table.component.ts

@ -37,6 +37,7 @@ import { DatePipe } from '@angular/common';
import { AlarmRulesTableConfig } from "@home/components/alarm-rules/alarm-rules-table-config";
import { UtilsService } from "@core/services/utils.service";
import { ActivatedRoute, Router } from "@angular/router";
import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
@Component({
selector: 'tb-alarm-rules-table',
@ -71,7 +72,8 @@ export class AlarmRulesTableComponent {
private utilsService: UtilsService,
private destroyRef: DestroyRef,
private route: ActivatedRoute,
private router: Router
private router: Router,
private iotHubActions: IotHubActionsService
) {
this.pageMode = !!this.route.snapshot.data.isPage;
effect(() => {
@ -91,6 +93,7 @@ export class AlarmRulesTableComponent {
this.entityDebugSettingsService,
this.utilsService,
this.router,
this.iotHubActions,
this.pageMode,
);
this.cd.markForCheck();

2
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-add-item-dialog.component.ts

@ -82,7 +82,7 @@ export class TbIotHubAddItemDialogComponent extends DialogComponent<TbIotHubAddI
this.installDeviceItem(item);
return;
}
if (this.itemType === ItemType.CALCULATED_FIELD && !this.data.entityId) {
if ((this.itemType === ItemType.CALCULATED_FIELD || this.itemType === ItemType.ALARM_RULE) && !this.data.entityId) {
this.dialog.open<TbIotHubSelectCfEntityDialogComponent, IotHubSelectCfEntityDialogData, EntityId | null>(
TbIotHubSelectCfEntityDialogComponent, {
panelClass: ['tb-dialog'],

3
ui-ngx/src/app/modules/home/pages/alarm/alarm-routing.module.ts

@ -36,6 +36,7 @@ import { ImportExportService } from '@shared/import-export/import-export.service
import { EntityDebugSettingsService } from '@home/components/entity/debug/entity-debug-settings.service';
import { UtilsService } from '@core/services/utils.service';
import { AlarmRulesTableConfig } from '@home/components/alarm-rules/alarm-rules-table-config';
import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
export const AlarmRulesTableConfigResolver: ResolveFn<AlarmRulesTableConfig> =
(_route: ActivatedRouteSnapshot,
@ -50,6 +51,7 @@ export const AlarmRulesTableConfigResolver: ResolveFn<AlarmRulesTableConfig> =
entityDebugSettingsService = inject(EntityDebugSettingsService),
utilsService = inject(UtilsService),
router = inject(Router),
iotHubActions = inject(IotHubActionsService),
) => {
return new AlarmRulesTableConfig(
alarmRulesService,
@ -66,6 +68,7 @@ export const AlarmRulesTableConfigResolver: ResolveFn<AlarmRulesTableConfig> =
entityDebugSettingsService,
utilsService,
router,
iotHubActions,
true,
);
};

Loading…
Cancel
Save