22 changed files with 908 additions and 876 deletions
@ -0,0 +1,398 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
--> |
||||
|
<section class="tb-template-header"> |
||||
|
<div class="tb-form-panel-title" translate>notification.customize-messages</div> |
||||
|
<div class="tb-form-panel-hint tb-hint-available-params"> |
||||
|
<span class="content">{{ 'notification.input-fields-support-templatization' | translate}}</span> |
||||
|
<span tb-help-popup="{{ NotificationTemplateTypeTranslateMap.get(notificationType).helpId }}" |
||||
|
tb-help-popup-placement="bottom" |
||||
|
trigger-style="letter-spacing:0.25px;font-size:12px;" |
||||
|
[tb-help-popup-style]="{maxWidth: '800px'}" |
||||
|
trigger-text="{{ 'notification.see-documentation' | translate }}"></span> |
||||
|
</div> |
||||
|
</section> |
||||
|
<section [formGroup]="templateConfigurationForm" class="tb-form-panel no-border no-padding"> |
||||
|
<section class="tb-form-panel tb-slide-toggle stroked" |
||||
|
[formGroupName]="NotificationDeliveryMethod.WEB" |
||||
|
*ngIf="templateConfigurationForm.get('WEB.enabled').value"> |
||||
|
<mat-expansion-panel class="tb-settings" expanded> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap" class="fill-width"> |
||||
|
<mat-panel-title class="template-tittle"> |
||||
|
<tb-icon>{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.WEB).icon }}</tb-icon> |
||||
|
{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.WEB).name | translate }} |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent class="tb-extension-panel"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>notification.subject</mat-label> |
||||
|
<input matInput formControlName="subject"> |
||||
|
<mat-error *ngIf="templateConfigurationForm.get('WEB.subject').hasError('required')"> |
||||
|
{{ 'notification.subject-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>notification.message</mat-label> |
||||
|
<textarea matInput |
||||
|
cdkTextareaAutosize |
||||
|
cols="1" |
||||
|
cdkAutosizeMinRows="1" |
||||
|
formControlName="body"> |
||||
|
</textarea> |
||||
|
<mat-error *ngIf="templateConfigurationForm.get('WEB.body').hasError('required')"> |
||||
|
{{ 'notification.message-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<section formGroupName="additionalConfig" class="tb-form-panel no-padding no-border"> |
||||
|
<div class="tb-form-row space-between" formGroupName="icon"> |
||||
|
<mat-slide-toggle formControlName="enabled" class="mat-slide"> |
||||
|
{{ 'icon.icon' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
||||
|
<tb-material-icon-select asBoxInput |
||||
|
[color]="templateConfigurationForm.get('WEB.additionalConfig.icon.color').value" |
||||
|
formControlName="icon"> |
||||
|
</tb-material-icon-select> |
||||
|
<tb-color-input asBoxInput |
||||
|
formControlName="color"> |
||||
|
</tb-color-input> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-form-panel tb-slide-toggle stroked" formGroupName="actionButtonConfig"> |
||||
|
<mat-expansion-panel class="tb-settings" |
||||
|
[expanded]="templateConfigurationForm.get('WEB.additionalConfig.actionButtonConfig.enabled').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap" class="fill-width"> |
||||
|
<mat-panel-title fxFlex="60"> |
||||
|
<mat-slide-toggle class="mat-slide" formControlName="enabled" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'notification.action-button' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</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> |
||||
|
<mat-label translate>notification.button-text</mat-label> |
||||
|
<input matInput formControlName="text" required> |
||||
|
<mat-error |
||||
|
*ngIf="templateConfigurationForm.get('WEB.additionalConfig.actionButtonConfig.text').hasError('required')"> |
||||
|
{{ 'notification.button-text-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error |
||||
|
*ngIf="templateConfigurationForm.get('WEB.additionalConfig.actionButtonConfig.text').hasError('maxlength')"> |
||||
|
{{ 'notification.button-text-max-length' | translate : |
||||
|
{length: templateConfigurationForm.get('WEB.additionalConfig.actionButtonConfig.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="templateConfigurationForm.get('WEB.additionalConfig.actionButtonConfig.linkType').value === actionButtonLinkType.LINK; else dashboardSelector"> |
||||
|
<mat-label translate>notification.link</mat-label> |
||||
|
<input matInput formControlName="link" required> |
||||
|
<mat-error |
||||
|
*ngIf="templateConfigurationForm.get('WEB.additionalConfig.actionButtonConfig.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]="templateConfigurationForm.get('WEB.additionalConfig.actionButtonConfig.dashboardId').value" |
||||
|
formControlName="dashboardState"> |
||||
|
</tb-dashboard-state-autocomplete> |
||||
|
</ng-template> |
||||
|
</div> |
||||
|
<mat-slide-toggle formControlName="setEntityIdInState" class="toggle" |
||||
|
*ngIf="templateConfigurationForm.get('WEB.additionalConfig.actionButtonConfig.linkType').value === actionButtonLinkType.DASHBOARD"> |
||||
|
{{ 'notification.set-entity-from-notification' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</div> |
||||
|
</section> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</section> |
||||
|
<section class="tb-form-panel tb-slide-toggle stroked" |
||||
|
[formGroupName]="NotificationDeliveryMethod.MOBILE_APP" |
||||
|
*ngIf="templateConfigurationForm.get('MOBILE_APP.enabled').value"> |
||||
|
<mat-expansion-panel class="tb-settings" expanded> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap" class="fill-width"> |
||||
|
<mat-panel-title class="template-tittle"> |
||||
|
<tb-icon>{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.MOBILE_APP).icon }}</tb-icon> |
||||
|
{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.MOBILE_APP).name | translate }} |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent class="tb-extension-panel"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>notification.subject</mat-label> |
||||
|
<input matInput formControlName="subject"> |
||||
|
<mat-error *ngIf="templateConfigurationForm.get('MOBILE_APP.subject').hasError('required')"> |
||||
|
{{ 'notification.subject-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>notification.message</mat-label> |
||||
|
<textarea matInput |
||||
|
cdkTextareaAutosize |
||||
|
cols="1" |
||||
|
cdkAutosizeMinRows="1" |
||||
|
formControlName="body"> |
||||
|
</textarea> |
||||
|
<mat-error *ngIf="templateConfigurationForm.get('MOBILE_APP.body').hasError('required')"> |
||||
|
{{ 'notification.message-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<div class="tb-form-panel tb-slide-toggle stroked" formGroupName="additionalConfig"> |
||||
|
<mat-expansion-panel class="tb-settings" |
||||
|
formGroupName="onClick" |
||||
|
[expanded]="templateConfigurationForm.get('MOBILE_APP.additionalConfig.onClick.enabled').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap" class="fill-width"> |
||||
|
<mat-panel-title fxFlex="60"> |
||||
|
<mat-slide-toggle class="mat-slide" formControlName="enabled" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'notification.open-dashboard-on-click-notification' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent class="tb-extension-panel"> |
||||
|
<div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column"> |
||||
|
<tb-dashboard-autocomplete |
||||
|
fxFlex fxFlex.xs="100" |
||||
|
required |
||||
|
formControlName="dashboardId"> |
||||
|
</tb-dashboard-autocomplete> |
||||
|
<tb-dashboard-state-autocomplete fxFlex fxFlex.xs="100" |
||||
|
[dashboardId]="templateConfigurationForm.get('MICROSOFT_TEAMS.button.dashboardId').value" |
||||
|
formControlName="dashboardState"> |
||||
|
</tb-dashboard-state-autocomplete> |
||||
|
</div> |
||||
|
<mat-slide-toggle formControlName="setEntityIdInState" class="toggle"> |
||||
|
{{ 'notification.set-entity-from-notification' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</section> |
||||
|
<section class="tb-form-panel tb-slide-toggle stroked" |
||||
|
[formGroupName]="NotificationDeliveryMethod.SMS" |
||||
|
*ngIf="templateConfigurationForm.get('SMS.enabled').value"> |
||||
|
<mat-expansion-panel class="tb-settings" expanded> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap" class="fill-width"> |
||||
|
<mat-panel-title class="template-tittle"> |
||||
|
<tb-icon>{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.SMS).icon }}</tb-icon> |
||||
|
{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.SMS).name | translate }} |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent class="tb-extension-panel"> |
||||
|
<mat-form-field class="mat-block" subscriptSizing="dynamic"> |
||||
|
<mat-label translate>notification.message</mat-label> |
||||
|
<textarea matInput |
||||
|
cdkTextareaAutosize |
||||
|
cols="1" |
||||
|
cdkAutosizeMinRows="1" |
||||
|
formControlName="body"> |
||||
|
</textarea> |
||||
|
<mat-hint></mat-hint> |
||||
|
<mat-error *ngIf="templateConfigurationForm.get('SMS.body').hasError('required')"> |
||||
|
{{ 'notification.message-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="templateConfigurationForm.get('SMS.body').hasError('maxlength')"> |
||||
|
{{ 'notification.message-max-length' | translate : |
||||
|
{length: templateConfigurationForm.get('SMS.body').getError('maxlength').requiredLength} |
||||
|
}} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</section> |
||||
|
<section class="tb-form-panel tb-slide-toggle stroked" |
||||
|
[formGroupName]="NotificationDeliveryMethod.MICROSOFT_TEAMS" |
||||
|
*ngIf="templateConfigurationForm.get('MICROSOFT_TEAMS.enabled').value"> |
||||
|
<mat-expansion-panel class="tb-settings" expanded> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap" class="fill-width"> |
||||
|
<mat-panel-title class="template-tittle"> |
||||
|
<tb-icon>{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.MICROSOFT_TEAMS).icon }}</tb-icon> |
||||
|
{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.MICROSOFT_TEAMS).name | translate }} |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent class="tb-extension-panel"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>notification.subject</mat-label> |
||||
|
<input matInput formControlName="subject"> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>notification.message</mat-label> |
||||
|
<textarea matInput |
||||
|
cdkTextareaAutosize |
||||
|
cols="1" |
||||
|
cdkAutosizeMinRows="1" |
||||
|
formControlName="body"> |
||||
|
</textarea> |
||||
|
<mat-error *ngIf="templateConfigurationForm.get('MICROSOFT_TEAMS.body').hasError('required')"> |
||||
|
{{ 'notification.message-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<div class="tb-form-panel no-padding no-border"> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div translate>notification.theme-color</div> |
||||
|
<tb-color-input asBoxInput formControlName="themeColor"></tb-color-input> |
||||
|
</div> |
||||
|
<div class="tb-form-panel tb-slide-toggle stroked" formGroupName="button"> |
||||
|
<mat-expansion-panel class="tb-settings" |
||||
|
[expanded]="templateConfigurationForm.get('MICROSOFT_TEAMS.button.enabled').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap" class="fill-width"> |
||||
|
<mat-panel-title fxFlex="60"> |
||||
|
<mat-slide-toggle class="mat-slide" formControlName="enabled" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'notification.action-button' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</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> |
||||
|
<mat-label translate>notification.button-text</mat-label> |
||||
|
<input matInput formControlName="text" required> |
||||
|
<mat-error |
||||
|
*ngIf="templateConfigurationForm.get('MICROSOFT_TEAMS.button.text').hasError('required')"> |
||||
|
{{ 'notification.button-text-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error |
||||
|
*ngIf="templateConfigurationForm.get('MICROSOFT_TEAMS.button.text').hasError('maxlength')"> |
||||
|
{{'notification.button-text-max-length' | translate : |
||||
|
{length: templateConfigurationForm.get('MICROSOFT_TEAMS.button.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="templateConfigurationForm.get('MICROSOFT_TEAMS.button.linkType').value === actionButtonLinkType.LINK; else dashboardSelector"> |
||||
|
<mat-label translate>notification.link</mat-label> |
||||
|
<input matInput formControlName="link" required> |
||||
|
<mat-error |
||||
|
*ngIf="templateConfigurationForm.get('MICROSOFT_TEAMS.button.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]="templateConfigurationForm.get('MICROSOFT_TEAMS.button.dashboardId').value" |
||||
|
formControlName="dashboardState"> |
||||
|
</tb-dashboard-state-autocomplete> |
||||
|
</ng-template> |
||||
|
</div> |
||||
|
<mat-slide-toggle formControlName="setEntityIdInState" class="toggle" |
||||
|
*ngIf="templateConfigurationForm.get('MICROSOFT_TEAMS.button.linkType').value === actionButtonLinkType.DASHBOARD"> |
||||
|
{{ 'notification.set-entity-from-notification' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</div> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</section> |
||||
|
<section class="tb-form-panel tb-slide-toggle stroked" |
||||
|
[formGroupName]="NotificationDeliveryMethod.SLACK" |
||||
|
*ngIf="templateConfigurationForm.get('SLACK.enabled').value"> |
||||
|
<mat-expansion-panel class="tb-settings" expanded> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap" class="fill-width"> |
||||
|
<mat-panel-title class="template-tittle"> |
||||
|
<tb-icon>{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.SLACK).icon }}</tb-icon> |
||||
|
{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.SLACK).name | translate }} |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent class="tb-extension-panel"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>notification.message</mat-label> |
||||
|
<textarea matInput |
||||
|
cdkTextareaAutosize |
||||
|
cols="1" |
||||
|
cdkAutosizeMinRows="1" |
||||
|
formControlName="body"> |
||||
|
</textarea> |
||||
|
<mat-error *ngIf="templateConfigurationForm.get('SLACK.body').hasError('required')"> |
||||
|
{{ 'notification.message-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</section> |
||||
|
<section class="tb-form-panel tb-slide-toggle stroked" |
||||
|
[formGroupName]="NotificationDeliveryMethod.EMAIL" |
||||
|
*ngIf="templateConfigurationForm.get('EMAIL.enabled').value"> |
||||
|
<mat-expansion-panel class="tb-settings" expanded> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap" class="fill-width"> |
||||
|
<mat-panel-title class="template-tittle"> |
||||
|
<tb-icon>{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.EMAIL).icon }}</tb-icon> |
||||
|
{{ NotificationDeliveryMethodInfoMap.get(NotificationDeliveryMethod.EMAIL).name | translate }} |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent class="tb-extension-panel"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>notification.subject</mat-label> |
||||
|
<input matInput formControlName="subject"> |
||||
|
<mat-error *ngIf="templateConfigurationForm.get('EMAIL.subject').hasError('required')"> |
||||
|
{{ 'notification.subject-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-label class="tb-title tb-required" |
||||
|
[class.tb-error]="(interacted || templateConfigurationForm.get('EMAIL.body').touched) && templateConfigurationForm.get('EMAIL.body').hasError('required')" |
||||
|
translate>notification.message |
||||
|
</mat-label> |
||||
|
<editor [init]="tinyMceOptions" formControlName="body"></editor> |
||||
|
<mat-error class="tb-mat-error" |
||||
|
*ngIf="(interacted || templateConfigurationForm.get('EMAIL.body').touched) && templateConfigurationForm.get('EMAIL.body').hasError('required')"> |
||||
|
{{ 'notification.message-required' | translate }} |
||||
|
</mat-error> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</section> |
||||
|
</section> |
||||
@ -0,0 +1,66 @@ |
|||||
|
/** |
||||
|
* 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. |
||||
|
*/ |
||||
|
:host { |
||||
|
.tb-template-header { |
||||
|
margin-bottom: 12px; |
||||
|
.tb-hint-available-params { |
||||
|
color: rgba(0,0,0,0.54); |
||||
|
letter-spacing: 0.4px; |
||||
|
|
||||
|
.content { |
||||
|
vertical-align: middle; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.template-tittle { |
||||
|
gap: 12px; |
||||
|
font-weight: normal; |
||||
|
tb-icon { |
||||
|
color: rgba(0, 0, 0, .38); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.tb-mat-error { |
||||
|
font-size: 13px; |
||||
|
} |
||||
|
|
||||
|
.tb-title { |
||||
|
font-size: 16px; |
||||
|
line-height: 24px; |
||||
|
|
||||
|
&.tb-required::after { |
||||
|
font-size: initial; |
||||
|
content: "*"; |
||||
|
} |
||||
|
|
||||
|
&.tb-error { |
||||
|
color: var(--mdc-theme-error, #f44336); |
||||
|
|
||||
|
&.tb-required::after { |
||||
|
color: var(--mdc-theme-error, #f44336); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
:host ::ng-deep { |
||||
|
.tb-form-panel .mat-expansion-panel.tb-settings { |
||||
|
& > .mat-expansion-panel-content > .mat-expansion-panel-body { |
||||
|
gap: 0; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,312 @@ |
|||||
|
///
|
||||
|
/// 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.
|
||||
|
///
|
||||
|
|
||||
|
import { Component, forwardRef, Input, OnDestroy } from '@angular/core'; |
||||
|
import { |
||||
|
ControlValueAccessor, |
||||
|
FormBuilder, |
||||
|
FormGroup, |
||||
|
NG_VALIDATORS, |
||||
|
NG_VALUE_ACCESSOR, |
||||
|
ValidationErrors, |
||||
|
Validator, |
||||
|
Validators |
||||
|
} from '@angular/forms'; |
||||
|
import { |
||||
|
ActionButtonLinkType, |
||||
|
ActionButtonLinkTypeTranslateMap, |
||||
|
DeliveryMethodsTemplates, |
||||
|
NotificationDeliveryMethod, |
||||
|
NotificationDeliveryMethodInfoMap, |
||||
|
NotificationTemplateTypeTranslateMap, |
||||
|
NotificationType |
||||
|
} from '@shared/models/notification.models'; |
||||
|
import { takeUntil } from 'rxjs/operators'; |
||||
|
import { Subject } from 'rxjs'; |
||||
|
import { isDefinedAndNotNull } from '@core/utils'; |
||||
|
import { coerceBoolean } from '@shared/decorators/coercion'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-template-configuration', |
||||
|
templateUrl: './notification-template-configuration.component.html', |
||||
|
styleUrls: ['./notification-template-configuration.component.scss'], |
||||
|
providers: [ |
||||
|
{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => NotificationTemplateConfigurationComponent), |
||||
|
multi: true |
||||
|
}, |
||||
|
{ |
||||
|
provide: NG_VALIDATORS, |
||||
|
useExisting: forwardRef(() => NotificationTemplateConfigurationComponent), |
||||
|
multi: true, |
||||
|
} |
||||
|
] |
||||
|
}) |
||||
|
export class NotificationTemplateConfigurationComponent implements OnDestroy, ControlValueAccessor, Validator { |
||||
|
|
||||
|
templateConfigurationForm: FormGroup; |
||||
|
|
||||
|
NotificationDeliveryMethodInfoMap = NotificationDeliveryMethodInfoMap; |
||||
|
|
||||
|
@Input() |
||||
|
set predefinedDeliveryMethodsTemplate(value: Partial<DeliveryMethodsTemplates>) { |
||||
|
if (isDefinedAndNotNull(value)) { |
||||
|
this.templateConfigurationForm.patchValue(value, {emitEvent: false}); |
||||
|
this.updateDisabledForms(); |
||||
|
this.templateConfigurationForm.updateValueAndValidity(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Input() |
||||
|
notificationType: NotificationType; |
||||
|
|
||||
|
@Input() |
||||
|
@coerceBoolean() |
||||
|
interacted: boolean; |
||||
|
|
||||
|
readonly NotificationDeliveryMethod = NotificationDeliveryMethod; |
||||
|
readonly NotificationTemplateTypeTranslateMap = NotificationTemplateTypeTranslateMap; |
||||
|
|
||||
|
readonly actionButtonLinkType = ActionButtonLinkType; |
||||
|
readonly actionButtonLinkTypes = Object.keys(ActionButtonLinkType) as ActionButtonLinkType[]; |
||||
|
readonly actionButtonLinkTypeTranslateMap = ActionButtonLinkTypeTranslateMap; |
||||
|
|
||||
|
tinyMceOptions: Record<string, any> = { |
||||
|
base_url: '/assets/tinymce', |
||||
|
suffix: '.min', |
||||
|
plugins: ['link table image imagetools code fullscreen'], |
||||
|
menubar: 'edit insert tools view format table', |
||||
|
toolbar: 'fontselect fontsizeselect | formatselect | bold italic strikethrough forecolor backcolor ' + |
||||
|
'| link | table | image | alignleft aligncenter alignright alignjustify ' + |
||||
|
'| numlist bullist outdent indent | removeformat | code | fullscreen', |
||||
|
toolbar_mode: 'sliding', |
||||
|
height: 400, |
||||
|
autofocus: false, |
||||
|
branding: false |
||||
|
}; |
||||
|
|
||||
|
private propagateChange = (v: any) => { }; |
||||
|
private readonly destroy$ = new Subject<void>(); |
||||
|
|
||||
|
constructor(private fb: FormBuilder) { |
||||
|
this.templateConfigurationForm = this.buildForm(); |
||||
|
this.templateConfigurationForm.valueChanges.pipe( |
||||
|
takeUntil(this.destroy$) |
||||
|
).subscribe((value) => { |
||||
|
this.propagateChange(value); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
ngOnDestroy() { |
||||
|
this.destroy$.next(); |
||||
|
this.destroy$.complete(); |
||||
|
} |
||||
|
|
||||
|
writeValue(value: any) { |
||||
|
this.templateConfigurationForm.patchValue(value, {emitEvent: false}); |
||||
|
} |
||||
|
|
||||
|
registerOnChange(fn: any): void { |
||||
|
this.propagateChange = fn; |
||||
|
} |
||||
|
|
||||
|
registerOnTouched(fn: any): void { |
||||
|
} |
||||
|
|
||||
|
setDisabledState(isDisabled: boolean) { |
||||
|
if (isDisabled) { |
||||
|
this.templateConfigurationForm.disable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.updateDisabledForms(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
validate(): ValidationErrors { |
||||
|
return this.templateConfigurationForm.valid ? null : { |
||||
|
templateConfiguration: { |
||||
|
valid: false, |
||||
|
}, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
private updateDisabledForms(){ |
||||
|
Object.values(NotificationDeliveryMethod).forEach((method) => { |
||||
|
const form = this.templateConfigurationForm.get(method); |
||||
|
if (!form.get('enabled').value) { |
||||
|
form.disable({emitEvent: false}); |
||||
|
} else { |
||||
|
form.enable({emitEvent: false}); |
||||
|
switch (method) { |
||||
|
case NotificationDeliveryMethod.WEB: |
||||
|
form.get('additionalConfig.icon.enabled').updateValueAndValidity({onlySelf: true}); |
||||
|
form.get('additionalConfig.actionButtonConfig.enabled').updateValueAndValidity({onlySelf: true}); |
||||
|
break; |
||||
|
case NotificationDeliveryMethod.MICROSOFT_TEAMS: |
||||
|
form.get('button.enabled').updateValueAndValidity({onlySelf: true}); |
||||
|
break; |
||||
|
case NotificationDeliveryMethod.MOBILE_APP: |
||||
|
form.get('additionalConfig.onClick.enabled').updateValueAndValidity({onlySelf: true}); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private buildForm(): FormGroup { |
||||
|
const form = this.fb.group({}); |
||||
|
|
||||
|
Object.values(NotificationDeliveryMethod).forEach((method) => { |
||||
|
form.addControl(method, this.buildDeliveryMethodControl(method), {emitEvent: false}); |
||||
|
}); |
||||
|
|
||||
|
return form; |
||||
|
} |
||||
|
|
||||
|
private buildDeliveryMethodControl(deliveryMethod: NotificationDeliveryMethod): FormGroup { |
||||
|
let deliveryMethodForm: FormGroup; |
||||
|
switch (deliveryMethod) { |
||||
|
case NotificationDeliveryMethod.WEB: |
||||
|
deliveryMethodForm = this.fb.group({ |
||||
|
subject: ['', Validators.required], |
||||
|
body: ['', Validators.required], |
||||
|
additionalConfig: this.fb.group({ |
||||
|
icon: this.fb.group({ |
||||
|
enabled: [false], |
||||
|
icon: [{value: 'notifications', disabled: true}, Validators.required], |
||||
|
color: [{value: '#757575', disabled: true}] |
||||
|
}), |
||||
|
actionButtonConfig: this.createButtonConfigForm() |
||||
|
}) |
||||
|
}); |
||||
|
|
||||
|
deliveryMethodForm.get('additionalConfig.icon.enabled').valueChanges.pipe( |
||||
|
takeUntil(this.destroy$) |
||||
|
).subscribe((value) => { |
||||
|
if (value) { |
||||
|
deliveryMethodForm.get('additionalConfig.icon.icon').enable({emitEvent: false}); |
||||
|
deliveryMethodForm.get('additionalConfig.icon.color').enable({emitEvent: false}); |
||||
|
} else { |
||||
|
deliveryMethodForm.get('additionalConfig.icon.icon').disable({emitEvent: false}); |
||||
|
deliveryMethodForm.get('additionalConfig.icon.color').disable({emitEvent: false}); |
||||
|
} |
||||
|
}); |
||||
|
break; |
||||
|
case NotificationDeliveryMethod.EMAIL: |
||||
|
deliveryMethodForm = this.fb.group({ |
||||
|
subject: ['', Validators.required], |
||||
|
body: ['', Validators.required] |
||||
|
}); |
||||
|
break; |
||||
|
case NotificationDeliveryMethod.SMS: |
||||
|
deliveryMethodForm = this.fb.group({ |
||||
|
body: ['', [Validators.required, Validators.maxLength(320)]] |
||||
|
}); |
||||
|
break; |
||||
|
case NotificationDeliveryMethod.SLACK: |
||||
|
deliveryMethodForm = this.fb.group({ |
||||
|
body: ['', Validators.required] |
||||
|
}); |
||||
|
break; |
||||
|
case NotificationDeliveryMethod.MOBILE_APP: |
||||
|
deliveryMethodForm = this.fb.group({ |
||||
|
subject: ['', Validators.required], |
||||
|
body: ['', Validators.required], |
||||
|
additionalConfig: this.fb.group({ |
||||
|
onClick: this.fb.group({ |
||||
|
enabled: [false], |
||||
|
linkType: [{value: ActionButtonLinkType.DASHBOARD, disabled: true}], |
||||
|
dashboardId: [{value: null, disabled: true}, Validators.required], |
||||
|
dashboardState: [{value: null, disabled: true}], |
||||
|
setEntityIdInState: [{value: true, disabled: true}] |
||||
|
}) |
||||
|
}) |
||||
|
}); |
||||
|
deliveryMethodForm.get('additionalConfig.onClick.enabled').valueChanges.pipe( |
||||
|
takeUntil(this.destroy$) |
||||
|
).subscribe((value) => { |
||||
|
if (value) { |
||||
|
deliveryMethodForm.get('additionalConfig.onClick.linkType').enable({emitEvent: false}); |
||||
|
deliveryMethodForm.get('additionalConfig.onClick.dashboardId').enable({emitEvent: false}); |
||||
|
deliveryMethodForm.get('additionalConfig.onClick.dashboardState').enable({emitEvent: false}); |
||||
|
deliveryMethodForm.get('additionalConfig.onClick.setEntityIdInState').enable({emitEvent: false}); |
||||
|
} else { |
||||
|
deliveryMethodForm.get('additionalConfig.onClick.linkType').disable({emitEvent: false}); |
||||
|
deliveryMethodForm.get('additionalConfig.onClick.dashboardId').disable({emitEvent: false}); |
||||
|
deliveryMethodForm.get('additionalConfig.onClick.dashboardState').disable({emitEvent: false}); |
||||
|
deliveryMethodForm.get('additionalConfig.onClick.setEntityIdInState').disable({emitEvent: false}); |
||||
|
} |
||||
|
}); |
||||
|
break; |
||||
|
case NotificationDeliveryMethod.MICROSOFT_TEAMS: |
||||
|
deliveryMethodForm = this.fb.group({ |
||||
|
subject: [''], |
||||
|
body: ['', Validators.required], |
||||
|
themeColor: [''], |
||||
|
button: this.createButtonConfigForm() |
||||
|
}); |
||||
|
break; |
||||
|
default: |
||||
|
throw new Error(`Not configured templated for notification delivery method: ${deliveryMethod}`); |
||||
|
} |
||||
|
deliveryMethodForm.addControl('enabled', this.fb.control(false), {emitEvent: false}); |
||||
|
deliveryMethodForm.addControl('method', this.fb.control(deliveryMethod), {emitEvent: false}); |
||||
|
return deliveryMethodForm; |
||||
|
} |
||||
|
|
||||
|
private createButtonConfigForm(): FormGroup { |
||||
|
const form = this.fb.group({ |
||||
|
enabled: [false], |
||||
|
text: [{value: '', disabled: true}, [Validators.required, Validators.maxLength(50)]], |
||||
|
linkType: [ActionButtonLinkType.LINK], |
||||
|
link: [{value: '', disabled: true}, Validators.required], |
||||
|
dashboardId: [{value: null, disabled: true}, Validators.required], |
||||
|
dashboardState: [{value: null, disabled: true}], |
||||
|
setEntityIdInState: [{value: true, disabled: true}] |
||||
|
}); |
||||
|
|
||||
|
form.get('enabled').valueChanges.pipe( |
||||
|
takeUntil(this.destroy$) |
||||
|
).subscribe((value) => { |
||||
|
if (value) { |
||||
|
form.enable({emitEvent: false}); |
||||
|
form.get('linkType').updateValueAndValidity({onlySelf: true}); |
||||
|
} else { |
||||
|
form.disable({emitEvent: false}); |
||||
|
form.get('enabled').enable({emitEvent: false}); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
form.get('linkType').valueChanges.pipe( |
||||
|
takeUntil(this.destroy$) |
||||
|
).subscribe((value) => { |
||||
|
const isEnabled = form.get('enabled').value; |
||||
|
if (isEnabled) { |
||||
|
if (value === ActionButtonLinkType.LINK) { |
||||
|
form.get('link').enable({emitEvent: false}); |
||||
|
form.get('dashboardId').disable({emitEvent: false}); |
||||
|
form.get('dashboardState').disable({emitEvent: false}); |
||||
|
form.get('setEntityIdInState').disable({emitEvent: false}); |
||||
|
} else { |
||||
|
form.get('link').disable({emitEvent: false}); |
||||
|
form.get('dashboardId').enable({emitEvent: false}); |
||||
|
form.get('dashboardState').enable({emitEvent: false}); |
||||
|
form.get('setEntityIdInState').enable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
return form; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue