UI: Add enabled notification rule property

This commit is contained in:
Vladyslav_Prykhodko 2023-05-19 13:43:33 +03:00
parent 5cec1b8af2
commit 30ac9942f0
5 changed files with 35 additions and 7 deletions

View File

@ -224,7 +224,8 @@
matTooltip="{{ actionDescriptor.nameFunction ? actionDescriptor.nameFunction(entity) : actionDescriptor.name }}"
matTooltipPosition="above"
(click)="actionDescriptor.onAction($event, entity)">
<mat-icon [svgIcon]="actionDescriptor.mdiIcon" [ngStyle]="actionDescriptor.style">
<mat-icon svgIcon="{{ actionDescriptor.mdiIconFunction ? actionDescriptor.mdiIconFunction(entity) : actionDescriptor.mdiIcon }}"
[ngStyle]="actionDescriptor.style">
{{actionDescriptor.icon}}</mat-icon>
</button>
</div>
@ -239,7 +240,8 @@
[disabled]="isLoading$ | async"
[fxShow]="actionDescriptor.isEnabled(entity)"
(click)="actionDescriptor.onAction($event, entity)">
<mat-icon [svgIcon]="actionDescriptor.mdiIcon" [ngStyle]="actionDescriptor.style">
<mat-icon svgIcon="{{ actionDescriptor.mdiIconFunction ? actionDescriptor.mdiIconFunction(entity) : actionDescriptor.mdiIcon }}"
[ngStyle]="actionDescriptor.style">
{{actionDescriptor.icon}}</mat-icon>
<span>{{ actionDescriptor.nameFunction ? actionDescriptor.nameFunction(entity) : actionDescriptor.name }}</span>
</button>

View File

@ -58,6 +58,7 @@ export interface CellActionDescriptor<T extends BaseData<HasId>> {
nameFunction?: (entity: T) => string;
icon?: string;
mdiIcon?: string;
mdiIconFunction?: (entity: T) => string;
style?: any;
isEnabled: (entity: T) => boolean;
onAction: ($event: MouseEvent, entity: T) => any;

View File

@ -44,6 +44,9 @@
{{ 'notification.rule-name-required' | translate }}
</mat-error>
</mat-form-field>
<mat-slide-toggle formControlName="enabled" style="margin-bottom: 22px;">
{{ 'notification.rule-enable' | translate }}
</mat-slide-toggle>
<mat-form-field class="mat-block">
<mat-label translate>notification.trigger.trigger</mat-label>
<mat-select formControlName="triggerType" required>
@ -55,11 +58,6 @@
{{ 'notification.trigger.trigger-required' | translate }}
</mat-error>
</mat-form-field>
<div>
<mat-slide-toggle formControlName="enabled">
{{ 'notification.rule-enable' | translate }}
</mat-slide-toggle>
</div>
<tb-template-autocomplete
required
allowCreate

View File

@ -92,6 +92,15 @@ export class RuleTableConfigResolver implements Resolve<EntityTableConfig<Notifi
private configureCellActions(): Array<CellActionDescriptor<NotificationRule>> {
return [{
name: '',
nameFunction: (entity) =>
this.translate.instant(entity.enabled ? 'notification.rule-disable' : 'notification.rule-enable'),
mdiIcon: 'mdi:toggle-switch',
isEnabled: () => true,
mdiIconFunction: (entity) => entity.enabled ? 'mdi:toggle-switch' : 'mdi:toggle-switch-off-outline',
onAction: ($event, entity) => this.toggleEnableMode($event, entity)
},
{
name: this.translate.instant('notification.copy-rule'),
icon: 'content_copy',
isEnabled: () => true,
@ -128,4 +137,21 @@ export class RuleTableConfigResolver implements Resolve<EntityTableConfig<Notifi
}
return false;
}
private toggleEnableMode($event: Event, rule: NotificationRule): void {
if ($event) {
$event.stopPropagation();
}
const modifyRule: NotificationRule = {
...rule,
enabled: !rule.enabled
};
this.notificationService.saveNotificationRule(modifyRule, {ignoreLoading: true})
.subscribe((notificationRule) => {
rule.enabled = notificationRule.enabled;
this.config.getTable().detectChanges();
});
}
}

View File

@ -2954,6 +2954,7 @@
"rule-engine-filter": "Rule engine filter",
"rule-name": "Rule name",
"rule-name-required": "Name is required",
"rule-disable": "Disable notification rule",
"rule-enable": "Enable notification rule",
"rule-node-filter": "Rule node filter",
"rules": "Rules",