Skip to content

Commit 4f1f68d

Browse files
authored
Merge pull request #3396 from ProgrammeVitam/cp_8.1__bugs_15437
CP V8.1 - bugs #15437 (fix): the confirmation button stays disabled when the notice is updated via a file
2 parents 2ae2d04 + 7927e83 commit 4f1f68d

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

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

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The fact that you are presently reading this means that you have had
7272
knowledge of the CeCILL-C license and that you accept its terms.
7373
*/
7474
import { Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
75-
import { MatDialog } from '@angular/material/dialog';
75+
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
7676
import { MatTableDataSource } from '@angular/material/table';
7777
import { ActivatedRoute, Router } from '@angular/router';
7878
import { TranslateService } from '@ngx-translate/core';
@@ -93,8 +93,8 @@ 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 { MatDialogConfig } from '@angular/material/dialog';
9796
import { NotificationService } from '../../core/services/notification.service';
97+
import { map } from 'rxjs/operators';
9898

9999
const POPUP_CREATION_PATH = 'PROFILE.POP_UP_CREATION';
100100
const POPUP_UPLOAD_PATH = 'PROFILE.POP_UP_UPLOAD_FILE';
@@ -355,7 +355,7 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
355355
filter((confirmed) => confirmed),
356356
switchMap(() =>
357357
this.dialog
358-
.open<LoadProfileComponent, LoadProfileConfig>(LoadProfileComponent, {
358+
.open<LoadProfileComponent, LoadProfileConfig, File[]>(LoadProfileComponent, {
359359
data: {
360360
title: this.translations.popupUploadTitle,
361361
subTitle: this.translations.popupUploadSubTitle,
@@ -367,37 +367,36 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
367367
})
368368
.afterClosed(),
369369
),
370+
filter((files) => Boolean(files?.length)),
371+
map((files) => files.at(0)),
370372
)
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.notificationService.showError(
380-
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
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.notificationService.showError(
391-
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
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-
}
373+
.subscribe((fileToUpload) => {
374+
if (profileDescription.type === ProfileType.PA) {
375+
const profile: Profile = this.noticeService.profileDescriptionToPaProfile(profileDescription);
376+
this.profileService.updateProfileFilePa(profile, fileToUpload).subscribe({
377+
next: () => this.refreshListProfiles(),
378+
error: () =>
379+
this.notificationService.showError(
380+
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
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.notificationService.showError(
391+
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
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);
401400
}
402401
});
403402
}
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: 'vitamui-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)