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