@@ -93,6 +93,7 @@ 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 { map } from 'rxjs/operators' ;
9697
9798const POPUP_CREATION_PATH = 'PROFILE.POP_UP_CREATION' ;
9899const POPUP_UPLOAD_PATH = 'PROFILE.POP_UP_UPLOAD_FILE' ;
@@ -353,7 +354,7 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
353354 filter ( ( confirmed ) => confirmed ) ,
354355 switchMap ( ( ) =>
355356 this . dialog
356- . open < LoadProfileComponent , LoadProfileConfig > ( LoadProfileComponent , {
357+ . open < LoadProfileComponent , LoadProfileConfig , File [ ] > ( LoadProfileComponent , {
357358 data : {
358359 title : this . translations . popupUploadTitle ,
359360 subTitle : this . translations . popupUploadSubTitle ,
@@ -365,39 +366,38 @@ export class ListProfileComponent extends SidenavPage<ProfileDescription> implem
365366 } )
366367 . afterClosed ( ) ,
367368 ) ,
369+ filter ( ( files ) => Boolean ( files ?. length ) ) ,
370+ map ( ( files ) => files . at ( 0 ) ) ,
368371 )
369- . subscribe ( ( files ) => {
370- if ( files ) {
371- const fileToUpload : File = files [ 0 ] ;
372- if ( profileDescription . type === ProfileType . PA ) {
373- const profile : Profile = this . noticeService . profileDescriptionToPaProfile ( profileDescription ) ;
374- this . profileService . updateProfileFilePa ( profile , fileToUpload ) . subscribe (
375- ( ) => this . refreshListProfiles ( ) ,
376- ( ) =>
377- this . snackBarService . open ( {
378- message : 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION' ,
379- duration : 5000 ,
380- } ) ,
381- ) ;
382- }
383- if ( profileDescription . type === ProfileType . PUA && fileToUpload ) {
384- const fileReader = new FileReader ( ) ;
385- fileReader . readAsText ( fileToUpload , 'UTF-8' ) ;
386- fileReader . onload = ( ) => {
387- const jsonObj : ProfileDescription = JSON . parse ( fileReader . result . toString ( ) ) ;
388- if ( jsonObj . sedaVersion !== profileDescription . sedaVersion ) {
389- this . snackBarService . open ( {
390- message : 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION' ,
391- duration : 5000 ,
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- }
372+ . subscribe ( ( fileToUpload ) => {
373+ if ( profileDescription . type === ProfileType . PA ) {
374+ const profile : Profile = this . noticeService . profileDescriptionToPaProfile ( profileDescription ) ;
375+ this . profileService . updateProfileFilePa ( profile , fileToUpload ) . subscribe ( {
376+ next : ( ) => this . refreshListProfiles ( ) ,
377+ error : ( ) =>
378+ this . snackBarService . open ( {
379+ message : 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION' ,
380+ duration : 5000 ,
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 . snackBarService . open ( {
391+ message : 'PROFILE.LIST_PROFILE.PROFILE_PREVIEW.MODIFICATION_ERROR_SEDA_VERSION' ,
392+ duration : 5000 ,
393+ } ) ;
394+ } else {
395+ profileDescription . controlSchema = jsonObj . controlSchema ;
396+ const archivalProfileUnit : ArchivalProfileUnit = this . noticeService . profileDescriptionToPuaProfile ( profileDescription ) ;
397+ this . profileService . updateProfilePua ( archivalProfileUnit ) . subscribe ( ( ) => this . refreshListProfiles ( ) ) ;
398+ }
399+ } ;
400+ fileReader . onerror = ( error ) => console . error ( error ) ;
401401 }
402402 } ) ;
403403 }
0 commit comments