diff --git a/src/app/admin/components/panel/panel.component.ts b/src/app/admin/components/panel/panel.component.ts index 8168d693ff69afe60a5cc27e3b4fe21b64b05d5f..47b40251964500a0383d05f090ba24f22c253204 100644 --- a/src/app/admin/components/panel/panel.component.ts +++ b/src/app/admin/components/panel/panel.component.ts @@ -17,7 +17,7 @@ export class PanelComponent implements OnInit { this.selectedFeature = this.features.pendingStructures; } - public changeActiveFeature(newFeature: AdminPannelEnum) { + public changeActiveFeature(newFeature: AdminPannelEnum): void { this.selectedFeature = newFeature; } } diff --git a/src/app/carto/carto.component.ts b/src/app/carto/carto.component.ts index d55b420b7a1fb498be0ff97edfc08ae2d418f814..5d771dc45acd6db12c09c7197780d546c264bf86 100644 --- a/src/app/carto/carto.component.ts +++ b/src/app/carto/carto.component.ts @@ -8,6 +8,7 @@ import { Filter } from '../structure-list/models/filter.model'; import { GeoJson } from '../map/models/geojson.model'; import { GeojsonService } from '../services/geojson.service'; import { CustomRegExp } from '../utils/CustomRegExp'; +import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-carto', @@ -26,14 +27,21 @@ export class CartoComponent implements OnInit { public isMapPhone = false; public searchedValue = null; public locate = false; // Use to sync location between search and map - constructor(private structureService: StructureService, private geoJsonService: GeojsonService) {} + constructor( + private structureService: StructureService, + private geoJsonService: GeojsonService, + private activatedRoute: ActivatedRoute + ) {} ngOnInit(): void { - if (navigator.geolocation) { - this.getLocation(); - } else { - this.getStructures(null); + if (!this.activatedRoute.snapshot.queryParamMap.get('search')) { + if (navigator.geolocation) { + this.getLocation(); + } else { + this.getStructures(null); + } } + if (history.state.data) { this.currentStructure = new Structure(history.state.data); } diff --git a/src/app/structure-list/components/card/card.component.ts b/src/app/structure-list/components/card/card.component.ts index 5d2d7dd66fe0eb2dbe425cde4abf40b12f37de20..8a1b657e1851ff7c44558373391bea4b6ee73ee9 100644 --- a/src/app/structure-list/components/card/card.component.ts +++ b/src/app/structure-list/components/card/card.component.ts @@ -45,11 +45,17 @@ export class CardComponent implements OnInit { public cardClicked(): void { this.showDetails.emit(this.structure); + const queryString = this.route.snapshot.queryParamMap.get('search'); this.router.navigate([], { relativeTo: this.route, - queryParams: { - id: this.structure._id, - }, + queryParams: queryString + ? { + id: this.structure._id, + search: queryString, + } + : { + id: this.structure._id, + }, }); } diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts index 0382434a55cb76db398f6ff96653f9ccd5be14da..17d8d6b2a032c5518f60a0b4b1682b825048e2ab 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.ts @@ -130,8 +130,12 @@ export class StructureDetailsComponent implements OnInit { } public close(): void { - this.router.navigate([], { + this.router.navigate(['/acteurs'], { relativeTo: this.route, + queryParams: { + id: null, + }, + queryParamsHandling: 'merge', }); } diff --git a/src/app/structure-list/components/structure-list-search/structure-list-search.component.ts b/src/app/structure-list/components/structure-list-search/structure-list-search.component.ts index ad0bdcf73ec395751bff0c3c55e5fe169aaa745b..e38926865d1b586bd40aa359accd6bdd5b91e90d 100644 --- a/src/app/structure-list/components/structure-list-search/structure-list-search.component.ts +++ b/src/app/structure-list/components/structure-list-search/structure-list-search.component.ts @@ -9,6 +9,8 @@ import { Filter } from '../../models/filter.model'; import { Module } from '../../models/module.model'; import { StructureCounter } from '../../models/structureCounter.model'; import { SearchService } from '../../services/search.service'; +import { Location } from '@angular/common'; +import { ActivatedRoute, Router } from '@angular/router'; @Component({ selector: 'app-structure-list-search', @@ -36,20 +38,35 @@ export class StructureListSearchComponent implements OnInit, OnChanges { public numberAccompanimentChecked = 0; public numberMoreFiltersChecked = 0; + public queryString: string; // Modal confirmation variable public isConfirmationModalOpen = false; public confirmationModalContent = 'Afin d’ajouter votre structure,vous allez être redirigé vers le formulaire Grand Lyon à remplir.'; - constructor(public searchService: SearchService, private fb: FormBuilder, private geoJsonService: GeojsonService) { + constructor( + public searchService: SearchService, + private fb: FormBuilder, + private geoJsonService: GeojsonService, + private activatedRoute: ActivatedRoute, + private location: Location, + private route: ActivatedRoute, + private router: Router + ) { this.searchForm = this.fb.group({ searchTerm: '', }); } ngOnInit(): void { // Will store the different categories + this.queryString = this.activatedRoute.snapshot.queryParamMap.get('search'); this.categories = []; this.checkedModulesFilter = new Array(); + if (this.queryString) { + const filters: Filter[] = []; + filters.push(new Filter('query', this.queryString)); + this.searchEvent.emit(filters); + } } ngOnChanges(changes: SimpleChanges): void { @@ -75,6 +92,15 @@ export class StructureListSearchComponent implements OnInit, OnChanges { // Sends an array containing all filters public applyFilter(term: string): void { // Add search input filter + if (term) { + this.router.navigate(['/acteurs'], { + relativeTo: this.route, + queryParams: { + search: term, + }, + queryParamsHandling: 'merge', + }); + } const filters: Filter[] = []; if (term) { filters.push(new Filter('query', term)); diff --git a/src/app/structure-list/structure-list.component.html b/src/app/structure-list/structure-list.component.html index 951c2726ab0b736b89d2a13bba450c674e46b033..1b39ec645a918b527da515ed058348472ef6b30f 100644 --- a/src/app/structure-list/structure-list.component.html +++ b/src/app/structure-list/structure-list.component.html @@ -16,7 +16,7 @@ <app-card *ngFor="let structure of structuresListChunked" [structure]="structure" - (showDetails)="showDetails($event)" + (showDetails)="showDetails($event, filters)" (hover)="handleCardHover($event)" ></app-card> <p *ngIf="structureList && structureList.length <= 0">Il n'y a aucune réponse correspondant à votre recherche</p>