@@ -479,32 +479,28 @@ export class ProjectFilesComponent implements OnInit {
479479 this . dataSource . data = [ ...this . projectFiles ] ;
480480
481481 const typeCode = fileToDelete . attachmentContentTypeCode ?. attachmentContentTypeCode ;
482- if ( typeCode === 'MAP' ) {
482+ if ( typeCode === 'MAP' && fileToDelete . sourceObjectUniqueId ) {
483483 // only run boundary deletion logic for MAP files
484- this . projectService . getActivityBoundaries ( this . projectGuid , this . fiscalGuid , this . activityGuid ) . subscribe ( response => {
485- const boundaries = response ?. _embedded ?. activityBoundary ;
486- if ( boundaries && boundaries . length > 0 ) {
487- const latest = boundaries . sort ( ( a : ActivityBoundary , b : ActivityBoundary ) =>
488- new Date ( b . systemStartTimestamp ?? 0 ) . getTime ( ) - new Date ( a . systemStartTimestamp ?? 0 ) . getTime ( )
489- ) [ 0 ] ;
490-
491- const activityBoundaryGuid = latest . activityBoundaryGuid ;
492- this . projectService . deleteActivityBoundary ( this . projectGuid , this . fiscalGuid , this . activityGuid , activityBoundaryGuid ) . subscribe ( {
493- next : ( ) => {
494- this . filesUpdated . emit ( ) ;
495- // Show success message in snackbar
496- this . snackbarService . open ( 'File has been deleted successfully.' , 'Close' , {
497- duration : 5000 ,
498- panelClass : 'snackbar-success' ,
499- } ) ;
500- this . loadActivityAttachments ( ) ;
501- }
502- } )
503-
504- } else {
505- console . log ( 'No boundaries found' ) ;
484+ this . projectService . deleteActivityBoundary ( this . projectGuid , this . fiscalGuid , this . activityGuid , fileToDelete . sourceObjectUniqueId ) . subscribe ( {
485+ next : ( ) => {
486+ this . filesUpdated . emit ( ) ;
487+ // Show success message in snackbar
488+ this . snackbarService . open ( 'File has been deleted successfully.' , 'Close' , {
489+ duration : 5000 ,
490+ panelClass : 'snackbar-success' ,
491+ } ) ;
492+ this . loadActivityAttachments ( ) ;
493+ } ,
494+ error : ( err ) => {
495+ console . error ( 'Failed to delete activity boundary' , err ) ;
496+ this . snackbarService . open ( 'Failed to delete the boundary.' , 'Close' , {
497+ duration : 5000 ,
498+ panelClass : 'snackbar-warning' ,
499+ } ) ;
500+ // Still reload attachments as the file might be gone
501+ this . loadActivityAttachments ( ) ;
506502 }
507- } )
503+ } ) ;
508504 } else {
509505 this . filesUpdated . emit ( ) ;
510506 this . snackbarService . open ( 'File has been deleted successfully.' , 'Close' , {
@@ -531,32 +527,26 @@ export class ProjectFilesComponent implements OnInit {
531527 this . dataSource . data = [ ...this . projectFiles ] ;
532528
533529 const typeCode = fileToDelete . attachmentContentTypeCode ?. attachmentContentTypeCode ;
534- if ( typeCode === 'MAP' ) {
535- this . projectService . getProjectBoundaries ( this . projectGuid ) . subscribe ( response => {
536- const boundaries = response ?. _embedded ?. projectBoundary ;
537-
538- if ( boundaries && boundaries . length > 0 ) {
539- const latest = boundaries . sort ( ( a : ProjectBoundary , b : ProjectBoundary ) =>
540- new Date ( b . systemStartTimestamp ?? 0 ) . getTime ( ) - new Date ( a . systemStartTimestamp ?? 0 ) . getTime ( )
541- ) [ 0 ] ;
542-
543- const boundaryGuid = latest . projectBoundaryGuid ;
544- this . projectService . deleteProjectBoundary ( this . projectGuid , boundaryGuid ) . subscribe ( {
545- next : ( ) => {
546- this . filesUpdated . emit ( ) ;
547- // Show success message in snackbar
548- this . snackbarService . open ( 'File has been deleted successfully.' , 'Close' , {
549- duration : 5000 ,
550- panelClass : 'snackbar-success' ,
551- } ) ;
552- this . loadProjectAttachments ( ) ;
553- }
554- } )
555-
556- } else {
557- console . log ( 'No boundaries found' ) ;
530+ if ( typeCode === 'MAP' && fileToDelete . sourceObjectUniqueId ) {
531+ this . projectService . deleteProjectBoundary ( this . projectGuid , fileToDelete . sourceObjectUniqueId ) . subscribe ( {
532+ next : ( ) => {
533+ this . filesUpdated . emit ( ) ;
534+ // Show success message in snackbar
535+ this . snackbarService . open ( 'File has been deleted successfully.' , 'Close' , {
536+ duration : 5000 ,
537+ panelClass : 'snackbar-success' ,
538+ } ) ;
539+ this . loadProjectAttachments ( ) ;
540+ } ,
541+ error : ( err ) => {
542+ console . error ( 'Failed to delete project boundary' , err ) ;
543+ this . snackbarService . open ( 'Failed to delete the boundary.' , 'Close' , {
544+ duration : 5000 ,
545+ panelClass : 'snackbar-warning' ,
546+ } ) ;
547+ this . loadProjectAttachments ( ) ;
558548 }
559- } )
549+ } ) ;
560550 } else {
561551 this . filesUpdated . emit ( ) ;
562552 this . snackbarService . open ( 'File has been deleted successfully.' , 'Close' , {
0 commit comments