2018-11-27 18:33:17 +01:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
|
|
import { FormBuilder, FormControl } from '@angular/forms';
|
2017-12-14 18:13:28 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { ValidationErrorModel } from '../../../../common/forms/validation/error-model/validation-error-model';
|
2019-01-30 17:37:49 +01:00
|
|
|
import { ProjectListingModel } from '../../../../core/model/project/project-listing';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { DmpCriteria } from '../../../../core/query/dmp/dmp-criteria';
|
|
|
|
import { ProjectCriteria } from '../../../../core/query/project/project-criteria';
|
|
|
|
import { ProjectService } from '../../../../core/services/project/project.service';
|
|
|
|
import { MultipleAutoCompleteConfiguration } from '../../../../library/auto-complete/multiple/multiple-auto-complete-configuration';
|
|
|
|
import { RequestItem } from '../../../../core/query/request-item';
|
|
|
|
import { BaseCriteriaComponent } from '../../../misc/criteria/base-criteria.component';
|
2019-01-30 17:37:49 +01:00
|
|
|
import { DataTableRequest } from '../../../../core/model/data-table/data-table-request';
|
2019-03-05 12:59:34 +01:00
|
|
|
import { DmpService } from '../../../../core/services/dmp/dmp.service';
|
|
|
|
import { MatDialog } from '@angular/material';
|
|
|
|
import { DmpUploadDialogue } from './upload-dialogue/dmp-upload-dialogue.component';
|
2017-12-14 18:13:28 +01:00
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-dmp-criteria-component',
|
|
|
|
templateUrl: './dmp-criteria.component.html',
|
|
|
|
styleUrls: ['./dmp-criteria.component.scss'],
|
2017-12-14 18:13:28 +01:00
|
|
|
})
|
2019-01-18 18:03:45 +01:00
|
|
|
export class DmpCriteriaComponent extends BaseCriteriaComponent implements OnInit {
|
2017-12-14 18:13:28 +01:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
@Input() showProject: boolean;
|
2018-10-05 17:00:54 +02:00
|
|
|
filteringProjectsAsync = false;
|
2019-03-05 12:59:34 +01:00
|
|
|
sizeError = false;
|
|
|
|
maxFileSize: number = 1048576;
|
|
|
|
|
2019-01-30 17:37:49 +01:00
|
|
|
filteredProjects: ProjectListingModel[];
|
2018-10-05 17:00:54 +02:00
|
|
|
public formGroup = new FormBuilder().group({
|
|
|
|
like: new FormControl(),
|
|
|
|
projects: new FormControl()
|
|
|
|
});
|
2019-01-18 18:03:45 +01:00
|
|
|
projectAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.filterProject.bind(this),
|
|
|
|
initialItems: (excludedItems: any[]) => this.filterProject('').map(result => result.filter(resultItem => excludedItems.map(x => x.id).indexOf(resultItem.id) === -1)),
|
|
|
|
displayFn: (item) => item['label'],
|
2019-01-21 12:14:20 +01:00
|
|
|
titleFn: (item) => item['label']
|
2019-01-18 18:03:45 +01:00
|
|
|
};
|
2017-12-14 18:13:28 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
constructor(
|
|
|
|
public language: TranslateService,
|
|
|
|
public projectService: ProjectService,
|
2019-03-05 12:59:34 +01:00
|
|
|
private dmpService: DmpService,
|
|
|
|
public formBuilder: FormBuilder,
|
|
|
|
private dialog: MatDialog
|
2018-10-05 17:00:54 +02:00
|
|
|
) {
|
2019-01-18 18:03:45 +01:00
|
|
|
super(new ValidationErrorModel());
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2017-12-14 18:13:28 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngOnInit() {
|
|
|
|
super.ngOnInit();
|
2018-08-24 17:21:02 +02:00
|
|
|
|
2018-11-27 18:33:17 +01:00
|
|
|
this.formGroup.get('projects').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => this.controlModified());
|
|
|
|
this.formGroup.get('like').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => this.controlModified());
|
2018-10-05 17:00:54 +02:00
|
|
|
//if (this.criteria == null) { this.criteria = new DataManagementPlanCriteria(); }
|
|
|
|
}
|
2017-12-14 18:13:28 +01:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
setCriteria(criteria: DmpCriteria): void {
|
2018-10-05 17:00:54 +02:00
|
|
|
this.formGroup.get('like').patchValue(criteria.like);
|
|
|
|
this.formGroup.get('projects').patchValue(criteria.projects);
|
|
|
|
}
|
2017-12-19 10:53:52 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
onCallbackError(error: any) {
|
|
|
|
this.setErrorModel(error.error);
|
|
|
|
}
|
2017-12-19 10:53:52 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
controlModified(): void {
|
|
|
|
this.clearErrorModel();
|
|
|
|
if (this.refreshCallback != null &&
|
|
|
|
(this.formGroup.get('like').value == null || this.formGroup.get('like').value.length === 0 || this.formGroup.get('like').value.length > 2)
|
|
|
|
) {
|
|
|
|
this.refreshCallback();
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 10:53:52 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
filterProject(query: string) {
|
2019-01-30 17:37:49 +01:00
|
|
|
const fields: Array<string> = new Array<string>();
|
|
|
|
fields.push('asc');
|
|
|
|
const projectRequestItem: DataTableRequest<ProjectCriteria> = new DataTableRequest(0, null, { fields: fields });
|
2018-10-05 17:00:54 +02:00
|
|
|
projectRequestItem.criteria = new ProjectCriteria();
|
|
|
|
projectRequestItem.criteria.like = query;
|
2019-01-31 12:24:11 +01:00
|
|
|
return this.projectService.getPaged(projectRequestItem, "autocomplete").map(x => x.data);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2019-03-05 12:59:34 +01:00
|
|
|
|
|
|
|
fileSave(event) {
|
|
|
|
const dialogRef = this.dialog.open(DmpUploadDialogue, {
|
|
|
|
data: {
|
|
|
|
fileList: FileList,
|
|
|
|
success: Boolean,
|
|
|
|
dmpTitle: String
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result && result.success) {
|
|
|
|
this.dmpService.uploadXml(result.fileList, result.dmpTitle)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|