|
|
@ -1,8 +1,12 @@
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
import { CommonModule, ViewportScroller } from '@angular/common';
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
|
|
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
|
|
|
|
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
|
|
|
|
|
|
|
|
import { NavigationEnd, Router } from '@angular/router';
|
|
|
|
|
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
|
|
|
|
import { filter } from 'rxjs/operators';
|
|
|
|
import { Pin } from '../../model/Pin';
|
|
|
|
import { Pin } from '../../model/Pin';
|
|
|
|
import { ImageService } from '../../services/image/image.service';
|
|
|
|
import { ImageService } from '../../services/image/image.service';
|
|
|
|
|
|
|
|
import { ModalService } from '../../services/modal/modal.service';
|
|
|
|
import { PinService } from '../../services/pin/pin.service';
|
|
|
|
import { PinService } from '../../services/pin/pin.service';
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
@ -11,7 +15,7 @@ import { PinService } from '../../services/pin/pin.service';
|
|
|
|
imports: [CommonModule],
|
|
|
|
imports: [CommonModule],
|
|
|
|
templateUrl: './timeline.component.html',
|
|
|
|
templateUrl: './timeline.component.html',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class TimelineComponent implements OnInit {
|
|
|
|
export class TimelineComponent implements OnInit, OnDestroy {
|
|
|
|
pins: Pin[] = [];
|
|
|
|
pins: Pin[] = [];
|
|
|
|
imageUrls: SafeUrl[][] = [];
|
|
|
|
imageUrls: SafeUrl[][] = [];
|
|
|
|
loading = true;
|
|
|
|
loading = true;
|
|
|
@ -19,12 +23,52 @@ export class TimelineComponent implements OnInit {
|
|
|
|
sortedYears: string[] = [];
|
|
|
|
sortedYears: string[] = [];
|
|
|
|
carouselIndexes: number[] = [];
|
|
|
|
carouselIndexes: number[] = [];
|
|
|
|
expandedDescriptions: { [index: number]: boolean } = {};
|
|
|
|
expandedDescriptions: { [index: number]: boolean } = {};
|
|
|
|
|
|
|
|
private navigationSubscription: Subscription;
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
constructor(
|
|
|
|
private pinService: PinService,
|
|
|
|
private pinService: PinService,
|
|
|
|
private imageService: ImageService,
|
|
|
|
private imageService: ImageService,
|
|
|
|
private sanitizer: DomSanitizer
|
|
|
|
private sanitizer: DomSanitizer,
|
|
|
|
) {}
|
|
|
|
private modalService: ModalService,
|
|
|
|
|
|
|
|
private router: Router,
|
|
|
|
|
|
|
|
private viewportScroller: ViewportScroller
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
// Écouter les événements de navigation
|
|
|
|
|
|
|
|
this.navigationSubscription = this.router.events
|
|
|
|
|
|
|
|
.pipe(filter((event) => event instanceof NavigationEnd))
|
|
|
|
|
|
|
|
.subscribe(() => {
|
|
|
|
|
|
|
|
// Attendre que le contenu soit chargé
|
|
|
|
|
|
|
|
if (!this.loading) {
|
|
|
|
|
|
|
|
this.restoreScrollPosition();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
|
|
|
// Nettoyer la souscription lors de la destruction du composant
|
|
|
|
|
|
|
|
if (this.navigationSubscription) {
|
|
|
|
|
|
|
|
this.navigationSubscription.unsubscribe();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private restoreScrollPosition() {
|
|
|
|
|
|
|
|
const scrollPosition = sessionStorage.getItem('timelineScrollPosition');
|
|
|
|
|
|
|
|
if (scrollPosition) {
|
|
|
|
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
|
|
|
|
this.viewportScroller.scrollToPosition([0, parseInt(scrollPosition)]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
openPinModal() {
|
|
|
|
|
|
|
|
this.modalService.openModal('add-pin-modal');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
navigateToPinOnMap(pinId: string) {
|
|
|
|
|
|
|
|
const scrollPosition = window.scrollY;
|
|
|
|
|
|
|
|
sessionStorage.setItem('timelineScrollPosition', scrollPosition.toString());
|
|
|
|
|
|
|
|
this.router.navigate(['/map'], { queryParams: { pin: pinId } });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.pinService.getPins().subscribe((pins: Pin[]) => {
|
|
|
|
this.pinService.getPins().subscribe((pins: Pin[]) => {
|
|
|
@ -46,10 +90,11 @@ export class TimelineComponent implements OnInit {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.carouselIndexes = this.pins.map(() => 0);
|
|
|
|
this.carouselIndexes = this.pins.map(() => 0);
|
|
|
|
|
|
|
|
|
|
|
|
this.loading = false;
|
|
|
|
this.loading = false;
|
|
|
|
|
|
|
|
|
|
|
|
this.groupPinsByYear();
|
|
|
|
this.groupPinsByYear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Restaurer la position de défilement après le chargement initial
|
|
|
|
|
|
|
|
this.restoreScrollPosition();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -69,7 +114,7 @@ export class TimelineComponent implements OnInit {
|
|
|
|
this.groupedPins[year].sort((a, b) => a.date!.localeCompare(b.date!));
|
|
|
|
this.groupedPins[year].sort((a, b) => a.date!.localeCompare(b.date!));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Trie les années dans l’ordre croissant (utilisé dans le template)
|
|
|
|
// Trie les années dans l'ordre croissant (utilisé dans le template)
|
|
|
|
this.sortedYears = Object.keys(this.groupedPins).sort((a, b) => +a - +b);
|
|
|
|
this.sortedYears = Object.keys(this.groupedPins).sort((a, b) => +a - +b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|