Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { DataService } from '../../services/data.service';
3
import { CountryOverviewData, EuropeData, SelectedCountry } from '../../domain/overview-map-data';
4
import { DataHandlerService } from '../../services/data-handler.service';
5
import { countries } from '../../domain/countries';
6
import { Router } from '@angular/router';
7

    
8
@Component({
9
  selector: 'app-home',
10
  templateUrl: './home.component.html',
11
})
12

    
13
export class HomeComponent implements OnInit {
14

    
15
  europeOverviewData: EuropeData;
16

    
17
  selectedCountry: SelectedCountry = null;
18
  selectedCountryData: CountryOverviewData = null;
19

    
20
  leadingOpenScienceData: CountryOverviewData[];
21

    
22
  countriesCollection = countries;
23
  keyword = 'name';
24

    
25
  constructor(private dataService: DataService,
26
              private dataHandlerService: DataHandlerService,
27
              private router: Router) { }
28

    
29
  ngOnInit(): void {
30

    
31
    window.scroll(0, 0);
32

    
33
    // const searchIcon = document.getElementById('search-icon');
34
    // const inputContainer = document.getElementsByClassName('input-container')[0];
35
    // inputContainer.insertAdjacentElement('afterbegin', searchIcon);
36

    
37
    this.dataService.getEuropeOverviewData().subscribe(
38
      rawData => {
39
        this.europeOverviewData = this.dataHandlerService.convertRawDataToEuropeOverviewData(rawData);
40
      }, error => {
41
        console.log(error);
42
      }
43
    );
44

    
45
    this.dataService.getLeadingOpenScienceMobileData().subscribe(
46
      rawData => {
47
        this.leadingOpenScienceData = this.dataHandlerService.convertRawDataToLeadingOpenScienceData(rawData);
48
      }, error => {
49
        console.log(error);
50
      }
51
    );
52
  }
53

    
54
  countrySelected(selectedCountry: SelectedCountry) {
55
    this.selectedCountry = selectedCountry;
56
    this.selectedCountryData = null;
57

    
58
    this.dataService.getCountryOverviewData(this.selectedCountry.code).subscribe(
59
      rawData => {
60
        this.selectedCountryData = this.dataHandlerService.convertRawDataToCountryOverviewData(rawData);
61
      }, error => {
62
        console.log(error);
63
      }
64
    );
65
  }
66

    
67
  deselectCountry() {
68
    this.selectedCountry = null;
69
    this.selectedCountryData = null;
70
  }
71

    
72

    
73
  selectCountryFromAutocompleteEvent(item) {
74
    // do something with selected item
75
    // console.log('country selected: ', item);
76
    this.router.navigate([`/countryDashboard/${item.id}`]);
77
  }
78

    
79
  onChangeSearch(search: string) {
80
    // fetch remote data from here
81
    // And reassign the 'data' which is binded to 'data' property.
82
  }
83

    
84
  onFocused(e) {
85
    // do something
86
  }
87
}
(12-12/12)