Skip to content

Commit 336243b

Browse files
committed
bugs #15437 (fix): the confirmation button stays disabled when the notice is updated via a file
1 parent c547180 commit 336243b

File tree

3 files changed

+47
-36
lines changed

3 files changed

+47
-36
lines changed

ui/ui-frontend/projects/pastis/src/app/profile/list-profile/list-profile.component.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import { LoadProfileComponent, LoadProfileConfig } from './load-profile/load-pro
9494
import { Profile } from '../../models/profile';
9595
import { ArchivalProfileUnit } from '../../models/archival-profile-unit';
9696
import { NoticeService } from '../../core/services/notice.service';
97+
import { map } from 'rxjs/operators';
9798

9899
const POPUP_CREATION_PATH = 'PROFILE.POP_UP_CREATION';
99100
const POPUP_UPLOAD_PATH = 'PROFILE.POP_UP_UPLOAD_FILE';
@@ -355,7 +356,7 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
355356
filter((confirmed) => confirmed),
356357
switchMap(() =>
357358
this.dialog
358-
.open<LoadProfileComponent, LoadProfileConfig>(LoadProfileComponent, {
359+
.open<LoadProfileComponent, LoadProfileConfig, File[]>(LoadProfileComponent, {
359360
data: {
360361
title: this.translations.popupUploadTitle,
361362
subTitle: this.translations.popupUploadSubTitle,
@@ -367,39 +368,38 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
367368
})
368369
.afterClosed(),
369370
),
371+
filter((files) => Boolean(files?.length)),
372+
map((files) => files.at(0)),
370373
)
371-
.subscribe((files) => {
372-
if (files) {
373-
const fileToUpload: File = files[0];
374-
if (profileDescription.type === ProfileType.PA) {
375-
const profile: Profile = this.noticeService.profileDescriptionToPaProfile(profileDescription);
376-
this.profileService.updateProfileFilePa(profile, fileToUpload).subscribe(
377-
() => this.refreshListProfiles(),
378-
() =>
379-
this.snackBarService.open({
380-
message: 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION',
381-
duration: 5000,
382-
}),
383-
);
384-
}
385-
if (profileDescription.type === ProfileType.PUA && fileToUpload) {
386-
const fileReader = new FileReader();
387-
fileReader.readAsText(fileToUpload, 'UTF-8');
388-
fileReader.onload = () => {
389-
const jsonObj: ProfileDescription = JSON.parse(fileReader.result.toString());
390-
if (jsonObj.sedaVersion !== profileDescription.sedaVersion) {
391-
this.snackBarService.open({
392-
message: 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION',
393-
duration: 5000,
394-
});
395-
} else {
396-
profileDescription.controlSchema = jsonObj.controlSchema;
397-
const archivalProfileUnit: ArchivalProfileUnit = this.noticeService.profileDescriptionToPuaProfile(profileDescription);
398-
this.profileService.updateProfilePua(archivalProfileUnit).subscribe(() => this.refreshListProfiles());
399-
}
400-
};
401-
fileReader.onerror = (error) => console.error(error);
402-
}
374+
.subscribe((fileToUpload) => {
375+
if (profileDescription.type === ProfileType.PA) {
376+
const profile: Profile = this.noticeService.profileDescriptionToPaProfile(profileDescription);
377+
this.profileService.updateProfileFilePa(profile, fileToUpload).subscribe({
378+
next: () => this.refreshListProfiles(),
379+
error: () =>
380+
this.snackBarService.open({
381+
message: 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION',
382+
duration: 5000,
383+
}),
384+
});
385+
}
386+
if (profileDescription.type === ProfileType.PUA && fileToUpload) {
387+
const fileReader = new FileReader();
388+
fileReader.readAsText(fileToUpload, 'UTF-8');
389+
fileReader.onload = () => {
390+
const jsonObj: ProfileDescription = JSON.parse(fileReader.result.toString());
391+
if (jsonObj.sedaVersion !== profileDescription.sedaVersion) {
392+
this.snackBarService.open({
393+
message: 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION',
394+
duration: 5000,
395+
});
396+
} else {
397+
profileDescription.controlSchema = jsonObj.controlSchema;
398+
const archivalProfileUnit: ArchivalProfileUnit = this.noticeService.profileDescriptionToPuaProfile(profileDescription);
399+
this.profileService.updateProfilePua(archivalProfileUnit).subscribe(() => this.refreshListProfiles());
400+
}
401+
};
402+
fileReader.onerror = (error) => console.error(error);
403403
}
404404
});
405405
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<vitamui-dialog-header [subhead]="config.title" [title]="config.subTitle"></vitamui-dialog-header>
22

33
<mat-dialog-content>
4-
<vitamui-file-selector #fs class="d-flex" [extensions]="config.extensions" [multiple]="config.multipleFiles"> </vitamui-file-selector>
4+
<vitamui-file-selector class="d-flex" [formControl]="files" [extensions]="config.extensions" [multiple]="config.multipleFiles">
5+
</vitamui-file-selector>
56
</mat-dialog-content>
67

78
<mat-dialog-actions>
8-
<button type="button" class="btn primary" [disabled]="!fs.files?.length" [matDialogClose]="fs.files">{{ config.okLabel }}</button>
9+
<button type="button" class="btn primary" [disabled]="isEmpty$ | async" [matDialogClose]="files.value">{{ config.okLabel }}</button>
910
<button type="button" class="btn cancel link" matDialogClose>{{ config.cancelLabel }}</button>
1011
</mat-dialog-actions>

ui/ui-frontend/projects/pastis/src/app/profile/list-profile/load-profile/load-profile.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
import { Component, Inject } from '@angular/core';
3838
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
3939
import { FileSelectorComponent, PipesModule, VitamUILibraryModule } from 'vitamui-library';
40+
import { FormControl, ReactiveFormsModule } from '@angular/forms';
41+
import { map, startWith, switchMap } from 'rxjs/operators';
42+
import { AsyncPipe } from '@angular/common';
43+
import { BehaviorSubject } from 'rxjs';
4044

4145
export interface LoadProfileConfig {
4246
title: string;
@@ -54,9 +58,15 @@ export interface LoadProfileConfig {
5458
selector: 'app-load-profile',
5559
templateUrl: './load-profile.component.html',
5660
styleUrl: './load-profile.component.scss',
57-
imports: [FileSelectorComponent, PipesModule, MatDialogModule, VitamUILibraryModule],
61+
imports: [FileSelectorComponent, PipesModule, MatDialogModule, VitamUILibraryModule, AsyncPipe, ReactiveFormsModule],
5862
})
5963
export class LoadProfileComponent {
64+
protected files = new FormControl([]);
65+
protected isEmpty$ = new BehaviorSubject(true).pipe(
66+
switchMap(() => this.files.valueChanges.pipe(startWith(this.files.value))),
67+
map((files: File[] | FileList) => files?.length === 0),
68+
);
69+
6070
constructor(
6171
@Inject(MAT_DIALOG_DATA)
6272
public config: LoadProfileConfig,

0 commit comments

Comments
 (0)