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';
|
|
|
|
import { ProjectModel } from '../../../../core/model/project/project';
|
|
|
|
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';
|
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;
|
|
|
|
filteredProjects: ProjectModel[];
|
|
|
|
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,
|
|
|
|
public formBuilder: FormBuilder
|
|
|
|
) {
|
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) {
|
|
|
|
const projectRequestItem: RequestItem<ProjectCriteria> = new RequestItem();
|
|
|
|
projectRequestItem.criteria = new ProjectCriteria();
|
|
|
|
projectRequestItem.criteria.like = query;
|
2018-11-30 15:57:20 +01:00
|
|
|
return this.projectService.get(projectRequestItem);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|