add general settings service
This commit is contained in:
parent
ca07dc417c
commit
65b2f25844
@ -5,7 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
import { BaseScreenComponent } from '@components/base-screen/base-screen.component';
|
||||
import { ApiModule, GeneralSettingsControllerService } from '@redaction/red-ui-http';
|
||||
import { ApiModule } from '@redaction/red-ui-http';
|
||||
import { ApiPathInterceptor } from '@utils/api-path-interceptor';
|
||||
import { MissingTranslationHandler, TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { languageInitializer } from '@i18n/language.initializer';
|
||||
@ -36,6 +36,7 @@ import { DatePipe } from '@shared/pipes/date.pipe';
|
||||
import * as links from '../assets/help-mode/links.json';
|
||||
import { HELP_DOCS, IqserHelpModeModule, MAX_RETRIES_ON_SERVER_ERROR, ServerErrorInterceptor, ToastComponent } from '@iqser/common-ui';
|
||||
import { KeycloakService } from 'keycloak-angular';
|
||||
import { GeneralSettingsService } from '@services/general-settings.service';
|
||||
|
||||
export function httpLoaderFactory(httpClient: HttpClient): PruningTranslationLoader {
|
||||
return new PruningTranslationLoader(httpClient, '/assets/i18n/', '.json');
|
||||
@ -121,7 +122,7 @@ const components = [AppComponent, AuthErrorComponent, NotificationsComponent, Sp
|
||||
provide: APP_INITIALIZER,
|
||||
multi: true,
|
||||
useFactory: configurationInitializer,
|
||||
deps: [KeycloakService, Title, ConfigService, GeneralSettingsControllerService],
|
||||
deps: [KeycloakService, Title, ConfigService, GeneralSettingsService],
|
||||
},
|
||||
{
|
||||
provide: MONACO_PATH,
|
||||
|
||||
@ -1,16 +1,12 @@
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { AdminDialogService } from '../../services/admin-dialog.service';
|
||||
import {
|
||||
GeneralConfigurationModel,
|
||||
GeneralSettingsControllerService,
|
||||
SMTPConfiguration,
|
||||
SmtpConfigurationControllerService,
|
||||
} from '@redaction/red-ui-http';
|
||||
import { GeneralConfigurationModel, SMTPConfiguration, SmtpConfigurationControllerService } from '@redaction/red-ui-http';
|
||||
import { ConfigService } from '@services/config.service';
|
||||
import { AutoUnsubscribe, IconButtonTypes, LoadingService, Toaster } from '@iqser/common-ui';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { GeneralSettingsService } from '@services/general-settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-general-config-screen',
|
||||
@ -35,7 +31,7 @@ export class GeneralConfigScreenComponent extends AutoUnsubscribe implements OnI
|
||||
private readonly _dialogService: AdminDialogService,
|
||||
private readonly _configService: ConfigService,
|
||||
private readonly _smtpConfigService: SmtpConfigurationControllerService,
|
||||
private readonly _generalSettingsControllerService: GeneralSettingsControllerService,
|
||||
private readonly _generalSettingsService: GeneralSettingsService,
|
||||
) {
|
||||
super();
|
||||
|
||||
@ -110,8 +106,8 @@ export class GeneralConfigScreenComponent extends AutoUnsubscribe implements OnI
|
||||
|
||||
const configFormValues = this.configForm.getRawValue();
|
||||
|
||||
await this._generalSettingsControllerService.updateGeneralConfigurations(configFormValues).toPromise();
|
||||
this._initialGeneralConfiguration = await this._generalSettingsControllerService.getGeneralConfigurations().toPromise();
|
||||
await this._generalSettingsService.updateGeneralConfigurations(configFormValues).toPromise();
|
||||
this._initialGeneralConfiguration = await this._generalSettingsService.getGeneralConfigurations().toPromise();
|
||||
this._configService.updateDisplayName(this._initialGeneralConfiguration.displayName);
|
||||
this._loadingService.stop();
|
||||
}
|
||||
@ -141,7 +137,7 @@ export class GeneralConfigScreenComponent extends AutoUnsubscribe implements OnI
|
||||
private async _loadData() {
|
||||
this._loadingService.start();
|
||||
try {
|
||||
this._initialGeneralConfiguration = await this._generalSettingsControllerService.getGeneralConfigurations().toPromise();
|
||||
this._initialGeneralConfiguration = await this._generalSettingsService.getGeneralConfigurations().toPromise();
|
||||
this.configForm.patchValue(this._initialGeneralConfiguration, { emitEvent: false });
|
||||
} catch (e) {}
|
||||
|
||||
|
||||
22
apps/red-ui/src/app/services/general-settings.service.ts
Normal file
22
apps/red-ui/src/app/services/general-settings.service.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { GenericService, RequiredParam, Validate } from '@iqser/common-ui';
|
||||
import { GeneralConfigurationModel } from '@redaction/red-ui-http';
|
||||
import { tap } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class GeneralSettingsService extends GenericService<GeneralConfigurationModel> {
|
||||
constructor(protected readonly _injector: Injector) {
|
||||
super(_injector, 'configuration');
|
||||
}
|
||||
|
||||
getGeneralConfigurations() {
|
||||
return this._getOne(['general']).pipe(tap(console.log));
|
||||
}
|
||||
|
||||
@Validate()
|
||||
updateGeneralConfigurations(@RequiredParam() body: GeneralConfigurationModel) {
|
||||
return this._post<unknown>(body, `${this._defaultModelPath}/general`);
|
||||
}
|
||||
}
|
||||
@ -1,21 +1,21 @@
|
||||
import { GeneralSettingsControllerService } from '@redaction/red-ui-http';
|
||||
import { catchError, filter, mergeMap, take, tap } from 'rxjs/operators';
|
||||
import { ConfigService } from '@services/config.service';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
import { of } from 'rxjs';
|
||||
import { KeycloakEventType, KeycloakService } from 'keycloak-angular';
|
||||
import { GeneralSettingsService } from '@services/general-settings.service';
|
||||
|
||||
export function configurationInitializer(
|
||||
keycloakService: KeycloakService,
|
||||
title: Title,
|
||||
configService: ConfigService,
|
||||
generalSettingsControllerService: GeneralSettingsControllerService,
|
||||
generalSettingsService: GeneralSettingsService,
|
||||
) {
|
||||
return () =>
|
||||
keycloakService.keycloakEvents$
|
||||
.pipe(
|
||||
filter(event => event.type === KeycloakEventType.OnReady),
|
||||
mergeMap(() => generalSettingsControllerService.getGeneralConfigurations()),
|
||||
mergeMap(() => generalSettingsService.getGeneralConfigurations()),
|
||||
tap(configuration => configService.updateDisplayName(configuration.displayName)),
|
||||
catchError(() => {
|
||||
title.setTitle('RedactManager');
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
|
||||
import { Configuration } from './configuration';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { GeneralSettingsControllerService } from './api/generalSettingsController.service';
|
||||
import { LicenseReportControllerService } from './api/licenseReportController.service';
|
||||
import { ManualRedactionControllerService } from './api/manualRedactionController.service';
|
||||
import { ReanalysisControllerService } from './api/reanalysisController.service';
|
||||
@ -20,7 +19,6 @@ import { NotificationControllerService } from './api/notificationController.serv
|
||||
declarations: [],
|
||||
exports: [],
|
||||
providers: [
|
||||
GeneralSettingsControllerService,
|
||||
LicenseReportControllerService,
|
||||
ManualRedactionControllerService,
|
||||
ReanalysisControllerService,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user