notification-action-button-configuration.component.html 4.04 KB
<!--

    Copyright © 2016-2024 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="tb-form-panel tb-slide-toggle stroked" [formGroup]="actionButtonConfigForm">
  <mat-expansion-panel class="tb-settings"
                       [expanded]="actionButtonConfigForm.get('enabled').value">
    <mat-expansion-panel-header fxLayout="row wrap" class="fill-width">
      <mat-panel-title fxFlex="60">
        <div tb-hint-tooltip-icon="{{ sliderHint }}" class="tb-form-row no-border no-padding">
          <mat-slide-toggle class="mat-slide" formControlName="enabled" (click)="$event.stopPropagation()"
                            fxLayoutAlign="center">
            {{ actionTitle }}
          </mat-slide-toggle>
        </div>
      </mat-panel-title>
    </mat-expansion-panel-header>
    <ng-template matExpansionPanelContent class="tb-extension-panel">
      <div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column">
        <mat-form-field class="mat-block" fxFlex *ngIf="!hideButtonText">
          <mat-label translate>notification.button-text</mat-label>
          <input matInput formControlName="text" required>
          <mat-error
            *ngIf="actionButtonConfigForm.get('text').hasError('required')">
            {{ 'notification.button-text-required' | translate }}
          </mat-error>
          <mat-error
            *ngIf="actionButtonConfigForm.get('text').hasError('maxlength')">
            {{ 'notification.button-text-max-length' | translate :
                {length: actionButtonConfigForm.get('text').getError('maxlength').requiredLength}
            }}
          </mat-error>
        </mat-form-field>
      </div>
      <div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column">
        <mat-form-field fxFlex="30" fxFlex.xs="100">
          <mat-label translate>notification.action-type</mat-label>
          <mat-select formControlName="linkType">
            <mat-option *ngFor="let actionButtonLinkType of actionButtonLinkTypes"
                        [value]="actionButtonLinkType">
              {{ actionButtonLinkTypeTranslateMap.get(actionButtonLinkType) | translate }}
            </mat-option>
          </mat-select>
        </mat-form-field>
        <mat-form-field fxFlex
                        *ngIf="actionButtonConfigForm.get('linkType').value === actionButtonLinkType.LINK; else dashboardSelector">
          <mat-label translate>notification.link</mat-label>
          <input matInput formControlName="link" required>
          <mat-error
            *ngIf="actionButtonConfigForm.get('link').hasError('required')">
            {{ 'notification.link-required' | translate }}
          </mat-error>
        </mat-form-field>
        <ng-template #dashboardSelector>
          <tb-dashboard-autocomplete
            fxFlex="35" fxFlex.xs="100"
            required
            formControlName="dashboardId">
          </tb-dashboard-autocomplete>
          <tb-dashboard-state-autocomplete fxFlex="35" fxFlex.xs="100"
                                           [dashboardId]="actionButtonConfigForm.get('dashboardId').value"
                                           formControlName="dashboardState">
          </tb-dashboard-state-autocomplete>
        </ng-template>
      </div>
      <mat-slide-toggle formControlName="setEntityIdInState" class="toggle"
                        *ngIf="actionButtonConfigForm.get('linkType').value === actionButtonLinkType.DASHBOARD">
        {{ 'notification.set-entity-from-notification' | translate }}
      </mat-slide-toggle>
    </ng-template>
  </mat-expansion-panel>
</div>