1
|
/*
|
2
|
* created by myrto on 1/22/2018
|
3
|
*/
|
4
|
|
5
|
import { Component, OnInit } from '@angular/core';
|
6
|
import { formErrorRequiredFields, formSuccessRegisteredDatasource, noServiceMessage } from '../../../domain/shared-messages';
|
7
|
import { RepositoryService } from "../../../services/repository.service";
|
8
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
9
|
import { Country, Repository } from '../../../domain/typeScriptClasses';
|
10
|
import { typologies } from '../../../domain/typologies';
|
11
|
import { timezones } from '../../../domain/timezones';
|
12
|
import {
|
13
|
Description,
|
14
|
softwarePlatformDesc,
|
15
|
platformNameDesc,
|
16
|
officialNameDesc,
|
17
|
repoDescriptionDesc,
|
18
|
countryDesc,
|
19
|
longtitudeDesc,
|
20
|
latitudeDesc,
|
21
|
websiteUrlDesc,
|
22
|
institutionNameDesc,
|
23
|
englishNameDesc,
|
24
|
logoUrlDesc,
|
25
|
timezoneDesc,
|
26
|
aggregatorTypeDesc,
|
27
|
adminEmailDesc
|
28
|
} from '../../../domain/oa-description';
|
29
|
|
30
|
@Component ({
|
31
|
selector: 'aggregator-info-form',
|
32
|
templateUrl: 'aggregator-info-form.component.html'
|
33
|
})
|
34
|
|
35
|
export class AggregatorInfoFormComponent implements OnInit {
|
36
|
errorMessage: string;
|
37
|
successMessage: string;
|
38
|
showSpinner: boolean;
|
39
|
loadingMessage: string;
|
40
|
|
41
|
typologies = typologies;
|
42
|
timezones = timezones;
|
43
|
countries: Country[] = [];
|
44
|
datasourceClasses: Map<string,string> = new Map<string,string>();
|
45
|
classCodes: string[] = [];
|
46
|
|
47
|
newDatasource: Repository;
|
48
|
|
49
|
group: FormGroup;
|
50
|
readonly groupDefinition = {
|
51
|
softwarePlatform : '',
|
52
|
platformName : '',
|
53
|
officialName : ['', Validators.required],
|
54
|
repoDescription : ['', Validators.required],
|
55
|
country : ['', Validators.required],
|
56
|
longtitude : ['', [Validators.required, Validators.maxLength(9), Validators.min(-180), Validators.max(180)] ],
|
57
|
latitude : ['', [Validators.required, Validators.maxLength(9), Validators.min(-90), Validators.max(90)] ],
|
58
|
websiteUrl : ['', Validators.required],
|
59
|
institutionName : ['', Validators.required],
|
60
|
englishName: ['', Validators.required],
|
61
|
logoUrl: '',
|
62
|
timezone: ['', Validators.required],
|
63
|
aggregatorType: ['', Validators.required],
|
64
|
adminEmail: ['', [Validators.required, Validators.email] ]
|
65
|
};
|
66
|
|
67
|
softwarePlatformDesc : Description = softwarePlatformDesc;
|
68
|
platformNameDesc : Description = platformNameDesc;
|
69
|
officialNameDesc : Description = officialNameDesc;
|
70
|
repoDescriptionDesc : Description = repoDescriptionDesc;
|
71
|
countryDesc : Description = countryDesc;
|
72
|
longtitudeDesc : Description = longtitudeDesc;
|
73
|
latitudeDesc : Description = latitudeDesc;
|
74
|
websiteUrlDesc : Description = websiteUrlDesc;
|
75
|
institutionNameDesc : Description = institutionNameDesc;
|
76
|
englishNameDesc : Description = englishNameDesc;
|
77
|
logoUrlDesc : Description = logoUrlDesc;
|
78
|
timezoneDesc : Description = timezoneDesc;
|
79
|
aggregatorTypeDesc : Description = aggregatorTypeDesc;
|
80
|
adminEmailDesc : Description = adminEmailDesc;
|
81
|
|
82
|
|
83
|
constructor(
|
84
|
private fb: FormBuilder,
|
85
|
private repoService: RepositoryService
|
86
|
) {}
|
87
|
|
88
|
ngOnInit() {
|
89
|
this.loadForm();
|
90
|
}
|
91
|
|
92
|
loadForm(){
|
93
|
this.group = this.fb.group(this.groupDefinition);
|
94
|
this.getCountries();
|
95
|
this.getDatasourceClasses();
|
96
|
}
|
97
|
|
98
|
getCountries(){
|
99
|
this.repoService.getCountries()
|
100
|
.subscribe(
|
101
|
countries => this.countries = countries.sort( function(a,b){
|
102
|
if(a.name<b.name){
|
103
|
return -1;
|
104
|
} else if(a.name>b.name){
|
105
|
return 1;
|
106
|
} else {
|
107
|
return 0;
|
108
|
}
|
109
|
} ),
|
110
|
error => {
|
111
|
this.errorMessage = noServiceMessage;
|
112
|
console.log(error);
|
113
|
});
|
114
|
}
|
115
|
|
116
|
getDatasourceClasses() {
|
117
|
this.repoService.getDatasourceClasses('aggregator').subscribe(
|
118
|
classes => this.datasourceClasses = classes,
|
119
|
error => {
|
120
|
this.errorMessage = noServiceMessage;
|
121
|
console.log(error);
|
122
|
},
|
123
|
() => {
|
124
|
for (let key in this.datasourceClasses){
|
125
|
this.classCodes.push(key);
|
126
|
}
|
127
|
}
|
128
|
);
|
129
|
}
|
130
|
|
131
|
registerDatasource(): boolean {
|
132
|
if(this.group.valid){
|
133
|
this.successMessage = formSuccessRegisteredDatasource;
|
134
|
this.errorMessage = '';
|
135
|
return true;
|
136
|
} else {
|
137
|
this.errorMessage = formErrorRequiredFields;
|
138
|
this.successMessage = '';
|
139
|
return false;
|
140
|
}
|
141
|
}
|
142
|
}
|