@@ -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 { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog' ;
75+ import { MatLegacyDialog as MatDialog , MatLegacyDialogConfig as MatDialogConfig } from '@angular/material/legacy-dialog' ;
7676import { MatLegacyTableDataSource as MatTableDataSource } from '@angular/material/legacy-table' ;
7777import { ActivatedRoute , Router } from '@angular/router' ;
7878import { TranslateService } from '@ngx-translate/core' ;
@@ -94,8 +94,8 @@ 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 { MatDialogConfig } from '@angular/material/dialog' ;
9897import { NotificationService } from '../../core/services/notification.service' ;
98+ import { map } from 'rxjs/operators' ;
9999
100100const POPUP_CREATION_PATH = 'PROFILE.POP_UP_CREATION' ;
101101const 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 }
0 commit comments