56 lines
2.5 KiB
TypeScript
56 lines
2.5 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {OaipmhValidatorService} from "../../../services/oaipmh-validator.service";
|
|
import {UntypedFormBuilder, UntypedFormGroup, Validators} from "@angular/forms";
|
|
import {Option} from "../../../openaire-library/sharedComponents/input/input.component";
|
|
import {StringUtils} from "../../../openaire-library/utils/string-utils.class";
|
|
|
|
@Component({
|
|
selector: 'app-oaipmh-validator',
|
|
templateUrl: './oaipmh-validator.component.html',
|
|
styleUrls: ['./oaipmh-validator.component.less']
|
|
})
|
|
export class OaipmhValidatorComponent implements OnInit {
|
|
public options: Option[] = [
|
|
{label: 'OpenAIRE Guidelines for Data Archives Profile v2', value: 'OpenAIRE Guidelines for Data Archives Profile v2'},
|
|
{label: 'OpenAIRE Guidelines for Literature Repositories Profile v3', value: 'OpenAIRE Guidelines for Literature Repositories Profile v3'},
|
|
{label: 'OpenAIRE Guidelines for Literature Repositories Profile v4', value: 'OpenAIRE Guidelines for Literature Repositories Profile v4'},
|
|
{label: 'OpenAIRE FAIR Guidelines for Data Repositories Profile', value: 'OpenAIRE FAIR Guidelines for Data Repositories Profile'}
|
|
];
|
|
public form: UntypedFormGroup;
|
|
public sets: Option[] = [{label: 'All sets', value: 'all'}];
|
|
public recordsNum: number = 10;
|
|
|
|
constructor(private fb: UntypedFormBuilder, private validator: OaipmhValidatorService) {
|
|
this.form = this.fb.group({
|
|
url: this.fb.control("", StringUtils.urlValidator()),//[Validators.required/*, Validators.email*/]),
|
|
guidelines: this.fb.control("", Validators.required),
|
|
recordsNum: this.fb.control(null, Validators.required),
|
|
set: this.fb.control('', Validators.required)
|
|
});
|
|
}
|
|
|
|
ngOnInit() {}
|
|
|
|
updateRecordsNum(increase: boolean = true) {
|
|
this.recordsNum = this.recordsNum + (increase ? 10 : -10);
|
|
this.form.get('recordsNum').setValue(this.recordsNum);
|
|
}
|
|
|
|
getSets() {
|
|
let options: Option[] = [{label: 'All sets', value: 'all'}];
|
|
if(this.form.get('url') && this.form.get('url').value && StringUtils.isValidUrl(this.form.get('url').value)) {
|
|
this.validator.getSets(this.form.get('url').value).subscribe(sets => {
|
|
for(let set of sets) {
|
|
options.push({label: set['setName'], value: set['setSpec']});
|
|
}
|
|
this.sets = options;
|
|
});
|
|
}
|
|
}
|
|
|
|
validate() {
|
|
console.log(this.form.value);
|
|
this.validator.validate(this.form.get('guidelines').value, this.form.get('url').value, this.form.get('recordsNum').value, this.form.get('set').value);
|
|
}
|
|
}
|