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';
|
2017-12-14 18:13:28 +01:00
|
|
|
import { DataManagementPlanCriteria } from '../../../../models/criteria/data-management-plan/DataManagementPlanCriteria';
|
|
|
|
import { DataManagementPlanCriteriaErrorModel } from '../../../../models/criteria/data-management-plan/DataManagementPlanCriteriaErrorModel';
|
2017-12-19 10:53:52 +01:00
|
|
|
import { ProjectCriteria } from '../../../../models/criteria/project/ProjectCriteria';
|
|
|
|
import { RequestItem } from '../../../../models/criteria/RequestItem';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { ProjectModel } from '../../../../models/projects/ProjectModel';
|
|
|
|
import { ProjectService } from '../../../../services/project/project.service';
|
2018-08-24 17:21:02 +02:00
|
|
|
import { MultipleAutoCompleteConfiguration } from '../../autocompletes/multiple/multiple-auto-complete-configuration';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { BaseCriteriaComponent } from '../base/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
|
|
|
})
|
|
|
|
|
|
|
|
export class DataManagementPlanCriteriaComponent extends BaseCriteriaComponent implements OnInit {
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
@Input()
|
|
|
|
showProject: boolean;
|
|
|
|
filteringProjectsAsync = false;
|
|
|
|
filteredProjects: ProjectModel[];
|
|
|
|
projectAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
|
|
public formGroup = new FormBuilder().group({
|
|
|
|
like: new FormControl(),
|
|
|
|
projects: new FormControl()
|
|
|
|
});
|
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
|
|
|
|
) {
|
|
|
|
super(new DataManagementPlanCriteriaErrorModel());
|
|
|
|
}
|
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-10-05 17:00:54 +02:00
|
|
|
this.projectAutoCompleteConfiguration = {
|
|
|
|
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'],
|
|
|
|
titleFn: (item) => item['label'],
|
|
|
|
//mapFn: (item) => new JsonSerializer<ProjectReference>().fromJSONArray(item, ProjectReference).map(item => item.toDropdownList()),
|
|
|
|
loadDataOnStart: true
|
|
|
|
};
|
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
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
setCriteria(criteria: DataManagementPlanCriteria): void {
|
|
|
|
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;
|
|
|
|
return this.projectService.getWithExternal(projectRequestItem);
|
|
|
|
}
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|