Browse Source

Merge branch 'improvement/mail-setting/edit-password' of https://github.com/vvlladd28/thingsboard

pull/4993/head
AndrewVolosytnykhThingsboard 5 years ago
parent
commit
5d8d19282a
  1. 9
      ui-ngx/src/app/modules/home/pages/admin/mail-server.component.html
  2. 51
      ui-ngx/src/app/modules/home/pages/admin/mail-server.component.ts
  3. 4
      ui-ngx/src/app/shared/models/settings.models.ts
  4. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

9
ui-ngx/src/app/modules/home/pages/admin/mail-server.component.html

@ -39,7 +39,7 @@
</mat-form-field> </mat-form-field>
<mat-form-field class="mat-block"> <mat-form-field class="mat-block">
<mat-label translate>admin.smtp-protocol</mat-label> <mat-label translate>admin.smtp-protocol</mat-label>
<mat-select matInput formControlName="smtpProtocol"> <mat-select formControlName="smtpProtocol">
<mat-option *ngFor="let protocol of smtpProtocols" [value]="protocol"> <mat-option *ngFor="let protocol of smtpProtocols" [value]="protocol">
{{protocol.toUpperCase()}} {{protocol.toUpperCase()}}
</mat-option> </mat-option>
@ -126,10 +126,13 @@
<input matInput formControlName="username" placeholder="{{ 'common.enter-username' | translate }}" <input matInput formControlName="username" placeholder="{{ 'common.enter-username' | translate }}"
autocomplete="new-username"/> autocomplete="new-username"/>
</mat-form-field> </mat-form-field>
<mat-form-field class="mat-block"> <mat-checkbox *ngIf="!isAdd" formControlName="changePassword" style="padding-bottom: 16px;">
{{ 'admin.change-password' | translate }}
</mat-checkbox>
<mat-form-field class="mat-block" *ngIf="mailSettings.get('changePassword').value || isAdd">
<mat-label translate>common.password</mat-label> <mat-label translate>common.password</mat-label>
<input matInput formControlName="password" type="password" <input matInput formControlName="password" type="password"
placeholder="{{ 'common.enter-password' | translate }}" autocomplete="new-password"/> placeholder="{{ 'common.enter-password' | translate }}" autocomplete="new-password">
</mat-form-field> </mat-form-field>
<div fxLayout="row" fxLayoutAlign="end center" fxLayout.xs="column" fxLayoutAlign.xs="end" fxLayoutGap="16px"> <div fxLayout="row" fxLayoutAlign="end center" fxLayout.xs="column" fxLayoutAlign.xs="end" fxLayoutGap="16px">
<button mat-raised-button type="button" <button mat-raised-button type="button"

