UI: Add tenant admin notification settings
This commit is contained in:
parent
299c159ca1
commit
f4de754202
@ -573,6 +573,14 @@ export class MenuService {
|
||||
path: '/settings/home',
|
||||
icon: 'settings_applications'
|
||||
},
|
||||
{
|
||||
id: guid(),
|
||||
name: 'admin.notifications',
|
||||
type: 'link',
|
||||
path: '/settings/notifications',
|
||||
icon: 'mdi:message-badge',
|
||||
isMdiIcon: true
|
||||
},
|
||||
{
|
||||
id: guid(),
|
||||
name: 'admin.repository',
|
||||
|
||||
@ -164,7 +164,7 @@ const routes: Routes = [
|
||||
component: SmsProviderComponent,
|
||||
canDeactivate: [ConfirmOnExitGuard],
|
||||
data: {
|
||||
auth: [Authority.SYS_ADMIN],
|
||||
auth: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
|
||||
title: 'admin.notifications-settings',
|
||||
breadcrumb: {
|
||||
label: 'admin.notifications',
|
||||
|
||||
@ -15,11 +15,10 @@
|
||||
limitations under the License.
|
||||
|
||||
-->
|
||||
<div>
|
||||
<mat-card appearance="outlined" class="settings-card">
|
||||
<mat-card appearance="outlined" class="settings-card" *ngIf="isSysAdmin()">
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
<span class="mat-headline-5" translate>admin.notifications-settings</span>
|
||||
<span class="mat-headline-5" translate>admin.sms-provider-settings</span>
|
||||
</mat-card-title>
|
||||
<span fxFlex></span>
|
||||
<div tb-help="smsProviderSettings"></div>
|
||||
@ -48,28 +47,27 @@
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
<mat-card appearance="outlined" class="settings-card">
|
||||
<!-- <mat-card-header>-->
|
||||
<!-- <mat-card-title>-->
|
||||
<!-- <div fxLayout="row">-->
|
||||
<!-- <span class="mat-headline-5" translate>admin.notifications-settings</span>-->
|
||||
<!-- </div>-->
|
||||
<!-- </mat-card-title>-->
|
||||
<!-- </mat-card-header>-->
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
<span class="mat-headline-5" translate>admin.slack-settings</span>
|
||||
</mat-card-title>
|
||||
<span fxFlex></span>
|
||||
<div tb-help="slackSettings"></div>
|
||||
</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)="saveNotification()">
|
||||
<form [formGroup]="slackSettingsForm" (ngSubmit)="saveNotification()">
|
||||
<fieldset [disabled]="isLoading$ | async" formGroupName="deliveryMethodsConfigs">
|
||||
<fieldset class="fields-group" formGroupName="SLACK">
|
||||
<legend class="group-title" translate>admin.slack</legend>
|
||||
<section formGroupName="SLACK">
|
||||
<mat-form-field class="mat-block">
|
||||
<mat-label translate>admin.slack-api-token</mat-label>
|
||||
<input matInput formControlName="botToken" />
|
||||
</mat-form-field>
|
||||
</fieldset>
|
||||
</section>
|
||||
<div fxLayout="row" fxLayoutAlign="end center" class="layout-wrap">
|
||||
<button mat-button mat-raised-button color="primary" [disabled]="(isLoading$ | async) || notificationSettingsForm.invalid || !notificationSettingsForm.dirty"
|
||||
<button mat-button mat-raised-button color="primary" [disabled]="(isLoading$ | async) || slackSettingsForm.invalid || !slackSettingsForm.dirty"
|
||||
type="submit">{{'action.save' | translate}}
|
||||
</button>
|
||||
</div>
|
||||
@ -77,4 +75,3 @@
|
||||
</form>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</div>
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
/// limitations under the License.
|
||||
///
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppState } from '@core/core.state';
|
||||
import { PageComponent } from '@shared/components/page.component';
|
||||
@ -28,20 +28,25 @@ import { SendTestSmsDialogComponent, SendTestSmsDialogData } from '@home/pages/a
|
||||
import { NotificationSettings } from '@shared/models/notification.models';
|
||||
import { deepTrim, isEmptyStr } from '@core/utils';
|
||||
import { NotificationService } from '@core/http/notification.service';
|
||||
import { Authority } from '@shared/models/authority.enum';
|
||||
import { AuthUser } from '@shared/models/user.model';
|
||||
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-sms-provider',
|
||||
templateUrl: './sms-provider.component.html',
|
||||
styleUrls: ['./sms-provider.component.scss', './settings-card.scss']
|
||||
})
|
||||
export class SmsProviderComponent extends PageComponent implements OnInit, HasConfirmForm {
|
||||
export class SmsProviderComponent extends PageComponent implements HasConfirmForm {
|
||||
|
||||
smsProvider: FormGroup;
|
||||
adminSettings: AdminSettings<SmsProviderConfiguration>;
|
||||
private adminSettings: AdminSettings<SmsProviderConfiguration>;
|
||||
|
||||
notificationSettingsForm: FormGroup;
|
||||
slackSettingsForm: FormGroup;
|
||||
private notificationSettings: NotificationSettings;
|
||||
|
||||
private readonly authUser: AuthUser;
|
||||
|
||||
constructor(protected store: Store<AppState>,
|
||||
private router: Router,
|
||||
private adminService: AdminService,
|
||||
@ -49,17 +54,16 @@ export class SmsProviderComponent extends PageComponent implements OnInit, HasCo
|
||||
private dialog: MatDialog,
|
||||
public fb: FormBuilder) {
|
||||
super(store);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.authUser = getCurrentAuthUser(this.store);
|
||||
this.buildSmsProviderForm();
|
||||
this.buildGeneralServerSettingsForm();
|
||||
this.notificationService.getNotificationSettings().subscribe(
|
||||
(settings) => {
|
||||
this.notificationSettings = settings;
|
||||
this.notificationSettingsForm.reset(this.notificationSettings);
|
||||
this.slackSettingsForm.reset(this.notificationSettings);
|
||||
}
|
||||
);
|
||||
if (this.isSysAdmin()) {
|
||||
this.adminService.getAdminSettings<SmsProviderConfiguration>('sms', {ignoreErrors: true}).subscribe({
|
||||
next: adminSettings => {
|
||||
this.adminSettings = adminSettings;
|
||||
@ -74,6 +78,7 @@ export class SmsProviderComponent extends PageComponent implements OnInit, HasCo
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private buildSmsProviderForm() {
|
||||
this.smsProvider = this.fb.group({
|
||||
@ -103,23 +108,24 @@ export class SmsProviderComponent extends PageComponent implements OnInit, HasCo
|
||||
}
|
||||
|
||||
confirmForm(): FormGroup {
|
||||
return this.smsProvider.dirty ? this.smsProvider : this.notificationSettingsForm;
|
||||
return this.smsProvider.dirty ? this.smsProvider : this.slackSettingsForm;
|
||||
}
|
||||
|
||||
private buildGeneralServerSettingsForm() {
|
||||
this.notificationSettingsForm = this.fb.group({
|
||||
this.slackSettingsForm = this.fb.group({
|
||||
deliveryMethodsConfigs: this.fb.group({
|
||||
SLACK: this.fb.group({
|
||||
botToken: ['']
|
||||
})
|
||||
})
|
||||
});
|
||||
this.registerDisableOnLoadFormControl(this.slackSettingsForm.get('deliveryMethodsConfigs'));
|
||||
}
|
||||
|
||||
saveNotification(): void {
|
||||
this.notificationSettings = deepTrim({
|
||||
...this.notificationSettings,
|
||||
...this.notificationSettingsForm.value
|
||||
...this.slackSettingsForm.value
|
||||
});
|
||||
// eslint-disable-next-line guard-for-in
|
||||
for (const method in this.notificationSettings.deliveryMethodsConfigs) {
|
||||
@ -132,8 +138,12 @@ export class SmsProviderComponent extends PageComponent implements OnInit, HasCo
|
||||
}
|
||||
this.notificationService.saveNotificationSettings(this.notificationSettings).subscribe(setting => {
|
||||
this.notificationSettings = setting;
|
||||
this.notificationSettingsForm.reset(this.notificationSettings);
|
||||
this.slackSettingsForm.reset(this.notificationSettings);
|
||||
});
|
||||
}
|
||||
|
||||
isSysAdmin(): boolean {
|
||||
return this.authUser.authority === Authority.SYS_ADMIN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -76,6 +76,7 @@ export const HelpLinks = {
|
||||
linksMap: {
|
||||
outgoingMailSettings: helpBaseUrl + '/docs/user-guide/ui/mail-settings',
|
||||
smsProviderSettings: helpBaseUrl + '/docs/user-guide/ui/sms-provider-settings',
|
||||
slackSettings: helpBaseUrl + '/docs/user-guide/ui/slack-settings',
|
||||
securitySettings: helpBaseUrl + '/docs/user-guide/ui/security-settings',
|
||||
oauth2Settings: helpBaseUrl + '/docs/user-guide/oauth-2-support/',
|
||||
twoFactorAuthSettings: helpBaseUrl + '/docs/',
|
||||
|
||||
@ -417,7 +417,8 @@
|
||||
"notifications": "Notifications",
|
||||
"notifications-settings": "Notifications settings",
|
||||
"slack-api-token": "Slack api token",
|
||||
"slack": "Slack"
|
||||
"slack": "Slack",
|
||||
"slack-settings": "Slack settings"
|
||||
},
|
||||
"alarm": {
|
||||
"alarm": "Alarm",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user