|
|
|
@ -1,12 +1,11 @@ |
|
|
|
import { NgbModalOptions } from '@ng-bootstrap/ng-bootstrap'; |
|
|
|
import { |
|
|
|
ButtonComponent, |
|
|
|
collapse, |
|
|
|
ModalCloseDirective, |
|
|
|
ModalComponent, |
|
|
|
ToasterService, |
|
|
|
} from '@abp/ng.theme.shared'; |
|
|
|
import { Component, inject, OnInit } from '@angular/core'; |
|
|
|
import { Component, inject, OnInit, signal } from '@angular/core'; |
|
|
|
import { toSignal } from '@angular/core/rxjs-interop'; |
|
|
|
import { |
|
|
|
ReactiveFormsModule, |
|
|
|
@ -22,17 +21,15 @@ import { |
|
|
|
ConfigStateService, |
|
|
|
LocalizationPipe, |
|
|
|
LocalizationService, |
|
|
|
PermissionDirective |
|
|
|
PermissionDirective, |
|
|
|
} from '@abp/ng.core'; |
|
|
|
import { NgxValidateCoreModule } from '@ngx-validate/core'; |
|
|
|
|
|
|
|
|
|
|
|
const { required, email } = Validators; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'abp-email-setting-group', |
|
|
|
templateUrl: 'email-setting-group.component.html', |
|
|
|
animations: [collapse], |
|
|
|
imports: [ |
|
|
|
ReactiveFormsModule, |
|
|
|
LocalizationPipe, |
|
|
|
@ -40,8 +37,8 @@ const { required, email } = Validators; |
|
|
|
ModalComponent, |
|
|
|
ModalCloseDirective, |
|
|
|
NgxValidateCoreModule, |
|
|
|
PermissionDirective |
|
|
|
], |
|
|
|
PermissionDirective, |
|
|
|
], |
|
|
|
}) |
|
|
|
export class EmailSettingGroupComponent implements OnInit { |
|
|
|
private emailSettingsService = inject(EmailSettingsService); |
|
|
|
@ -54,8 +51,10 @@ export class EmailSettingGroupComponent implements OnInit { |
|
|
|
this.configStateSevice.getDeep$(['currentUser', 'email']), |
|
|
|
); |
|
|
|
|
|
|
|
form!: UntypedFormGroup; |
|
|
|
emailTestForm: UntypedFormGroup; |
|
|
|
readonly form = signal<UntypedFormGroup | undefined>(undefined); |
|
|
|
readonly loading = signal(true); |
|
|
|
|
|
|
|
emailTestForm!: UntypedFormGroup; |
|
|
|
saving = false; |
|
|
|
emailingPolicy = SettingManagementPolicyNames.Emailing; |
|
|
|
isEmailTestModalOpen = false; |
|
|
|
@ -66,13 +65,20 @@ export class EmailSettingGroupComponent implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
private getData() { |
|
|
|
this.emailSettingsService.get().subscribe(res => { |
|
|
|
this.buildForm(res); |
|
|
|
this.loading.set(true); |
|
|
|
this.emailSettingsService.get().subscribe({ |
|
|
|
next: res => { |
|
|
|
this.form.set(this.buildForm(res)); |
|
|
|
this.loading.set(false); |
|
|
|
}, |
|
|
|
error: () => { |
|
|
|
this.loading.set(false); |
|
|
|
}, |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private buildForm(emailSettings: EmailSettingsDto) { |
|
|
|
this.form = this.fb.group({ |
|
|
|
return this.fb.group({ |
|
|
|
defaultFromDisplayName: [emailSettings.defaultFromDisplayName, [Validators.required]], |
|
|
|
defaultFromAddress: [emailSettings.defaultFromAddress, [Validators.required]], |
|
|
|
smtpHost: [emailSettings.smtpHost], |
|
|
|
@ -86,11 +92,12 @@ export class EmailSettingGroupComponent implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
submit() { |
|
|
|
if (this.saving || this.form.invalid) return; |
|
|
|
const form = this.form(); |
|
|
|
if (!form || this.saving || form.invalid) return; |
|
|
|
|
|
|
|
this.saving = true; |
|
|
|
this.emailSettingsService |
|
|
|
.update(this.form.value) |
|
|
|
.update(form.value) |
|
|
|
.pipe(finalize(() => (this.saving = false))) |
|
|
|
.subscribe(() => { |
|
|
|
this.toasterService.success('AbpSettingManagement::SavedSuccessfully'); |
|
|
|
@ -104,7 +111,7 @@ export class EmailSettingGroupComponent implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
buildEmailTestForm() { |
|
|
|
const { defaultFromAddress } = this.form.value || {}; |
|
|
|
const { defaultFromAddress } = this.form()?.value || {}; |
|
|
|
const defaultSubject = this.localizationService.instant( |
|
|
|
'AbpSettingManagement::TestEmailSubject', |
|
|
|
...[Math.floor(Math.random() * 9999).toString()], |
|
|
|
@ -124,7 +131,7 @@ export class EmailSettingGroupComponent implements OnInit { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.emailSettingsService.sendTestEmail(this.emailTestForm.value).subscribe(res => { |
|
|
|
this.emailSettingsService.sendTestEmail(this.emailTestForm.value).subscribe(() => { |
|
|
|
this.toasterService.success('AbpSettingManagement::SentSuccessfully'); |
|
|
|
this.isEmailTestModalOpen = false; |
|
|
|
}); |
|
|
|
|