1
|
import { Component, Input, OnInit } from '@angular/core';
|
2
|
import { formErrorRequiredFields, formSuccessUpdatedRepo } from '../../../domain/shared-messages';
|
3
|
import { RepositoryService } from "../../../services/repository.service";
|
4
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
5
|
import { Country, Repository } from '../../../domain/typeScriptClasses';
|
6
|
import {
|
7
|
Description,
|
8
|
softwarePlatformDesc,
|
9
|
platformNameDesc,
|
10
|
officialNameDesc,
|
11
|
repoDescriptionDesc,
|
12
|
countryDesc,
|
13
|
longtitudeDesc,
|
14
|
latitudeDesc,
|
15
|
websiteUrlDesc,
|
16
|
institutionNameDesc,
|
17
|
englishNameDesc,
|
18
|
logoUrlDesc,
|
19
|
timezoneDesc,
|
20
|
datasourceTypeDesc,
|
21
|
adminEmailDesc
|
22
|
} from '../../../domain/oa-description';
|
23
|
|
24
|
@Component ({
|
25
|
selector: 'datasource-info-form',
|
26
|
templateUrl: './datasource-info-form.component.html'
|
27
|
})
|
28
|
|
29
|
export class DatasourceInfoFormComponent implements OnInit {
|
30
|
|
31
|
errorMessage: string;
|
32
|
successMessage: string;
|
33
|
|
34
|
selectedRepo: Repository;
|
35
|
countries: Country[];
|
36
|
|
37
|
@Input() datasourceId: string;
|
38
|
|
39
|
updateGroup: FormGroup;
|
40
|
readonly updateGroupDefinition = {
|
41
|
softwarePlatform : '',
|
42
|
platformName : '',
|
43
|
officialName : '',
|
44
|
repoDescription : '',
|
45
|
country : '',
|
46
|
longtitude : '',
|
47
|
latitude : '',
|
48
|
websiteUrl : '',
|
49
|
institutionName : '',
|
50
|
englishName: ['', Validators.required],
|
51
|
logoUrl: '',
|
52
|
timezone: ['', Validators.required],
|
53
|
datasourceType: ['', Validators.required],
|
54
|
adminEmail: ['', Validators.required]
|
55
|
};
|
56
|
|
57
|
softwarePlatformDesc : Description = softwarePlatformDesc;
|
58
|
platformNameDesc : Description = platformNameDesc;
|
59
|
officialNameDesc : Description = officialNameDesc;
|
60
|
repoDescriptionDesc : Description = repoDescriptionDesc;
|
61
|
countryDesc : Description = countryDesc;
|
62
|
longtitudeDesc : Description = longtitudeDesc;
|
63
|
latitudeDesc : Description = latitudeDesc;
|
64
|
websiteUrlDesc : Description = websiteUrlDesc;
|
65
|
institutionNameDesc : Description = institutionNameDesc;
|
66
|
englishNameDesc : Description = englishNameDesc;
|
67
|
logoUrlDesc : Description = logoUrlDesc;
|
68
|
timezoneDesc : Description = timezoneDesc;
|
69
|
datasourceTypeDesc : Description = datasourceTypeDesc;
|
70
|
adminEmailDesc : Description = adminEmailDesc;
|
71
|
|
72
|
constructor(
|
73
|
private fb: FormBuilder,
|
74
|
private repoService: RepositoryService
|
75
|
) {}
|
76
|
|
77
|
ngOnInit(){
|
78
|
this.loadUpdateTab();
|
79
|
}
|
80
|
|
81
|
getRepo() {
|
82
|
this.repoService.getRepositoryById(this.datasourceId).subscribe(
|
83
|
repo => {
|
84
|
this.selectedRepo = repo;
|
85
|
if(this.selectedRepo) {
|
86
|
this.updateGroup.setValue({
|
87
|
softwarePlatform: '', //this.selectedRepo.WHICH FIELD ??
|
88
|
platformName: this.selectedRepo.typology,
|
89
|
officialName: this.selectedRepo.officialName,
|
90
|
repoDescription: this.selectedRepo.description,
|
91
|
country: this.selectedRepo.countryCode,
|
92
|
longtitude: this.selectedRepo.longitude,
|
93
|
latitude: this.selectedRepo.latitude,
|
94
|
websiteUrl: this.selectedRepo.websiteUrl,
|
95
|
institutionName: this.selectedRepo.organization,
|
96
|
englishName: this.selectedRepo.englishName,
|
97
|
logoUrl: this.selectedRepo.logoUrl,
|
98
|
timezone: this.selectedRepo.timezone,
|
99
|
datasourceType: this.selectedRepo.datasourceType,
|
100
|
adminEmail: this.selectedRepo.contactEmail
|
101
|
});
|
102
|
}
|
103
|
this.updateGroup.get('softwarePlatform').disable();
|
104
|
this.updateGroup.get('platformName').disable();
|
105
|
this.updateGroup.get('officialName').disable();
|
106
|
this.updateGroup.get('repoDescription').disable();
|
107
|
this.updateGroup.get('country').disable();
|
108
|
this.updateGroup.get('longtitude').disable();
|
109
|
this.updateGroup.get('latitude').disable();
|
110
|
this.updateGroup.get('websiteUrl').disable();
|
111
|
this.updateGroup.get('institutionName').disable();
|
112
|
},
|
113
|
error =>console.log(error)
|
114
|
)
|
115
|
}
|
116
|
|
117
|
getCountries() {
|
118
|
this.repoService.getCountries()
|
119
|
.subscribe(
|
120
|
countries => this.countries = countries.sort( function(a,b){
|
121
|
if(a.name<b.name){
|
122
|
return -1;
|
123
|
} else if(a.name>b.name){
|
124
|
return 1;
|
125
|
} else {
|
126
|
return 0;
|
127
|
}
|
128
|
} ),
|
129
|
error => console.log(error)
|
130
|
);
|
131
|
}
|
132
|
|
133
|
loadUpdateTab() {
|
134
|
this.updateGroup = this.fb.group(this.updateGroupDefinition);
|
135
|
this.getCountries();
|
136
|
this.getRepo();
|
137
|
}
|
138
|
|
139
|
|
140
|
updateRepo(){
|
141
|
if(this.updateGroup.valid){
|
142
|
this.successMessage = formSuccessUpdatedRepo;
|
143
|
this.errorMessage = '';
|
144
|
} else {
|
145
|
this.errorMessage = formErrorRequiredFields;
|
146
|
this.successMessage = '';
|
147
|
}
|
148
|
}
|
149
|
|
150
|
}
|