1
|
import {Component, OnInit} from '@angular/core';
|
2
|
import {noServiceMessage} from '../../domain/shared-messages';
|
3
|
import {Country, RepositorySnippet} from '../../domain/typeScriptClasses';
|
4
|
import {RepositoryService} from '../../services/repository.service';
|
5
|
import {FormBuilder, FormGroup} from '@angular/forms';
|
6
|
|
7
|
@Component({
|
8
|
selector: 'app-registration',
|
9
|
templateUrl: 'registration.component.html'
|
10
|
})
|
11
|
|
12
|
export class RegistrationComponent implements OnInit {
|
13
|
|
14
|
errorMessage: string;
|
15
|
successMessage: string;
|
16
|
loadingMessage: string;
|
17
|
countries: Country[] = [];
|
18
|
repositorySnippet: RepositorySnippet[] = [];
|
19
|
|
20
|
formPrepare = {
|
21
|
country: '',
|
22
|
typology: '',
|
23
|
englishname: '',
|
24
|
officialname: '',
|
25
|
requestSortBy: 'registrationdate',
|
26
|
order: 'DESCENDING',
|
27
|
page: '0',
|
28
|
pageSize: '25'
|
29
|
};
|
30
|
|
31
|
dataForm: FormGroup;
|
32
|
|
33
|
constructor(private repoService: RepositoryService,
|
34
|
private fb: FormBuilder) {
|
35
|
}
|
36
|
|
37
|
ngOnInit() {
|
38
|
this.dataForm = this.fb.group(this.formPrepare);
|
39
|
|
40
|
this.getCountries();
|
41
|
this.getRegisteredRepositories();
|
42
|
|
43
|
}
|
44
|
|
45
|
getCountries() {
|
46
|
this.repoService.getCountries()
|
47
|
.subscribe(
|
48
|
countries => this.countries = countries.sort(function (a, b) {
|
49
|
if (a.name < b.name) {
|
50
|
return -1;
|
51
|
} else if (a.name > b.name) {
|
52
|
return 1;
|
53
|
} else {
|
54
|
return 0;
|
55
|
}
|
56
|
}),
|
57
|
error => {
|
58
|
this.loadingMessage = '';
|
59
|
this.errorMessage = noServiceMessage;
|
60
|
console.log(error);
|
61
|
},
|
62
|
);
|
63
|
}
|
64
|
|
65
|
getRegisteredRepositories() {
|
66
|
this.repoService.searchRegisteredRepositories(this.dataForm.get('country').value, this.dataForm.get('typology').value, this.dataForm.get('englishname').value,
|
67
|
this.dataForm.get('officialname').value, this.dataForm.get('requestSortBy').value, this.dataForm.get('order').value, this.dataForm.get('page').value,
|
68
|
this.dataForm.get('pageSize').value).subscribe(
|
69
|
suc => this.repositorySnippet = suc,
|
70
|
error => console.log(error),
|
71
|
() => console.log(this.repositorySnippet)
|
72
|
);
|
73
|
}
|
74
|
|
75
|
handleChange() {
|
76
|
this.getRegisteredRepositories();
|
77
|
}
|
78
|
|
79
|
}
|