Skip to content

Commit dba0ce6

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

File tree

3 files changed

+48
-40
lines changed

3 files changed

+48
-40
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 { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog';
75+
import { MatLegacyDialog as MatDialog, MatLegacyDialogConfig as MatDialogConfig } from '@angular/material/legacy-dialog';
7676
import { MatLegacyTableDataSource as MatTableDataSource } from '@angular/material/legacy-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';
@@ -356,7 +356,7 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
356356
filter((confirmed) => confirmed),
357357
switchMap(() =>
358358
this.dialog
359-
.open<LoadProfileComponent, LoadProfileConfig>(LoadProfileComponent, {
359+
.open<LoadProfileComponent, LoadProfileConfig, File[]>(LoadProfileComponent, {
360360
panelClass: 'vitamui-modal',
361361
data: {
362362
title: this.translations.popupUploadTitle,
@@ -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
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
<p class="subtitle text large bold">{{ config.subTitle }}</p>
66
</div>
77
</div>
8-
<vitamui-file-selector #fs class="d-flex" [extensions]="config.extensions" [multiple]="config.multipleFiles"> </vitamui-file-selector>
8+
<vitamui-file-selector class="d-flex" [formControl]="files" [extensions]="config.extensions" [multiple]="config.multipleFiles">
9+
</vitamui-file-selector>
910
<div class="actions">
10-
<button type="button" class="btn primary" [disabled]="!fs.files?.length" [matDialogClose]="fs.files">{{ config.okLabel }}</button>
11+
<button type="button" class="btn primary" [disabled]="isEmpty$ | async" [matDialogClose]="files.value">{{ config.okLabel }}</button>
1112
<button type="button" class="btn cancel link" matDialogClose>{{ config.cancelLabel }}</button>
1213
</div>
1314
</div>

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
* knowledge of the CeCILL-C license and that you accept its terms.
3636
*/
3737
import { Component, Inject } from '@angular/core';
38-
import { MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA, MatLegacyDialogModule } from '@angular/material/legacy-dialog';
39-
import { FileSelectorComponent, PipesModule } from 'vitamui-library';
40-
import { AsyncPipe, NgForOf, NgIf } from '@angular/common';
41-
import { TranslateModule } from '@ngx-translate/core';
38+
import { MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA, MatLegacyDialogModule as MatDialogModule } from '@angular/material/legacy-dialog';
39+
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';
4244

4345
export interface LoadProfileConfig {
4446
title: string;
@@ -56,10 +58,16 @@ export interface LoadProfileConfig {
5658
selector: 'vitamui-load-profile',
5759
templateUrl: './load-profile.component.html',
5860
styleUrl: './load-profile.component.scss',
61+
imports: [FileSelectorComponent, PipesModule, MatDialogModule, VitamUILibraryModule, AsyncPipe, ReactiveFormsModule],
5962
standalone: true,
60-
imports: [FileSelectorComponent, NgIf, TranslateModule, NgForOf, PipesModule, MatLegacyDialogModule, AsyncPipe],
6163
})
6264
export class LoadProfileComponent {
65+
protected files = new FormControl([]);
66+
protected isEmpty$ = new BehaviorSubject(true).pipe(
67+
switchMap(() => this.files.valueChanges.pipe(startWith(this.files.value))),
68+
map((files: File[] | FileList) => files?.length === 0),
69+
);
70+
6371
constructor(
6472
@Inject(MAT_DIALOG_DATA)
6573
public config: LoadProfileConfig,

0 commit comments

Comments
 (0)