firstValueFrom instead of toPromise() in admin module

This commit is contained in:
Edi Cziszter 2022-01-20 14:00:38 +02:00
parent 04fc1dd3f6
commit 13b013c736
26 changed files with 201 additions and 276 deletions

View File

@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, Inject, Injector } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Observable } from 'rxjs';
import { firstValueFrom, Observable } from 'rxjs';
import { BaseDialogComponent, shareDistinctLast, Toaster } from '@iqser/common-ui';
import { TranslateService } from '@ngx-translate/core';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@ -77,8 +77,7 @@ export class AddEditDictionaryDialogComponent extends BaseDialogComponent {
observable = this._dictionaryService.addDictionary({ ...dictionary, dossierTemplateId });
}
return observable
.toPromise()
return firstValueFrom(observable)
.then(() => this._dialogRef.close(true))
.catch(error => {
if (error.status === HttpStatusCode.Conflict) {

View File

@ -11,6 +11,7 @@ import { BaseDialogComponent, LoadingService, Toaster } from '@iqser/common-ui';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { DownloadFileType, IDossierTemplate } from '@red/domain';
import { HttpStatusCode } from '@angular/common/http';
import { firstValueFrom } from 'rxjs';
@Component({
templateUrl: './add-edit-dossier-template-dialog.component.html',

View File

@ -4,6 +4,7 @@ import { UserService } from '@services/user.service';
import { LoadingService, Toaster } from '@iqser/common-ui';
import { User } from '@red/domain';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'redaction-reset-password',
@ -25,15 +26,15 @@ export class ResetPasswordComponent {
async save() {
this._loadingService.start();
try {
await this._userService
.resetPassword(
await firstValueFrom(
this._userService.resetPassword(
{
password: this.form.get('temporaryPassword').value,
temporary: true,
},
this.user.id,
)
.toPromise();
),
);
this.toggleResetPassword.emit();
} catch (error) {
this._toaster.error(_('reset-password-dialog.error.password-policy'));

View File

@ -7,6 +7,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { User } from '@red/domain';
import { UserService } from '@services/user.service';
import { HttpStatusCode } from '@angular/common/http';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'redaction-user-details',
@ -107,9 +108,7 @@ export class UserDetailsComponent extends AutoUnsubscribe implements OnChanges,
const userData = { ...this.form.getRawValue(), roles: this.activeRoles };
if (!this.user) {
await this.userService
.create(userData)
.toPromise()
await firstValueFrom(this.userService.create(userData))
.then(() => {
this.closeDialog.emit(true);
})
@ -122,7 +121,7 @@ export class UserDetailsComponent extends AutoUnsubscribe implements OnChanges,
this._loadingService.stop();
});
} else {
await this.userService.updateProfile(userData, this.user.id).toPromise();
await firstValueFrom(this.userService.updateProfile(userData, this.user.id));
this.closeDialog.emit(true);
}
}

View File

@ -4,6 +4,7 @@ import { List, LoadingService } from '@iqser/common-ui';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { DossiersService } from '@services/entity-services/dossiers.service';
import { UserService } from '@services/user.service';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'redaction-confirm-delete-users-dialog',
@ -40,7 +41,7 @@ export class ConfirmDeleteUsersDialogComponent {
async deleteUser() {
if (this.valid) {
this._loadingService.start();
await this._userService.delete(this.userIds).toPromise();
await firstValueFrom(this._userService.delete(this.userIds));
this.dialogRef.close(true);
} else {
this.showToast = true;

View File

@ -7,6 +7,7 @@ import { TranslateService } from '@ngx-translate/core';
import { defaultColorsTranslations } from '../../translations/default-colors-translations';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { DictionaryService } from '@shared/services/dictionary.service';
import { firstValueFrom } from 'rxjs';
interface IEditColorData {
colors: IColors;
@ -46,7 +47,7 @@ export class EditColorDialogComponent extends BaseDialogComponent {
};
try {
await this._dictionaryService.setColors(colors, this._dossierTemplateId).toPromise();
await firstValueFrom(this._dictionaryService.setColors(colors, this._dossierTemplateId));
this._dialogRef.close(true);
const color = this._translateService.instant(defaultColorsTranslations[this.data.colorKey]);
this._toaster.info(_('edit-color-dialog.success'), { params: { color: color } });

View File

@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, Inject, Injector } from '@angular/c
import { AbstractControl, FormBuilder, FormGroup, ValidatorFn, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import * as Papa from 'papaparse';
import { Observable } from 'rxjs';
import { firstValueFrom, Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { DefaultListingServices, ListingComponent, TableColumnConfig, Toaster, trackBy } from '@iqser/common-ui';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@ -56,14 +56,6 @@ export class FileAttributesCsvImportDialogComponent extends ListingComponent<IFi
);
}
private _getForm(): FormGroup {
return this._formBuilder.group({
filenameMappingColumnHeaderName: ['', [Validators.required, this._autocompleteStringValidator()]],
delimiter: [undefined, Validators.required],
encoding: ['UTF-8', Validators.required],
});
}
readFile() {
const reader = new FileReader();
reader.addEventListener('load', event => {
@ -183,7 +175,7 @@ export class FileAttributesCsvImportDialogComponent extends ListingComponent<IFi
};
try {
await this._fileAttributesService.setFileAttributeConfig(fileAttributes, this.data.dossierTemplateId).toPromise();
await firstValueFrom(this._fileAttributesService.setFileAttributeConfig(fileAttributes, this.data.dossierTemplateId));
this._toaster.success(_('file-attributes-csv-import.save.success'), { params: { count: this.activeFields.length } });
} catch (e) {
this._toaster.error(_('file-attributes-csv-import.save.error'));
@ -207,6 +199,14 @@ export class FileAttributesCsvImportDialogComponent extends ListingComponent<IFi
}, 0);
}
private _getForm(): FormGroup {
return this._formBuilder.group({
filenameMappingColumnHeaderName: ['', [Validators.required, this._autocompleteStringValidator()]],
delimiter: [undefined, Validators.required],
encoding: ['UTF-8', Validators.required],
});
}
private _autocompleteStringValidator(): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } | null => {
if ((this.parseResult?.meta?.fields || []).indexOf(control.value) !== -1) {

View File

@ -8,6 +8,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { UserService } from '@services/user.service';
import { Audit, IAudit, IAuditResponse, IAuditSearchRequest } from '@red/domain';
import { AuditService } from '../../services/audit.service';
import { firstValueFrom } from 'rxjs';
const PAGE_SIZE = 50;
@ -52,15 +53,6 @@ export class AuditScreenComponent extends ListingComponent<Audit> implements OnD
});
}
private _getForm(): FormGroup {
return this._formBuilder.group({
category: [this.ALL_CATEGORIES],
userId: [this.ALL_USERS],
from: [],
to: [],
});
}
get totalPages(): number {
if (!this.logs) {
return 0;
@ -76,6 +68,15 @@ export class AuditScreenComponent extends ListingComponent<Audit> implements OnD
await this._fetchData();
}
private _getForm(): FormGroup {
return this._formBuilder.group({
category: [this.ALL_CATEGORIES],
userId: [this.ALL_USERS],
from: [],
to: [],
});
}
private _updateDateFilters(value): boolean {
if (applyIntervalConstraints(value, this._previousFrom, this._previousTo, this.form, 'from', 'to')) {
return true;
@ -105,8 +106,8 @@ export class AuditScreenComponent extends ListingComponent<Audit> implements OnD
to,
};
promises.push(this._auditService.getCategories().toPromise());
promises.push(this._auditService.searchAuditLog(logsRequestBody).toPromise());
promises.push(firstValueFrom(this._auditService.getCategories()));
promises.push(firstValueFrom(this._auditService.searchAuditLog(logsRequestBody)));
const data = await Promise.all(promises);
this.categories = data[0].map(c => c.category);

View File

@ -15,6 +15,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { UserService } from '@services/user.service';
import { DictionaryService } from '@shared/services/dictionary.service';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { firstValueFrom } from 'rxjs';
interface ListItem extends IListable {
readonly key: string;
@ -72,7 +73,7 @@ export class DefaultColorsScreenComponent extends ListingComponent<ListItem> imp
private async _loadColors() {
this._loadingService.start();
const data = await this._appStateService.loadColors(this._dossierTemplatesService.activeDossierTemplateId).toPromise();
const data = await firstValueFrom(this._appStateService.loadColors(this._dossierTemplatesService.activeDossierTemplateId));
this._colorsObj = data;
const entities = Object.keys(data)
.map(key => ({

View File

@ -66,8 +66,8 @@ export class DictionaryListingScreenComponent extends ListingComponent<Dictionar
openDeleteDictionariesDialog($event?: MouseEvent, types = this.listingService.selected) {
this._dialogService.openDialog('confirm', $event, null, async () => {
this._loadingService.start();
await this._dictionaryService
.deleteDictionaries(
await firstValueFrom(
this._dictionaryService.deleteDictionaries(
types.map(t => t.type),
this._dossierTemplatesService.activeDossierTemplateId,
)

View File

@ -11,6 +11,7 @@ import { CircleButtonTypes, LoadingService } from '@iqser/common-ui';
import { UserService } from '@services/user.service';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { Dictionary } from '@red/domain';
import { firstValueFrom } from 'rxjs';
@Component({
templateUrl: './dictionary-overview-screen.component.html',
@ -72,7 +73,7 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges imple
$event?.stopPropagation();
this._dialogService.openDialog('confirm', $event, null, async () => {
await this._dictionaryService.deleteDictionaries([this.dictionary.type], this.dictionary.dossierTemplateId).toPromise();
await firstValueFrom(this._dictionaryService.deleteDictionaries([this.dictionary.type], this.dictionary.dossierTemplateId));
await this._appStateService.loadDictionaryData();
await this._router.navigate([
'/main',
@ -149,9 +150,7 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges imple
private async _loadEntries() {
this._loadingService.start();
await this._dictionaryService
.getForType(this.dictionary.dossierTemplateId, this.dictionary.type)
.toPromise()
await firstValueFrom(this._dictionaryService.getForType(this.dictionary.dossierTemplateId, this.dictionary.type))
.then(
data => {
this._loadingService.stop();

View File

@ -15,6 +15,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { UserService } from '@services/user.service';
import { DossierAttributeConfig, IDossierAttributeConfig } from '@red/domain';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { firstValueFrom } from 'rxjs';
@Component({
templateUrl: './dossier-attributes-listing-screen.component.html',
@ -56,7 +57,7 @@ export class DossierAttributesListingScreenComponent extends ListingComponent<Do
this._dialogService.openDialog('confirm', $event, null, async () => {
this._loadingService.start();
const ids = dossierAttribute ? [dossierAttribute.id] : this.listingService.selected.map(item => item.id);
await this._dossierAttributesService.delete(ids).toPromise();
await firstValueFrom(this._dossierAttributesService.delete(ids));
await this._loadData();
});
}
@ -71,7 +72,7 @@ export class DossierAttributesListingScreenComponent extends ListingComponent<Do
private async _loadData() {
this._loadingService.start();
await this._dossierAttributesService.loadAll().toPromise();
await firstValueFrom(this._dossierAttributesService.loadAll());
this._loadingService.stop();
}
}

View File

@ -1,81 +0,0 @@
import { ChangeDetectionStrategy, Component, forwardRef, Injector } from '@angular/core';
import { AppStateService } from '@state/app-state.service';
import { UserPreferenceService } from '@services/user-preference.service';
import { AdminDialogService } from '../../../services/admin-dialog.service';
import { DossierTemplate } from '@red/domain';
import {
CircleButtonTypes,
DefaultListingServicesTmp,
EntitiesService,
IconButtonTypes,
ListingComponent,
LoadingService,
TableColumnConfig,
Toaster,
} from '@iqser/common-ui';
import { UserService } from '@services/user.service';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { RouterHistoryService } from '@services/router-history.service';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { HttpStatusCode } from '@angular/common/http';
@Component({
templateUrl: './dossier-templates-listing-screen.component.html',
styleUrls: ['./dossier-templates-listing-screen.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
...DefaultListingServicesTmp,
{ provide: EntitiesService, useExisting: DossierTemplatesService },
{ provide: ListingComponent, useExisting: forwardRef(() => DossierTemplatesListingScreenComponent) },
],
})
export class DossierTemplatesListingScreenComponent extends ListingComponent<DossierTemplate> {
readonly iconButtonTypes = IconButtonTypes;
readonly circleButtonTypes = CircleButtonTypes;
readonly currentUser = this._userService.currentUser;
readonly tableHeaderLabel = _('dossier-templates-listing.table-header.title');
readonly tableColumnConfigs: TableColumnConfig<DossierTemplate>[] = [
{ label: _('dossier-templates-listing.table-col-names.name'), sortByKey: 'searchKey' },
{ label: _('dossier-templates-listing.table-col-names.created-by'), class: 'user-column' },
{ label: _('dossier-templates-listing.table-col-names.created-on'), sortByKey: 'dateAdded' },
{ label: _('dossier-templates-listing.table-col-names.modified-on'), sortByKey: 'dateModified' },
];
constructor(
private readonly _toaster: Toaster,
protected readonly _injector: Injector,
private readonly _userService: UserService,
private readonly _loadingService: LoadingService,
private readonly _appStateService: AppStateService,
private readonly _dialogService: AdminDialogService,
readonly routerHistoryService: RouterHistoryService,
readonly userPreferenceService: UserPreferenceService,
private readonly _dossierTemplatesService: DossierTemplatesService,
) {
super(_injector);
}
openBulkDeleteTemplatesDialog($event?: MouseEvent) {
return this._dialogService.openDialog('confirm', $event, null, () => {
this._loadingService.loadWhile(this._deleteTemplates());
});
}
openAddDossierTemplateDialog() {
this._dialogService.openDialog('addEditDossierTemplate', null, null);
}
private async _deleteTemplates(templateIds = this.listingService.selected.map(d => d.dossierTemplateId)) {
await this._dossierTemplatesService
.delete(templateIds)
.toPromise()
.catch(error => {
if (error.status === HttpStatusCode.Conflict) {
this._toaster.error(_('dossier-templates-listing.error.conflict'));
} else {
this._toaster.error(_('dossier-templates-listing.error.generic'));
}
});
await this._appStateService.loadDictionaryData();
}
}

View File

@ -17,6 +17,7 @@ import { FileAttributeConfig, IFileAttributeConfig, IFileAttributesConfig } from
import { FileAttributesService } from '@services/entity-services/file-attributes.service';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { HttpStatusCode } from '@angular/common/http';
import { firstValueFrom } from 'rxjs';
@Component({
templateUrl: './file-attributes-listing-screen.component.html',
@ -92,14 +93,14 @@ export class FileAttributesListingScreenComponent extends ListingComponent<FileA
this._loadingService.start();
const dossierTemplateId = this._dossierTemplatesService.activeDossierTemplateId;
if (fileAttribute) {
await this._fileAttributesService.deleteFileAttributes([fileAttribute.id], dossierTemplateId).toPromise();
await firstValueFrom(this._fileAttributesService.deleteFileAttributes([fileAttribute.id], dossierTemplateId));
} else {
await this._fileAttributesService
.deleteFileAttributes(
await firstValueFrom(
this._fileAttributesService.deleteFileAttributes(
this.listingService.selected.map(f => f.id),
dossierTemplateId,
)
.toPromise();
),
);
}
await this._appStateService.refreshDossierTemplate(dossierTemplateId);
await this._loadData();
@ -123,17 +124,16 @@ export class FileAttributesListingScreenComponent extends ListingComponent<FileA
}
private async _createNewFileAttributeAndRefreshView(newValue: IFileAttributeConfig): Promise<void> {
await this._fileAttributesService
.setFileAttributesConfig(newValue, this._dossierTemplatesService.activeDossierTemplateId)
.toPromise()
.catch(error => {
if (error.status === HttpStatusCode.Conflict) {
this._toaster.error(_('file-attributes-listing.error.conflict'));
} else {
this._toaster.error(_('file-attributes-listing.error.generic'));
}
this._loadingService.stop();
});
await firstValueFrom(
this._fileAttributesService.setFileAttributesConfig(newValue, this._dossierTemplatesService.activeDossierTemplateId),
).catch(error => {
if (error.status === HttpStatusCode.Conflict) {
this._toaster.error(_('file-attributes-listing.error.conflict'));
} else {
this._toaster.error(_('file-attributes-listing.error.generic'));
}
this._loadingService.stop();
});
await this._appStateService.refreshDossierTemplate(this._dossierTemplatesService.activeDossierTemplateId);
await this._loadData();
}
@ -142,9 +142,9 @@ export class FileAttributesListingScreenComponent extends ListingComponent<FileA
this._loadingService.start();
try {
const response = await this._fileAttributesService
.getFileAttributesConfig(this._dossierTemplatesService.activeDossierTemplateId)
.toPromise();
const response = await firstValueFrom(
this._fileAttributesService.getFileAttributesConfig(this._dossierTemplatesService.activeDossierTemplateId),
);
this._existingConfiguration = response;
const fileAttributeConfig = response?.fileAttributeConfigs.map(item => new FileAttributeConfig(item)) || [];
this.entitiesService.setEntities(fileAttributeConfig);

View File

@ -4,6 +4,7 @@ import { GeneralSettingsService } from '@services/general-settings.service';
import { IGeneralConfiguration } from '@red/domain';
import { ConfigService } from '@services/config.service';
import { FormBuilder, FormGroup } from '@angular/forms';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'redaction-general-config-form',
@ -11,8 +12,8 @@ import { FormBuilder, FormGroup } from '@angular/forms';
styleUrls: ['./general-config-form.component.scss'],
})
export class GeneralConfigFormComponent extends AutoUnsubscribe implements OnInit, OnDestroy {
private _initialConfiguration: IGeneralConfiguration;
readonly form: FormGroup = this._getForm();
private _initialConfiguration: IGeneralConfiguration;
constructor(
private readonly _loadingService: LoadingService,
@ -23,28 +24,6 @@ export class GeneralConfigFormComponent extends AutoUnsubscribe implements OnIni
super();
}
private _getForm(): FormGroup {
return this._formBuilder.group({
forgotPasswordFunctionEnabled: [false],
auxiliaryName: [undefined],
});
}
async ngOnInit(): Promise<void> {
await this._loadData();
}
async saveGeneralConfig() {
this._loadingService.start();
const configFormValues = this.form.getRawValue();
await this._generalSettingsService.updateGeneralConfigurations(configFormValues).toPromise();
this._initialConfiguration = await this._generalSettingsService.getGeneralConfigurations().toPromise();
this._configService.updateDisplayName(this._initialConfiguration.displayName);
this._loadingService.stop();
}
get generalConfigurationChanged(): boolean {
if (!this._initialConfiguration) {
return true;
@ -59,10 +38,32 @@ export class GeneralConfigFormComponent extends AutoUnsubscribe implements OnIni
return false;
}
async ngOnInit(): Promise<void> {
await this._loadData();
}
async saveGeneralConfig() {
this._loadingService.start();
const configFormValues = this.form.getRawValue();
await firstValueFrom(this._generalSettingsService.updateGeneralConfigurations(configFormValues));
this._initialConfiguration = await firstValueFrom(this._generalSettingsService.getGeneralConfigurations());
this._configService.updateDisplayName(this._initialConfiguration.displayName);
this._loadingService.stop();
}
private _getForm(): FormGroup {
return this._formBuilder.group({
forgotPasswordFunctionEnabled: [false],
auxiliaryName: [undefined],
});
}
private async _loadData() {
this._loadingService.start();
try {
this._initialConfiguration = await this._generalSettingsService.getGeneralConfigurations().toPromise();
this._initialConfiguration = await firstValueFrom(this._generalSettingsService.getGeneralConfigurations());
this.form.patchValue(this._initialConfiguration, { emitEvent: false });
} catch (e) {}

View File

@ -5,6 +5,7 @@ import { AutoUnsubscribe, IconButtonTypes, LoadingService, Toaster } from '@iqse
import { AdminDialogService } from '../../../services/admin-dialog.service';
import { SmtpConfigService } from '../../../services/smtp-config.service';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'redaction-smtp-form',
@ -13,8 +14,8 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
})
export class SmtpFormComponent extends AutoUnsubscribe implements OnInit, OnDestroy {
readonly iconButtonTypes = IconButtonTypes;
private _initialConfiguration: ISmtpConfiguration;
readonly form: FormGroup = this._getForm();
private _initialConfiguration: ISmtpConfiguration;
constructor(
private readonly _formBuilder: FormBuilder,
@ -31,10 +32,53 @@ export class SmtpFormComponent extends AutoUnsubscribe implements OnInit, OnDest
});
}
get smtpConfigurationChanged(): boolean {
if (!this._initialConfiguration) {
return true;
}
for (const key of Object.keys(this.form.getRawValue())) {
if (this._initialConfiguration[key] !== this.form.get(key).value) {
return true;
}
}
return false;
}
async ngOnInit(): Promise<void> {
await this._loadData();
}
openAuthConfigDialog(skipDisableOnCancel?: boolean) {
this._dialogService.openDialog('smtpAuthConfig', null, this.form.getRawValue(), null, authConfig => {
if (authConfig) {
this.form.patchValue(authConfig);
} else if (!skipDisableOnCancel) {
this.form.patchValue({ auth: false }, { emitEvent: false });
}
});
}
async save() {
this._loadingService.start();
await firstValueFrom(this._smtpConfigService.updateSMTPConfiguration(this.form.getRawValue()));
this._initialConfiguration = this.form.getRawValue();
this._loadingService.stop();
}
async testConnection() {
this._loadingService.start();
try {
await firstValueFrom(this._smtpConfigService.testSMTPConfiguration(this.form.getRawValue()));
this._toaster.success(_('general-config-screen.test.success'));
} catch (e) {
this._toaster.error(_('general-config-screen.test.error'));
} finally {
this._loadingService.stop();
}
}
private _getForm(): FormGroup {
return this._formBuilder.group({
host: [undefined, Validators.required],
@ -52,54 +96,11 @@ export class SmtpFormComponent extends AutoUnsubscribe implements OnInit, OnDest
});
}
openAuthConfigDialog(skipDisableOnCancel?: boolean) {
this._dialogService.openDialog('smtpAuthConfig', null, this.form.getRawValue(), null, authConfig => {
if (authConfig) {
this.form.patchValue(authConfig);
} else if (!skipDisableOnCancel) {
this.form.patchValue({ auth: false }, { emitEvent: false });
}
});
}
async save() {
this._loadingService.start();
await this._smtpConfigService.updateSMTPConfiguration(this.form.getRawValue()).toPromise();
this._initialConfiguration = this.form.getRawValue();
this._loadingService.stop();
}
get smtpConfigurationChanged(): boolean {
if (!this._initialConfiguration) {
return true;
}
for (const key of Object.keys(this.form.getRawValue())) {
if (this._initialConfiguration[key] !== this.form.get(key).value) {
return true;
}
}
return false;
}
async testConnection() {
this._loadingService.start();
try {
await this._smtpConfigService.testSMTPConfiguration(this.form.getRawValue()).toPromise();
this._toaster.success(_('general-config-screen.test.success'));
} catch (e) {
this._toaster.error(_('general-config-screen.test.error'));
} finally {
this._loadingService.stop();
}
}
private async _loadData() {
this._loadingService.start();
try {
this._initialConfiguration = await this._smtpConfigService.getCurrentSMTPConfiguration().toPromise();
this._initialConfiguration = await firstValueFrom(this._smtpConfigService.getCurrentSMTPConfiguration());
this.form.patchValue(this._initialConfiguration, { emitEvent: false });
} catch (e) {}

View File

@ -5,6 +5,7 @@ import { Justification } from '@red/domain';
import { JustificationsService } from '@services/entity-services/justifications.service';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { LoadingService } from '@iqser/common-ui';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'redaction-add-edit-justification-dialog',
@ -35,8 +36,8 @@ export class AddEditJustificationDialogComponent {
const dossierTemplateId = this._dossierTemplatesService.activeDossierTemplateId;
this._loadingService.start();
await this._justificationService.createOrUpdate(this.form.getRawValue(), dossierTemplateId).toPromise();
await this._justificationService.loadAll(dossierTemplateId).toPromise();
await firstValueFrom(this._justificationService.createOrUpdate(this.form.getRawValue(), dossierTemplateId));
await firstValueFrom(this._justificationService.loadAll(dossierTemplateId));
this._loadingService.stop();
this.dialogRef.close(true);
}

View File

@ -13,6 +13,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { JustificationsService } from '@services/entity-services/justifications.service';
import { Justification } from '@red/domain';
import { firstValueFrom } from 'rxjs';
type DialogType = 'confirm' | 'addEditJustification';
@ -51,8 +52,8 @@ export class JustificationsDialogService extends DialogService<DialogType> {
this._loadingService.start();
const dossierTemplateId = this._dossierTemplatesService.activeDossierTemplateId;
const justificationIds = justifications.map(j => j.id);
await this._justificationService.delete(justificationIds, dossierTemplateId).toPromise();
await this._justificationService.loadAll(dossierTemplateId).toPromise();
await firstValueFrom(this._justificationService.delete(justificationIds, dossierTemplateId));
await firstValueFrom(this._justificationService.loadAll(dossierTemplateId));
this._loadingService.stop();
});
}

View File

@ -15,6 +15,7 @@ import { DossierTemplatesService } from '@services/entity-services/dossier-templ
import { JustificationsDialogService } from '../justifications-dialog.service';
import { UserService } from '@services/user.service';
import { UserPreferenceService } from '@services/user-preference.service';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'redaction-justifications-screen',
@ -52,7 +53,7 @@ export class JustificationsScreenComponent extends ListingComponent<Justificatio
async ngOnInit(): Promise<void> {
this._loadingService.start();
await this._justificationService.loadAll(this._dossierTemplatesService.activeDossierTemplateId).toPromise();
await firstValueFrom(this._justificationService.loadAll(this._dossierTemplatesService.activeDossierTemplateId));
this._loadingService.stop();
}

View File

@ -9,6 +9,7 @@ import { RouterHistoryService } from '@services/router-history.service';
import { LicenseReportService } from '../../services/licence-report.service';
import { ILicenseReport } from '@red/domain';
import { Color, ScaleType } from '@swimlane/ngx-charts';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'redaction-license-information-screen',
@ -72,15 +73,15 @@ export class LicenseInformationScreenComponent implements OnInit {
endDate: endDate.toDate(),
};
const promises = [
this._licenseReportService.licenseReport(currentConfig).toPromise(),
this._licenseReportService.licenseReport({}).toPromise(),
firstValueFrom(this._licenseReportService.licenseReport(currentConfig)),
firstValueFrom(this._licenseReportService.licenseReport({})),
];
if (endDate.isBefore(moment())) {
const unlicensedConfig = {
startDate: endDate.toDate(),
};
promises.push(this._licenseReportService.licenseReport(unlicensedConfig).toPromise());
promises.push(firstValueFrom(this._licenseReportService.licenseReport(unlicensedConfig)));
}
Promise.all(promises).then(reports => {
@ -135,12 +136,12 @@ export class LicenseInformationScreenComponent implements OnInit {
}
promises.push(
this._licenseReportService
.licenseReport({
firstValueFrom(
this._licenseReportService.licenseReport({
startDate: moment(`01-${m + 1}-${y}`, 'DD-MM-YYYY').toDate(),
endDate: moment(`01-${nm + 1}-${ny}`, 'DD-MM-YYYY').toDate(),
})
.toPromise(),
}),
),
);
y = ny;

View File

@ -12,6 +12,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { AdminDialogService } from '../../services/admin-dialog.service';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { ReportTemplateService } from '@services/report-template.service';
import { firstValueFrom } from 'rxjs';
interface Placeholder {
placeholder: string;
@ -56,9 +57,9 @@ export class ReportsScreenComponent implements OnInit {
async download(template: IReportTemplate) {
this._loadingService.start();
try {
const data = await this._reportTemplateService
.downloadReportTemplate(template.dossierTemplateId, template.templateId, 'response')
.toPromise();
const data = await firstValueFrom(
this._reportTemplateService.downloadReportTemplate(template.dossierTemplateId, template.templateId, 'response'),
);
this._loadingService.stop();
download(data, template.fileName);
} catch (e) {
@ -130,31 +131,31 @@ export class ReportsScreenComponent implements OnInit {
});
this._dialogService.openDialog('confirm', null, data, null, async result => {
if (result) {
await this._reportTemplateService.uploadTemplateForm(dossierTemplateId, result > 1, file).toPromise();
await firstValueFrom(this._reportTemplateService.uploadTemplateForm(dossierTemplateId, result > 1, file));
await this._loadReportTemplates();
}
});
} else {
await this._reportTemplateService.uploadTemplateForm(dossierTemplateId, false, file).toPromise();
await firstValueFrom(this._reportTemplateService.uploadTemplateForm(dossierTemplateId, false, file));
await this._loadReportTemplates();
}
}
private async _deleteTemplate(template: IReportTemplate) {
await this._reportTemplateService.delete(template.dossierTemplateId, template.templateId).toPromise();
await firstValueFrom(this._reportTemplateService.delete(template.dossierTemplateId, template.templateId));
await this._loadReportTemplates();
}
private async _loadReportTemplates() {
this.availableTemplates = await this._reportTemplateService
.getAvailableReportTemplates(this._dossierTemplatesService.activeDossierTemplateId)
.toPromise();
this.availableTemplates = await firstValueFrom(
this._reportTemplateService.getAvailableReportTemplates(this._dossierTemplatesService.activeDossierTemplateId),
);
}
private async _loadPlaceholders() {
const placeholdersResponse: IPlaceholdersResponse = await this._reportTemplateService
.getAvailablePlaceholders(this._dossierTemplatesService.activeDossierTemplateId)
.toPromise();
const placeholdersResponse: IPlaceholdersResponse = await firstValueFrom(
this._reportTemplateService.getAvailablePlaceholders(this._dossierTemplatesService.activeDossierTemplateId),
);
this.placeholders = placeholderTypes.flatMap(type =>
placeholdersResponse[type].map(placeholder => ({
placeholder,

View File

@ -7,6 +7,7 @@ import { ComponentHasChanges } from '@guards/can-deactivate.guard';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { RulesService } from '../../services/rules.service';
import { firstValueFrom } from 'rxjs';
import ICodeEditor = monaco.editor.ICodeEditor;
import IModelDeltaDecoration = monaco.editor.IModelDeltaDecoration;
import IStandaloneEditorConstructionOptions = monaco.editor.IStandaloneEditorConstructionOptions;
@ -87,22 +88,21 @@ export class RulesScreenComponent extends ComponentHasChanges implements OnInit
async save(): Promise<void> {
this._loadingService.start();
await this._rulesService
.uploadRules({
await firstValueFrom(
this._rulesService.uploadRules({
rules: this._codeEditor.getModel().getValue(),
dossierTemplateId: this._dossierTemplatesService.activeDossierTemplateId,
})
.toPromise()
.then(
async () => {
await this._initialize();
this._toaster.success(_('rules-screen.success.generic'));
},
() => {
this._loadingService.stop();
this._toaster.error(_('rules-screen.error.generic'));
},
);
}),
).then(
async () => {
await this._initialize();
this._toaster.success(_('rules-screen.success.generic'));
},
() => {
this._loadingService.stop();
this._toaster.error(_('rules-screen.error.generic'));
},
);
}
revert(): void {
@ -148,15 +148,12 @@ export class RulesScreenComponent extends ComponentHasChanges implements OnInit
private async _initialize() {
this._loadingService.start();
await this._rulesService
.download(this._dossierTemplatesService.activeDossierTemplateId)
.toPromise()
.then(
rules => {
this.currentLines = this.initialLines = rules.rules.split('\n');
this.revert();
},
() => this._loadingService.stop(),
);
await firstValueFrom(this._rulesService.download(this._dossierTemplatesService.activeDossierTemplateId)).then(
rules => {
this.currentLines = this.initialLines = rules.rules.split('\n');
this.revert();
},
() => this._loadingService.stop(),
);
}
}

View File

@ -14,7 +14,7 @@ import {
NestedFilter,
TableColumnConfig,
} from '@iqser/common-ui';
import { Observable } from 'rxjs';
import { firstValueFrom, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { rolesTranslations } from '../../../../translations/roles-translations';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@ -96,7 +96,7 @@ export class UserListingScreenComponent extends ListingComponent<User> implement
async toggleActive(user: User) {
this._loadingService.start();
const requestBody = { ...user, roles: user.isActive ? [] : ['RED_USER'] };
await this.userService.updateProfile(requestBody, user.id).toPromise();
await firstValueFrom(this.userService.updateProfile(requestBody, user.id));
await this._loadData();
}
@ -105,7 +105,7 @@ export class UserListingScreenComponent extends ListingComponent<User> implement
}
private async _loadData() {
await this.userService.loadAll().toPromise();
await firstValueFrom(this.userService.loadAll());
this._computeStats();
this._loadingService.stop();
}

View File

@ -11,6 +11,7 @@ import { stampPDFPage } from '@utils/page-stamper';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { WatermarkService } from '@shared/services/watermark.service';
import { firstValueFrom } from 'rxjs';
export const DEFAULT_WATERMARK: IWatermark = {
text: null,
@ -80,7 +81,7 @@ export class WatermarkScreenComponent implements OnInit {
? this._watermarkService.saveWatermark(watermark, dossierTemplateId)
: this._watermarkService.deleteWatermark(dossierTemplateId);
observable.toPromise().then(
firstValueFrom(observable).then(
() => {
this._loadWatermark();
this._toaster.success(

View File

@ -7,6 +7,7 @@ import { UserService } from '@services/user.service';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
import { HttpStatusCode } from '@angular/common/http';
import { firstValueFrom } from 'rxjs';
@Component({
selector: 'redaction-dossier-template-actions',
@ -45,11 +46,9 @@ export class DossierTemplateActionsComponent implements OnInit {
this._dialogService.openDialog('confirm', $event, null, async () => {
this._loadingService.start();
await this._dossierTemplatesService
.delete([this.dossierTemplateId])
.toPromise()
await firstValueFrom(this._dossierTemplatesService.delete([this.dossierTemplateId]))
.then(async () => {
await this._dossierTemplatesService.loadAll().toPromise();
await firstValueFrom(this._dossierTemplatesService.loadAll());
await this._appStateService.loadDictionaryData();
await this._router.navigate(['main', 'admin']);
})

View File

@ -5,6 +5,7 @@ import { HttpClientModule } from '@angular/common/http';
import { KeycloakAngularModule, KeycloakOptions, KeycloakService } from 'keycloak-angular';
import { ConfigService } from '@services/config.service';
import { BASE_HREF } from '../../tokens';
import { firstValueFrom } from 'rxjs';
function getKeycloakOptions(configService: ConfigService, baseUrl: string) {
let url: string = configService.values.OAUTH_URL;
@ -36,14 +37,11 @@ function configureAutomaticRedirectToLoginScreen(keyCloakService: KeycloakServic
export function keycloakInitializer(keycloakService: KeycloakService, configService: ConfigService, baseUrl: string): () => Promise<void> {
return () =>
configService
.loadAppConfig()
.toPromise()
.then(() =>
keycloakService
.init(getKeycloakOptions(configService, baseUrl))
.then(() => configureAutomaticRedirectToLoginScreen(keycloakService)),
);
firstValueFrom(configService.loadAppConfig()).then(() =>
keycloakService
.init(getKeycloakOptions(configService, baseUrl))
.then(() => configureAutomaticRedirectToLoginScreen(keycloakService)),
);
}
@NgModule({