From e2244d3d621880f056126bdf8b99eb0aa8e4c729 Mon Sep 17 00:00:00 2001 From: Antonin Coquet <ext.sopra.acoquet@grandlyon.com> Date: Mon, 12 Apr 2021 17:35:45 +0200 Subject: [PATCH 1/5] add querystring to route param --- .../components/search/search.component.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/app/structure-list/components/search/search.component.ts b/src/app/structure-list/components/search/search.component.ts index b743d1cfd..82e9ec82e 100644 --- a/src/app/structure-list/components/search/search.component.ts +++ b/src/app/structure-list/components/search/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 } from '@angular/router'; @Component({ selector: 'app-structure-list-search', @@ -36,20 +38,34 @@ export class SearchComponent implements OnInit, OnChanges { public numberAccompanimentChecked = 0; public numberMoreFiltersChecked = 0; + public queryString = 'placeholder'; // 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 + ) { 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) { + console.log('we search', this.queryString); + const filters: Filter[] = []; + filters.push(new Filter('query', this.queryString)); + this.searchEvent.emit(filters); + } } ngOnChanges(changes: SimpleChanges): void { @@ -75,6 +91,13 @@ export class SearchComponent implements OnInit, OnChanges { // Sends an array containing all filters public applyFilter(term: string): void { // Add search input filter + if (term) { + this.location.go('/acteurs?search=' + term); + } else { + this.location.go('/acteurs'); + } + this.queryString = this.activatedRoute.snapshot.queryParamMap.get('search'); + console.log('query string is:', this.queryString); const filters: Filter[] = []; if (term) { filters.push(new Filter('query', term)); -- GitLab From 0aca5b2128f5199ac20aad57d9e7743f7d60d135 Mon Sep 17 00:00:00 2001 From: Antonin Coquet <ext.sopra.acoquet@grandlyon.com> Date: Tue, 13 Apr 2021 10:49:42 +0200 Subject: [PATCH 2/5] fix auto reload of structure --- src/app/carto/carto.component.ts | 18 +++++++++++++----- .../components/search/search.component.ts | 2 -- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/app/carto/carto.component.ts b/src/app/carto/carto.component.ts index d55b420b7..5d771dc45 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/search/search.component.ts b/src/app/structure-list/components/search/search.component.ts index 82e9ec82e..a0a863b10 100644 --- a/src/app/structure-list/components/search/search.component.ts +++ b/src/app/structure-list/components/search/search.component.ts @@ -61,7 +61,6 @@ export class SearchComponent implements OnInit, OnChanges { this.categories = []; this.checkedModulesFilter = new Array(); if (this.queryString) { - console.log('we search', this.queryString); const filters: Filter[] = []; filters.push(new Filter('query', this.queryString)); this.searchEvent.emit(filters); @@ -97,7 +96,6 @@ export class SearchComponent implements OnInit, OnChanges { this.location.go('/acteurs'); } this.queryString = this.activatedRoute.snapshot.queryParamMap.get('search'); - console.log('query string is:', this.queryString); const filters: Filter[] = []; if (term) { filters.push(new Filter('query', term)); -- GitLab From 8e9f59796fb1da5a2bd5ebea900b521057231c03 Mon Sep 17 00:00:00 2001 From: Antonin Coquet <ext.sopra.acoquet@grandlyon.com> Date: Tue, 13 Apr 2021 11:03:41 +0200 Subject: [PATCH 3/5] remove useless lines --- src/app/structure-list/components/search/search.component.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app/structure-list/components/search/search.component.ts b/src/app/structure-list/components/search/search.component.ts index a0a863b10..e6011a8fe 100644 --- a/src/app/structure-list/components/search/search.component.ts +++ b/src/app/structure-list/components/search/search.component.ts @@ -38,7 +38,7 @@ export class SearchComponent implements OnInit, OnChanges { public numberAccompanimentChecked = 0; public numberMoreFiltersChecked = 0; - public queryString = 'placeholder'; + public queryString: string; // Modal confirmation variable public isConfirmationModalOpen = false; public confirmationModalContent = @@ -95,7 +95,6 @@ export class SearchComponent implements OnInit, OnChanges { } else { this.location.go('/acteurs'); } - this.queryString = this.activatedRoute.snapshot.queryParamMap.get('search'); const filters: Filter[] = []; if (term) { filters.push(new Filter('query', term)); -- GitLab From cd68c31ed73329d0ff244e92ce4bd7b9ef5059c2 Mon Sep 17 00:00:00 2001 From: Antonin Coquet <ext.sopra.acoquet@grandlyon.com> Date: Tue, 13 Apr 2021 17:21:57 +0200 Subject: [PATCH 4/5] fix: send query string to structure details components --- .../structure-list/components/card/card.component.ts | 12 +++++++++--- src/app/structure-list/structure-list.component.html | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/structure-list/components/card/card.component.ts b/src/app/structure-list/components/card/card.component.ts index 5d2d7dd66..8a1b657e1 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/structure-list.component.html b/src/app/structure-list/structure-list.component.html index 951c2726a..1b39ec645 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> -- GitLab From 4cafe7d707f9c90f7c6822520837248be9c568ec Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Wed, 14 Apr 2021 11:46:51 +0200 Subject: [PATCH 5/5] fix: search query param --- .../admin/components/panel/panel.component.ts | 3 +-- .../components/search/search.component.ts | 16 +++++++++++----- .../structure-details.component.ts | 6 +++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/app/admin/components/panel/panel.component.ts b/src/app/admin/components/panel/panel.component.ts index 15052b621..47b402519 100644 --- a/src/app/admin/components/panel/panel.component.ts +++ b/src/app/admin/components/panel/panel.component.ts @@ -15,10 +15,9 @@ export class PanelComponent implements OnInit { ngOnInit(): void { this.selectedFeature = this.features.pendingStructures; - console.log(this.ghostLink); } - public changeActiveFeature(newFeature: AdminPannelEnum) { + public changeActiveFeature(newFeature: AdminPannelEnum): void { this.selectedFeature = newFeature; } } diff --git a/src/app/structure-list/components/search/search.component.ts b/src/app/structure-list/components/search/search.component.ts index e6011a8fe..a95eacead 100644 --- a/src/app/structure-list/components/search/search.component.ts +++ b/src/app/structure-list/components/search/search.component.ts @@ -10,7 +10,7 @@ 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 } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; @Component({ selector: 'app-structure-list-search', @@ -49,7 +49,9 @@ export class SearchComponent implements OnInit, OnChanges { private fb: FormBuilder, private geoJsonService: GeojsonService, private activatedRoute: ActivatedRoute, - private location: Location + private location: Location, + private route: ActivatedRoute, + private router: Router ) { this.searchForm = this.fb.group({ searchTerm: '', @@ -91,9 +93,13 @@ export class SearchComponent implements OnInit, OnChanges { public applyFilter(term: string): void { // Add search input filter if (term) { - this.location.go('/acteurs?search=' + term); - } else { - this.location.go('/acteurs'); + this.router.navigate(['/acteurs'], { + relativeTo: this.route, + queryParams: { + search: term, + }, + queryParamsHandling: 'merge', + }); } const filters: Filter[] = []; if (term) { 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 79042b400..ae688aeaa 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 @@ -121,8 +121,12 @@ export class StructureDetailsComponent implements OnInit { } public close(): void { - this.router.navigate([], { + this.router.navigate(['/acteurs'], { relativeTo: this.route, + queryParams: { + id: null, + }, + queryParamsHandling: 'merge', }); } -- GitLab