2019-07-01 11:35:09 +02:00
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { Router } from '@angular/router';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DatasetStatus } from '@app/core/common/enum/dataset-status';
|
|
|
|
import { DatasetService } from '@app/core/services/dataset/dataset.service';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2021-05-10 14:51:10 +02:00
|
|
|
import { Observable, of } from 'rxjs';
|
|
|
|
import { catchError, map, takeUntil } from 'rxjs/operators';
|
|
|
|
|
2018-10-11 13:22:03 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-01-18 18:03:45 +01:00
|
|
|
selector: 'app-dmp-finalize-dialog-component',
|
|
|
|
templateUrl: 'dmp-finalize-dialog.component.html',
|
2019-02-08 11:31:22 +01:00
|
|
|
styleUrls: ['./dmp-finalize-dialog.component.scss']
|
2018-10-11 13:22:03 +02:00
|
|
|
})
|
2019-01-18 18:03:45 +01:00
|
|
|
export class DmpFinalizeDialogComponent extends BaseComponent implements OnInit {
|
2018-10-11 13:22:03 +02:00
|
|
|
|
2019-07-01 11:35:09 +02:00
|
|
|
inputModel: DmpFinalizeDialogInput;
|
|
|
|
outputModel: DmpFinalizeDialogOutput;
|
|
|
|
|
2021-05-10 14:51:10 +02:00
|
|
|
protected datasetLookupStatus:DatasetStatusLookup[] = [];
|
|
|
|
protected datasetLookupStatusEnum = DatasetStatusLookup;
|
2018-10-11 13:22:03 +02:00
|
|
|
constructor(
|
|
|
|
public router: Router,
|
2019-01-18 18:03:45 +01:00
|
|
|
public dialogRef: MatDialogRef<DmpFinalizeDialogComponent>,
|
2019-07-01 11:35:09 +02:00
|
|
|
public datasetService: DatasetService,
|
2018-10-11 13:22:03 +02:00
|
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
|
|
) {
|
2018-11-27 18:33:17 +01:00
|
|
|
super();
|
2019-07-01 11:35:09 +02:00
|
|
|
this.inputModel = data['dialogInputModel'];
|
|
|
|
this.outputModel = { datasetsToBeFinalized: [] };
|
2018-10-12 10:22:23 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 14:51:10 +02:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.inputModel.datasets.forEach(ds=>{
|
|
|
|
|
|
|
|
this.validateDataset(ds.id).subscribe(_=>{
|
|
|
|
console.log('response', _);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
const drafts = this.getDraftDatasets();
|
|
|
|
|
|
|
|
drafts.forEach(draft=>{
|
|
|
|
this.datasetLookupStatus[draft.id] == DatasetStatusLookup.PENDING_VALIDATION;
|
|
|
|
this.validateDataset(draft.id)
|
|
|
|
.subscribe(isValid=>{
|
|
|
|
if(isValid){
|
|
|
|
this.datasetLookupStatus[draft.id] = DatasetStatusLookup.VALID;
|
|
|
|
}else{
|
|
|
|
this.datasetLookupStatus[draft.id] = DatasetStatusLookup.INVALID;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-10-12 10:22:23 +02:00
|
|
|
|
|
|
|
onSubmit() {
|
2019-07-01 11:35:09 +02:00
|
|
|
this.dialogRef.close(this.outputModel);
|
2018-10-12 10:22:23 +02:00
|
|
|
}
|
|
|
|
|
2019-07-01 11:35:09 +02:00
|
|
|
getFinalizedDatasets() {
|
|
|
|
return this.inputModel.datasets.filter(x => x.status === DatasetStatus.Finalized);
|
2018-10-11 13:22:03 +02:00
|
|
|
}
|
|
|
|
|
2019-07-01 11:35:09 +02:00
|
|
|
getDraftDatasets() {
|
|
|
|
return this.inputModel.datasets.filter(x => x.status === DatasetStatus.Draft);
|
2019-06-21 15:55:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
2019-07-01 11:35:09 +02:00
|
|
|
this.dialogRef.close({ cancelled: true } as DmpFinalizeDialogOutput);
|
2019-06-21 15:55:38 +02:00
|
|
|
}
|
2021-05-10 14:51:10 +02:00
|
|
|
|
|
|
|
validateDataset(datasetId: string) : Observable<boolean>{
|
|
|
|
return this.datasetService
|
|
|
|
.validateDataset(datasetId)
|
|
|
|
.pipe(
|
|
|
|
takeUntil(this._destroyed),
|
|
|
|
map(_=>{
|
|
|
|
return true
|
|
|
|
}),
|
|
|
|
catchError(error=>{
|
|
|
|
return of(false);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get validDrafts(){
|
|
|
|
return this.getDraftDatasets().filter(x=> this.datasetLookupStatus[x.id] && (this.datasetLookupStatus[x.id] == DatasetStatusLookup.VALID));
|
|
|
|
}
|
2019-07-01 11:35:09 +02:00
|
|
|
}
|
2019-06-21 15:55:38 +02:00
|
|
|
|
2019-07-01 11:35:09 +02:00
|
|
|
export interface DmpFinalizeDialogInput {
|
|
|
|
dmpLabel: string;
|
|
|
|
dmpDescription: string;
|
|
|
|
datasets: DmpFinalizeDialogDataset[];
|
2022-11-24 15:29:11 +01:00
|
|
|
accessRights: boolean;
|
2019-07-01 11:35:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface DmpFinalizeDialogDataset {
|
|
|
|
label: string;
|
|
|
|
id?: string;
|
|
|
|
status: DatasetStatus;
|
|
|
|
}
|
2019-06-21 15:55:38 +02:00
|
|
|
|
2019-07-01 11:35:09 +02:00
|
|
|
export interface DmpFinalizeDialogOutput {
|
|
|
|
cancelled?: boolean;
|
|
|
|
datasetsToBeFinalized?: string[];
|
2018-10-11 13:22:03 +02:00
|
|
|
}
|
2021-05-10 14:51:10 +02:00
|
|
|
enum DatasetStatusLookup{
|
|
|
|
VALID = "VALID",
|
|
|
|
INVALID = "INVALID",
|
|
|
|
PENDING_VALIDATION = "PENDING"
|
|
|
|
}
|