1
|
import { Component, DoCheck, OnInit, ViewEncapsulation } from '@angular/core';
|
2
|
import { DataService } from '../../services/data.service';
|
3
|
import { CountryOverview, OverviewData } from '../../domain/overview-data';
|
4
|
import {CountryOverviewData, EuropeData, SelectedCountry} from '../../domain/overview-map-data';
|
5
|
import {DataHandlerService} from '../../services/data-handler.service';
|
6
|
|
7
|
@Component({
|
8
|
selector: 'app-home',
|
9
|
templateUrl: './home.component.html',
|
10
|
})
|
11
|
|
12
|
export class HomeComponent implements OnInit {
|
13
|
|
14
|
// overviewData: OverviewData;
|
15
|
|
16
|
europeOverviewData: EuropeData;
|
17
|
|
18
|
selectedCountry: SelectedCountry = null;
|
19
|
selectedCountryData: CountryOverviewData = null;
|
20
|
|
21
|
// countrySelectedName: string = null;
|
22
|
// countrySelectedOverview: CountryOverview = null;
|
23
|
|
24
|
constructor(private dataService: DataService,
|
25
|
private dataHandlerService: DataHandlerService) { }
|
26
|
|
27
|
ngOnInit(): void {
|
28
|
|
29
|
window.scroll(0, 0);
|
30
|
|
31
|
this.dataService.getEuropeOverviewData().subscribe(
|
32
|
rawData => {
|
33
|
this.europeOverviewData = this.dataHandlerService.convertRawDataToEuropeOverviewData(rawData);
|
34
|
}, error => {
|
35
|
console.log(error);
|
36
|
}
|
37
|
);
|
38
|
|
39
|
// this.dataService.getOverviewData().subscribe(
|
40
|
// overviewData => {
|
41
|
// this.overviewData = overviewData;
|
42
|
// },
|
43
|
// error => {
|
44
|
// console.log(error);
|
45
|
// }
|
46
|
// );
|
47
|
}
|
48
|
|
49
|
countrySelected(selectedCountry: SelectedCountry) {
|
50
|
this.selectedCountry = selectedCountry;
|
51
|
this.selectedCountryData = null;
|
52
|
|
53
|
this.dataService.getCountryOverviewData(this.selectedCountry.code).subscribe(
|
54
|
rawData => {
|
55
|
this.selectedCountryData = this.dataHandlerService.convertRawDataToCountryOverviewData(rawData);
|
56
|
}, error => {
|
57
|
console.log(error);
|
58
|
}
|
59
|
);
|
60
|
|
61
|
|
62
|
// this.countrySelectedOverview = this.overviewData.countries.filter(x => x.country === this.selectedCountry.name)[0];
|
63
|
// console.log('Country selected overview: ', this.countrySelectedOverview);
|
64
|
}
|
65
|
|
66
|
deselectCountry() {
|
67
|
|
68
|
this.selectedCountry = null;
|
69
|
this.selectedCountryData = null;
|
70
|
|
71
|
// this.countrySelectedName = null;
|
72
|
// this.countrySelectedOverview = null;
|
73
|
}
|
74
|
}
|