1
|
/*
|
2
|
* created by myrto on 12/12/2017
|
3
|
*/
|
4
|
|
5
|
import { Component, OnInit } from '@angular/core';
|
6
|
import { Country, Repository } from '../../../domain/typeScriptClasses';
|
7
|
import { RepositoryService } from '../../../services/repository.service';
|
8
|
import { Subject } from 'rxjs/Subject';
|
9
|
/*
|
10
|
import { Observable } from 'rxjs/Observable';
|
11
|
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
|
12
|
*/
|
13
|
|
14
|
@Component ({
|
15
|
selector:'app-sr-literature',
|
16
|
templateUrl: 'sr-literature.component.html'
|
17
|
})
|
18
|
|
19
|
export class SRLiteratureComponent implements OnInit {
|
20
|
countries: Country[] = [];
|
21
|
hasSelectedCountry: boolean;
|
22
|
selectedCountry: string;
|
23
|
countryRepos: Repository[] = [];
|
24
|
noRepositories: boolean;
|
25
|
hasSelectedRepo: boolean;
|
26
|
showAlert: boolean;
|
27
|
showSpinner: boolean;
|
28
|
private searchString = new Subject<string>();
|
29
|
|
30
|
|
31
|
constructor(private repoService:RepositoryService) {}
|
32
|
|
33
|
ngOnInit() {
|
34
|
this.getCountries();
|
35
|
this.hasSelectedCountry = false;
|
36
|
this.selectedCountry = '';
|
37
|
this.noRepositories = false;
|
38
|
this.showAlert = false;
|
39
|
}
|
40
|
|
41
|
getCountries(){
|
42
|
this.repoService.getCountries()
|
43
|
.subscribe(countries => this.countries = countries.sort( function(a,b){
|
44
|
if(a.name<b.name){
|
45
|
return -1;
|
46
|
} else if(a.name>b.name){
|
47
|
return 1;
|
48
|
} else {
|
49
|
return 0;
|
50
|
}
|
51
|
} ));
|
52
|
}
|
53
|
|
54
|
getReposInCountry(country: string, mode: string){
|
55
|
console.log(`I got ${country} and ${mode}`);
|
56
|
this.countryRepos = [];
|
57
|
this.noRepositories = false;
|
58
|
this.hasSelectedCountry = true;
|
59
|
this.selectedCountry = country;
|
60
|
this.showSpinner = true;
|
61
|
this.repoService.getRepositoriesOfCountry(country,mode).subscribe(
|
62
|
repos => this.countryRepos = repos,
|
63
|
error => console.log(error),
|
64
|
() => {
|
65
|
if (!this.countryRepos.length) this.noRepositories = true;
|
66
|
this.showSpinner = false;
|
67
|
this.showAlert = false;
|
68
|
}
|
69
|
);
|
70
|
}
|
71
|
|
72
|
onChooseRepository(){
|
73
|
this.hasSelectedRepo = true;
|
74
|
this.showAlert = false;
|
75
|
}
|
76
|
|
77
|
goToNextStep(){
|
78
|
if(!this.hasSelectedRepo || this.noRepositories){
|
79
|
this.showAlert = true;
|
80
|
} else {
|
81
|
//move to the next step
|
82
|
}
|
83
|
}
|
84
|
|
85
|
refreshSearch(term: string): void {
|
86
|
/*this.searchString.next(term);*/
|
87
|
console.log(`read ${term}`)
|
88
|
}
|
89
|
/*
|
90
|
searchRepo(): void {
|
91
|
this.searchString.pipe(
|
92
|
debounceTime(500),
|
93
|
distinctUntilChanged(),
|
94
|
switchMap((term: string) => this.countryRepos.filter(
|
95
|
repo => repo.officialName.includes(term)
|
96
|
) )
|
97
|
);
|
98
|
}*/
|
99
|
|
100
|
}
|