diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ce872498..06785c36 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,15 +1,8 @@ -import { - HttpClientModule, - HttpClient, - HTTP_INTERCEPTORS -} from '@angular/common/http'; +import { HttpClientModule, HttpClient } from '@angular/common/http'; import { NgModule, APP_INITIALIZER } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { RouteReuseStrategy } from '@angular/router'; -import { MoreItemResolver } from '@app/resolvers/more-item.resolver'; -import { MoreResolver } from '@app/resolvers/more.resolver'; -import { LoadingInterceptor } from '@app/services/loading/loading.service'; import { IonicModule, IonicRouteStrategy } from '@ionic/angular'; import { registerLocaleData } from '@angular/common'; import localeFr from '@angular/common/locales/fr'; @@ -17,8 +10,6 @@ import localeFr from '@angular/common/locales/fr'; import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; import { TranslateHttpLoader } from '@ngx-translate/http-loader'; -import { TrekContextResolver } from '@app/resolvers/trek.resolver'; -import { TreksContextResolver } from '@app/resolvers/treks.resolver'; import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx'; import { File } from '@ionic-native/file/ngx'; @@ -105,12 +96,7 @@ registerLocaleData(localeFr, 'fr'); Network, FirebaseAnalytics, DeviceOrientation, - MoreResolver, - MoreItemResolver, - TrekContextResolver, - TreksContextResolver, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, - { provide: HTTP_INTERCEPTORS, useClass: LoadingInterceptor, multi: true }, { provide: APP_INITIALIZER, useFactory: diff --git a/src/app/interfaces/interfaces.ts b/src/app/interfaces/interfaces.ts index acb9f81a..77b03811 100644 --- a/src/app/interfaces/interfaces.ts +++ b/src/app/interfaces/interfaces.ts @@ -271,26 +271,3 @@ export interface TreksService { getMapConfigForTrekById(trek: Trek, isOffline: boolean): MapboxOptions; getCommonImgSrc(): string; } - -/* Navigation contexts */ - -export interface TrekContext { - offline: boolean; - pois: Pois; - originalTrek: Trek; - trek: HydratedTrek; - treksTool: TreksService; - mapConfig: MapboxOptions; - touristicContents: TouristicContents; - touristicCategoriesWithFeatures: TouristicCategoryWithFeatures[]; - touristicEvents: TouristicEvents; - commonSrc: string; - isStage: boolean; - parentTrek: Trek | null; -} - -export interface TreksContext { - offline: boolean; - treksTool: TreksService; - mapConfig: any; -} diff --git a/src/app/pages/more/more-item/more-item.module.ts b/src/app/pages/more/more-item/more-item.module.ts index 641af0f8..6648afbf 100644 --- a/src/app/pages/more/more-item/more-item.module.ts +++ b/src/app/pages/more/more-item/more-item.module.ts @@ -4,7 +4,6 @@ import { RouterModule, Routes } from '@angular/router'; import { IonicModule } from '@ionic/angular'; import { TranslateModule } from '@ngx-translate/core'; -import { MoreItemResolver } from '@app/resolvers/more-item.resolver'; import { SharedUiModule } from '@app/shared/shared-ui.module'; import { MoreItemPage } from './more-item.page'; @@ -12,11 +11,7 @@ import { MoreItemPage } from './more-item.page'; const routes: Routes = [ { path: '', - component: MoreItemPage, - runGuardsAndResolvers: 'always', - resolve: { - item: MoreItemResolver - } + component: MoreItemPage } ]; diff --git a/src/app/pages/more/more-item/more-item.page.html b/src/app/pages/more/more-item/more-item.page.html index 94a18b90..8bb1536f 100644 --- a/src/app/pages/more/more-item/more-item.page.html +++ b/src/app/pages/more/more-item/more-item.page.html @@ -7,15 +7,26 @@ - - + + +
+ +
+
+ + + + + +
+ diff --git a/src/app/pages/more/more-item/more-item.page.ts b/src/app/pages/more/more-item/more-item.page.ts index 4abcff88..6e0b272e 100644 --- a/src/app/pages/more/more-item/more-item.page.ts +++ b/src/app/pages/more/more-item/more-item.page.ts @@ -1,40 +1,42 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; -import { ActivatedRoute, Data, Router } from '@angular/router'; -import { Subscription } from 'rxjs'; +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; import { InformationItem } from '@app/interfaces/interfaces'; +import { MoreInformationsService } from '@app/services/more-informations/more-informations.service'; +import { first } from 'rxjs/operators'; @Component({ selector: 'app-more-item', templateUrl: './more-item.page.html', styleUrls: ['./more-item.page.scss'] }) -export class MoreItemPage implements OnInit, OnDestroy { +export class MoreItemPage implements OnInit { moreItem: InformationItem; moreItemId: number; connectionError = false; - private moreItemSubscription: Subscription; - constructor(private route: ActivatedRoute, private router: Router) {} + constructor( + private route: ActivatedRoute, + private router: Router, + private more: MoreInformationsService + ) {} ngOnInit() { - this.moreItemSubscription = this.route.data.subscribe((data: Data) => { - const item = data['item'] as InformationItem | 'connectionError'; - if (item === 'connectionError') { - this.connectionError = true; - } else { - if (!this.moreItem) { - this.connectionError = false; - this.moreItem = item; - } - } - }); - } + const moreItemId = +(( + this.route.snapshot.paramMap.get('moreItemId') + )); - ngOnDestroy(): void { - if (this.moreItemSubscription) { - this.moreItemSubscription.unsubscribe(); - } + this.more + .getMoreItemById(moreItemId) + .pipe(first()) + .subscribe( + (moreItem) => { + this.moreItem = moreItem; + }, + () => { + this.connectionError = true; + } + ); } refresh() { diff --git a/src/app/pages/more/more.module.ts b/src/app/pages/more/more.module.ts index b325caf7..5bf2596a 100644 --- a/src/app/pages/more/more.module.ts +++ b/src/app/pages/more/more.module.ts @@ -1,7 +1,6 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { MoreResolver } from '@app/resolvers/more.resolver'; import { SharedUiModule } from '@app/shared/shared-ui.module'; import { IonicModule } from '@ionic/angular'; import { TranslateModule } from '@ngx-translate/core'; @@ -11,11 +10,7 @@ import { MorePage } from './more.page'; const routes: Routes = [ { path: '', - runGuardsAndResolvers: 'always', - component: MorePage, - resolve: { - items: MoreResolver - } + component: MorePage } ]; diff --git a/src/app/pages/more/more.page.html b/src/app/pages/more/more.page.html index 0beb9290..767837a7 100644 --- a/src/app/pages/more/more.page.html +++ b/src/app/pages/more/more.page.html @@ -5,28 +5,42 @@ - - + +
+ +
+
-
- - + - -

{{ moreInformationIntro.title }}

-
-
-
-
+ +
+ + + +
+ + + +

{{ moreInformationIntro.title }}

+
+
+
+
+
diff --git a/src/app/pages/more/more.page.ts b/src/app/pages/more/more.page.ts index ef60895c..a1d3b6d7 100644 --- a/src/app/pages/more/more.page.ts +++ b/src/app/pages/more/more.page.ts @@ -1,43 +1,35 @@ -import { Component, OnInit, OnDestroy } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; -import { Subscription } from 'rxjs'; +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { first } from 'rxjs/operators'; import { environment } from '@env/environment'; import { InformationIntro } from '@app/interfaces/interfaces'; +import { MoreInformationsService } from '@app/services/more-informations/more-informations.service'; @Component({ selector: 'app-more', templateUrl: './more.page.html', styleUrls: ['./more.page.scss'] }) -export class MorePage implements OnInit, OnDestroy { +export class MorePage implements OnInit { + public appName: string = environment.appName; moreInformationsIntro: InformationIntro[]; connectionError = false; - public appName: string = environment.appName; - private moreInformationsIntroSubscription: Subscription; - constructor(private route: ActivatedRoute, private router: Router) {} + constructor(private router: Router, private more: MoreInformationsService) {} ngOnInit(): void { - this.moreInformationsIntroSubscription = this.route.data.subscribe( - (data) => { - const items: InformationIntro[] | 'connectionError' = data.items; - if (items === 'connectionError') { + this.more + .getMoreItems() + .pipe(first()) + .subscribe( + (moreItems) => { + this.moreInformationsIntro = moreItems; + }, + () => { this.connectionError = true; - } else { - if (!this.moreInformationsIntro) { - this.connectionError = false; - this.moreInformationsIntro = items; - } } - } - ); - } - - ngOnDestroy(): void { - if (this.moreInformationsIntroSubscription) { - this.moreInformationsIntroSubscription.unsubscribe(); - } + ); } public refresh() { diff --git a/src/app/pages/tabs/tabs.routing.module.ts b/src/app/pages/tabs/tabs.routing.module.ts index 6f61b720..aad7466f 100644 --- a/src/app/pages/tabs/tabs.routing.module.ts +++ b/src/app/pages/tabs/tabs.routing.module.ts @@ -1,6 +1,5 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { TreksContextResolver } from '@app/resolvers/treks.resolver'; import { TreksPage } from '../treks/treks.page'; import { TabsPage } from './tabs.page'; @@ -14,10 +13,7 @@ const routes: Routes = [ children: [ { path: '', - component: TreksPage, - resolve: { - context: TreksContextResolver - } + component: TreksPage } ] }, @@ -27,10 +23,7 @@ const routes: Routes = [ { path: '', component: TreksPage, - data: { offline: true }, - resolve: { - context: TreksContextResolver - } + data: { offline: true } } ] }, diff --git a/src/app/pages/trek-details/trek-details.module.ts b/src/app/pages/trek-details/trek-details.module.ts index 0a056b88..99a2c6c8 100644 --- a/src/app/pages/trek-details/trek-details.module.ts +++ b/src/app/pages/trek-details/trek-details.module.ts @@ -4,19 +4,14 @@ import { IonicModule } from '@ionic/angular'; import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { TrekContextResolver } from '@app/resolvers/trek.resolver'; import { SharedTreksModule } from '@app/shared/shared-treks.module'; import { SharedUiModule } from '@app/shared/shared-ui.module'; import { TrekDetailsPage } from './trek-details.page'; -import { CustomPipesModule } from '@app/shared/custom-pipes.module'; +import { PoiComponent } from '@app/components/poi/poi.component'; const routes: Routes = [ { path: '', - runGuardsAndResolvers: 'always', - resolve: { - context: TrekContextResolver - }, component: TrekDetailsPage } ]; @@ -28,9 +23,8 @@ const routes: Routes = [ RouterModule.forChild(routes), SharedTreksModule, SharedUiModule, - TranslateModule.forChild(), - CustomPipesModule + TranslateModule.forChild() ], - declarations: [TrekDetailsPage] + declarations: [TrekDetailsPage, PoiComponent] }) export class TrekDetailsPageModule {} diff --git a/src/app/pages/trek-details/trek-details.page.html b/src/app/pages/trek-details/trek-details.page.html index bbe07bd9..adc1621c 100644 --- a/src/app/pages/trek-details/trek-details.page.html +++ b/src/app/pages/trek-details/trek-details.page.html @@ -48,17 +48,29 @@ - - + - +
+ +
+
+ + + + - + -
-
@@ -121,7 +131,6 @@

-
{{ parentTrek.properties.name }}
@@ -179,7 +188,6 @@

- @@ -319,7 +327,6 @@
{{ 'trek.details.theme' | translate }}
-
@@ -351,7 +358,6 @@
Balisage
-
@@ -382,7 +388,6 @@

- @@ -400,7 +405,6 @@

- @@ -416,7 +420,6 @@

- @@ -428,7 +431,6 @@

- @@ -440,7 +442,6 @@

- @@ -452,7 +453,6 @@

- @@ -488,7 +488,6 @@

- @@ -518,7 +517,6 @@

-
diff --git a/src/app/pages/trek-details/trek-details.page.ts b/src/app/pages/trek-details/trek-details.page.ts index 2db00e25..4c028cb3 100644 --- a/src/app/pages/trek-details/trek-details.page.ts +++ b/src/app/pages/trek-details/trek-details.page.ts @@ -2,10 +2,9 @@ import { Component, OnInit, ChangeDetectionStrategy, - ChangeDetectorRef, - OnDestroy + ChangeDetectorRef } from '@angular/core'; -import { ActivatedRoute, Data, Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { AlertController, Platform } from '@ionic/angular'; import { TranslateService } from '@ngx-translate/core'; import { SocialSharing } from '@ionic-native/social-sharing/ngx'; @@ -15,12 +14,13 @@ import { Picture, Poi, Trek, - TrekContext, TreksService, TouristicEvent, TouristicCategoryWithFeatures, TouristicContents, - DataSetting + DataSetting, + Pois, + TouristicEvents } from '@app/interfaces/interfaces'; import { OfflineTreksService } from '@app/services/offline-treks/offline-treks.service'; import { OnlineTreksService } from '@app/services/online-treks/online-treks.service'; @@ -28,8 +28,8 @@ import { environment } from '@env/environment'; import { ModalController } from '@ionic/angular'; import { ProgressComponent } from '@app/components/progress/progress.component'; import { SettingsService } from '@app/services/settings/settings.service'; -import { first } from 'rxjs/internal/operators/first'; -import { Subscription } from 'rxjs'; +import { forkJoin, of } from 'rxjs'; +import { first } from 'rxjs/operators'; @Component({ selector: 'app-trek-details', @@ -37,7 +37,7 @@ import { Subscription } from 'rxjs'; styleUrls: ['./trek-details.page.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) -export class TrekDetailsPage implements OnInit, OnDestroy { +export class TrekDetailsPage implements OnInit { public originalTrek: Trek; public currentTrek: HydratedTrek; public offline = false; @@ -68,7 +68,6 @@ export class TrekDetailsPage implements OnInit, OnDestroy { 'mobile', 'api' )}/${this.translate.getDefaultLang()}/treks`; - private dataSubscription: Subscription; constructor( private onlineTreks: OnlineTreksService, @@ -86,16 +85,54 @@ export class TrekDetailsPage implements OnInit, OnDestroy { ) {} ngOnInit(): void { - this.dataSubscription = this.route.data.subscribe(async (data: Data) => { - const context: TrekContext | null | 'connectionError' = data.context; - if (context === 'connectionError') { - this.connectionError = true; - } else { - if (!this.currentTrek) { + const offline = !!this.route.snapshot.data['offline']; + const isStage = !!this.route.snapshot.data['isStage']; + const trekId = +(this.route.snapshot.paramMap.get('trekId')); + const stageId = +(this.route.snapshot.paramMap.get('stageId')); + const currentTrekId = isStage ? stageId : trekId; + const parentId: number | undefined = isStage ? trekId : undefined; + + const treksService: TreksService = offline + ? this.offlineTreks + : this.onlineTreks; + + forkJoin([ + treksService.getTrekById(currentTrekId, parentId), + treksService.getPoisForTrekById(currentTrekId, parentId), + treksService.getTouristicContentsForTrekById(currentTrekId, parentId), + treksService.getTouristicEventsForTrekById(currentTrekId, parentId), + isStage && parentId ? treksService.getTrekById(parentId) : of(null) + ]) + .pipe(first()) + .subscribe( + async ([trek, pois, touristicContents, touristicEvents, parentTrek]: [ + Trek | null, + Pois, + TouristicContents, + TouristicEvents, + Trek | null + ]): Promise => { + const commonSrc = treksService.getCommonImgSrc(); + const hydratedTrek: HydratedTrek = this.settings.getHydratedTrek( + trek, + commonSrc + ); + const touristicCategoriesWithFeatures = + this.settings.getTouristicCategoriesWithFeatures(touristicContents); + + if ( + (this.platform.is('ios') || this.platform.is('android')) && + environment.useFirebase + ) { + this.firebaseAnalytics.setCurrentScreen( + `${trek.properties.name} details` + ); + } + this.connectionError = false; this.isAvailableOffline = await this.offlineTreks.trekIsAvailableOffline( - context.trek.properties.id + hydratedTrek.properties.id ); if (this.settings.data$.value) { @@ -105,29 +142,29 @@ export class TrekDetailsPage implements OnInit, OnDestroy { } this.isItinerancy = !!( - context.trek.properties.children && - context.trek.properties.children.features.length > 0 + hydratedTrek.properties.children && + hydratedTrek.properties.children.features.length > 0 ); - this.offline = context.offline; - this.currentTrek = context.trek; - this.originalTrek = context.originalTrek; - this.currentPois = context.pois.features; - this.treksTool = context.treksTool; - this.touristicContents = context.touristicContents; + this.offline = offline; + this.currentTrek = hydratedTrek; + this.originalTrek = trek; + this.currentPois = pois.features; + this.treksTool = treksService; + this.touristicContents = touristicContents; this.touristicCategoriesWithFeatures = - context.touristicCategoriesWithFeatures; - this.touristicEvents = context.touristicEvents.features; + touristicCategoriesWithFeatures; + this.touristicEvents = touristicEvents.features; this.treksUrl = this.treksTool.getTreksUrl(); - this.commonSrc = context.commonSrc; - this.mapLink = context.treksTool.getTrekMapUrl( - context.trek.properties.id, - context.parentTrek ? context.parentTrek.properties.id : undefined + this.commonSrc = commonSrc; + this.mapLink = this.treksTool.getTrekMapUrl( + hydratedTrek.properties.id, + parentTrek ? parentTrek.properties.id : undefined ); - this.isStage = context.isStage; - if (context.isStage && context.parentTrek) { - this.parentTrek = context.parentTrek; + this.isStage = isStage; + if (isStage && parentTrek) { + this.parentTrek = parentTrek; this.stageIndex = this.parentTrek.properties.children.features.findIndex( @@ -154,14 +191,10 @@ export class TrekDetailsPage implements OnInit, OnDestroy { } this.ref.markForCheck(); } - } - }); - } - - ngOnDestroy(): void { - if (this.dataSubscription) { - this.dataSubscription.unsubscribe(); - } + ), + () => { + this.connectionError = true; + }; } async downloadTrek() { diff --git a/src/app/pages/trek-map/trek-map.module.ts b/src/app/pages/trek-map/trek-map.module.ts index 3ef3412f..43035979 100644 --- a/src/app/pages/trek-map/trek-map.module.ts +++ b/src/app/pages/trek-map/trek-map.module.ts @@ -1,21 +1,17 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Routes, RouterModule } from '@angular/router'; -import { TrekContextResolver } from '@app/resolvers/trek.resolver'; import { IonicModule } from '@ionic/angular'; -import { SharedModule } from '@app/shared/shared.module'; import { SharedUiModule } from '@app/shared/shared-ui.module'; import { TranslateModule } from '@ngx-translate/core'; import { TrekMapPage } from './trek-map.page'; +import { GeolocateNotificationsComponent } from '@app/components/geolocate-notifications/geolocate-notifications.component'; +import { MapTrekVizComponent } from '@app/components/map-trek-viz/map-trek-viz.component'; const routes: Routes = [ { path: '', - component: TrekMapPage, - runGuardsAndResolvers: 'always', - resolve: { - context: TrekContextResolver - } + component: TrekMapPage } ]; @@ -24,10 +20,14 @@ const routes: Routes = [ CommonModule, IonicModule, RouterModule.forChild(routes), - SharedModule, SharedUiModule, TranslateModule.forChild() ], - declarations: [TrekMapPage] + declarations: [ + TrekMapPage, + GeolocateNotificationsComponent, + MapTrekVizComponent + ], + exports: [GeolocateNotificationsComponent, MapTrekVizComponent] }) export class TrekMapPageModule {} diff --git a/src/app/pages/trek-map/trek-map.page.ts b/src/app/pages/trek-map/trek-map.page.ts index ce1aed03..f39828ab 100644 --- a/src/app/pages/trek-map/trek-map.page.ts +++ b/src/app/pages/trek-map/trek-map.page.ts @@ -1,5 +1,5 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; -import { ActivatedRoute, Data, Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { ModalController, Platform, PopoverController } from '@ionic/angular'; import { Subscription } from 'rxjs/internal/Subscription'; @@ -12,13 +12,22 @@ import { HydratedTrek, Poi, Pois, - TrekContext, InformationDesk, TouristicCategoryWithFeatures, - TreksService + TreksService, + Trek, + TouristicContents, + TouristicEvents } from '@app/interfaces/interfaces'; import { SettingsService } from '@app/services/settings/settings.service'; import { Location } from '@angular/common'; +import { OnlineTreksService } from '@app/services/online-treks/online-treks.service'; +import { OfflineTreksService } from '@app/services/offline-treks/offline-treks.service'; +import { forkJoin } from 'rxjs/internal/observable/forkJoin'; +import { environment } from '@env/environment'; +import { FirebaseAnalytics } from '@ionic-native/firebase-analytics/ngx'; +import { first } from 'rxjs/operators'; +import { of } from 'rxjs'; @Component({ selector: 'app-trek-map', @@ -36,7 +45,6 @@ export class TrekMapPage implements OnInit, OnDestroy { public commonSrc: string; public offline = false; private treksTool: TreksService; - private dataSubscription: Subscription; private backButtonSubscription: Subscription; public canDisplayMap = false; @@ -47,31 +55,78 @@ export class TrekMapPage implements OnInit, OnDestroy { public settings: SettingsService, private platform: Platform, private popoverCtrl: PopoverController, - private location: Location + private location: Location, + private onlineTreks: OnlineTreksService, + private offlineTreks: OfflineTreksService, + private firebaseAnalytics: FirebaseAnalytics ) {} ngOnInit(): void { - this.dataSubscription = this.route.data.subscribe((data: Data): void => { - const context: TrekContext | 'connectionError' = data.context; - if (context === 'connectionError') { - this.connectionError = true; - } else { - if (!this.currentTrek) { + const offline = !!this.route.snapshot.data['offline']; + const isStage = !!this.route.snapshot.data['isStage']; + const trekId = +(this.route.snapshot.paramMap.get('trekId')); + const stageId = +(this.route.snapshot.paramMap.get('stageId')); + const currentTrekId = isStage ? stageId : trekId; + const parentId: number | undefined = isStage ? trekId : undefined; + + const treksService: TreksService = offline + ? this.offlineTreks + : this.onlineTreks; + + forkJoin([ + treksService.getTrekById(currentTrekId, parentId), + treksService.getPoisForTrekById(currentTrekId, parentId), + treksService.getTouristicContentsForTrekById(currentTrekId, parentId), + treksService.getTouristicEventsForTrekById(currentTrekId, parentId), + isStage && parentId ? treksService.getTrekById(parentId) : of(null) + ]) + .pipe(first()) + .subscribe( + async ([trek, pois, touristicContents, touristicEvents, parentTrek]: [ + Trek | null, + Pois, + TouristicContents, + TouristicEvents, + Trek | null + ]): Promise => { + const mapConfig: MapboxOptions = treksService.getMapConfigForTrekById( + isStage && parentId ? (parentTrek as Trek) : (trek as Trek), + offline + ); + const commonSrc = treksService.getCommonImgSrc(); + const hydratedTrek: HydratedTrek = this.settings.getHydratedTrek( + trek, + commonSrc + ); + const touristicCategoriesWithFeatures = + this.settings.getTouristicCategoriesWithFeatures(touristicContents); + + if ( + (this.platform.is('ios') || this.platform.is('android')) && + environment.useFirebase + ) { + this.firebaseAnalytics.setCurrentScreen( + `${trek.properties.name} map` + ); + } + this.connectionError = false; - this.offline = context.offline; - this.currentTrek = context.trek; - this.currentPois = context.pois; + this.offline = offline; + this.currentTrek = hydratedTrek; + this.currentPois = pois; this.touristicCategoriesWithFeatures = - context.touristicCategoriesWithFeatures; - this.mapConfig = context.mapConfig; - this.treksTool = context.treksTool; - this.commonSrc = context.treksTool.getCommonImgSrc(); - this.trekUrl = context.treksTool.getTrekDetailsUrl( + touristicCategoriesWithFeatures; + this.mapConfig = mapConfig; + this.treksTool = treksService; + this.commonSrc = treksService.getCommonImgSrc(); + this.trekUrl = treksService.getTrekDetailsUrl( (this.currentTrek as any).properties.id ); + }, + () => { + this.connectionError = true; } - } - }); + ); if (this.platform.is('android')) { this.backButtonSubscription = @@ -96,10 +151,6 @@ export class TrekMapPage implements OnInit, OnDestroy { } ngOnDestroy() { - if (this.dataSubscription) { - this.dataSubscription.unsubscribe(); - } - if (this.backButtonSubscription) { this.backButtonSubscription.unsubscribe(); } diff --git a/src/app/pages/treks-map/treks-map.module.ts b/src/app/pages/treks-map/treks-map.module.ts index 2afbadf0..6af5d4b2 100644 --- a/src/app/pages/treks-map/treks-map.module.ts +++ b/src/app/pages/treks-map/treks-map.module.ts @@ -1,22 +1,18 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { TreksContextResolver } from '@app/resolvers/treks.resolver'; import { SharedUiModule } from '@app/shared/shared-ui.module'; -import { SharedModule } from '@app/shared/shared.module'; import { IonicModule } from '@ionic/angular'; import { TranslateModule } from '@ngx-translate/core'; import { TreksMapPage } from './treks-map.page'; import { SelectTrekComponent } from '@app/components/select-trek/select-trek.component'; +import { MapTreksVizComponent } from '@app/components/map-treks-viz/map-treks-viz.component'; const routes: Routes = [ { path: '', - component: TreksMapPage, - resolve: { - context: TreksContextResolver - } + component: TreksMapPage } ]; @@ -25,10 +21,10 @@ const routes: Routes = [ CommonModule, IonicModule, RouterModule.forChild(routes), - SharedModule, SharedUiModule, TranslateModule.forChild() ], - declarations: [TreksMapPage, SelectTrekComponent] + declarations: [TreksMapPage, SelectTrekComponent, MapTreksVizComponent], + exports: [MapTreksVizComponent] }) export class TreksMapPageModule {} diff --git a/src/app/pages/treks-map/treks-map.page.ts b/src/app/pages/treks-map/treks-map.page.ts index 947f6115..f8b90095 100644 --- a/src/app/pages/treks-map/treks-map.page.ts +++ b/src/app/pages/treks-map/treks-map.page.ts @@ -1,23 +1,20 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { OnlineTreksService } from '@app/services/online-treks/online-treks.service'; import { MapboxOptions } from 'mapbox-gl'; +import { combineLatest } from 'rxjs'; +import { Subscription } from 'rxjs/internal/Subscription'; +import { cloneDeep } from 'lodash'; +import { Network } from '@ionic-native/network/ngx'; + import { environment } from '@env/environment'; +import { OnlineTreksService } from '@app/services/online-treks/online-treks.service'; +import { OfflineTreksService } from '@app/services/offline-treks/offline-treks.service'; import { FiltersComponent } from '@app/components/filters/filters.component'; import { SearchComponent } from '@app/components/search/search.component'; -import { - MinimalTrek, - TreksContext, - TreksService -} from '@app/interfaces/interfaces'; +import { MinimalTrek, TreksService } from '@app/interfaces/interfaces'; import { FilterTreksService } from '@app/services/filter-treks/filter-treks.service'; import { SettingsService } from '@app/services/settings/settings.service'; import { ModalController, Platform } from '@ionic/angular'; -import { combineLatest } from 'rxjs'; -import { Subscription } from 'rxjs/internal/Subscription'; -import { map, mergeMap, first } from 'rxjs/operators'; -import { cloneDeep } from 'lodash'; -import { Network } from '@ionic-native/network/ngx'; @Component({ selector: 'app-treks-map', @@ -36,13 +33,13 @@ export class TreksMapPage implements OnInit, OnDestroy { public mapConfig: MapboxOptions; public commonSrc: string; public noNetwork = false; - private dataSubscription: Subscription; public canDisplayMap = false; constructor( private filterTreks: FilterTreksService, private modalController: ModalController, public onlineTreks: OnlineTreksService, + public offlineTreks: OfflineTreksService, private router: Router, private route: ActivatedRoute, public settings: SettingsService, @@ -53,21 +50,25 @@ export class TreksMapPage implements OnInit, OnDestroy { ngOnInit() { this.checkNetwork(); - this.dataSubscription = this.route.data.subscribe((data) => { - const context: TreksContext = data.context; - this.offline = context.offline; - this.treksTool = context.treksTool; + if (!this.treksTool) { + this.offline = !!this.route.snapshot.data['offline']; + this.treksTool = this.offline ? this.offlineTreks : this.onlineTreks; this.treksUrl = this.treksTool.getTreksUrl(); - this.mapConfig = cloneDeep(context.mapConfig); + this.mapConfig = cloneDeep( + (this.offline && + (this.platform.is('ios') || this.platform.is('android')) + ? environment.offlineMapConfig + : environment.onlineMapConfig) as any + ); this.commonSrc = this.treksTool.getCommonImgSrc(); - }); + } + + const filteredTreks$ = this.offline + ? this.offlineTreks.filteredTreks$ + : this.onlineTreks.filteredTreks$; this.mergeFiltersTreks$ = combineLatest([ - this.route.data.pipe( - first(), - map((data) => data.context), - mergeMap((context: TreksContext) => context.treksTool.filteredTreks$) - ), + filteredTreks$, this.filterTreks.activeFiltersNumber$ ]).subscribe(([filteredTreks, numberOfActiveFilters]) => { this.numberOfActiveFilters = @@ -80,10 +81,6 @@ export class TreksMapPage implements OnInit, OnDestroy { if (this.mergeFiltersTreks$) { this.mergeFiltersTreks$.unsubscribe(); } - - if (this.dataSubscription) { - this.dataSubscription.unsubscribe(); - } } ionViewWillEnter() { diff --git a/src/app/pages/treks/treks.page.ts b/src/app/pages/treks/treks.page.ts index b75aabe8..15c4b137 100644 --- a/src/app/pages/treks/treks.page.ts +++ b/src/app/pages/treks/treks.page.ts @@ -1,6 +1,5 @@ import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { SettingsService } from '@app/services/settings/settings.service'; import { IonContent, ModalController, @@ -8,26 +7,20 @@ import { AlertController } from '@ionic/angular'; import { combineLatest, Subscription } from 'rxjs'; -import { map, mergeMap, first } from 'rxjs/operators'; import { Network } from '@ionic-native/network/ngx'; import { Platform } from '@ionic/angular'; +import { TranslateService } from '@ngx-translate/core'; import { environment } from '@env/environment'; +import { SettingsService } from '@app/services/settings/settings.service'; import { InAppDisclosureComponent } from '@app/components/in-app-disclosure/in-app-disclosure.component'; import { FiltersComponent } from '@app/components/filters/filters.component'; import { SearchComponent } from '@app/components/search/search.component'; -import { - MinimalTrek, - TreksContext, - TreksService, - Order -} from '@app/interfaces/interfaces'; +import { MinimalTrek, TreksService, Order } from '@app/interfaces/interfaces'; import { FilterTreksService } from '@app/services/filter-treks/filter-treks.service'; import { OnlineTreksService } from '@app/services/online-treks/online-treks.service'; import { OfflineTreksService } from '@app/services/offline-treks/offline-treks.service'; -import { LoadingService } from '@app/services/loading/loading.service'; import { GeolocateService } from '@app/services/geolocate/geolocate.service'; -import { TranslateService } from '@ngx-translate/core'; import { TreksOrderComponent } from '@app/components/treks-order/treks-order.component'; @Component({ @@ -49,7 +42,6 @@ export class TreksPage implements OnInit, OnDestroy { public currentMaxTreks: number = environment.treksByStep; private treksTool: TreksService; - private dataSubscription: Subscription; private filteredTreksSubscription: Subscription; private nbOfflineTreksSubscription: Subscription; @@ -57,7 +49,6 @@ export class TreksPage implements OnInit, OnDestroy { constructor( private filterTreks: FilterTreksService, - public loading: LoadingService, private modalController: ModalController, public offlineTreks: OfflineTreksService, public onlineTreks: OnlineTreksService, @@ -77,21 +68,18 @@ export class TreksPage implements OnInit, OnDestroy { await this.handleInitialOrder(); - this.dataSubscription = this.route.data.subscribe((data) => { - if (!this.treksTool) { - const context: TreksContext = data.context; - this.treksTool = context.treksTool; - this.mapLink = context.treksTool.getTreksMapUrl(); - this.offline = context.offline; - } - }); + if (!this.treksTool) { + this.offline = !!this.route.snapshot.data['offline']; + this.treksTool = this.offline ? this.offlineTreks : this.onlineTreks; + this.mapLink = this.treksTool.getTreksMapUrl(); + } + + const filteredTreks$ = this.offline + ? this.offlineTreks.filteredTreks$ + : this.onlineTreks.filteredTreks$; this.filteredTreksSubscription = combineLatest([ - this.route.data.pipe( - first(), - map((data) => data.context), - mergeMap((context: TreksContext) => context.treksTool.filteredTreks$) - ), + filteredTreks$, this.filterTreks.activeFiltersNumber$, this.settings.data$ ]).subscribe(([filteredTreks, numberOfActiveFilters, settings]) => { @@ -106,20 +94,12 @@ export class TreksPage implements OnInit, OnDestroy { this.nbOfflineTreksSubscription = this.offlineTreks.treks$.subscribe( (treks) => { - if (!treks) { - this.nbOfflineTreks = 0; - } else { - this.nbOfflineTreks = treks.features.length; - } + this.nbOfflineTreks = !treks ? 0 : treks.features.length; } ); } ngOnDestroy(): void { - if (this.dataSubscription) { - this.dataSubscription.unsubscribe(); - } - if (this.filteredTreksSubscription) { this.filteredTreksSubscription.unsubscribe(); } diff --git a/src/app/pipes/lower-round.pipe.ts b/src/app/pipes/lower-round.pipe.ts deleted file mode 100644 index 46bee087..00000000 --- a/src/app/pipes/lower-round.pipe.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; - -@Pipe({ name: 'lowerRound' }) -export class LowerRoundPipe implements PipeTransform { - transform(value: number): number { - return Math.floor(value); - } -} diff --git a/src/app/resolvers/more-item.resolver.ts b/src/app/resolvers/more-item.resolver.ts deleted file mode 100644 index b6f457cc..00000000 --- a/src/app/resolvers/more-item.resolver.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { HttpErrorResponse } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; - -import { InformationItem } from '@app/interfaces/interfaces'; -import { MoreInformationsService } from '@app/services/more-informations/more-informations.service'; -import { of } from 'rxjs'; -import { throwError } from 'rxjs'; -import { catchError, tap } from 'rxjs/operators'; -import { Platform } from '@ionic/angular'; -import { FirebaseAnalytics } from '@ionic-native/firebase-analytics/ngx'; -import { environment } from '@env/environment'; - -@Injectable() -export class MoreItemResolver - implements Resolve { - constructor( - private more: MoreInformationsService, - private platform: Platform, - private firebaseAnalytics: FirebaseAnalytics - ) {} - - resolve(route: ActivatedRouteSnapshot) { - const moreItemId = +(route.paramMap.get('moreItemId')); - return this.more.getMoreItemById(moreItemId).pipe( - tap((item) => { - if ( - (this.platform.is('ios') || this.platform.is('android')) && - environment.useFirebase - ) { - this.firebaseAnalytics.setCurrentScreen(`${item.title}`); - } - }), - catchError((error: HttpErrorResponse) => { - if (!error.status) { - return of('connectionError' as 'connectionError'); - } else { - return throwError(error); - } - }) - ); - } -} diff --git a/src/app/resolvers/more.resolver.ts b/src/app/resolvers/more.resolver.ts deleted file mode 100644 index 3280b5a6..00000000 --- a/src/app/resolvers/more.resolver.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { HttpErrorResponse } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { Resolve, ActivatedRouteSnapshot } from '@angular/router'; - -import { InformationIntro } from '@app/interfaces/interfaces'; -import { MoreInformationsService } from '@app/services/more-informations/more-informations.service'; -import { of } from 'rxjs/internal/observable/of'; -import { throwError } from 'rxjs/internal/observable/throwError'; -import { catchError, tap } from 'rxjs/operators'; -import { Platform } from '@ionic/angular'; -import { FirebaseAnalytics } from '@ionic-native/firebase-analytics/ngx'; -import { environment } from '@env/environment'; - -@Injectable() -export class MoreResolver - implements Resolve { - constructor( - private more: MoreInformationsService, - private platform: Platform, - private firebaseAnalytics: FirebaseAnalytics - ) {} - - resolve = (route: ActivatedRouteSnapshot) => - this.more.getMoreItems().pipe( - tap(() => { - if ( - (this.platform.is('ios') || this.platform.is('android')) && - environment.useFirebase - ) { - this.firebaseAnalytics.setCurrentScreen(`Information`); - } - }), - catchError((error: HttpErrorResponse) => { - if (!error.status) { - return of('connectionError' as 'connectionError'); - } else { - return throwError(error); - } - }) - ); -} diff --git a/src/app/resolvers/trek.resolver.ts b/src/app/resolvers/trek.resolver.ts deleted file mode 100644 index f2c2749d..00000000 --- a/src/app/resolvers/trek.resolver.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { HttpErrorResponse } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router'; -import { MapboxOptions } from 'mapbox-gl'; -import { forkJoin, of, throwError } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; - -import { - Pois, - Trek, - HydratedTrek, - TrekContext, - TreksService, - TouristicContents, - TouristicEvents -} from '@app/interfaces/interfaces'; -import { OfflineTreksService } from '@app/services/offline-treks/offline-treks.service'; -import { OnlineTreksService } from '@app/services/online-treks/online-treks.service'; -import { SettingsService } from '@app/services/settings/settings.service'; -import { LoadingService } from '@app/services/loading/loading.service'; -import { FirebaseAnalytics } from '@ionic-native/firebase-analytics/ngx'; -import { Platform } from '@ionic/angular'; -import { environment } from '@env/environment'; - -@Injectable() -export class TrekContextResolver - implements Resolve -{ - constructor( - private loading: LoadingService, - private offlineTreks: OfflineTreksService, - private onlineTreks: OnlineTreksService, - private router: Router, - private settingsService: SettingsService, - private platform: Platform, - private firebaseAnalytics: FirebaseAnalytics - ) {} - - resolve(route: ActivatedRouteSnapshot) { - const offline = !!route.data['offline']; - const isStage = !!route.data['isStage']; - const trekId = +(route.paramMap.get('trekId')); - const stageId = +(route.paramMap.get('stageId')); - const currentTrekId = isStage ? stageId : trekId; - const parentId: number | undefined = isStage ? trekId : undefined; - - const treksService: TreksService = offline - ? this.offlineTreks - : this.onlineTreks; - - return forkJoin( - treksService.getTrekById(currentTrekId, parentId), - treksService.getPoisForTrekById(currentTrekId, parentId), - treksService.getTouristicContentsForTrekById(currentTrekId, parentId), - treksService.getTouristicEventsForTrekById(currentTrekId, parentId), - isStage && parentId ? treksService.getTrekById(parentId) : of(null) - ).pipe( - map( - ([trek, pois, touristicContents, touristicEvents, parentTrek]: [ - Trek | null, - Pois, - TouristicContents, - TouristicEvents, - Trek | null - ]): TrekContext | null => { - if (trek === null) { - this.router.navigate(['/']); - console.error('No trek found: ', currentTrekId); - return null; - } else { - const mapConfig: MapboxOptions = - treksService.getMapConfigForTrekById( - isStage && parentId ? (parentTrek as Trek) : (trek as Trek), - offline - ); - const commonSrc = treksService.getCommonImgSrc(); - const hydratedTrek: HydratedTrek = - this.settingsService.getHydratedTrek(trek, commonSrc); - const touristicCategoriesWithFeatures = - this.settingsService.getTouristicCategoriesWithFeatures( - touristicContents - ); - - if ( - (this.platform.is('ios') || this.platform.is('android')) && - environment.useFirebase - ) { - this.firebaseAnalytics.setCurrentScreen( - `${trek.properties.name}` - ); - } - - return { - treksTool: treksService, - offline: offline, - originalTrek: trek, - trek: hydratedTrek, - pois, - touristicContents, - touristicCategoriesWithFeatures, - touristicEvents, - mapConfig, - commonSrc, - isStage, - parentTrek - }; - } - } - ), - catchError((error: HttpErrorResponse) => { - this.loading.finish(); - if (!error.status) { - return of('connectionError' as 'connectionError'); - } else { - return throwError(error); - } - }) - ); - } -} diff --git a/src/app/resolvers/treks.resolver.ts b/src/app/resolvers/treks.resolver.ts deleted file mode 100644 index 0b9dbf4c..00000000 --- a/src/app/resolvers/treks.resolver.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; -import { Observable, of } from 'rxjs'; -import { Platform } from '@ionic/angular'; - -import { TreksContext, TreksService } from '@app/interfaces/interfaces'; -import { OfflineTreksService } from '@app/services/offline-treks/offline-treks.service'; -import { OnlineTreksService } from '@app/services/online-treks/online-treks.service'; -import { environment } from '@env/environment'; -import { FirebaseAnalytics } from '@ionic-native/firebase-analytics/ngx'; - -@Injectable() -export class TreksContextResolver implements Resolve { - constructor( - private onlineTreks: OnlineTreksService, - private offlineTreks: OfflineTreksService, - private platform: Platform, - private firebaseAnalytics: FirebaseAnalytics - ) {} - - resolve(route: ActivatedRouteSnapshot): Observable { - const offline = !!route.data['offline']; - const treksService: TreksService = offline - ? this.offlineTreks - : this.onlineTreks; - const mapConfig = - offline && (this.platform.is('ios') || this.platform.is('android')) - ? environment.offlineMapConfig - : environment.onlineMapConfig; - - if ( - (this.platform.is('ios') || this.platform.is('android')) && - environment.useFirebase - ) { - this.firebaseAnalytics.setCurrentScreen(`Treks`); - } - - return of({ - treksTool: treksService, - offline: offline, - mapConfig - }); - } -} diff --git a/src/app/services/cache/cache.service.ts b/src/app/services/cache/cache.service.ts deleted file mode 100644 index eebbfd0b..00000000 --- a/src/app/services/cache/cache.service.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { HttpClient } from '@angular/common/http'; -import { EventEmitter, Injectable } from '@angular/core'; -import { Observable, throwError } from 'rxjs'; -import { catchError, publishReplay, refCount, take, tap } from 'rxjs/operators'; - -@Injectable({ - providedIn: 'root' -}) -export class CacheService { - private cache: { [key: string]: Observable } = {}; - private refreshDelay = 4 * 60 * 60 * 1000; - private maxSize = 200; - public revoke: EventEmitter = new EventEmitter(); - public hits: { [key: string]: number } = {}; - - constructor(private http: HttpClient) { - this.revoke.subscribe((revoked: string | null) => { - if (!revoked) { - this.cache = {}; - this.hits = {}; - } else { - delete this.cache[revoked]; - delete this.hits[revoked]; - } - }); - } - - /* - * gets an observable - * that broadcasts a ReplaySubject - * which emits the response of a get request - * during this.refreshDelay ms without sending a new http request - */ - public get(url: string, options: any): Observable { - if (!this.cache.hasOwnProperty(url)) { - if (Object.keys(this.cache).length >= this.maxSize) { - // TODO: do not revoke everything - this.revoke.emit(); - } - this.cache[url] = this.http.get(url, options).pipe( - // set hits to 0 each time request is actually sent - tap(() => { - this.hits[url] = 0; - }), - // create a ReplaySubject that stores and emit last response during delay - publishReplay(1, this.refreshDelay), - // broadcast ReplaySubject - refCount(), - // complete each observer after response has been emitted - take(1), - // increment hits each time request is subscribed - tap(() => { - const hits = this.hits[url]; - this.hits[url] = hits ? hits + 1 : 1; - }), - catchError((error) => { - delete this.cache[url]; - return throwError(error); - }) - ); - } - return this.cache[url]; - } - - /* - Make the observable revoke the cache when it emits - */ - public revoking( - observable: Observable, - revoked?: string | null - ): Observable { - return observable.pipe( - tap(() => { - this.revoke.emit(revoked); - }) - ); - } -} diff --git a/src/app/services/loading/loading.service.ts b/src/app/services/loading/loading.service.ts deleted file mode 100644 index b1495327..00000000 --- a/src/app/services/loading/loading.service.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { - HttpEvent, - HttpHandler, - HttpInterceptor, - HttpRequest, - HttpResponse -} from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { BehaviorSubject, Observable, throwError } from 'rxjs'; -import { catchError, map, tap } from 'rxjs/operators'; - -@Injectable({ - providedIn: 'root' -}) -export class LoadingService { - public status = new BehaviorSubject(false); // loading state - - private loadingIds = new BehaviorSubject([]); // list of ids - - constructor() { - const service = this; - this.loadingIds - .pipe(map((ids: string[]) => ids.length > 0)) - .subscribe((isLoading: boolean) => { - if (isLoading !== service.status.getValue()) { - service.status.next(isLoading); - } - }); - this.status.subscribe(); - } - - begin(id: string): void { - const ids = this.loadingIds.getValue(); - ids.push(id); - this.loadingIds.next(ids); - } - - finish(id?: string): void { - if (id === undefined) { - this.loadingIds.next([]); - } else { - const ids = this.loadingIds - .getValue() - .filter((loadingId: string) => loadingId !== id); - this.loadingIds.next(ids); - } - } - - isLoading(id: string): Observable { - return this.loadingIds.pipe( - map((loadingIds: string[]) => { - return loadingIds.indexOf(id) >= 0; - }) - ); - } -} - -@Injectable() -export class LoadingInterceptor implements HttpInterceptor { - constructor(protected loading: LoadingService) {} - - intercept( - req: HttpRequest, - next: HttpHandler - ): Observable> { - const loadingId = `${req.method}-${req.urlWithParams}`; - this.loading.begin(loadingId); - return next.handle(req).pipe( - tap((event: HttpEvent) => { - if (event instanceof HttpResponse) { - this.loading.finish(loadingId); - } - }), - catchError((error: any) => { - this.loading.finish(loadingId); - return throwError(error); - }) - ); - } -} diff --git a/src/app/services/more-informations/more-informations.service.ts b/src/app/services/more-informations/more-informations.service.ts index 97c5f321..f259cc32 100644 --- a/src/app/services/more-informations/more-informations.service.ts +++ b/src/app/services/more-informations/more-informations.service.ts @@ -1,10 +1,9 @@ import { Injectable } from '@angular/core'; -import { HttpHeaders } from '@angular/common/http'; +import { HttpClient,HttpHeaders } from '@angular/common/http'; import { InformationIntro, InformationItem } from '@app/interfaces/interfaces'; import { Observable } from 'rxjs'; import { TranslateService } from '@ngx-translate/core'; -import { CacheService } from '@app/services/cache/cache.service'; import { environment } from '@env/environment'; @Injectable({ @@ -14,7 +13,7 @@ export class MoreInformationsService { private apiUrl = `${environment.onlineBaseUrl}`; constructor( - private cache: CacheService, + private http:HttpClient, private translate: TranslateService ) {} @@ -24,7 +23,7 @@ export class MoreInformationsService { 'Accept-Language': this.translate.getDefaultLang() }) }; - return this.cache.get( + return this.http.get( `${this.apiUrl}/flatpages.json`, httpOptions ); @@ -36,7 +35,7 @@ export class MoreInformationsService { 'Accept-Language': this.translate.getDefaultLang() }) }; - return this.cache.get( + return this.http.get( `${this.apiUrl}/flatpages/${id}.json`, httpOptions ); diff --git a/src/app/services/online-treks/online-treks.service.ts b/src/app/services/online-treks/online-treks.service.ts index 954ed5ea..8d50cebb 100644 --- a/src/app/services/online-treks/online-treks.service.ts +++ b/src/app/services/online-treks/online-treks.service.ts @@ -14,7 +14,6 @@ import { TouristicContents, TouristicEvents } from '@app/interfaces/interfaces'; -import { CacheService } from '@app/services/cache/cache.service'; import { FilterTreksService } from '@app/services/filter-treks/filter-treks.service'; import { environment } from '@env/environment'; @@ -33,7 +32,6 @@ export class OnlineTreksService implements TreksService { constructor( private http: HttpClient, - private cache: CacheService, private filterTreks: FilterTreksService, private translate: TranslateService ) {} @@ -108,12 +106,12 @@ export class OnlineTreksService implements TreksService { }) }; if (parentId) { - return this.cache.get( + return this.http.get( `${this.apiUrl}/${parentId}/treks/${trekId}.geojson`, httpOptions ); } else { - return this.cache.get( + return this.http.get( `${this.apiUrl}/${trekId}/trek.geojson`, httpOptions ); @@ -131,12 +129,12 @@ export class OnlineTreksService implements TreksService { }; if (parentId) { - return this.cache.get( + return this.http.get( `${this.apiUrl}/${parentId}/pois/${trekId}.geojson`, httpOptions ); } else { - return this.cache.get( + return this.http.get( `${this.apiUrl}/${trekId}/pois.geojson`, httpOptions ); @@ -153,12 +151,12 @@ export class OnlineTreksService implements TreksService { }) }; if (parentId) { - return this.cache.get( + return this.http.get( `${this.apiUrl}/${parentId}/touristic_contents/${trekId}.geojson`, httpOptions ); } else { - return this.cache.get( + return this.http.get( `${this.apiUrl}/${trekId}/touristic_contents.geojson`, httpOptions ); @@ -175,12 +173,12 @@ export class OnlineTreksService implements TreksService { }) }; if (parentId) { - return this.cache.get( + return this.http.get( `${this.apiUrl}/${parentId}/touristic_events/${trekId}.geojson`, httpOptions ); } else { - return this.cache.get( + return this.http.get( `${this.apiUrl}/${trekId}/touristic_events.geojson`, httpOptions ); @@ -201,7 +199,7 @@ export class OnlineTreksService implements TreksService { ...cloneDeep(environment.onlineMapConfig), zoom: environment.trekZoom.zoom }; - (mapConfig as any).trekBounds = trek.bbox as [ + (mapConfig as any).trekBounds = (trek as any).bbox as [ number, number, number, diff --git a/src/app/shared/custom-pipes.module.ts b/src/app/shared/custom-pipes.module.ts deleted file mode 100644 index f5b7477a..00000000 --- a/src/app/shared/custom-pipes.module.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { NgModule } from '@angular/core'; -import { LowerRoundPipe } from '@app/pipes/lower-round.pipe'; - -@NgModule({ - imports: [], - declarations: [LowerRoundPipe], - exports: [LowerRoundPipe] -}) -export class CustomPipesModule {} diff --git a/src/app/shared/shared-treks.module.ts b/src/app/shared/shared-treks.module.ts index 39aa2099..b175769a 100644 --- a/src/app/shared/shared-treks.module.ts +++ b/src/app/shared/shared-treks.module.ts @@ -1,22 +1,25 @@ import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; +import { NgModule, Pipe, PipeTransform } from '@angular/core'; import { RouterModule } from '@angular/router'; import { IonicModule } from '@ionic/angular'; import { TranslateModule } from '@ngx-translate/core'; -import { PoiComponent } from '@app/components/poi/poi.component'; import { TrekCardComponent } from '@app/components/trek-card/trek-card.component'; -import { CustomPipesModule } from './custom-pipes.module'; +@Pipe({ name: 'lowerRound' }) +export class LowerRoundPipe implements PipeTransform { + transform(value: number): number { + return Math.floor(value); + } +} @NgModule({ - declarations: [PoiComponent, TrekCardComponent], + declarations: [TrekCardComponent, LowerRoundPipe], imports: [ CommonModule, IonicModule, RouterModule, - TranslateModule.forChild(), - CustomPipesModule + TranslateModule.forChild() ], - exports: [PoiComponent, TrekCardComponent] + exports: [TrekCardComponent, LowerRoundPipe] }) export class SharedTreksModule {} diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts deleted file mode 100644 index 9c310661..00000000 --- a/src/app/shared/shared.module.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; -import { TranslateModule } from '@ngx-translate/core'; - -import { GeolocateNotificationsComponent } from '@app/components/geolocate-notifications/geolocate-notifications.component'; -import { MapTrekVizComponent } from '@app/components/map-trek-viz/map-trek-viz.component'; -import { MapTreksVizComponent } from '@app/components/map-treks-viz/map-treks-viz.component'; - -import { IonicModule } from '@ionic/angular'; - -@NgModule({ - declarations: [ - MapTreksVizComponent, - MapTrekVizComponent, - GeolocateNotificationsComponent - ], - imports: [CommonModule, IonicModule, TranslateModule.forChild()], - exports: [ - MapTreksVizComponent, - MapTrekVizComponent, - GeolocateNotificationsComponent - ] -}) -export class SharedModule {} diff --git a/src/global.scss b/src/global.scss index b4120e4e..c7107761 100644 --- a/src/global.scss +++ b/src/global.scss @@ -76,7 +76,6 @@ ion-fab { --max-width: none; } -// Pulse effect for geolocation marker .pulse, .pulse-and-view { position: relative; @@ -169,7 +168,6 @@ ion-fab-button { margin-bottom: 15px; } -// display modal with full size .full-size { .modal-wrapper { width: 100%; @@ -207,3 +205,12 @@ ion-fab-button { } } } + +.spinner-container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; +}