diff --git a/src/app/map-location/map-location-edit/map-location-edit.component.html b/src/app/map-location/map-location-edit/map-location-edit.component.html index eb7773b..ca0f498 100644 --- a/src/app/map-location/map-location-edit/map-location-edit.component.html +++ b/src/app/map-location/map-location-edit/map-location-edit.component.html @@ -85,6 +85,14 @@

Audio Files

+
+

Loading audio files, please wait...

+
+ +
+

Error loading audio files. Please try again later.

+
+
diff --git a/src/app/map-location/map-location-edit/map-location-edit.component.ts b/src/app/map-location/map-location-edit/map-location-edit.component.ts index 413ef64..8542b62 100644 --- a/src/app/map-location/map-location-edit/map-location-edit.component.ts +++ b/src/app/map-location/map-location-edit/map-location-edit.component.ts @@ -46,6 +46,8 @@ export class MapLocationEditComponent implements OnInit, CanComponentDeactivate selectedAudioFile: File | null = null; temporaryAudioData: { audio: Audio, url: SafeUrl,file: File }[] = []; returnUrl: string | null = null; + isLoadingAudio = false; + isErrorAudio = false; private submittingChangesInProcess: boolean = false; constructor(private activatedRoute: ActivatedRoute, @@ -309,8 +311,9 @@ export class MapLocationEditComponent implements OnInit, CanComponentDeactivate }); } - private fetchMapLocationAudio() { - + fetchMapLocationAudio() { + this.isLoadingAudio = true; + this.isErrorAudio = false; this.mapLocationService.getMapLocationsById(this.mapLocationId).subscribe(response => { this.mapLocation = response; @@ -338,7 +341,11 @@ export class MapLocationEditComponent implements OnInit, CanComponentDeactivate }); Promise.all(audioPromises).then(() => { + this.isLoadingAudio = false; }); + }, error => { + this.isErrorAudio = true; + this.isLoadingAudio = false; }); }); } diff --git a/src/app/map-location/map-location-list/map-location-list.component.html b/src/app/map-location/map-location-list/map-location-list.component.html index bd2302a..62f7eec 100644 --- a/src/app/map-location/map-location-list/map-location-list.component.html +++ b/src/app/map-location/map-location-list/map-location-list.component.html @@ -1,4 +1,13 @@
    + +
    +

    Loading map locations, please wait...

    +
    + +
    +

    Error loading map locations. Please try again later.

    +
    +
  • { - this.mapLocations = response.content; - this.mapService.routeSelectedEventEmitter.emit(this.mapLocations); - }); + .subscribe( + response => { + this.mapLocations = response.content; + this.mapService.routeSelectedEventEmitter.emit(this.mapLocations); + this.isLoading = false; + }, + error => { + this.isError = true; + this.isLoading = false; + console.error('Error fetching map locations:', error); + } + ); } } diff --git a/src/app/map-location/map-location-modal/map-location-modal.component.html b/src/app/map-location/map-location-modal/map-location-modal.component.html index cb20164..db61bcf 100644 --- a/src/app/map-location/map-location-modal/map-location-modal.component.html +++ b/src/app/map-location/map-location-modal/map-location-modal.component.html @@ -11,6 +11,12 @@
    {{mapLocation.name}}
    Navigate
    • +
      +

      Loading audio files, please wait...

      +
      +
      +

      Error loading audio files. Please try again later.

      +
    • diff --git a/src/app/map-location/map-location-modal/map-location-modal.component.ts b/src/app/map-location/map-location-modal/map-location-modal.component.ts index 40f554e..83c50ef 100644 --- a/src/app/map-location/map-location-modal/map-location-modal.component.ts +++ b/src/app/map-location/map-location-modal/map-location-modal.component.ts @@ -29,6 +29,8 @@ export class MapLocationModalComponent implements OnInit { audiosEntities: Audio[] = []; audioData: { audio: Audio, url: SafeUrl }[] = []; mobileVersion: boolean; + isError: boolean; + isLoading: boolean; constructor( private mapLocationService: MapLocationService, @@ -50,49 +52,56 @@ export class MapLocationModalComponent implements OnInit { } } - //fetch images for map locations + private fetchMapLocationImage() { this.mapLocationService.getMapLocationImageById(this.mapLocation.id).subscribe({ next: (response: Blob | null) => { if (response) { - //convert Blob (raw byte object) to url to display it in the template const objectURL = URL.createObjectURL(response); this.mapLocationImageUrl = this.sanitizer.bypassSecurityTrustUrl(objectURL); - } - }, + }}, error: (error: any) => { - // } }); } private fetchMapLocationAudio() { + this.isLoading= true; + this.isError = false; this.audiosEntities = []; this.audioData = []; - - this.audioService.getAudiosByMapLocation(this.mapLocation, 0, maxPageSize).subscribe(response => { - this.audiosEntities = response.content; - - const audioPromises = this.audiosEntities.map((audio, index) => { - return this.audioService.getAudioFileByAudio(audio).toPromise() - .then(response => { - let audioUrl: SafeUrl = null; - if (response) { - const objectURL = URL.createObjectURL(response); - audioUrl = this.sanitizer.bypassSecurityTrustUrl(objectURL); - } - this.audioData[index] = {audio: audio, url: audioUrl}; - }) - .catch(error => { - console.log("getaudio error", error); - this.audioData[index] = {audio: audio, url: null}; - }); - }); - - Promise.all(audioPromises).then(() => { - // All audio files fetched and URLs are set - }); + this.audioService.getAudiosByMapLocation(this.mapLocation, 0, maxPageSize).subscribe({ + next: (response) => { + this.audiosEntities = response.content; + + const audioPromises = this.audiosEntities.map((audio, index) => { + return this.audioService.getAudioFileByAudio(audio).toPromise() + .then((audioBlob) => { + let audioUrl: SafeUrl = null; + if (audioBlob) { + const objectURL = URL.createObjectURL(audioBlob); + audioUrl = this.sanitizer.bypassSecurityTrustUrl(objectURL); + } + this.audioData[index] = {audio, url: audioUrl}; + }) + .catch(error => { + console.error("Error fetching audio:", error); + this.audioData[index] = {audio, url: null}; + }); + }); + Promise.all(audioPromises).then(() => { + this.isLoading = false; + }).catch(() => { + this.isError = true; + this.isLoading = false; + }); + }, + error: (error) => { + console.error('Error fetching audio:', error); + this.isError = true; + this.isLoading= false; + } }); } diff --git a/src/app/route/route-list/route-list.component.html b/src/app/route/route-list/route-list.component.html index b332404..17dd4a3 100644 --- a/src/app/route/route-list/route-list.component.html +++ b/src/app/route/route-list/route-list.component.html @@ -26,6 +26,15 @@
      +
      +

      Loading routes, please wait...

      +
      + +
      +

      Error loading routes. Please try again later.

      +
      + +
      diff --git a/src/app/route/route-list/route-list.component.ts b/src/app/route/route-list/route-list.component.ts index deabe74..9a60c20 100644 --- a/src/app/route/route-list/route-list.component.ts +++ b/src/app/route/route-list/route-list.component.ts @@ -49,6 +49,8 @@ export class RouteListComponent implements OnInit{ @Input() addingPointToRoute: boolean = false; @Input() pointIdToBeAdded: string; + protected isLoading: boolean; + protected isError: boolean; constructor(private routeService: RouteService, private router: Router, @@ -154,28 +156,48 @@ export class RouteListComponent implements OnInit{ } getRoutes() { + this.isLoading = true; + this.isError = false; + this.validateQueryParams(); + if (this.userMode || this.addingPointToRoute) { - this.routeService.getRouteByUserId(this.currentPageNumber, this.pageSize, this.routeNameToSearch).subscribe(response => { - this.routes = response.content; - this.totalPages = response.totalPages; - if (this.currentPageNumber > this.totalPages) { - this.currentPageNumber = this.totalPages; - this.onPageChanged(); - } - }); + this.routeService.getRouteByUserId(this.currentPageNumber, this.pageSize, this.routeNameToSearch) + .subscribe( + response => { + this.routes = response.content; + this.totalPages = response.totalPages; + if (this.currentPageNumber > this.totalPages) { + this.currentPageNumber = this.totalPages; + this.onPageChanged(); + } + this.isLoading = false; + }, + error => { + this.isError = true; + this.isLoading = false; + console.error('Error fetching user routes:', error); + } + ); } else { - this.routeService.getRoutes(this.currentPageNumber, this.pageSize, this.routeNameToSearch).subscribe(response => { - this.routes = response.content; - this.totalPages = response.totalPages; - if (this.currentPageNumber > this.totalPages) { - this.currentPageNumber = this.totalPages; - this.onPageChanged(); - - } - }); + this.routeService.getRoutes(this.currentPageNumber, this.pageSize, this.routeNameToSearch) + .subscribe( + response => { + this.routes = response.content; + this.totalPages = response.totalPages; + if (this.currentPageNumber > this.totalPages) { + this.currentPageNumber = this.totalPages; + this.onPageChanged(); + } + this.isLoading = false; + }, + error => { + this.isError = true; + this.isLoading = false; + console.error('Error fetching routes:', error); + } + ); } - } validateQueryParams() {