Revision 50977
Added by Myrto Koukouli about 6 years ago
aggregator-info-form.component.ts | ||
---|---|---|
2 | 2 |
* created by myrto on 1/22/2018 |
3 | 3 |
*/ |
4 | 4 |
|
5 |
import { Component, OnInit } from '@angular/core';
|
|
5 |
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
|
|
6 | 6 |
import { formErrorRequiredFields, formSuccessRegisteredDatasource, noServiceMessage } from '../../../domain/shared-messages'; |
7 | 7 |
import { RepositoryService } from "../../../services/repository.service"; |
8 | 8 |
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
... | ... | |
26 | 26 |
aggregatorTypeDesc, |
27 | 27 |
adminEmailDesc |
28 | 28 |
} from '../../../domain/oa-description'; |
29 |
import { AuthenticationService } from '../../../services/authentication.service'; |
|
29 | 30 |
|
30 | 31 |
@Component ({ |
31 | 32 |
selector: 'aggregator-info-form', |
... | ... | |
43 | 44 |
datasourceClasses: Map<string,string> = new Map<string,string>(); |
44 | 45 |
classCodes: string[] = []; |
45 | 46 |
|
46 |
newDatasource: Repository;
|
|
47 |
@Output() emittedInfo: EventEmitter<Repository> = new EventEmitter();
|
|
47 | 48 |
|
48 | 49 |
group: FormGroup; |
49 | 50 |
readonly groupDefinition = { |
50 | 51 |
softwarePlatform : '', |
51 |
platformName : '', |
|
52 | 52 |
officialName : ['', Validators.required], |
53 | 53 |
repoDescription : ['', Validators.required], |
54 | 54 |
country : ['', Validators.required], |
... | ... | |
64 | 64 |
}; |
65 | 65 |
|
66 | 66 |
softwarePlatformDesc : Description = softwarePlatformDesc; |
67 |
platformNameDesc : Description = platformNameDesc; |
|
68 | 67 |
officialNameDesc : Description = officialNameDesc; |
69 | 68 |
repoDescriptionDesc : Description = repoDescriptionDesc; |
70 | 69 |
countryDesc : Description = countryDesc; |
... | ... | |
81 | 80 |
|
82 | 81 |
constructor( |
83 | 82 |
private fb: FormBuilder, |
84 |
private repoService: RepositoryService |
|
83 |
private repoService: RepositoryService, |
|
84 |
private authService: AuthenticationService |
|
85 | 85 |
) {} |
86 | 86 |
|
87 | 87 |
ngOnInit() { |
... | ... | |
129 | 129 |
|
130 | 130 |
registerDatasource(): boolean { |
131 | 131 |
if(this.group.valid){ |
132 |
let newRepo = this.createNewRepository(); |
|
133 |
this.repoService.addRepository('aggregator', newRepo).subscribe( |
|
134 |
response => console.log(`${JSON.stringify(response)}`), |
|
135 |
error => console.log(error) |
|
136 |
); |
|
132 | 137 |
this.successMessage = formSuccessRegisteredDatasource; |
133 | 138 |
this.errorMessage = ''; |
134 | 139 |
return true; |
135 | 140 |
} else { |
136 | 141 |
this.errorMessage = formErrorRequiredFields; |
137 |
this.successMessage = ''; |
|
138 | 142 |
return false; |
139 | 143 |
} |
140 | 144 |
} |
145 |
|
|
146 |
createNewRepository(): Repository { |
|
147 |
let newRepo: Repository = new Repository(); |
|
148 |
newRepo.dateOfCreation = new Date(Date.now()); |
|
149 |
newRepo.officialName = this.group.get('officialName').value; |
|
150 |
newRepo.englishName = this.group.get('englishName').value; |
|
151 |
newRepo.websiteUrl = this.group.get('websiteUrl').value; |
|
152 |
newRepo.logoUrl = this.group.get('logoUrl').value; |
|
153 |
newRepo.contactEmail = this.group.get('adminEmail').value; |
|
154 |
newRepo.countryName = this.countries.filter(x => x.code == this.group.get('country').value)[0].name; |
|
155 |
newRepo.countryCode = this.group.get('country').value; |
|
156 |
newRepo.organization = this.group.get('institutionName').value; |
|
157 |
newRepo.latitude = this.group.get('latitude').value; |
|
158 |
newRepo.longitude = this.group.get('longtitude').value; |
|
159 |
newRepo.timezone = this.group.get('timezone').value; |
|
160 |
newRepo.datasourceClass = this.group.get('journalType').value; |
|
161 |
newRepo.typology = this.group.get('softwarePlatform').value; |
|
162 |
newRepo.description = this.group.get('repoDescription').value; |
|
163 |
newRepo.registeredBy = this.authService.userEmail; |
|
164 |
newRepo.datasourceType = 'aggregator'; |
|
165 |
newRepo.registered = true; |
|
166 |
|
|
167 |
this.emittedInfo.emit(newRepo); |
|
168 |
|
|
169 |
return newRepo; |
|
170 |
} |
|
171 |
|
|
141 | 172 |
} |
Also available in: Unified diff
finalized sources register and update