22 changed files with 531 additions and 73 deletions
@ -0,0 +1,24 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2022 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 fxFlex="100" fxLayout="row" fxLayoutAlign="end center"> |
|||
<button mat-stroked-button color="primary" (click)="createTarget($event)"> |
|||
<div fxLayout="row" fxLayoutAlign="start center"> |
|||
<mat-icon>add</mat-icon>{{ 'notification.add-target' | translate }} |
|||
</div> |
|||
</button> |
|||
</div> |
|||
@ -0,0 +1,18 @@ |
|||
/** |
|||
* Copyright © 2016-2022 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{ |
|||
width: 100%; |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
///
|
|||
/// Copyright © 2016-2022 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 } from '@angular/core'; |
|||
import { EntityTableHeaderComponent } from '@home/components/entity/entity-table-header.component'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { NotificationTarget } from '@shared/models/notification.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-target-table-header', |
|||
templateUrl: './target-table-header.component.html', |
|||
styleUrls: ['target-table-header.component.scss'] |
|||
}) |
|||
export class TargetTableHeaderComponent extends EntityTableHeaderComponent<NotificationTarget> { |
|||
|
|||
constructor(protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
createTarget($event: Event) { |
|||
this.entitiesTableConfig.onEntityAction({event: $event, action: 'add', entity: null}); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2022 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. |
|||
|
|||
--> |
|||
<mat-toolbar color="primary"> |
|||
<h2>{{ dialogTitle | translate }}</h2> |
|||
<span fxFlex></span> |
|||
<button mat-icon-button |
|||
(click)="cancel()" |
|||
type="button"> |
|||
<mat-icon class="material-icons">close</mat-icon> |
|||
</button> |
|||
</mat-toolbar> |
|||
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> |
|||
</mat-progress-bar> |
|||
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div> |
|||
<form mat-dialog-content [formGroup]="templateNotificationForm"> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>notification.target-name</mat-label> |
|||
<input matInput formControlName="name" required> |
|||
<mat-error *ngIf="templateNotificationForm.get('name').hasError('required')"> |
|||
{{ 'notification.target-name-required' | translate }} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<label style="margin-bottom: 8px">{{ 'notification.type' | translate }}<sup> *</sup></label> |
|||
<mat-radio-group formControlName="type"> |
|||
<mat-radio-button [value]="NotificationType.GENERIC"> |
|||
<div fxLayout="column"> |
|||
<div>Generic</div> |
|||
<div class="tb-hint">hint</div> |
|||
</div> |
|||
</mat-radio-button> |
|||
<mat-radio-button [value]="NotificationType.ALARM"> |
|||
<div>Alarm</div> |
|||
<div class="tb-hint">hint</div> |
|||
</mat-radio-button> |
|||
</mat-radio-group> |
|||
<section formGroupName="configuration"> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>notification.message</mat-label> |
|||
<input matInput formControlName="defaultTextTemplate" required> |
|||
<mat-error *ngIf="templateNotificationForm.get('configuration.defaultTextTemplate').hasError('required')"> |
|||
{{ 'notification.message-required' | translate }} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>notification.subject</mat-label> |
|||
<input matInput required> |
|||
</mat-form-field> |
|||
</section> |
|||
</form> |
|||
<mat-divider></mat-divider> |
|||
<div mat-dialog-actions fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="end"> |
|||
<button mat-button |
|||
[disabled]="(isLoading$ | async)" |
|||
(click)="cancel()">{{ 'action.cancel' | translate }}</button> |
|||
<button mat-raised-button |
|||
[disabled]="(isLoading$ | async) || templateNotificationForm.invalid || !templateNotificationForm.dirty" |
|||
color="primary" |
|||
(click)="save()">{{ saveButtonLabel | translate }}</button> |
|||
</div> |
|||
@ -0,0 +1,25 @@ |
|||
:host { |
|||
width: 600px; |
|||
|
|||
.tb-hint { |
|||
padding: 0; |
|||
} |
|||
} |
|||
|
|||
:host ::ng-deep { |
|||
.mat-radio-group { |
|||
display: flex; |
|||
flex-direction: row; |
|||
|
|||
.mat-radio-button { |
|||
flex: 1 1 100%; |
|||
padding: 14px; |
|||
border: 1px solid rgba(0, 0, 0, 0.12); |
|||
border-radius: 6px; |
|||
|
|||
&:not(:last-child){ |
|||
margin-right: 8px; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,95 @@ |
|||
///
|
|||
/// Copyright © 2016-2022 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 { NotificationTemplate, NotificationType } from '@shared/models/notification.models'; |
|||
import { Component, Inject, OnDestroy } from '@angular/core'; |
|||
import { DialogComponent } from '@shared/components/dialog.component'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { Router } from '@angular/router'; |
|||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|||
import { NotificationService } from '@core/http/notification.service'; |
|||
import { deepTrim, isDefined } from '@core/utils'; |
|||
import { Subject } from 'rxjs'; |
|||
|
|||
export interface TemplateNotificationDialogData { |
|||
template?: NotificationTemplate; |
|||
isAdd?: boolean; |
|||
isCopy?: boolean; |
|||
} |
|||
|
|||
@Component({ |
|||
selector: 'tb-template-notification-dialog', |
|||
templateUrl: './template-notification-dialog.component.html', |
|||
styleUrls: ['./template-notification-dialog.component.scss'] |
|||
}) |
|||
export class TemplateNotificationDialogComponent |
|||
extends DialogComponent<TemplateNotificationDialogComponent, NotificationTemplate> implements OnDestroy { |
|||
|
|||
templateNotificationForm: FormGroup; |
|||
dialogTitle = 'notification.edit-notification-template'; |
|||
saveButtonLabel = 'action.save'; |
|||
|
|||
NotificationType = NotificationType; |
|||
|
|||
private readonly destroy$ = new Subject<void>(); |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected router: Router, |
|||
protected dialogRef: MatDialogRef<TemplateNotificationDialogComponent, NotificationTemplate>, |
|||
@Inject(MAT_DIALOG_DATA) public data: TemplateNotificationDialogData, |
|||
private fb: FormBuilder, |
|||
private notificationService: NotificationService) { |
|||
super(store, router, dialogRef); |
|||
|
|||
if (data.isAdd) { |
|||
this.dialogTitle = 'notification.add-notification-template'; |
|||
this.saveButtonLabel = 'action.add'; |
|||
} |
|||
if (data.isCopy) { |
|||
this.dialogTitle = 'notification.copy-notification-template'; |
|||
} |
|||
|
|||
this.templateNotificationForm = this.fb.group({ |
|||
name: [null, Validators.required], |
|||
type: [NotificationType.GENERIC], |
|||
configuration: this.fb.group({ |
|||
defaultTextTemplate: [null, Validators.required] |
|||
}) |
|||
}); |
|||
} |
|||
|
|||
ngOnDestroy() { |
|||
super.ngOnDestroy(); |
|||
this.destroy$.next(); |
|||
this.destroy$.complete(); |
|||
} |
|||
|
|||
cancel(): void { |
|||
this.dialogRef.close(null); |
|||
} |
|||
|
|||
save() { |
|||
let formValue = deepTrim(this.templateNotificationForm.value); |
|||
if (isDefined(this.data.template)) { |
|||
formValue = Object.assign({}, this.data.template, formValue); |
|||
} |
|||
this.notificationService.saveNotificationTemplate(formValue).subscribe( |
|||
(target) => this.dialogRef.close(target) |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2022 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 fxFlex="100" fxLayout="row" fxLayoutAlign="end center"> |
|||
<button mat-stroked-button color="primary" (click)="createTemplate($event)"> |
|||
<div fxLayout="row" fxLayoutAlign="start center"> |
|||
<mat-icon>add</mat-icon>{{ 'notification.add-template' | translate }} |
|||
</div> |
|||
</button> |
|||
</div> |
|||
@ -0,0 +1,18 @@ |
|||
/** |
|||
* Copyright © 2016-2022 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{ |
|||
width: 100%; |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
///
|
|||
/// Copyright © 2016-2022 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 } from '@angular/core'; |
|||
import { EntityTableHeaderComponent } from '@home/components/entity/entity-table-header.component'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { NotificationTemplate } from '@shared/models/notification.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-template-table-header', |
|||
templateUrl: './template-table-header.component.html', |
|||
styleUrls: ['template-table-header.component.scss'] |
|||
}) |
|||
export class TemplateTableHeaderComponent extends EntityTableHeaderComponent<NotificationTemplate> { |
|||
|
|||
constructor(protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
createTemplate($event: Event) { |
|||
this.entitiesTableConfig.onEntityAction({event: $event, action: 'add', entity: null}); |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue