From 1f1ffb94f5b08038fe800bd8df6fb710aa42869f Mon Sep 17 00:00:00 2001
From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com>
Date: Tue, 9 Mar 2021 14:21:52 +0100
Subject: [PATCH] fix(structure-details) : can go back on Home page

---
 .../components/card/card.component.ts         |  9 +++++++-
 .../structure-details.component.html          |  2 +-
 .../structure-details.component.scss          |  2 +-
 .../structure-details.component.ts            |  6 +++--
 .../structure-list.component.ts               | 22 ++++++++++++++++++-
 src/index.html                                |  1 -
 6 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/src/app/structure-list/components/card/card.component.ts b/src/app/structure-list/components/card/card.component.ts
index ed8b3158f..94440ab2d 100644
--- a/src/app/structure-list/components/card/card.component.ts
+++ b/src/app/structure-list/components/card/card.component.ts
@@ -1,4 +1,5 @@
 import { Component, Input, Output, OnInit, EventEmitter } from '@angular/core';
+import { ActivatedRoute, Router } from '@angular/router';
 import { Structure } from '../../../models/structure.model';
 import { GeojsonService } from '../../../services/geojson.service';
 
@@ -12,7 +13,7 @@ export class CardComponent implements OnInit {
   @Output() public showDetails: EventEmitter<Structure> = new EventEmitter<Structure>();
   @Output() public hover: EventEmitter<Structure> = new EventEmitter<Structure>();
 
-  constructor(private geoJsonService: GeojsonService) {}
+  constructor(private route: ActivatedRoute, private router: Router) {}
   ngOnInit(): void {}
 
   /**
@@ -28,6 +29,12 @@ export class CardComponent implements OnInit {
 
   public cardClicked(): void {
     this.showDetails.emit(this.structure);
+    this.router.navigate([], {
+      relativeTo: this.route,
+      queryParams: {
+        id: this.structure._id,
+      },
+    });
   }
 
   public cardHover(): void {
diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html
index 99d3963e8..160c48a0b 100644
--- a/src/app/structure-list/components/structure-details/structure-details.component.html
+++ b/src/app/structure-list/components/structure-details/structure-details.component.html
@@ -1,7 +1,7 @@
 <div class="structrue-details-container" *ngIf="structure && !isLoading">
   <!-- Header info -->
   <div fxLayout="row" fxLayoutAlign="end center">
-    <div (click)="close(false)" class="ico-close-details"></div>
+    <div (click)="close()" class="ico-close-details"></div>
   </div>
   <div fxLayout="row" class="structure-details-block" fxLayoutAlign="baseline baseline" fxLayoutGap="8px">
     <div fxLayout="column" fxLayoutGap="10px" fxFlex="100%">
diff --git a/src/app/structure-list/components/structure-details/structure-details.component.scss b/src/app/structure-list/components/structure-details/structure-details.component.scss
index 19284a7cc..77a9025cc 100644
--- a/src/app/structure-list/components/structure-details/structure-details.component.scss
+++ b/src/app/structure-list/components/structure-details/structure-details.component.scss
@@ -18,7 +18,7 @@ a {
   left: 0;
   max-width: 980px;
   width: 100%;
-  height: calc(100vh - #{$header-height} - #{$footer-height});
+  height: calc(100vh - #{$header-height} - #{$footer-height} - 20px);
   padding: 10px 24px;
   overflow: auto;
   @media #{$tablet} {
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 215f44fa9..2bea610b8 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
@@ -107,8 +107,10 @@ export class StructureDetailsComponent implements OnInit {
     }
   }
 
-  public close(refreshRequired: boolean): void {
-    this.closeDetails.emit(refreshRequired);
+  public close(): void {
+    this.router.navigate([], {
+      relativeTo: this.route,
+    });
   }
 
   public print(): void {
diff --git a/src/app/structure-list/structure-list.component.ts b/src/app/structure-list/structure-list.component.ts
index 45624ec9e..22404f28f 100644
--- a/src/app/structure-list/structure-list.component.ts
+++ b/src/app/structure-list/structure-list.component.ts
@@ -3,6 +3,8 @@ import { Filter } from './models/filter.model';
 import { Structure } from '../models/structure.model';
 import { GeoJson } from '../map/models/geojson.model';
 import * as _ from 'lodash';
+import { ActivatedRoute, Router } from '@angular/router';
+import { StructureService } from '../services/structure.service';
 
 @Component({
   selector: 'app-structure-list',
@@ -28,11 +30,29 @@ export class StructureListComponent implements OnChanges {
   private arrayChunked: Structure[][] = [];
   private chunck = 10;
 
-  constructor() {}
+  constructor(private route: ActivatedRoute, private router: Router, private structureService: StructureService) {
+    this.route.queryParams.subscribe((queryParams) => {
+      if (queryParams.id) {
+        if (!this.structure) {
+          this.structureService.getStructure(queryParams.id).subscribe((s) => {
+            this.showDetails(new Structure(s));
+          });
+        }
+      } else {
+        this.closeDetails();
+      }
+    });
+  }
 
   ngOnChanges(changes: SimpleChanges): void {
     if (changes.selectedStructure && this.selectedStructure) {
       this.showDetails(this.selectedStructure);
+      this.router.navigate([], {
+        relativeTo: this.route,
+        queryParams: {
+          id: this.selectedStructure._id,
+        },
+      });
     }
     if (changes.structureList) {
       this.structuresListChunked = this.chunckAnArray(this.structureList);
diff --git a/src/index.html b/src/index.html
index 17a60d8dc..51427aa9d 100644
--- a/src/index.html
+++ b/src/index.html
@@ -11,7 +11,6 @@
       content="Plateforme à destination des acteurs de l'inclusion numérique de la métropole de Lyon"
     />
     <meta property="og:image" content="https://resin.grandlyon.com/assets/logos/logo_1200.svg" />
-    >
 
     <link rel="icon" type="image/x-icon" href="favicon.ico" />
     <link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css" />
-- 
GitLab