|
@@ -14,7 +14,7 @@ |
|
@@ -14,7 +14,7 @@ |
14
|
/// limitations under the License.
|
14
|
/// limitations under the License.
|
15
|
///
|
15
|
///
|
16
|
|
16
|
|
17
|
-import { Component, OnInit } from '@angular/core';
|
17
|
+import { Component, OnDestroy, OnInit } from '@angular/core';
|
18
|
import { Store } from '@ngrx/store';
|
18
|
import { Store } from '@ngrx/store';
|
19
|
import { AppState } from '@core/core.state';
|
19
|
import { AppState } from '@core/core.state';
|
20
|
import { PageComponent } from '@shared/components/page.component';
|
20
|
import { PageComponent } from '@shared/components/page.component';
|
|
@@ -26,20 +26,25 @@ import { ActionNotificationShow } from '@core/notification/notification.actions' |
|
@@ -26,20 +26,25 @@ import { ActionNotificationShow } from '@core/notification/notification.actions' |
26
|
import { TranslateService } from '@ngx-translate/core';
|
26
|
import { TranslateService } from '@ngx-translate/core';
|
27
|
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard';
|
27
|
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard';
|
28
|
import { isString } from '@core/utils';
|
28
|
import { isString } from '@core/utils';
|
|
|
29
|
+import { Subject } from 'rxjs';
|
|
|
30
|
+import { takeUntil } from 'rxjs/operators';
|
29
|
|
31
|
|
30
|
@Component({
|
32
|
@Component({
|
31
|
selector: 'tb-mail-server',
|
33
|
selector: 'tb-mail-server',
|
32
|
templateUrl: './mail-server.component.html',
|
34
|
templateUrl: './mail-server.component.html',
|
33
|
styleUrls: ['./mail-server.component.scss', './settings-card.scss']
|
35
|
styleUrls: ['./mail-server.component.scss', './settings-card.scss']
|
34
|
})
|
36
|
})
|
35
|
-export class MailServerComponent extends PageComponent implements OnInit, HasConfirmForm {
|
37
|
+export class MailServerComponent extends PageComponent implements OnInit, OnDestroy, HasConfirmForm {
|
36
|
|
38
|
|
37
|
mailSettings: FormGroup;
|
39
|
mailSettings: FormGroup;
|
38
|
adminSettings: AdminSettings<MailServerSettings>;
|
40
|
adminSettings: AdminSettings<MailServerSettings>;
|
39
|
smtpProtocols = ['smtp', 'smtps'];
|
41
|
smtpProtocols = ['smtp', 'smtps'];
|
|
|
42
|
+ isAdd = true;
|
40
|
|
43
|
|
41
|
tlsVersions = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'];
|
44
|
tlsVersions = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'];
|
42
|
|
45
|
|
|
|
46
|
+ private destroy$ = new Subject();
|
|
|
47
|
+
|
43
|
constructor(protected store: Store<AppState>,
|
48
|
constructor(protected store: Store<AppState>,
|
44
|
private router: Router,
|
49
|
private router: Router,
|
45
|
private adminService: AdminService,
|
50
|
private adminService: AdminService,
|
|
@@ -56,12 +61,21 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
|
@@ -56,12 +61,21 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
56
|
if (this.adminSettings.jsonValue && isString(this.adminSettings.jsonValue.enableTls)) {
|
61
|
if (this.adminSettings.jsonValue && isString(this.adminSettings.jsonValue.enableTls)) {
|
57
|
this.adminSettings.jsonValue.enableTls = (this.adminSettings.jsonValue.enableTls as any) === 'true';
|
62
|
this.adminSettings.jsonValue.enableTls = (this.adminSettings.jsonValue.enableTls as any) === 'true';
|
58
|
}
|
63
|
}
|
|
|
64
|
+ this.isAdd = this.adminSettings.jsonValue.isAdd;
|
|
|
65
|
+ delete this.adminSettings.jsonValue.isAdd;
|
59
|
this.mailSettings.reset(this.adminSettings.jsonValue);
|
66
|
this.mailSettings.reset(this.adminSettings.jsonValue);
|
|
|
67
|
+ this.enableMailPassword(this.isAdd);
|
60
|
this.enableProxyChanged();
|
68
|
this.enableProxyChanged();
|
61
|
}
|
69
|
}
|
62
|
);
|
70
|
);
|
63
|
}
|
71
|
}
|
64
|
|
72
|
|
|
|
73
|
+ ngOnDestroy() {
|
|
|
74
|
+ this.destroy$.next();
|
|
|
75
|
+ this.destroy$.complete();
|
|
|
76
|
+ super.ngOnDestroy();
|
|
|
77
|
+ }
|
|
|
78
|
+
|
65
|
buildMailServerSettingsForm() {
|
79
|
buildMailServerSettingsForm() {
|
66
|
this.mailSettings = this.fb.group({
|
80
|
this.mailSettings = this.fb.group({
|
67
|
mailFrom: ['', [Validators.required]],
|
81
|
mailFrom: ['', [Validators.required]],
|
|
@@ -81,14 +95,23 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
|
@@ -81,14 +95,23 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
81
|
proxyUser: [''],
|
95
|
proxyUser: [''],
|
82
|
proxyPassword: [''],
|
96
|
proxyPassword: [''],
|
83
|
username: [''],
|
97
|
username: [''],
|
|
|
98
|
+ changePassword: [false],
|
84
|
password: ['']
|
99
|
password: ['']
|
85
|
});
|
100
|
});
|
86
|
this.registerDisableOnLoadFormControl(this.mailSettings.get('smtpProtocol'));
|
101
|
this.registerDisableOnLoadFormControl(this.mailSettings.get('smtpProtocol'));
|
87
|
this.registerDisableOnLoadFormControl(this.mailSettings.get('enableTls'));
|
102
|
this.registerDisableOnLoadFormControl(this.mailSettings.get('enableTls'));
|
88
|
this.registerDisableOnLoadFormControl(this.mailSettings.get('enableProxy'));
|
103
|
this.registerDisableOnLoadFormControl(this.mailSettings.get('enableProxy'));
|
89
|
- this.mailSettings.get('enableProxy').valueChanges.subscribe(() => {
|
104
|
+ this.registerDisableOnLoadFormControl(this.mailSettings.get('changePassword'));
|
|
|
105
|
+ this.mailSettings.get('enableProxy').valueChanges.pipe(
|
|
|
106
|
+ takeUntil(this.destroy$)
|
|
|
107
|
+ ).subscribe(() => {
|
90
|
this.enableProxyChanged();
|
108
|
this.enableProxyChanged();
|
91
|
});
|
109
|
});
|
|
|
110
|
+ this.mailSettings.get('changePassword').valueChanges.pipe(
|
|
|
111
|
+ takeUntil(this.destroy$)
|
|
|
112
|
+ ).subscribe((value) => {
|
|
|
113
|
+ this.enableMailPassword(value);
|
|
|
114
|
+ });
|
92
|
}
|
115
|
}
|
93
|
|
116
|
|
94
|
enableProxyChanged(): void {
|
117
|
enableProxyChanged(): void {
|
|
@@ -102,8 +125,16 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
|
@@ -102,8 +125,16 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
102
|
}
|
125
|
}
|
103
|
}
|
126
|
}
|
104
|
|
127
|
|
|
|
128
|
+ enableMailPassword(enable: boolean) {
|
|
|
129
|
+ if (enable) {
|
|
|
130
|
+ this.mailSettings.get('password').enable({emitEvent: false});
|
|
|
131
|
+ } else {
|
|
|
132
|
+ this.mailSettings.get('password').disable({emitEvent: false});
|
|
|
133
|
+ }
|
|
|
134
|
+ }
|
|
|
135
|
+
|
105
|
sendTestMail(): void {
|
136
|
sendTestMail(): void {
|
106
|
- this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettings.value};
|
137
|
+ this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettingsFormValue};
|
107
|
this.adminService.sendTestMail(this.adminSettings).subscribe(
|
138
|
this.adminService.sendTestMail(this.adminSettings).subscribe(
|
108
|
() => {
|
139
|
() => {
|
109
|
this.store.dispatch(new ActionNotificationShow({ message: this.translate.instant('admin.test-mail-sent'),
|
140
|
this.store.dispatch(new ActionNotificationShow({ message: this.translate.instant('admin.test-mail-sent'),
|
|
@@ -113,12 +144,11 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
|
@@ -113,12 +144,11 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
113
|
}
|
144
|
}
|
114
|
|
145
|
|
115
|
save(): void {
|
146
|
save(): void {
|
116
|
- this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettings.value};
|
147
|
+ this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettingsFormValue};
|
117
|
this.adminService.saveAdminSettings(this.adminSettings).subscribe(
|
148
|
this.adminService.saveAdminSettings(this.adminSettings).subscribe(
|
118
|
(adminSettings) => {
|
149
|
(adminSettings) => {
|
119
|
- if (!adminSettings.jsonValue.password) {
|
|
|
120
|
- adminSettings.jsonValue.password = this.mailSettings.value.password;
|
|
|
121
|
- }
|
150
|
+ adminSettings.jsonValue.password = this.mailSettings.value.password;
|
|
|
151
|
+ adminSettings.jsonValue.changePassword = this.mailSettings.value.changePassword;
|
122
|
this.adminSettings = adminSettings;
|
152
|
this.adminSettings = adminSettings;
|
123
|
this.mailSettings.reset(this.adminSettings.jsonValue);
|
153
|
this.mailSettings.reset(this.adminSettings.jsonValue);
|
124
|
}
|
154
|
}
|
|
@@ -129,4 +159,9 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
|
@@ -129,4 +159,9 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon |
129
|
return this.mailSettings;
|
159
|
return this.mailSettings;
|
130
|
}
|
160
|
}
|
131
|
|
161
|
|
|
|
162
|
+ private get mailSettingsFormValue(): MailServerSettings {
|
|
|
163
|
+ const formValue = this.mailSettings.value;
|
|
|
164
|
+ delete formValue.changePassword;
|
|
|
165
|
+ return formValue;
|
|
|
166
|
+ }
|
132
|
} |
167
|
} |