]> git.ipfire.org Git - thirdparty/paperless-ngx.git/blob
9a068ac886421ac62face1a0aef5461246da3d33
[thirdparty/paperless-ngx.git] /
1 import { Component, ViewChild } from '@angular/core'
2 import { FormControl, FormGroup } from '@angular/forms'
3 import { NgbActiveModal, NgbAlert } from '@ng-bootstrap/ng-bootstrap'
4 import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component'
5 import { IMAPSecurity, MailAccount } from 'src/app/data/mail-account'
6 import { MailAccountService } from 'src/app/services/rest/mail-account.service'
7 import { UserService } from 'src/app/services/rest/user.service'
8 import { SettingsService } from 'src/app/services/settings.service'
9
10 const IMAP_SECURITY_OPTIONS = [
11 { id: IMAPSecurity.None, name: $localize`No encryption` },
12 { id: IMAPSecurity.SSL, name: $localize`SSL` },
13 { id: IMAPSecurity.STARTTLS, name: $localize`STARTTLS` },
14 ]
15
16 @Component({
17 selector: 'pngx-mail-account-edit-dialog',
18 templateUrl: './mail-account-edit-dialog.component.html',
19 styleUrls: ['./mail-account-edit-dialog.component.scss'],
20 })
21 export class MailAccountEditDialogComponent extends EditDialogComponent<MailAccount> {
22 testActive: boolean = false
23 testResult: string
24 alertTimeout
25
26 @ViewChild('testResultAlert', { static: false }) testResultAlert: NgbAlert
27
28 constructor(
29 service: MailAccountService,
30 activeModal: NgbActiveModal,
31 userService: UserService,
32 settingsService: SettingsService
33 ) {
34 super(service, activeModal, userService, settingsService)
35 }
36
37 getCreateTitle() {
38 return $localize`Create new mail account`
39 }
40
41 getEditTitle() {
42 return $localize`Edit mail account`
43 }
44
45 getForm(): FormGroup {
46 return new FormGroup({
47 name: new FormControl(null),
48 imap_server: new FormControl(null),
49 imap_port: new FormControl(null),
50 imap_security: new FormControl(IMAPSecurity.SSL),
51 username: new FormControl(null),
52 password: new FormControl(null),
53 is_token: new FormControl(false),
54 character_set: new FormControl('UTF-8'),
55 })
56 }
57
58 get imapSecurityOptions() {
59 return IMAP_SECURITY_OPTIONS
60 }
61
62 test() {
63 this.testActive = true
64 this.testResult = null
65 clearTimeout(this.alertTimeout)
66 const mailService = this.service as MailAccountService
67 const newObject = Object.assign(
68 Object.assign({}, this.object),
69 this.objectForm.value
70 )
71 mailService.test(newObject).subscribe({
72 next: (result: { success: boolean }) => {
73 this.testActive = false
74 this.testResult = result.success ? 'success' : 'danger'
75 this.alertTimeout = setTimeout(() => this.testResultAlert.close(), 5000)
76 },
77 error: (e) => {
78 this.testActive = false
79 this.testResult = 'danger'
80 this.alertTimeout = setTimeout(() => this.testResultAlert.close(), 5000)
81 },
82 })
83 }
84
85 get testResultMessage() {
86 return this.testResult === 'success'
87 ? $localize`Successfully connected to the mail server`
88 : $localize`Unable to connect to the mail server`
89 }
90 }