18 changed files with 193 additions and 187 deletions
@ -1,49 +0,0 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2023 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> |
|||
<mat-card appearance="outlined" class="settings-card"> |
|||
<mat-card-header> |
|||
<mat-card-title> |
|||
<div fxLayout="row"> |
|||
<span class="mat-headline-5" translate>admin.notification.notification-settings</span> |
|||
</div> |
|||
</mat-card-title> |
|||
</mat-card-header> |
|||
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> |
|||
</mat-progress-bar> |
|||
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div> |
|||
<mat-card-content style="padding-top: 16px;"> |
|||
<form [formGroup]="notificationSettingsForm" (ngSubmit)="save()"> |
|||
<fieldset [disabled]="isLoading$ | async" formGroupName="deliveryMethodsConfigs"> |
|||
<fieldset class="fields-group" formGroupName="SLACK"> |
|||
<legend class="group-title" translate>admin.notification.slack</legend> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>admin.notification.slack-api-token</mat-label> |
|||
<input matInput formControlName="botToken" /> |
|||
</mat-form-field> |
|||
</fieldset> |
|||
<div fxLayout="row" fxLayoutAlign="end center" class="layout-wrap"> |
|||
<button mat-button mat-raised-button color="primary" [disabled]="(isLoading$ | async) || notificationSettingsForm.invalid || !notificationSettingsForm.dirty" |
|||
type="submit">{{'action.save' | translate}} |
|||
</button> |
|||
</div> |
|||
</fieldset> |
|||
</form> |
|||
</mat-card-content> |
|||
</mat-card> |
|||
</div> |
|||
@ -1,86 +0,0 @@ |
|||
///
|
|||
/// Copyright © 2016-2023 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, OnInit } from '@angular/core'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { FormBuilder, FormGroup } from '@angular/forms'; |
|||
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard'; |
|||
import { NotificationService } from '@core/http/notification.service'; |
|||
import { NotificationSettings } from '@shared/models/notification.models'; |
|||
import { deepTrim, isEmptyStr } from '@core/utils'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-notification-settings', |
|||
templateUrl: './notification-settings.component.html', |
|||
styleUrls: ['./settings-card.scss'] |
|||
}) |
|||
export class NotificationSettingsComponent extends PageComponent implements OnInit, HasConfirmForm { |
|||
|
|||
notificationSettingsForm: FormGroup; |
|||
private notificationSettings: NotificationSettings; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
private notificationService: NotificationService, |
|||
public fb: FormBuilder) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit() { |
|||
this.buildGeneralServerSettingsForm(); |
|||
this.notificationService.getNotificationSettings().subscribe( |
|||
(settings) => { |
|||
this.notificationSettings = settings; |
|||
this.notificationSettingsForm.reset(this.notificationSettings); |
|||
} |
|||
); |
|||
} |
|||
|
|||
buildGeneralServerSettingsForm() { |
|||
this.notificationSettingsForm = this.fb.group({ |
|||
deliveryMethodsConfigs: this.fb.group({ |
|||
SLACK: this.fb.group({ |
|||
botToken: [''] |
|||
}) |
|||
}) |
|||
}); |
|||
} |
|||
|
|||
save(): void { |
|||
this.notificationSettings = deepTrim({ |
|||
...this.notificationSettings, |
|||
...this.notificationSettingsForm.value |
|||
}); |
|||
for (const method in this.notificationSettings.deliveryMethodsConfigs) { |
|||
const keys = Object.keys(this.notificationSettings.deliveryMethodsConfigs[method]); |
|||
if (keys.some(item => isEmptyStr(this.notificationSettings.deliveryMethodsConfigs[method][item]))) { |
|||
delete this.notificationSettings.deliveryMethodsConfigs[method]; |
|||
} else { |
|||
this.notificationSettings.deliveryMethodsConfigs[method].method = method; |
|||
} |
|||
} |
|||
this.notificationService.saveNotificationSettings(this.notificationSettings).subscribe(setting => { |
|||
this.notificationSettings = setting; |
|||
this.notificationSettingsForm.reset(this.notificationSettings); |
|||
}); |
|||
} |
|||
|
|||
confirmForm(): FormGroup { |
|||
return this.notificationSettingsForm; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2023 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-flat-button color="primary" (click)="sendNotification($event)"> |
|||
<div fxLayout="row" fxLayoutAlign="start center"> |
|||
<mat-icon>send</mat-icon>{{ 'notification.send-notification' | translate }} |
|||
</div> |
|||
</button> |
|||
</div> |
|||
@ -0,0 +1,18 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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: 10000px; |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
///
|
|||
/// Copyright © 2016-2023 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 { NotificationRequest, NotificationRequestInfo } from '@shared/models/notification.models'; |
|||
import { PageLink } from '@shared/models/page/page-link'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-sent-table-header', |
|||
templateUrl: './sent-table-header.component.html', |
|||
styleUrls: ['sent-table-header.component.scss'] |
|||
}) |
|||
export class SentTableHeaderComponent extends EntityTableHeaderComponent<NotificationRequest, PageLink, NotificationRequestInfo> { |
|||
|
|||
constructor(protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
sendNotification($event: Event) { |
|||
this.entitiesTableConfig.onEntityAction({event: $event, action: 'add', entity: null}); |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue