1
|
import { Component, OnInit, Type } from '@angular/core';
|
2
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
3
|
import { UpdateDatasourceInterfaceFormComponent } from './update-datasource-interface-form.component';
|
4
|
import { Country, Repository, RepositoryInterface } from '../../domain/typeScriptClasses';
|
5
|
import { RepositoryService } from '../../services/repository.service';
|
6
|
import { ActivatedRoute } from '@angular/router';
|
7
|
import {
|
8
|
Description,
|
9
|
interfaceFormDesc,
|
10
|
softwarePlatformDesc,
|
11
|
platformNameDesc,
|
12
|
officialNameDesc,
|
13
|
repoDescriptionDesc,
|
14
|
countryDesc,
|
15
|
longtitudeDesc,
|
16
|
latitudeDesc,
|
17
|
websiteUrlDesc,
|
18
|
institutionNameDesc,
|
19
|
englishNameDesc,
|
20
|
logoUrlDesc,
|
21
|
timezoneDesc,
|
22
|
datasourceTypeDesc,
|
23
|
adminEmailDesc
|
24
|
} from '../../domain/oa-description';
|
25
|
|
26
|
|
27
|
|
28
|
@Component ({
|
29
|
selector: 'sources-update-repo',
|
30
|
templateUrl: 'sources-update-repo.component.html'
|
31
|
})
|
32
|
|
33
|
export class SourcesUpdateRepoComponent implements OnInit {
|
34
|
|
35
|
repoId = '';
|
36
|
selectedRepo: Repository;
|
37
|
countries: Country[];
|
38
|
repoInterfaces: RepositoryInterface[] = [];
|
39
|
|
40
|
group: FormGroup;
|
41
|
interfaceFormDesc: Description = interfaceFormDesc;
|
42
|
updateDatasourceInterfaces : Type<any> = UpdateDatasourceInterfaceFormComponent;
|
43
|
|
44
|
interfaceDummyList = [
|
45
|
{
|
46
|
baseUrl: 'WWW.FDGLKSDJFGLKDJSF.GR',
|
47
|
selectValidationSet: 'blabla',
|
48
|
compatibilityLevel: 'moreblabla'
|
49
|
},
|
50
|
{
|
51
|
baseUrl: 'WWW.FDGLKSDJFGLKDJSfdgdfgF.GR',
|
52
|
selectValidationSet: 'blabla2',
|
53
|
compatibilityLevel: 'blabla1'
|
54
|
}
|
55
|
];
|
56
|
|
57
|
updateGroup: FormGroup;
|
58
|
readonly updateGroupDefinition = {
|
59
|
softwarePlatform : '',
|
60
|
platformName : '',
|
61
|
officialName : '',
|
62
|
repoDescription : '',
|
63
|
country : '',
|
64
|
longtitude : '',
|
65
|
latitude : '',
|
66
|
websiteUrl : '',
|
67
|
institutionName : '',
|
68
|
englishName: ['', Validators.required],
|
69
|
logoUrl: '',
|
70
|
timezone: ['', Validators.required],
|
71
|
datasourceType: ['', Validators.required],
|
72
|
adminEmail: ['', Validators.required]
|
73
|
};
|
74
|
|
75
|
softwarePlatformDesc : Description = softwarePlatformDesc;
|
76
|
platformNameDesc : Description = platformNameDesc;
|
77
|
officialNameDesc : Description = officialNameDesc;
|
78
|
repoDescriptionDesc : Description = repoDescriptionDesc;
|
79
|
countryDesc : Description = countryDesc;
|
80
|
longtitudeDesc : Description = longtitudeDesc;
|
81
|
latitudeDesc : Description = latitudeDesc;
|
82
|
websiteUrlDesc : Description = websiteUrlDesc;
|
83
|
institutionNameDesc : Description = institutionNameDesc;
|
84
|
englishNameDesc : Description = englishNameDesc;
|
85
|
logoUrlDesc : Description = logoUrlDesc;
|
86
|
timezoneDesc : Description = timezoneDesc;
|
87
|
datasourceTypeDesc : Description = datasourceTypeDesc;
|
88
|
adminEmailDesc : Description = adminEmailDesc;
|
89
|
|
90
|
|
91
|
constructor (
|
92
|
private fb: FormBuilder,
|
93
|
private repoService: RepositoryService,
|
94
|
private route: ActivatedRoute )
|
95
|
{}
|
96
|
|
97
|
|
98
|
ngOnInit() {
|
99
|
this.readRepoId();
|
100
|
this.loadUpdateTab();
|
101
|
this.loadInterfacesTab();
|
102
|
|
103
|
}
|
104
|
|
105
|
readRepoId() {
|
106
|
this.repoId = this.route.snapshot.paramMap.get('id');
|
107
|
}
|
108
|
|
109
|
getRepo() {
|
110
|
this.repoService.getRepositoryById(this.repoId).subscribe(
|
111
|
repo => {
|
112
|
this.selectedRepo = repo;
|
113
|
if(this.selectedRepo) {
|
114
|
this.updateGroup.setValue({
|
115
|
softwarePlatform: '', //this.selectedRepo.WHICH FIELD ??
|
116
|
platformName: this.selectedRepo.typology,
|
117
|
officialName: this.selectedRepo.officialName,
|
118
|
repoDescription: this.selectedRepo.description,
|
119
|
country: this.selectedRepo.countryCode,
|
120
|
longtitude: this.selectedRepo.longitude,
|
121
|
latitude: this.selectedRepo.latitude,
|
122
|
websiteUrl: this.selectedRepo.websiteUrl,
|
123
|
institutionName: this.selectedRepo.organization,
|
124
|
englishName: this.selectedRepo.englishName,
|
125
|
logoUrl: this.selectedRepo.logoUrl,
|
126
|
timezone: this.selectedRepo.timezone,
|
127
|
datasourceType: this.selectedRepo.datasourceType,
|
128
|
adminEmail: this.selectedRepo.contactEmail
|
129
|
});
|
130
|
}
|
131
|
this.updateGroup.get('softwarePlatform').disable();
|
132
|
this.updateGroup.get('platformName').disable();
|
133
|
this.updateGroup.get('officialName').disable();
|
134
|
this.updateGroup.get('repoDescription').disable();
|
135
|
this.updateGroup.get('country').disable();
|
136
|
this.updateGroup.get('longtitude').disable();
|
137
|
this.updateGroup.get('latitude').disable();
|
138
|
this.updateGroup.get('websiteUrl').disable();
|
139
|
this.updateGroup.get('institutionName').disable();
|
140
|
},
|
141
|
error =>console.log(error)
|
142
|
)
|
143
|
}
|
144
|
|
145
|
getRepoInterfaces() {
|
146
|
this.repoService.getRepositoryInterface(this.repoId).subscribe(
|
147
|
interfaces => this.repoInterfaces = interfaces,
|
148
|
error => console.log(error)
|
149
|
);
|
150
|
}
|
151
|
|
152
|
getCountries() {
|
153
|
this.repoService.getCountries()
|
154
|
.subscribe(
|
155
|
countries => this.countries = countries.sort( function(a,b){
|
156
|
if(a.name<b.name){
|
157
|
return -1;
|
158
|
} else if(a.name>b.name){
|
159
|
return 1;
|
160
|
} else {
|
161
|
return 0;
|
162
|
}
|
163
|
} ),
|
164
|
error => console.log(error)
|
165
|
);
|
166
|
}
|
167
|
|
168
|
loadUpdateTab() {
|
169
|
this.updateGroup = this.fb.group(this.updateGroupDefinition);
|
170
|
this.getCountries();
|
171
|
this.getRepo();
|
172
|
//set initial values
|
173
|
}
|
174
|
|
175
|
loadInterfacesTab() {
|
176
|
this.getRepoInterfaces();
|
177
|
this.group = this.fb.group({});
|
178
|
/*
|
179
|
setTimeout(() => {
|
180
|
console.log("PATCHING");
|
181
|
this.group.patchValue(this.interfaceDummyList);
|
182
|
},1000);
|
183
|
*/
|
184
|
}
|
185
|
|
186
|
}
|