Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
*/
import { Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog';
import { MatLegacyDialog as MatDialog, MatLegacyDialogConfig as MatDialogConfig } from '@angular/material/legacy-dialog';
import { MatLegacyTableDataSource as MatTableDataSource } from '@angular/material/legacy-table';
import { ActivatedRoute, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
Expand All @@ -94,8 +94,8 @@ import { LoadProfileComponent, LoadProfileConfig } from './load-profile/load-pro
import { Profile } from '../../models/profile';
import { ArchivalProfileUnit } from '../../models/archival-profile-unit';
import { NoticeService } from '../../core/services/notice.service';
import { MatDialogConfig } from '@angular/material/dialog';
import { NotificationService } from '../../core/services/notification.service';
import { map } from 'rxjs/operators';

const POPUP_CREATION_PATH = 'PROFILE.POP_UP_CREATION';
const POPUP_UPLOAD_PATH = 'PROFILE.POP_UP_UPLOAD_FILE';
Expand Down Expand Up @@ -356,7 +356,7 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
filter((confirmed) => confirmed),
switchMap(() =>
this.dialog
.open<LoadProfileComponent, LoadProfileConfig>(LoadProfileComponent, {
.open<LoadProfileComponent, LoadProfileConfig, File[]>(LoadProfileComponent, {
panelClass: 'vitamui-modal',
data: {
title: this.translations.popupUploadTitle,
Expand All @@ -369,37 +369,36 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
})
.afterClosed(),
),
filter((files) => Boolean(files?.length)),
map((files) => files.at(0)),
)
.subscribe((files) => {
if (files) {
const fileToUpload: File = files[0];
if (profileDescription.type === ProfileType.PA) {
const profile: Profile = this.noticeService.profileDescriptionToPaProfile(profileDescription);
this.profileService.updateProfileFilePa(profile, fileToUpload).subscribe(
() => this.refreshListProfiles(),
() =>
this.notificationService.showError(
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
),
);
}
if (profileDescription.type === ProfileType.PUA && fileToUpload) {
const fileReader = new FileReader();
fileReader.readAsText(fileToUpload, 'UTF-8');
fileReader.onload = () => {
const jsonObj: ProfileDescription = JSON.parse(fileReader.result.toString());
if (jsonObj.sedaVersion !== profileDescription.sedaVersion) {
this.notificationService.showError(
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
);
} else {
profileDescription.controlSchema = jsonObj.controlSchema;
const archivalProfileUnit: ArchivalProfileUnit = this.noticeService.profileDescriptionToPuaProfile(profileDescription);
this.profileService.updateProfilePua(archivalProfileUnit).subscribe(() => this.refreshListProfiles());
}
};
fileReader.onerror = (error) => console.error(error);
}
.subscribe((fileToUpload) => {
if (profileDescription.type === ProfileType.PA) {
const profile: Profile = this.noticeService.profileDescriptionToPaProfile(profileDescription);
this.profileService.updateProfileFilePa(profile, fileToUpload).subscribe({
next: () => this.refreshListProfiles(),
error: () =>
this.notificationService.showError(
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
),
});
}
if (profileDescription.type === ProfileType.PUA && fileToUpload) {
const fileReader = new FileReader();
fileReader.readAsText(fileToUpload, 'UTF-8');
fileReader.onload = () => {
const jsonObj: ProfileDescription = JSON.parse(fileReader.result.toString());
if (jsonObj.sedaVersion !== profileDescription.sedaVersion) {
this.notificationService.showError(
this.translateService.instant('PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION'),
);
} else {
profileDescription.controlSchema = jsonObj.controlSchema;
const archivalProfileUnit: ArchivalProfileUnit = this.noticeService.profileDescriptionToPuaProfile(profileDescription);
this.profileService.updateProfilePua(archivalProfileUnit).subscribe(() => this.refreshListProfiles());
}
};
fileReader.onerror = (error) => console.error(error);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<p class="subtitle text large bold">{{ config.subTitle }}</p>
</div>
</div>
<vitamui-file-selector #fs class="d-flex" [extensions]="config.extensions" [multiple]="config.multipleFiles"> </vitamui-file-selector>
<vitamui-file-selector class="d-flex" [formControl]="files" [extensions]="config.extensions" [multiple]="config.multipleFiles">
</vitamui-file-selector>
<div class="actions">
<button type="button" class="btn primary" [disabled]="!fs.files?.length" [matDialogClose]="fs.files">{{ config.okLabel }}</button>
<button type="button" class="btn primary" [disabled]="isEmpty$ | async" [matDialogClose]="files.value">{{ config.okLabel }}</button>
<button type="button" class="btn cancel link" matDialogClose>{{ config.cancelLabel }}</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import { Component, Inject } from '@angular/core';
import { MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA, MatLegacyDialogModule } from '@angular/material/legacy-dialog';
import { FileSelectorComponent, PipesModule } from 'vitamui-library';
import { AsyncPipe, NgForOf, NgIf } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA, MatLegacyDialogModule as MatDialogModule } from '@angular/material/legacy-dialog';
import { FileSelectorComponent, PipesModule, VitamUILibraryModule } from 'vitamui-library';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { map, startWith, switchMap } from 'rxjs/operators';
import { AsyncPipe } from '@angular/common';
import { BehaviorSubject } from 'rxjs';

export interface LoadProfileConfig {
title: string;
Expand All @@ -56,10 +58,16 @@ export interface LoadProfileConfig {
selector: 'vitamui-load-profile',
templateUrl: './load-profile.component.html',
styleUrl: './load-profile.component.scss',
imports: [FileSelectorComponent, PipesModule, MatDialogModule, VitamUILibraryModule, AsyncPipe, ReactiveFormsModule],
standalone: true,
imports: [FileSelectorComponent, NgIf, TranslateModule, NgForOf, PipesModule, MatLegacyDialogModule, AsyncPipe],
})
export class LoadProfileComponent {
protected files = new FormControl([]);
protected isEmpty$ = new BehaviorSubject(true).pipe(
switchMap(() => this.files.valueChanges.pipe(startWith(this.files.value))),
map((files: File[] | FileList) => files?.length === 0),
);

constructor(
@Inject(MAT_DIALOG_DATA)
public config: LoadProfileConfig,
Expand Down