2023-09-13 14:04:18 +02:00
|
|
|
import {ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core';
|
2023-07-14 17:22:25 +02:00
|
|
|
import {OaipmhValidatorService} from "../../../services/oaipmh-validator.service";
|
2023-07-25 10:58:23 +02:00
|
|
|
import {UntypedFormBuilder, UntypedFormGroup, Validators} from "@angular/forms";
|
2023-07-25 12:39:39 +02:00
|
|
|
import {Option} from "../../../openaire-library/sharedComponents/input/input.component";
|
|
|
|
import {StringUtils} from "../../../openaire-library/utils/string-utils.class";
|
2023-07-25 15:58:41 +02:00
|
|
|
import {JobResult} from "../../entities/JobResult";
|
|
|
|
import {Router} from "@angular/router";
|
|
|
|
import {Subscriber} from "rxjs";
|
2023-07-14 17:22:25 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-oaipmh-validator',
|
|
|
|
templateUrl: './oaipmh-validator.component.html',
|
|
|
|
styleUrls: ['./oaipmh-validator.component.less']
|
|
|
|
})
|
|
|
|
export class OaipmhValidatorComponent implements OnInit {
|
2023-09-13 14:04:18 +02:00
|
|
|
@ViewChild("right_sidebar") right_sidebar;
|
|
|
|
@ViewChild("right_sidebar_header") right_sidebar_header;
|
|
|
|
@ViewChild("right_sidebar_footer") right_sidebar_footer;
|
|
|
|
|
2023-07-25 10:58:23 +02:00
|
|
|
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;
|
2023-07-25 15:58:41 +02:00
|
|
|
public loadingSets: boolean = false;
|
2023-07-14 17:22:25 +02:00
|
|
|
|
2023-08-25 11:02:46 +02:00
|
|
|
public offset: number = 0;
|
|
|
|
public help: boolean = false;
|
|
|
|
|
2023-09-13 14:04:18 +02:00
|
|
|
public right_sidebar_body_height: number = 0;
|
2023-09-13 14:42:24 +02:00
|
|
|
public right_sidebar_card_height: number = 0;
|
2023-09-13 14:04:18 +02:00
|
|
|
|
2023-07-25 15:58:41 +02:00
|
|
|
subscriptions = [];
|
|
|
|
|
2023-09-13 14:04:18 +02:00
|
|
|
constructor(private fb: UntypedFormBuilder, private router: Router,
|
|
|
|
private cdr: ChangeDetectorRef,
|
|
|
|
private validator: OaipmhValidatorService) {
|
2023-07-25 10:58:23 +02:00
|
|
|
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),
|
2023-07-25 15:58:41 +02:00
|
|
|
set: this.fb.control('all', Validators.required)
|
2023-07-25 10:58:23 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {}
|
|
|
|
|
2023-08-25 11:02:46 +02:00
|
|
|
ngAfterViewInit() {
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
if(document.getElementById("main-menu")) {
|
|
|
|
this.offset = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--header-height'));
|
|
|
|
} else {
|
|
|
|
this.offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-25 15:58:41 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-13 14:04:18 +02:00
|
|
|
openHelp() {
|
|
|
|
this.help = true;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
console.log(this.right_sidebar.nativeElement.offsetHeight);
|
|
|
|
console.log(this.right_sidebar_header.nativeElement.offsetHeight);
|
|
|
|
console.log(this.right_sidebar_footer.nativeElement.offsetHeight);
|
2023-09-13 14:42:24 +02:00
|
|
|
this.right_sidebar_card_height = this.right_sidebar.nativeElement.offsetHeight - this.right_sidebar_header.nativeElement.offsetHeight + 1;
|
|
|
|
this.right_sidebar_body_height = this.right_sidebar_card_height - this.right_sidebar_footer.nativeElement.offsetHeight;
|
2023-09-13 14:04:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-25 10:58:23 +02:00
|
|
|
updateRecordsNum(increase: boolean = true) {
|
|
|
|
this.recordsNum = this.recordsNum + (increase ? 10 : -10);
|
|
|
|
this.form.get('recordsNum').setValue(this.recordsNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
getSets() {
|
2023-07-25 15:58:41 +02:00
|
|
|
this.loadingSets = true;
|
2023-07-25 10:58:23 +02:00
|
|
|
let options: Option[] = [{label: 'All sets', value: 'all'}];
|
2023-07-25 15:58:41 +02:00
|
|
|
if(this.form.get('setName')) {
|
|
|
|
this.form.get('setName').setValue('all');
|
|
|
|
}
|
2023-07-25 10:58:23 +02:00
|
|
|
if(this.form.get('url') && this.form.get('url').value && StringUtils.isValidUrl(this.form.get('url').value)) {
|
2023-07-25 15:58:41 +02:00
|
|
|
this.subscriptions.push(this.validator.getSets(this.form.get('url').value).subscribe(sets => {
|
2023-07-25 10:58:23 +02:00
|
|
|
for(let set of sets) {
|
|
|
|
options.push({label: set['setName'], value: set['setSpec']});
|
|
|
|
}
|
|
|
|
this.sets = options;
|
2023-07-25 15:58:41 +02:00
|
|
|
this.loadingSets = false;
|
|
|
|
}, error => {
|
|
|
|
this.sets = options;
|
|
|
|
this.loadingSets = false;
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
this.sets = options;
|
|
|
|
this.loadingSets = false;
|
2023-07-25 10:58:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
validate() {
|
2023-07-25 15:58:41 +02:00
|
|
|
this.subscriptions.push(this.validator.validate(this.form.get('guidelines').value, this.form.get('url').value, this.form.get('recordsNum').value, this.form.get('set').value).subscribe(
|
|
|
|
(result: JobResult) => {
|
|
|
|
this.router.navigate(['/oaipmh-history'], {
|
|
|
|
queryParams: { 'jobId': result.id }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
));
|
2023-07-14 17:22:25 +02:00
|
|
|
}
|
2023-09-13 14:04:18 +02:00
|
|
|
|
|
|
|
protected readonly innerHeight = innerHeight;
|
2023-07-14 17:22:25 +02:00
|
|
|
}
|