51
ui-ngx/src/app/modules/home/pages/admin/mail-server.component.ts

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, OnInit } from '@angular/core'; import { Component, OnDestroy, OnInit } from '@angular/core';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { PageComponent } from '@shared/components/page.component'; import { PageComponent } from '@shared/components/page.component';
@ -26,20 +26,25 @@ import { ActionNotificationShow } from '@core/notification/notification.actions'
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard'; import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard';
import { isString } from '@core/utils'; import { isString } from '@core/utils';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({ @Component({
selector: 'tb-mail-server', selector: 'tb-mail-server',
templateUrl: './mail-server.component.html', templateUrl: './mail-server.component.html',
styleUrls: ['./mail-server.component.scss', './settings-card.scss'] styleUrls: ['./mail-server.component.scss', './settings-card.scss']
}) })
export class MailServerComponent extends PageComponent implements OnInit, HasConfirmForm { export class MailServerComponent extends PageComponent implements OnInit, OnDestroy, HasConfirmForm {
mailSettings: FormGroup; mailSettings: FormGroup;
adminSettings: AdminSettings<MailServerSettings>; adminSettings: AdminSettings<MailServerSettings>;
smtpProtocols = ['smtp', 'smtps']; smtpProtocols = ['smtp', 'smtps'];
isAdd = true;
tlsVersions = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']; tlsVersions = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'];
private destroy$ = new Subject();
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
private router: Router, private router: Router,
private adminService: AdminService, private adminService: AdminService,
@ -56,12 +61,21 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon
if (this.adminSettings.jsonValue && isString(this.adminSettings.jsonValue.enableTls)) { if (this.adminSettings.jsonValue && isString(this.adminSettings.jsonValue.enableTls)) {
this.adminSettings.jsonValue.enableTls = (this.adminSettings.jsonValue.enableTls as any) === 'true'; this.adminSettings.jsonValue.enableTls = (this.adminSettings.jsonValue.enableTls as any) === 'true';
} }
this.isAdd = this.adminSettings.jsonValue.isAdd;
delete this.adminSettings.jsonValue.isAdd;
this.mailSettings.reset(this.adminSettings.jsonValue); this.mailSettings.reset(this.adminSettings.jsonValue);
this.enableMailPassword(this.isAdd);
this.enableProxyChanged(); this.enableProxyChanged();
} }
); );
} }
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
super.ngOnDestroy();
}
buildMailServerSettingsForm() { buildMailServerSettingsForm() {
this.mailSettings = this.fb.group({ this.mailSettings = this.fb.group({
mailFrom: ['', [Validators.required]], mailFrom: ['', [Validators.required]],
@ -81,14 +95,23 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon
proxyUser: [''], proxyUser: [''],
proxyPassword: [''], proxyPassword: [''],
username: [''], username: [''],
changePassword: [false],
password: [''] password: ['']
}); });
this.registerDisableOnLoadFormControl(this.mailSettings.get('smtpProtocol')); this.registerDisableOnLoadFormControl(this.mailSettings.get('smtpProtocol'));
this.registerDisableOnLoadFormControl(this.mailSettings.get('enableTls')); this.registerDisableOnLoadFormControl(this.mailSettings.get('enableTls'));
this.registerDisableOnLoadFormControl(this.mailSettings.get('enableProxy')); this.registerDisableOnLoadFormControl(this.mailSettings.get('enableProxy'));
this.mailSettings.get('enableProxy').valueChanges.subscribe(() => { this.registerDisableOnLoadFormControl(this.mailSettings.get('changePassword'));
this.mailSettings.get('enableProxy').valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe(() => {
this.enableProxyChanged(); this.enableProxyChanged();
}); });
this.mailSettings.get('changePassword').valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe((value) => {
this.enableMailPassword(value);
});
} }
enableProxyChanged(): void { enableProxyChanged(): void {
@ -102,8 +125,16 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon
} }
} }
enableMailPassword(enable: boolean) {
if (enable) {
this.mailSettings.get('password').enable({emitEvent: false});
} else {
this.mailSettings.get('password').disable({emitEvent: false});
}
}
sendTestMail(): void { sendTestMail(): void {
this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettings.value}; this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettingsFormValue};
this.adminService.sendTestMail(this.adminSettings).subscribe( this.adminService.sendTestMail(this.adminSettings).subscribe(
() => { () => {
this.store.dispatch(new ActionNotificationShow({ message: this.translate.instant('admin.test-mail-sent'), 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
} }
save(): void { save(): void {
this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettings.value}; this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettingsFormValue};
this.adminService.saveAdminSettings(this.adminSettings).subscribe( this.adminService.saveAdminSettings(this.adminSettings).subscribe(
(adminSettings) => { (adminSettings) => {
if (!adminSettings.jsonValue.password) { adminSettings.jsonValue.password = this.mailSettings.value.password;
adminSettings.jsonValue.password = this.mailSettings.value.password; adminSettings.jsonValue.changePassword = this.mailSettings.value.changePassword;
}
this.adminSettings = adminSettings; this.adminSettings = adminSettings;
this.mailSettings.reset(this.adminSettings.jsonValue); this.mailSettings.reset(this.adminSettings.jsonValue);
} }
@ -129,4 +159,9 @@ export class MailServerComponent extends PageComponent implements OnInit, HasCon
return this.mailSettings; return this.mailSettings;
} }
private get mailSettingsFormValue(): MailServerSettings {
const formValue = this.mailSettings.value;
delete formValue.changePassword;
return formValue;
}
} }

4
ui-ngx/src/app/shared/models/settings.models.ts

@ -27,6 +27,7 @@ export interface AdminSettings<T> {
export declare type SmtpProtocol = 'smtp' | 'smtps'; export declare type SmtpProtocol = 'smtp' | 'smtps';
export interface MailServerSettings { export interface MailServerSettings {
isAdd: boolean;
mailFrom: string; mailFrom: string;
smtpProtocol: SmtpProtocol; smtpProtocol: SmtpProtocol;
smtpHost: string; smtpHost: string;
@ -34,7 +35,8 @@ export interface MailServerSettings {
timeout: number; timeout: number;
enableTls: boolean; enableTls: boolean;
username: string; username: string;
password: string; changePassword?: boolean;
password?: string;
enableProxy: boolean; enableProxy: boolean;
proxyHost: string; proxyHost: string;
proxyPort: number; proxyPort: number;

1
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -104,6 +104,7 @@
"proxy-port-range": "Proxy port should be in a range from 1 to 65535.", "proxy-port-range": "Proxy port should be in a range from 1 to 65535.",
"proxy-user": "Proxy user", "proxy-user": "Proxy user",
"proxy-password": "Proxy password", "proxy-password": "Proxy password",
"change-password": "Change password",
"send-test-mail": "Send test mail", "send-test-mail": "Send test mail",
"sms-provider": "SMS provider", "sms-provider": "SMS provider",
"sms-provider-settings": "SMS provider settings", "sms-provider-settings": "SMS provider settings",

Loading…
Cancel
Save