-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstructure-list.component.ts
75 lines (67 loc) · 2.42 KB
/
structure-list.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { Component, EventEmitter, Inject, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ButtonType } from '@gouvfr-anct/mediation-numerique/shared';
import { GeoJson } from '../../../map/models/geojson.model';
import { Structure } from '../../../map/models/structure.model';
import { StructureRepository, STRUCTURE_TOKEN } from '../../repositories/structure.repository';
@Component({
selector: 'app-structure-list',
templateUrl: './structure-list.component.html',
styleUrls: ['./structure-list.component.scss']
})
export class StructureListComponent implements OnChanges {
@Input() public structureList: Structure[];
@Input() public location: GeoJson;
@Input() public selectedStructure: Structure = new Structure();
@Output() public displayMapMarkerId: EventEmitter<string> = new EventEmitter<string>();
@Output() public selectedMarkerId: EventEmitter<string> = new EventEmitter<string>();
public buttonTypeEnum = ButtonType;
public showStructureDetails = false;
public structure: Structure;
constructor(
private route: ActivatedRoute,
private router: Router,
@Inject(STRUCTURE_TOKEN) readonly structureService: StructureRepository
) {
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) {
document.getElementById('listCard').scrollTo(0, 0);
}
}
public showDetails(event: Structure): void {
this.showStructureDetails = true;
this.structure = event;
this.selectedMarkerId.emit(this.structure._id);
}
public closeDetails(): void {
this.selectedMarkerId.emit();
this.showStructureDetails = false;
}
public handleCardHover(structure: Structure): void {
this.displayMapMarkerId.emit(structure._id);
}
public mouseLeave(): void {
this.displayMapMarkerId.emit(undefined);
}
}