link general config with controller service

This commit is contained in:
Dan Percic 2021-06-24 13:47:43 +03:00
parent 3fff841463
commit 915d6d62f6
3 changed files with 30 additions and 7 deletions

View File

@ -29,7 +29,7 @@
<div class="dialog-content">
<div class="inline-input-group flex-align-items-center">
<mat-slide-toggle
[(ngModel)]="showForgotPassword"
[(ngModel)]="generalSettings.forgotPasswordFunctionEnabled"
color="primary"
></mat-slide-toggle>
<span

View File

@ -2,7 +2,12 @@ import { Component, OnInit } from '@angular/core';
import { PermissionsService } from '@services/permissions.service';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { AdminDialogService } from '../../services/admin-dialog.service';
import { SmtpConfigurationControllerService, SMTPConfigurationModel } from '@redaction/red-ui-http';
import {
GeneralConfigurationModel,
SmtpConfigurationControllerService,
GeneralSettingsControllerService,
SMTPConfigurationModel
} from '@redaction/red-ui-http';
import { NotificationService, NotificationType } from '@services/notification.service';
import { TranslateService } from '@ngx-translate/core';
@ -14,8 +19,11 @@ import { TranslateService } from '@ngx-translate/core';
export class SmtpConfigScreenComponent implements OnInit {
viewReady = false;
configForm: FormGroup;
showForgotPassword = false;
generalSettings: GeneralConfigurationModel = {
forgotPasswordFunctionEnabled: false
};
private _initialGeneralSettings: GeneralConfigurationModel;
private _initialValue: SMTPConfigurationModel;
constructor(
@ -24,7 +32,8 @@ export class SmtpConfigScreenComponent implements OnInit {
private readonly _formBuilder: FormBuilder,
private readonly _dialogService: AdminDialogService,
private readonly _notificationService: NotificationService,
private readonly _translateService: TranslateService
private readonly _translateService: TranslateService,
private readonly _generalSettingsControllerService: GeneralSettingsControllerService
) {
this.configForm = this._formBuilder.group({
host: [undefined, Validators.required],
@ -61,11 +70,19 @@ export class SmtpConfigScreenComponent implements OnInit {
}
get generalConfigChanged(): boolean {
return true;
if (!this._initialGeneralSettings) return false;
const toBool = key => this.generalSettings[key] !== this._initialGeneralSettings[key];
const changes = Object.keys(this.generalSettings).map(toBool);
return changes.filter(value => value).length > 0;
}
async ngOnInit() {
await this._loadData();
this.generalSettings = await this._generalSettingsControllerService
.getGeneralConfigurations()
.toPromise();
this._initialGeneralSettings = Object.assign({}, this.generalSettings);
}
async save() {
@ -79,7 +96,9 @@ export class SmtpConfigScreenComponent implements OnInit {
async saveGeneralConfig() {
this.viewReady = false;
console.log('Saving general configuration...');
await this._generalSettingsControllerService
.updateGeneralConfigurations(this.generalSettings)
.toPromise();
this.viewReady = true;
}

View File

@ -23,6 +23,7 @@ import { FileAttributesControllerService } from './fileAttributesController.serv
import { SmtpConfigurationControllerService } from './smtpConfigurationController.service';
import { ReportTemplateControllerService } from './reportTemplateController.service';
import { UploadControllerService } from './uploadController.service';
import { GeneralSettingsControllerService } from './generalSettingsController.service';
export * from './auditController.service';
@ -74,6 +75,8 @@ export * from './reportTemplateController.service';
export * from './uploadController.service';
export * from './generalSettingsController.service';
export const APIS = [
AuditControllerService,
DebugControllerService,
@ -99,5 +102,6 @@ export const APIS = [
FileAttributesControllerService,
SmtpConfigurationControllerService,
ReportTemplateControllerService,
UploadControllerService
UploadControllerService,
GeneralSettingsControllerService
];