Skip to content

Commit 7927e83

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

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';
@@ -94,8 +94,8 @@ 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 { MatDialogConfig } from '@angular/material/dialog';
9897
import { NotificationService } from '../../core/services/notification.service';
98+
import { map } from 'rxjs/operators';
9999

100100
const POPUP_CREATION_PATH = 'PROFILE.POP_UP_CREATION';
101101
const POPUP_UPLOAD_PATH = 'PROFILE.POP_UP_UPLOAD_FILE';
@@ -357,7 +357,7 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
357357
filter((confirmed) => confirmed),
358358
switchMap(() =>
359359
this.dialog
360-
.open<LoadProfileComponent, LoadProfileConfig>(LoadProfileComponent, {
360+
.open<LoadProfileComponent, LoadProfileConfig, File[]>(LoadProfileComponent, {
361361
data: {
362362
title: this.translations.popupUploadTitle,
363363
subTitle: this.translations.popupUploadSubTitle,
@@ -369,37 +369,36 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
369369
})
370370
.afterClosed(),
371371
),
372+
filter((files) => Boolean(files?.length)),
373+
map((files) => files.at(0)),
372374
)
373-
.subscribe((files) => {
374-
if (files) {
375-
const fileToUpload: File = files[0];
376-
if (profileDescription.type === ProfileType.PA) {
377-
const profile: Profile = this.noticeService.profileDescriptionToPaProfile(profileDescription);
378-
this.profileService.updateProfileFilePa(profile, fileToUpload).subscribe(
379-
() => this.refreshListProfiles(),
380-
() =>
381-
this.notificationService.showError(
382-
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
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.notificationService.showError(
393-
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
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-
}
375+
.subscribe((fileToUpload) => {
376+
if (profileDescription.type === ProfileType.PA) {
377+
const profile: Profile = this.noticeService.profileDescriptionToPaProfile(profileDescription);
378+
this.profileService.updateProfileFilePa(profile, fileToUpload).subscribe({
379+
next: () => this.refreshListProfiles(),
380+
error: () =>
381+
this.notificationService.showError(
382+
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
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.notificationService.showError(
393+
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
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);
403402
}
404403
});
405404
}
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)