2018-01-30 10:35:26 +01:00
|
|
|
import { BaseErrorModel } from '../../models/error/BaseErrorModel';
|
|
|
|
import { SnackBarNotificationComponent } from '../../shared/components/notificaiton/snack-bar-notification.component';
|
|
|
|
import { DatasetProfileCriteria } from '../../models/criteria/dataset-profile/DatasetProfileCriteria';
|
|
|
|
import { DataManagementPlanModel } from '../../models/data-managemnt-plans/DataManagementPlanModel';
|
|
|
|
import { JsonSerializer } from '../../utilities/JsonSerializer';
|
|
|
|
import { DataManagementPlanCriteria } from '../../models/criteria/data-management-plan/DataManagementPlanCriteria';
|
|
|
|
import { RequestItem } from '../../models/criteria/RequestItem';
|
|
|
|
import { DatasetService } from '../../services/dataset/dataset.service';
|
|
|
|
import { ExternalSourcesItemModel } from '../../models/external-sources/ExternalSourcesItemModel';
|
|
|
|
import { DatasetProfileModel } from '../../models/datasetprofile/DatasetProfileModel';
|
|
|
|
import { DatasetProfileDefinitionModel } from '../../models/DatasetProfileDefinitionModel';
|
|
|
|
import { DatasetWizardModel } from '../../models/datasets/DatasetWizardModel';
|
|
|
|
import { DataManagementPlanService } from '../../services/data-management-plan/data-management-plan.service';
|
|
|
|
import { ExternalSourcesService } from '../../services/external-sources/external-sources.service';
|
|
|
|
import { DatasetWizardService } from '../../services/dataset-wizard/dataset-wizard.service';
|
2017-12-21 10:44:57 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-01-12 11:17:37 +01:00
|
|
|
import { ActivatedRoute, Router, Params } from '@angular/router';
|
2017-12-19 14:57:07 +01:00
|
|
|
import { Component, ViewChild, OnInit, AfterViewInit, ViewEncapsulation } from "@angular/core";
|
|
|
|
import { FormGroup, Validators, FormBuilder } from "@angular/forms";
|
2018-03-05 17:18:45 +01:00
|
|
|
import * as FileSaver from 'file-saver';
|
2018-01-25 16:26:08 +01:00
|
|
|
import { MatPaginator, MatSort, MatSnackBar, MatStepper } from "@angular/material";
|
2017-12-19 14:57:07 +01:00
|
|
|
|
|
|
|
@Component({
|
2017-12-20 09:17:13 +01:00
|
|
|
selector: 'app-dataset-wizard-component',
|
|
|
|
templateUrl: 'dataset-wizard.component.html',
|
|
|
|
styleUrls: ['./dataset-wizard.component.scss'],
|
2018-01-25 09:14:43 +01:00
|
|
|
providers: [DatasetWizardService, ExternalSourcesService, DataManagementPlanService],
|
2017-12-19 14:57:07 +01:00
|
|
|
encapsulation: ViewEncapsulation.None
|
|
|
|
})
|
2018-01-25 09:14:43 +01:00
|
|
|
export class DatasetWizardComponent {
|
2018-03-05 17:18:45 +01:00
|
|
|
@ViewChild('stepper') stepper: MatStepper;
|
2017-12-19 14:57:07 +01:00
|
|
|
|
2018-01-17 12:57:41 +01:00
|
|
|
//dmpAutoCompleteConfiguration: AutoCompleteConfiguration;
|
|
|
|
//datasetProfileAutoCompleteConfiguration: AutoCompleteConfiguration;
|
2018-01-12 11:17:37 +01:00
|
|
|
datasetWizardModel: DatasetWizardModel;
|
2017-12-21 10:26:11 +01:00
|
|
|
isNew = true;
|
2018-01-12 11:17:37 +01:00
|
|
|
formGroup: FormGroup;
|
2018-01-26 15:24:23 +01:00
|
|
|
datasetProfileDefinitionModel: DatasetProfileDefinitionModel;
|
2018-01-17 12:57:41 +01:00
|
|
|
|
|
|
|
availableProfiles: DatasetProfileModel[] = [];
|
|
|
|
|
|
|
|
filtereddataRepositoriesAsync: boolean = false;
|
|
|
|
filteredRegistriesAsync: boolean = false;
|
|
|
|
filteredServicesAsync: boolean = false;
|
|
|
|
filteredExternalDatasetsAsync: boolean = false;
|
|
|
|
|
|
|
|
filtereddataRepositories: ExternalSourcesItemModel[];
|
|
|
|
filteredRegistries: ExternalSourcesItemModel[];
|
|
|
|
filteredServices: ExternalSourcesItemModel[];
|
2018-01-25 09:14:43 +01:00
|
|
|
filteredExternalDatasets: ExternalSourcesItemModel[];
|
2018-03-05 17:18:45 +01:00
|
|
|
itemId: string
|
2017-12-19 14:57:07 +01:00
|
|
|
constructor(
|
2017-12-20 14:34:32 +01:00
|
|
|
private datasetWizardService: DatasetWizardService,
|
2017-12-21 10:26:11 +01:00
|
|
|
private formBuilder: FormBuilder,
|
|
|
|
private datasetService: DatasetService,
|
|
|
|
private route: ActivatedRoute,
|
2018-01-12 11:17:37 +01:00
|
|
|
public snackBar: MatSnackBar,
|
2017-12-21 10:26:11 +01:00
|
|
|
public router: Router,
|
2018-01-12 11:17:37 +01:00
|
|
|
public language: TranslateService,
|
2018-01-17 12:57:41 +01:00
|
|
|
public externalSourcesService: ExternalSourcesService,
|
|
|
|
public dataManagementPlanService: DataManagementPlanService
|
2017-12-19 14:57:07 +01:00
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
isLinear = false;
|
2017-12-20 14:34:32 +01:00
|
|
|
firstStepFormGroup: FormGroup;
|
2017-12-19 14:57:07 +01:00
|
|
|
secondFormGroup: FormGroup;
|
|
|
|
|
|
|
|
ngOnInit() {
|
2017-12-20 14:34:32 +01:00
|
|
|
let dmpRequestItem: RequestItem<DataManagementPlanCriteria> = new RequestItem();
|
|
|
|
dmpRequestItem.criteria = new DataManagementPlanCriteria();
|
2018-01-25 09:14:43 +01:00
|
|
|
|
2018-01-17 12:57:41 +01:00
|
|
|
|
2017-12-21 10:26:11 +01:00
|
|
|
this.route.params.subscribe((params: Params) => {
|
2018-03-05 17:18:45 +01:00
|
|
|
this.itemId = params['id'];
|
2018-01-17 12:57:41 +01:00
|
|
|
const dmpId = params['dmpId'];
|
2018-03-05 17:18:45 +01:00
|
|
|
if (this.itemId != null) {
|
2017-12-21 10:26:11 +01:00
|
|
|
this.isNew = false;
|
2018-03-05 17:18:45 +01:00
|
|
|
this.datasetWizardService.getSingle(this.itemId).map(data => data as DatasetWizardModel)
|
2017-12-21 10:26:11 +01:00
|
|
|
.subscribe(data => {
|
2018-01-03 17:36:31 +01:00
|
|
|
this.datasetWizardModel = JsonSerializer.fromJSONObject(data, DatasetWizardModel);
|
2017-12-22 14:42:47 +01:00
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
2018-01-25 09:14:43 +01:00
|
|
|
this.loadDatasetProfiles();
|
2018-01-17 12:57:41 +01:00
|
|
|
});
|
|
|
|
} else if (dmpId != null) {
|
|
|
|
this.isNew = true;
|
|
|
|
this.dataManagementPlanService.getSingle(dmpId).map(data => data as DataManagementPlanModel)
|
|
|
|
.subscribe(data => {
|
|
|
|
this.datasetWizardModel = new DatasetWizardModel();
|
|
|
|
setTimeout(() => {
|
|
|
|
this.datasetWizardModel.dmp = data;
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
this.loadDatasetProfiles();
|
2018-01-12 11:17:37 +01:00
|
|
|
});
|
2017-12-21 10:26:11 +01:00
|
|
|
});
|
|
|
|
} else {
|
2018-01-17 12:57:41 +01:00
|
|
|
|
2017-12-21 10:26:11 +01:00
|
|
|
}
|
2017-12-19 14:57:07 +01:00
|
|
|
});
|
2018-01-12 11:17:37 +01:00
|
|
|
|
|
|
|
|
2017-12-19 14:57:07 +01:00
|
|
|
}
|
|
|
|
|
2018-01-25 16:26:08 +01:00
|
|
|
ngAfterViewInit() {
|
|
|
|
this.route.params.subscribe((params: Params) => {
|
|
|
|
let itemId = params['id'];
|
2018-03-05 17:18:45 +01:00
|
|
|
if (itemId != null) this.stepper.selectedIndex = 2;
|
2018-01-25 16:26:08 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-17 12:57:41 +01:00
|
|
|
loadDatasetProfiles() {
|
|
|
|
let datasetProfileRequestItem: RequestItem<DatasetProfileCriteria> = new RequestItem();
|
|
|
|
datasetProfileRequestItem.criteria = new DatasetProfileCriteria();
|
|
|
|
datasetProfileRequestItem.criteria.id = this.datasetWizardModel.dmp.id;
|
|
|
|
this.datasetWizardService.getAvailableProfiles(datasetProfileRequestItem).subscribe(items => {
|
2018-01-19 14:48:40 +01:00
|
|
|
this.availableProfiles = JsonSerializer.fromJSONArray(items, DatasetProfileModel);
|
2018-01-17 12:57:41 +01:00
|
|
|
});
|
|
|
|
}
|
2017-12-19 14:57:07 +01:00
|
|
|
|
|
|
|
public cancel(): void {
|
|
|
|
//this.router.navigate(['/dataManagementPlans']);
|
|
|
|
}
|
2017-12-21 10:44:57 +01:00
|
|
|
|
2018-01-25 09:14:43 +01:00
|
|
|
getDefinition() {
|
2018-01-25 16:24:21 +01:00
|
|
|
if (this.isNew) {
|
|
|
|
this.datasetWizardService.getDefinition(this.formGroup.get("profile").get("id").value).subscribe(item => {
|
2018-03-05 17:18:45 +01:00
|
|
|
this.datasetWizardModel.datasetProfileDefinition = JsonSerializer.fromJSONObject(item, DatasetProfileDefinitionModel);
|
2018-01-30 10:35:26 +01:00
|
|
|
this.datasetProfileDefinitionModel = this.datasetWizardModel.datasetProfileDefinition;
|
2018-03-05 17:18:45 +01:00
|
|
|
this.formGroup.addControl("datasetProfileDefinition", this.datasetProfileDefinitionModel.buildForm())
|
2018-01-25 16:24:21 +01:00
|
|
|
})
|
|
|
|
}
|
2018-01-25 09:14:43 +01:00
|
|
|
}
|
|
|
|
|
2017-12-21 10:44:57 +01:00
|
|
|
|
|
|
|
formSubmit(): void {
|
|
|
|
if (!this.isFormValid()) { return; }
|
|
|
|
this.onSubmit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public isFormValid() {
|
|
|
|
return this.formGroup.valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit(): void {
|
2017-12-22 14:42:47 +01:00
|
|
|
this.datasetWizardService.createDataset(this.formGroup.value).subscribe(
|
|
|
|
complete => {
|
|
|
|
this.datasetWizardService.getSingle(complete.id).subscribe(
|
2018-01-12 11:17:37 +01:00
|
|
|
result => {
|
|
|
|
this.datasetWizardModel = JsonSerializer.fromJSONObject(result, DatasetWizardModel);
|
2017-12-22 14:42:47 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
this.onCallbackSuccess()
|
|
|
|
},
|
2017-12-21 10:44:57 +01:00
|
|
|
error => this.onCallbackError(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-25 16:26:08 +01:00
|
|
|
submit() {
|
2018-01-30 12:07:51 +01:00
|
|
|
this.datasetWizardService.createDataset(this.formGroup.value).subscribe(data => {
|
2018-01-30 10:35:26 +01:00
|
|
|
this.router.navigateByUrl("/datasets/dmp/" + this.datasetWizardModel.dmp.id);
|
2018-01-25 16:26:08 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
save() {
|
2018-03-05 17:18:45 +01:00
|
|
|
this.formGroup.get("status").setValue("0");
|
2018-01-25 16:26:08 +01:00
|
|
|
this.submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
saveFinalize() {
|
2018-03-05 17:18:45 +01:00
|
|
|
this.formGroup.get("status").setValue("1");
|
2018-01-25 16:26:08 +01:00
|
|
|
this.submit();
|
|
|
|
}
|
|
|
|
|
2017-12-21 10:44:57 +01:00
|
|
|
onCallbackSuccess(): void {
|
|
|
|
this.snackBar.openFromComponent(SnackBarNotificationComponent, {
|
|
|
|
data: { message: this.isNew ? 'GENERAL.SNACK-BAR.SUCCESSFUL-CREATION' : 'GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE', language: this.language },
|
|
|
|
duration: 3000,
|
|
|
|
extraClasses: ['snackbar-success']
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackError(error: any) {
|
|
|
|
this.setErrorModel(error.error);
|
|
|
|
}
|
|
|
|
|
|
|
|
public setErrorModel(errorModel: BaseErrorModel) {
|
|
|
|
Object.keys(errorModel).forEach(item => {
|
2017-12-22 14:42:47 +01:00
|
|
|
(<any>this.datasetWizardModel.errorModel)[item] = (<any>errorModel)[item];
|
2017-12-21 10:44:57 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-17 12:57:41 +01:00
|
|
|
filterdataRepositories(value: string): void {
|
|
|
|
|
|
|
|
this.filtereddataRepositories = undefined;
|
|
|
|
if (value) {
|
|
|
|
this.filtereddataRepositoriesAsync = true;
|
|
|
|
|
2018-01-17 16:06:35 +01:00
|
|
|
this.externalSourcesService.searchDatasetRepository(value).subscribe(items => {
|
2018-01-17 12:57:41 +01:00
|
|
|
this.filtereddataRepositories = items;
|
|
|
|
this.filtereddataRepositoriesAsync = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filterRegistries(value: string): void {
|
|
|
|
|
|
|
|
this.filteredRegistries = undefined;
|
|
|
|
if (value) {
|
|
|
|
this.filteredRegistriesAsync = true;
|
|
|
|
|
2018-01-17 16:06:35 +01:00
|
|
|
this.externalSourcesService.searchDatasetRegistry(value).subscribe(items => {
|
2018-01-17 12:57:41 +01:00
|
|
|
this.filteredRegistries = items;
|
|
|
|
this.filteredRegistriesAsync = false;
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filterServices(value: string): void {
|
|
|
|
|
|
|
|
this.filteredServices = undefined;
|
|
|
|
if (value) {
|
|
|
|
this.filteredServicesAsync = true;
|
|
|
|
|
|
|
|
this.externalSourcesService.searchDatasetService(value).subscribe(items => {
|
|
|
|
this.filteredServices = items;
|
|
|
|
this.filteredServicesAsync = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
filterExternalDatasets(value: string): void {
|
|
|
|
|
|
|
|
this.filteredExternalDatasets = undefined;
|
|
|
|
if (value) {
|
|
|
|
this.filteredExternalDatasetsAsync = true;
|
|
|
|
|
|
|
|
this.externalSourcesService.searchDatasetSExternalDatasetservice(value).subscribe(items => {
|
|
|
|
this.filteredExternalDatasets = items;
|
|
|
|
this.filteredExternalDatasetsAsync = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-03-05 17:18:45 +01:00
|
|
|
|
|
|
|
downloadPDF(): void {
|
|
|
|
this.datasetWizardService.downloadPDF(this.itemId).subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/pdf' })
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-06 15:58:38 +01:00
|
|
|
downloadXML(): void {
|
|
|
|
this.datasetWizardService.downloadXML(this.itemId).subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/xml' })
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-05 17:18:45 +01:00
|
|
|
getFilenameFromContentDispositionHeader(header: string): string { // expecting filename=XXXX or filename="XXXX" to exist
|
|
|
|
// const regex: RegExp = new RegExp(/filename=((\"(.*)\")|([^;]*))/g);
|
|
|
|
const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
|
|
|
|
|
|
|
|
const matches = header.match(regex);
|
|
|
|
let filename: string;
|
|
|
|
for (let i = 0; i < matches.length; i++) {
|
|
|
|
const match = matches[i];
|
|
|
|
if (match.includes('filename="')) {
|
|
|
|
filename = match.substring(10, match.length - 1);
|
|
|
|
break;
|
|
|
|
} else if (match.includes('filename=')) {
|
|
|
|
filename = match.substring(9);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filename;
|
|
|
|
}
|
2017-12-19 14:57:07 +01:00
|
|
|
}
|