@@ -72,7 +72,7 @@ The fact that you are presently reading this means that you have had
7272knowledge of the CeCILL-C license and that you accept its terms.
7373*/
7474import { Component , OnDestroy , OnInit , TemplateRef , ViewChild } from '@angular/core' ;
75- import { MatDialog } from '@angular/material/dialog' ;
75+ import { MatDialog , MatDialogConfig } from '@angular/material/dialog' ;
7676import { MatTableDataSource } from '@angular/material/table' ;
7777import { ActivatedRoute , Router } from '@angular/router' ;
7878import { TranslateService } from '@ngx-translate/core' ;
@@ -93,8 +93,8 @@ import { LoadProfileComponent, LoadProfileConfig } from './load-profile/load-pro
9393import { Profile } from '../../models/profile' ;
9494import { ArchivalProfileUnit } from '../../models/archival-profile-unit' ;
9595import { NoticeService } from '../../core/services/notice.service' ;
96- import { MatDialogConfig } from '@angular/material/dialog' ;
9796import { NotificationService } from '../../core/services/notification.service' ;
97+ import { map } from 'rxjs/operators' ;
9898
9999const POPUP_CREATION_PATH = 'PROFILE.POP_UP_CREATION' ;
100100const 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 }
0 commit comments