UI: Add enabled notification rule property
This commit is contained in:
		
							parent
							
								
									5cec1b8af2
								
							
						
					
					
						commit
						30ac9942f0
					
				@ -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>
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
      });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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",
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user