metadata-validator-ui/src/app/pages/single-record-validator/single-record-validator.com...

120 lines
4.3 KiB
TypeScript

import {Component, OnInit, ViewChild} from '@angular/core';
import {UntypedFormBuilder, UntypedFormGroup, Validators} from "@angular/forms";
import {SingleRecordValidatorService} from "./single-record-validator.service";
import {Option} from "../../shared/utils/input/input.component";
import {RuleInfo, Status} from "../entities/RuleInfo";
import {XmlValidationResponse} from "../entities/XmlValidationResponse";
@Component({
selector: 'app-single-record-validator',
templateUrl: './single-record-validator.component.html',
styleUrls: ['./single-record-validator.component.less']
})
export class SingleRecordValidatorComponent implements OnInit {
public options: Option[] = [
{label: 'Data Archive Guidelines V2 Profile & FAIR Data Guidelines Profile', value: 'dataArchiveGuidelinesV2Profile'},
{label: 'Literature Guidelines V3 Profile', value: 'literatureGuidelinesV3Profile'},
{label: 'Literature Guidelines V4 Profile', value: 'literatureGuidelinesV4Profile'},
{label: 'FAIR Data Guidelines Profile', value: 'fairDataGuidelinesProfile'}
];
public form: UntypedFormGroup;
public result: XmlValidationResponse
public modalOpen: boolean = false;
public currentRule: RuleInfo;
@ViewChild('modal') modal;
public viewResults: boolean = false;
public validationAnalysis: boolean = true;
constructor(private fb: UntypedFormBuilder, private validator: SingleRecordValidatorService) {
this.form = this.fb.group({
guidelines: this.fb.control("", Validators.required),
xml: this.fb.control('', Validators.required)
});
}
ngOnInit(): void {}
public validate() {
this.validator.validateRecord(this.form.get('xml')?.getRawValue(), this.form.get('guidelines')?.getRawValue()).subscribe(
result => {
this.result = result;
}
)
}
public openMessagesModal(rule: RuleInfo) {
this.modalOpen = true;
this.currentRule = rule;
this.modal.cancelButton = false;
this.modal.okButton = false;
this.modal.alertTitle = "Warnings & Errors";
this.modal.open();
}
public get currentGuideline() {
return this.options.find(option => this.form.get("guidelines").getRawValue() == option.value);
}
// fileChangeEvent(fileInput: any, dropped: boolean = false) {
// if(this.form.value.value) {
// this.onRemove(false);
// }
//
// if(dropped) {
// this.filesToUpload = fileInput.addedFiles;
// } else {
// this.filesToUpload = fileInput.target.files;
// }
//
//
// let messages: string[] = [];
// if (this.filesToUpload.length == 0) {
// messages.push(this.language.instant('DATASET-WIZARD.MESSAGES.NO-FILES-SELECTED'));
// return;
// } else {
// let fileToUpload = this.filesToUpload[0];
// if (this.form.get("data") && this.form.get("data").value.types
// && this.form.get("data").value.types.map(type => type.value).includes(fileToUpload.type)
// && this.form.get("data").value.maxFileSizeInMB
// && this.form.get("data").value.maxFileSizeInMB*1048576 >= fileToUpload.size) {
// this.upload();
// } else {
// this.filesToUpload = null;
// messages.push(this.language.instant('DATASET-WIZARD.MESSAGES.LARGE-FILE-OR-UNACCEPTED-TYPE'));
// messages.push(this.language.instant('DATASET-WIZARD.MESSAGES.MAX-FILE-SIZE', {'maxfilesize': this.form.get("data").value.maxFileSizeInMB}));
// messages.push(this.language.instant('DATASET-WIZARD.MESSAGES.ACCEPTED-FILE-TYPES')+ this.form.get("data").value.types.map(type => type.value).join(", "));
// }
//
// if(messages && messages.length > 0) {
// this.dialog.open(FormValidationErrorsDialogComponent, {
// data: {
// errorMessages: messages
// }
// })
// }
// }
// }
// onRemove(makeFilesNull: boolean = true) {
// // delete from tmp folder - subscribe call
// this.fileService.deleteFromTempFolder(this.form.value.value.id).subscribe(res => {
// if(makeFilesNull) {
// this.makeFilesNull();
// }
// this.cdr.detectChanges();
// }, error => {
// if(makeFilesNull) {
// this.makeFilesNull();
// }
// })
// }
//
// makeFilesNull() {
// this.filesToUpload = null;
// this.form.value.value = null;
// this.form.get("value").patchValue(null);
// }
}