@@ -94,6 +94,7 @@ import { LoadProfileComponent, LoadProfileConfig } from './load-profile/load-pro
9494import { Profile } from '../../models/profile' ;
9595import { ArchivalProfileUnit } from '../../models/archival-profile-unit' ;
9696import { NoticeService } from '../../core/services/notice.service' ;
97+ import { map } from 'rxjs/operators' ;
9798
9899const POPUP_CREATION_PATH = 'PROFILE.POP_UP_CREATION' ;
99100const POPUP_UPLOAD_PATH = 'PROFILE.POP_UP_UPLOAD_FILE' ;
@@ -355,7 +356,7 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
355356 filter ( ( confirmed ) => confirmed ) ,
356357 switchMap ( ( ) =>
357358 this . dialog
358- . open < LoadProfileComponent , LoadProfileConfig > ( LoadProfileComponent , {
359+ . open < LoadProfileComponent , LoadProfileConfig , File [ ] > ( LoadProfileComponent , {
359360 data : {
360361 title : this . translations . popupUploadTitle ,
361362 subTitle : this . translations . popupUploadSubTitle ,
@@ -367,39 +368,38 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
367368 } )
368369 . afterClosed ( ) ,
369370 ) ,
371+ filter ( ( files ) => Boolean ( files ?. length ) ) ,
372+ map ( ( files ) => files . at ( 0 ) ) ,
370373 )
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 . snackBarService . open ( {
380- message : 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION' ,
381- duration : 5000 ,
382- } ) ,
383- ) ;
384- }
385- if ( profileDescription . type === ProfileType . PUA && fileToUpload ) {
386- const fileReader = new FileReader ( ) ;
387- fileReader . readAsText ( fileToUpload , 'UTF-8' ) ;
388- fileReader . onload = ( ) => {
389- const jsonObj : ProfileDescription = JSON . parse ( fileReader . result . toString ( ) ) ;
390- if ( jsonObj . sedaVersion !== profileDescription . sedaVersion ) {
391- this . snackBarService . open ( {
392- message : 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION' ,
393- duration : 5000 ,
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- }
374+ . subscribe ( ( fileToUpload ) => {
375+ if ( profileDescription . type === ProfileType . PA ) {
376+ const profile : Profile = this . noticeService . profileDescriptionToPaProfile ( profileDescription ) ;
377+ this . profileService . updateProfileFilePa ( profile , fileToUpload ) . subscribe ( {
378+ next : ( ) => this . refreshListProfiles ( ) ,
379+ error : ( ) =>
380+ this . snackBarService . open ( {
381+ message : 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION' ,
382+ duration : 5000 ,
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 . snackBarService . open ( {
393+ message : 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION' ,
394+ duration : 5000 ,
395+ } ) ;
396+ } else {
397+ profileDescription . controlSchema = jsonObj . controlSchema ;
398+ const archivalProfileUnit : ArchivalProfileUnit = this . noticeService . profileDescriptionToPuaProfile ( profileDescription ) ;
399+ this . profileService . updateProfilePua ( archivalProfileUnit ) . subscribe ( ( ) => this . refreshListProfiles ( ) ) ;
400+ }
401+ } ;
402+ fileReader . onerror = ( error ) => console . error ( error ) ;
403403 }
404404 } ) ;
405405 }
0 commit comments