|
|
|
@ -14,7 +14,7 @@ |
|
|
|
/// limitations under the License.
|
|
|
|
///
|
|
|
|
|
|
|
|
import { AfterViewInit, Component, QueryList, ViewChild, ViewChildren } from '@angular/core'; |
|
|
|
import { Component, QueryList, ViewChild, ViewChildren } from '@angular/core'; |
|
|
|
import { PageComponent } from '@shared/components/page.component'; |
|
|
|
import { Store } from '@ngrx/store'; |
|
|
|
import { AppState } from '@core/core.state'; |
|
|
|
@ -23,30 +23,16 @@ import { |
|
|
|
NotificationTableComponent |
|
|
|
} from '@home/pages/notification-center/notification-table/notification-table.component'; |
|
|
|
import { EntityType } from '@shared/models/entity-type.models'; |
|
|
|
import { MatDrawer } from '@angular/material/sidenav'; |
|
|
|
import { NotificationService } from '@core/http/notification.service'; |
|
|
|
import { |
|
|
|
NotificationDeliveryMethod, |
|
|
|
NotificationDeliveryMethodTranslateMap, |
|
|
|
NotificationTemplateTypeTranslateMap |
|
|
|
} from '@shared/models/notification.models'; |
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
|
import { deepTrim } from '@core/utils'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'tb-notification-center', |
|
|
|
templateUrl: './notification-center.component.html', |
|
|
|
styleUrls: ['notification-center.component.scss'] |
|
|
|
}) |
|
|
|
export class NotificationCenterComponent extends PageComponent implements AfterViewInit { |
|
|
|
export class NotificationCenterComponent extends PageComponent { |
|
|
|
|
|
|
|
entityType = EntityType; |
|
|
|
|
|
|
|
notificationSettingsForm: FormGroup; |
|
|
|
notificationDeliveryMethods = Object.keys(NotificationDeliveryMethod) as NotificationDeliveryMethod[]; |
|
|
|
notificationDeliveryMethodTranslateMap = NotificationDeliveryMethodTranslateMap; |
|
|
|
|
|
|
|
@ViewChild('notificationSettings', {static: true}) notificationSettings!: MatDrawer; |
|
|
|
@ViewChild('matTabGroup', {static: true}) matTabs: MatTabGroup; |
|
|
|
@ViewChild('requestTab', {static: true}) requestTab: MatTab; |
|
|
|
@ViewChild('notificationRequest', {static: true}) notificationRequestTable: NotificationTableComponent; |
|
|
|
@ -54,38 +40,8 @@ export class NotificationCenterComponent extends PageComponent implements AfterV |
|
|
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
protected store: Store<AppState>, |
|
|
|
private notificationService: NotificationService, |
|
|
|
private fb: FormBuilder) { |
|
|
|
protected store: Store<AppState>) { |
|
|
|
super(store); |
|
|
|
this.notificationSettingsForm = this.fb.group({ |
|
|
|
deliveryMethodsConfigs: this.fb.group({}) |
|
|
|
}); |
|
|
|
this.notificationDeliveryMethods.forEach(method => { |
|
|
|
(this.notificationSettingsForm.get('deliveryMethodsConfigs') as FormGroup) |
|
|
|
.addControl(method, this.fb.group({method, enabled: method !== NotificationDeliveryMethod.SLACK}), {emitEvent: false}); |
|
|
|
}); |
|
|
|
(this.notificationSettingsForm.get('deliveryMethodsConfigs.SLACK') as FormGroup) |
|
|
|
.addControl('botToken', this.fb.control({value: '', disabled: true}, Validators.required), {emitEvent: false}); |
|
|
|
this.notificationSettingsForm.get('deliveryMethodsConfigs.SLACK.enabled').valueChanges.subscribe(value => { |
|
|
|
if (value) { |
|
|
|
this.notificationSettingsForm.get('deliveryMethodsConfigs.SLACK.botToken').enable({emitEvent: true}); |
|
|
|
} else { |
|
|
|
this.notificationSettingsForm.get('deliveryMethodsConfigs.SLACK.botToken').disable({emitEvent: true}); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
ngAfterViewInit() { |
|
|
|
this.notificationSettings.openedStart.subscribe(() => { |
|
|
|
this.notificationService.getNotificationSettings().subscribe( |
|
|
|
value => { |
|
|
|
this.notificationSettingsForm.patchValue(value, {emitEvent: false}); |
|
|
|
this.notificationSettingsForm.get('deliveryMethodsConfigs.SLACK.enabled').updateValueAndValidity({onlySelf: true}); |
|
|
|
} |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
updateData() { |
|
|
|
@ -103,19 +59,4 @@ export class NotificationCenterComponent extends PageComponent implements AfterV |
|
|
|
sendNotification($event: Event) { |
|
|
|
this.notificationRequestTable.entityTableConfig.onEntityAction({event: $event, action: this.requestTab.isActive ? 'add' : 'add-without-update', entity: null}); |
|
|
|
} |
|
|
|
|
|
|
|
toggleNotificationSettings() { |
|
|
|
this.notificationSettings.toggle().then(() => {}); |
|
|
|
} |
|
|
|
|
|
|
|
saveNotificationSettigs($event: Event) { |
|
|
|
if ($event) { |
|
|
|
$event.stopPropagation(); |
|
|
|
} |
|
|
|
const formValue = deepTrim(this.notificationSettingsForm.getRawValue()); |
|
|
|
this.notificationService.saveNotificationSettings(formValue).subscribe(value => { |
|
|
|
this.notificationSettingsForm.patchValue(value, {emitEvent: false}); |
|
|
|
this.notificationSettingsForm.markAsPristine(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|