Skip to content

Commit 2c4df3a

Browse files
authored
Merge pull request #3397 from ProgrammeVitam/cp_9.0__bugs_15437
CP V9.0 - bugs #15437 (fix): the confirmation button stays disabled when the notice is updated via a file
2 parents 69dfe39 + 336243b commit 2c4df3a

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
@@ -93,6 +93,7 @@ import { LoadProfileComponent, LoadProfileConfig } from './load-profile/load-pro
9393
import { Profile } from '../../models/profile';
9494
import { ArchivalProfileUnit } from '../../models/archival-profile-unit';
9595
import { NoticeService } from '../../core/services/notice.service';
96+
import { map } from 'rxjs/operators';
9697

9798
const POPUP_CREATION_PATH = 'PROFILE.POP_UP_CREATION';
9899
const POPUP_UPLOAD_PATH = 'PROFILE.POP_UP_UPLOAD_FILE';
@@ -353,7 +354,7 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
353354
filter((confirmed) => confirmed),
354355
switchMap(() =>
355356
this.dialog
356-
.open<LoadProfileComponent, LoadProfileConfig>(LoadProfileComponent, {
357+
.open<LoadProfileComponent, LoadProfileConfig, File[]>(LoadProfileComponent, {
357358
data: {
358359
title: this.translations.popupUploadTitle,
359360
subTitle: this.translations.popupUploadSubTitle,
@@ -365,39 +366,38 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
365366
})
366367
.afterClosed(),
367368
),
369+
filter((files) => Boolean(files?.length)),
370+
map((files) => files.at(0)),
368371
)
369-
.subscribe((files) => {
370-
if (files) {
371-
const fileToUpload: File = files[0];
372-
if (profileDescription.type === ProfileType.PA) {
373-
const profile: Profile = this.noticeService.profileDescriptionToPaProfile(profileDescription);
374-
this.profileService.updateProfileFilePa(profile, fileToUpload).subscribe(
375-
() => this.refreshListProfiles(),
376-
() =>
377-
this.snackBarService.open({
378-
message: 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION',
379-
duration: 5000,
380-
}),
381-
);
382-
}
383-
if (profileDescription.type === ProfileType.PUA && fileToUpload) {
384-
const fileReader = new FileReader();
385-
fileReader.readAsText(fileToUpload, 'UTF-8');
386-
fileReader.onload = () => {
387-
const jsonObj: ProfileDescription = JSON.parse(fileReader.result.toString());
388-
if (jsonObj.sedaVersion !== profileDescription.sedaVersion) {
389-
this.snackBarService.open({
390-
message: 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION',
391-
duration: 5000,
392-
});
393-
} else {
394-
profileDescription.controlSchema = jsonObj.controlSchema;
395-
const archivalProfileUnit: ArchivalProfileUnit = this.noticeService.profileDescriptionToPuaProfile(profileDescription);
396-
this.profileService.updateProfilePua(archivalProfileUnit).subscribe(() => this.refreshListProfiles());
397-
}
398-
};
399-
fileReader.onerror = (error) => console.error(error);
400-
}
372+
.subscribe((fileToUpload) => {
373+
if (profileDescription.type === ProfileType.PA) {
374+
const profile: Profile = this.noticeService.profileDescriptionToPaProfile(profileDescription);
375+
this.profileService.updateProfileFilePa(profile, fileToUpload).subscribe({
376+
next: () => this.refreshListProfiles(),
377+
error: () =>
378+
this.snackBarService.open({
379+
message: 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION',
380+
duration: 5000,
381+
}),
382+
});
383+
}
384+
if (profileDescription.type === ProfileType.PUA && fileToUpload) {
385+
const fileReader = new FileReader();
386+
fileReader.readAsText(fileToUpload, 'UTF-8');
387+
fileReader.onload = () => {
388+
const jsonObj: ProfileDescription = JSON.parse(fileReader.result.toString());
389+
if (jsonObj.sedaVersion !== profileDescription.sedaVersion) {
390+
this.snackBarService.open({
391+
message: 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION',
392+
duration: 5000,
393+
});
394+
} else {
395+
profileDescription.controlSchema = jsonObj.controlSchema;
396+
const archivalProfileUnit: ArchivalProfileUnit = this.noticeService.profileDescriptionToPuaProfile(profileDescription);
397+
this.profileService.updateProfilePua(archivalProfileUnit).subscribe(() => this.refreshListProfiles());
398+
}
399+
};
400+
fileReader.onerror = (error) => console.error(error);
401401
}
402402
});
403403
}
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)