Revision 50977
Added by Myrto Koukouli about 6 years ago
datasource-info-form.component.ts | ||
---|---|---|
2 | 2 |
import { |
3 | 3 |
formErrorRequiredFields, |
4 | 4 |
formErrorWasntSaved, |
5 |
formInfoLoading, |
|
6 |
formSuccessUpdatedRepo, |
|
5 |
formInfoLoading, formSubmitting,
|
|
6 |
formSuccessUpdatedRepo, loadingRepoError,
|
|
7 | 7 |
noServiceMessage |
8 | 8 |
} from '../../../domain/shared-messages'; |
9 | 9 |
import { RepositoryService } from "../../../services/repository.service"; |
10 |
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
10 |
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
11 | 11 |
import { Country, Repository } from '../../../domain/typeScriptClasses'; |
12 | 12 |
import { typologies } from '../../../domain/typologies'; |
13 | 13 |
import { timezones } from '../../../domain/timezones'; |
... | ... | |
26 | 26 |
logoUrlDesc, |
27 | 27 |
timezoneDesc, |
28 | 28 |
datasourceTypeDesc, |
29 |
adminEmailDesc |
|
29 |
adminEmailDesc, lissnDesc, eissnDesc, issnDesc
|
|
30 | 30 |
} from '../../../domain/oa-description'; |
31 | 31 |
|
32 | 32 |
@Component ({ |
... | ... | |
39 | 39 |
errorMessage: string; |
40 | 40 |
successMessage: string; |
41 | 41 |
loadingMessage: string; |
42 |
sourceTitle: string; |
|
43 |
sourceLinkToRepo: string; |
|
44 | 42 |
|
45 | 43 |
typologies = typologies; |
46 | 44 |
timezones = timezones; |
... | ... | |
50 | 48 |
|
51 | 49 |
selectedRepo: Repository; |
52 | 50 |
id: string; |
53 |
source: string; |
|
54 | 51 |
|
55 | 52 |
|
56 | 53 |
@Input() datasourceId: string; |
57 | 54 |
|
58 | 55 |
@Input() showButton: boolean; |
59 | 56 |
|
60 |
@Output() emittedInfo: EventEmitter<string[]> = new EventEmitter();
|
|
57 |
@Output() emittedInfo: EventEmitter<Repository> = new EventEmitter();
|
|
61 | 58 |
|
62 | 59 |
updateGroup: FormGroup; |
63 | 60 |
readonly updateGroupDefinition = { |
64 | 61 |
softwarePlatform : '', |
65 | 62 |
platformName : '', |
66 | 63 |
officialName : ['', Validators.required], |
64 |
issn : ['', [Validators.minLength(8), Validators.maxLength(8)]], |
|
65 |
eissn : ['', [Validators.minLength(8), Validators.maxLength(8)]], |
|
66 |
lissn : ['', [Validators.minLength(8), Validators.maxLength(8)]], |
|
67 | 67 |
repoDescription : ['', Validators.required], |
68 | 68 |
country : ['', Validators.required], |
69 | 69 |
longtitude : ['', [Validators.required, Validators.maxLength(9), Validators.min(-180), Validators.max(180)] ], |
... | ... | |
80 | 80 |
softwarePlatformDesc : Description = softwarePlatformDesc; |
81 | 81 |
platformNameDesc : Description = platformNameDesc; |
82 | 82 |
officialNameDesc : Description = officialNameDesc; |
83 |
issnDesc : Description = issnDesc; |
|
84 |
eissnDesc : Description = eissnDesc; |
|
85 |
lissnDesc : Description = lissnDesc; |
|
83 | 86 |
repoDescriptionDesc : Description = repoDescriptionDesc; |
84 | 87 |
countryDesc : Description = countryDesc; |
85 | 88 |
longtitudeDesc : Description = longtitudeDesc; |
... | ... | |
101 | 104 |
this.loadForm(); |
102 | 105 |
} |
103 | 106 |
|
107 |
loadForm() { |
|
108 |
this.updateGroup = this.fb.group(this.updateGroupDefinition, {validator: checkPlatform}); |
|
109 |
this.getRepo(); |
|
110 |
} |
|
111 |
|
|
104 | 112 |
getRepo() { |
105 | 113 |
this.loadingMessage = formInfoLoading; |
106 | 114 |
if (this.datasourceId) { |
107 | 115 |
this.repoService.getRepositoryById(this.datasourceId).subscribe( |
108 | 116 |
repo => { |
109 | 117 |
this.selectedRepo = repo; |
110 |
if (this.selectedRepo) { |
|
111 |
this.updateGroup.setValue({ |
|
112 |
softwarePlatform: this.selectedRepo.typology, |
|
113 |
platformName: '', |
|
114 |
officialName: this.selectedRepo.officialName, |
|
115 |
repoDescription: this.selectedRepo.description, |
|
116 |
country: this.selectedRepo.countryCode, |
|
117 |
longtitude: this.selectedRepo.longitude, |
|
118 |
latitude: this.selectedRepo.latitude, |
|
119 |
websiteUrl: this.selectedRepo.websiteUrl, |
|
120 |
institutionName: this.selectedRepo.organization, |
|
121 |
englishName: this.selectedRepo.englishName, |
|
122 |
logoUrl: this.selectedRepo.logoUrl, |
|
123 |
timezone: this.selectedRepo.timezone, |
|
124 |
datasourceType: this.selectedRepo.datasourceClass, |
|
125 |
adminEmail: this.selectedRepo.contactEmail |
|
126 |
}); |
|
127 |
if (this.updateGroup.get('softwarePlatform').value == '') { |
|
128 |
this.updateGroup.setValue({platformName: this.selectedRepo.typology}); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
this.setUpSourceInfo(); |
|
133 |
this.getDatasourceClasses(); |
|
134 | 118 |
}, |
135 | 119 |
error => { |
136 | 120 |
console.log(error); |
137 | 121 |
this.loadingMessage = ''; |
122 |
this.errorMessage = loadingRepoError; |
|
138 | 123 |
}, |
139 | 124 |
() => { |
125 |
this.setupUpdateForm(); |
|
126 |
this.getDatasourceClasses(); |
|
140 | 127 |
this.getCountries(); |
128 |
this.emittedInfo.emit(this.selectedRepo); |
|
141 | 129 |
this.loadingMessage = ''; |
142 |
this.emittedInfo.emit([this.selectedRepo.id,this.selectedRepo.datasourceType]); |
|
143 | 130 |
} |
144 | 131 |
); |
145 | 132 |
} |
146 | 133 |
} |
147 | 134 |
|
148 |
setUpSourceInfo() { |
|
149 |
this.source = this.selectedRepo.datasourceType; |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
loadForm() { |
|
154 |
this.updateGroup = this.fb.group(this.updateGroupDefinition); |
|
155 |
this.getRepo(); |
|
156 |
} |
|
157 |
|
|
158 |
|
|
159 |
updateRepo(): boolean { |
|
160 |
if(this.updateGroup.valid){ |
|
161 |
/* |
|
162 |
if (!this.updateEnglishName()) { |
|
163 |
return false; |
|
164 |
} |
|
165 |
*/ |
|
166 |
this.successMessage = formSuccessUpdatedRepo; |
|
167 |
this.errorMessage = ''; |
|
168 |
return true; |
|
169 |
} else { |
|
170 |
this.errorMessage = formErrorRequiredFields; |
|
171 |
this.successMessage = ''; |
|
172 |
return false; |
|
135 |
setupUpdateForm(){ |
|
136 |
if (this.selectedRepo) { |
|
137 |
this.updateGroup.setValue({ |
|
138 |
softwarePlatform: this.selectedRepo.typology, |
|
139 |
platformName: '', |
|
140 |
officialName: this.selectedRepo.officialName, |
|
141 |
repoDescription: this.selectedRepo.description, |
|
142 |
country: this.selectedRepo.countryCode, |
|
143 |
longtitude: this.selectedRepo.longitude, |
|
144 |
latitude: this.selectedRepo.latitude, |
|
145 |
websiteUrl: this.selectedRepo.websiteUrl, |
|
146 |
institutionName: this.selectedRepo.organization, |
|
147 |
englishName: this.selectedRepo.englishName, |
|
148 |
logoUrl: this.selectedRepo.logoUrl, |
|
149 |
timezone: this.selectedRepo.timezone, |
|
150 |
datasourceType: this.selectedRepo.datasourceClass, |
|
151 |
adminEmail: this.selectedRepo.contactEmail |
|
152 |
}); |
|
153 |
if (this.updateGroup.get('softwarePlatform').value == '') { |
|
154 |
this.updateGroup.setValue({platformName: this.selectedRepo.typology}); |
|
155 |
} |
|
156 |
if (this.selectedRepo.datasourceType == 'journal') { |
|
157 |
this.updateGroup.setValue({ |
|
158 |
issn: this.selectedRepo.issn, |
|
159 |
eissn: this.selectedRepo.eissn, |
|
160 |
lissn: this.selectedRepo.lissn |
|
161 |
}); |
|
162 |
} |
|
173 | 163 |
} |
174 | 164 |
} |
175 | 165 |
|
... | ... | |
192 | 182 |
} |
193 | 183 |
|
194 | 184 |
getDatasourceClasses() { |
195 |
this.repoService.getDatasourceClasses(this.source).subscribe(
|
|
185 |
this.repoService.getDatasourceClasses(this.selectedRepo.datasourceType).subscribe(
|
|
196 | 186 |
classes => this.datasourceClasses = classes, |
197 | 187 |
error => { |
198 | 188 |
this.errorMessage = noServiceMessage; |
... | ... | |
206 | 196 |
); |
207 | 197 |
} |
208 | 198 |
|
209 |
updateEnglishName(){ |
|
199 |
updateRepo(): boolean { |
|
200 |
let result: boolean; |
|
201 |
this.errorMessage = ''; |
|
202 |
this.loadingMessage = ''; |
|
203 |
this.successMessage = ''; |
|
204 |
|
|
205 |
if (this.updateGroup.valid) { |
|
206 |
if ( this.selectedRepo.datasourceType != 'journal' || this.updateGroup.get('issn').value ) { |
|
207 |
this.refreshSelectedRepo(); |
|
208 |
this.loadingMessage = formSubmitting; |
|
209 |
this.errorMessage = ''; |
|
210 |
this.repoService.updateRepository(this.selectedRepo).subscribe( |
|
211 |
response => { |
|
212 |
console.log(`updateRepository responded: ${response}`); |
|
213 |
if (response == '200') { |
|
214 |
result = true; |
|
215 |
} else { |
|
216 |
result = false; |
|
217 |
} |
|
218 |
}, |
|
219 |
error => { |
|
220 |
console.log(error); |
|
221 |
this.errorMessage = formErrorWasntSaved; |
|
222 |
}, |
|
223 |
() => { |
|
224 |
this.loadingMessage = ''; |
|
225 |
if (result) { |
|
226 |
this.successMessage = formSuccessUpdatedRepo; |
|
227 |
this.emittedInfo.emit(this.selectedRepo); |
|
228 |
} else { |
|
229 |
this.errorMessage = formErrorWasntSaved; |
|
230 |
} |
|
231 |
} |
|
232 |
); |
|
233 |
} else { |
|
234 |
this.errorMessage = formErrorRequiredFields; |
|
235 |
result = false; |
|
236 |
} |
|
237 |
} else { |
|
238 |
this.errorMessage = formErrorRequiredFields; |
|
239 |
result = false; |
|
240 |
} |
|
241 |
return result; |
|
242 |
} |
|
243 |
|
|
244 |
refreshSelectedRepo() { |
|
245 |
if (this.updateGroup.get('platformName').value.trim() ) { |
|
246 |
this.selectedRepo.typology = this.updateGroup.get('platformName').value; |
|
247 |
} else if (this.updateGroup.get('softwarePlatform').value){ |
|
248 |
this.selectedRepo.typology = this.updateGroup.get('softwarePlatform').value; |
|
249 |
} |
|
250 |
this.selectedRepo.officialName = this.updateGroup.get('officialName').value; |
|
251 |
this.selectedRepo.description = this.updateGroup.get('repoDescription').value; |
|
252 |
this.selectedRepo.countryCode = this.updateGroup.get('country').value; |
|
253 |
this.selectedRepo.countryName = this.countries.filter(x => x.code == this.updateGroup.get('country').value)[0].name; |
|
254 |
this.selectedRepo.longitude = this.updateGroup.get('longtitude').value; |
|
255 |
this.selectedRepo.latitude = this.updateGroup.get('latitude').value; |
|
256 |
this.selectedRepo.websiteUrl = this.updateGroup.get('websiteUrl').value; |
|
257 |
this.selectedRepo.organization = this.updateGroup.get('institutionName').value; |
|
258 |
this.selectedRepo.englishName = this.updateGroup.get('englishName').value; |
|
259 |
this.selectedRepo.logoUrl = this.updateGroup.get('logoUrl').value; |
|
260 |
this.selectedRepo.timezone = this.updateGroup.get('timezone').value; |
|
261 |
this.selectedRepo.datasourceClass = this.updateGroup.get('datasourceType').value; |
|
262 |
this.selectedRepo.contactEmail = this.updateGroup.get('adminEmail').value; |
|
263 |
if (this.selectedRepo.datasourceType == 'journal') { |
|
264 |
this.selectedRepo.issn = this.updateGroup.get('issn').value; |
|
265 |
this.selectedRepo.eissn = this.updateGroup.get('eissn').value; |
|
266 |
this.selectedRepo.lissn = this.updateGroup.get('lissn').value; |
|
267 |
} |
|
268 |
} |
|
269 |
|
|
270 |
updateEnglishName() { |
|
210 | 271 |
let status: boolean; |
211 | 272 |
this.repoService.updateEnglishName(this.selectedRepo.id,this.updateGroup.get('englishName').value).subscribe( |
212 | 273 |
response => { |
... | ... | |
223 | 284 |
} |
224 | 285 |
|
225 | 286 |
} |
287 |
|
|
288 |
export function checkPlatform(c: AbstractControl) { |
|
289 |
if ( c.get('softwarePlatform').value || c.get('platformName').value ) |
|
290 |
return null; |
|
291 |
return 'invalid'; |
|
292 |
} |
Also available in: Unified diff
finalized sources register and update