Commit 378c9c8866d19c5dff7a74f2a00be58259aca2b2

Authored by Vladyslav_Prykhodko
1 parent 940c81b0

UI: Mail server page add checkbox change password

... ... @@ -39,7 +39,7 @@
39 39 </mat-form-field>
40 40 <mat-form-field class="mat-block">
41 41 <mat-label translate>admin.smtp-protocol</mat-label>
42   - <mat-select matInput formControlName="smtpProtocol">
  42 + <mat-select formControlName="smtpProtocol">
43 43 <mat-option *ngFor="let protocol of smtpProtocols" [value]="protocol">
44 44 {{protocol.toUpperCase()}}
45 45 </mat-option>
... ... @@ -126,10 +126,13 @@
126 126 <input matInput formControlName="username" placeholder="{{ 'common.enter-username' | translate }}"
127 127 autocomplete="new-username"/>
128 128 </mat-form-field>
129   - <mat-form-field class="mat-block">
  129 + <mat-checkbox *ngIf="!isAdd" formControlName="changePassword" style="padding-bottom: 16px;">
  130 + {{ 'admin.change-password' | translate }}
  131 + </mat-checkbox>
  132 + <mat-form-field class="mat-block" *ngIf="mailSettings.get('changePassword').value || isAdd">
130 133 <mat-label translate>common.password</mat-label>
131 134 <input matInput formControlName="password" type="password"
132   - placeholder="{{ 'common.enter-password' | translate }}" autocomplete="new-password"/>
  135 + placeholder="{{ 'common.enter-password' | translate }}" autocomplete="new-password">
133 136 </mat-form-field>
134 137 <div fxLayout="row" fxLayoutAlign="end center" fxLayout.xs="column" fxLayoutAlign.xs="end" fxLayoutGap="16px">
135 138 <button mat-raised-button type="button"
... ...
... ... @@ -14,7 +14,7 @@
14 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 18 import { Store } from '@ngrx/store';
19 19 import { AppState } from '@core/core.state';
20 20 import { PageComponent } from '@shared/components/page.component';
... ... @@ -26,20 +26,25 @@ import { ActionNotificationShow } from '@core/notification/notification.actions'
26 26 import { TranslateService } from '@ngx-translate/core';
27 27 import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard';
28 28 import { isString } from '@core/utils';
  29 +import { Subject } from 'rxjs';
  30 +import { takeUntil } from 'rxjs/operators';
29 31
30 32 @Component({
31 33 selector: 'tb-mail-server',
32 34 templateUrl: './mail-server.component.html',
33 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 39 mailSettings: FormGroup;
38 40 adminSettings: AdminSettings<MailServerSettings>;
39 41 smtpProtocols = ['smtp', 'smtps'];
  42 + isAdd = true;
40 43
41 44 tlsVersions = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'];
42 45
  46 + private destroy$ = new Subject();
  47 +
43 48 constructor(protected store: Store<AppState>,
44 49 private router: Router,
45 50 private adminService: AdminService,
... ... @@ -56,12 +61,21 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon
56 61 if (this.adminSettings.jsonValue && isString(this.adminSettings.jsonValue.enableTls)) {
57 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 66 this.mailSettings.reset(this.adminSettings.jsonValue);
  67 + this.enableMailPassword(this.isAdd);
60 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 79 buildMailServerSettingsForm() {
66 80 this.mailSettings = this.fb.group({
67 81 mailFrom: ['', [Validators.required]],
... ... @@ -81,14 +95,23 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon
81 95 proxyUser: [''],
82 96 proxyPassword: [''],
83 97 username: [''],
  98 + changePassword: [false],
84 99 password: ['']
85 100 });
86 101 this.registerDisableOnLoadFormControl(this.mailSettings.get('smtpProtocol'));
87 102 this.registerDisableOnLoadFormControl(this.mailSettings.get('enableTls'));
88 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 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 117 enableProxyChanged(): void {
... ... @@ -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 136 sendTestMail(): void {
106   - this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettings.value};
  137 + this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettingsFormValue};
107 138 this.adminService.sendTestMail(this.adminSettings).subscribe(
108 139 () => {
109 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 144 }
114 145
115 146 save(): void {
116   - this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettings.value};
  147 + this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettingsFormValue};
117 148 this.adminService.saveAdminSettings(this.adminSettings).subscribe(
118 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 152 this.adminSettings = adminSettings;
123 153 this.mailSettings.reset(this.adminSettings.jsonValue);
124 154 }
... ... @@ -129,4 +159,9 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon
129 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 }
... ...
... ... @@ -27,6 +27,7 @@ export interface AdminSettings<T> {
27 27 export declare type SmtpProtocol = 'smtp' | 'smtps';
28 28
29 29 export interface MailServerSettings {
  30 + isAdd: boolean;
30 31 mailFrom: string;
31 32 smtpProtocol: SmtpProtocol;
32 33 smtpHost: string;
... ... @@ -34,7 +35,8 @@ export interface MailServerSettings {
34 35 timeout: number;
35 36 enableTls: boolean;
36 37 username: string;
37   - password: string;
  38 + changePassword?: boolean;
  39 + password?: string;
38 40 enableProxy: boolean;
39 41 proxyHost: string;
40 42 proxyPort: number;
... ...
... ... @@ -104,6 +104,7 @@
104 104 "proxy-port-range": "Proxy port should be in a range from 1 to 65535.",
105 105 "proxy-user": "Proxy user",
106 106 "proxy-password": "Proxy password",
  107 + "change-password": "Change password",
107 108 "send-test-mail": "Send test mail",
108 109 "sms-provider": "SMS provider",
109 110 "sms-provider-settings": "SMS provider settings",
... ...