138 lines
5.3 KiB
TypeScript
138 lines
5.3 KiB
TypeScript
import { Component, Input, OnInit } from '@angular/core';
|
|
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
import { ValidationErrorModel } from '../../../../common/forms/validation/error-model/validation-error-model';
|
|
import { ProjectListingModel } from '../../../../core/model/project/project-listing';
|
|
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';
|
|
import { DataTableRequest } from '../../../../core/model/data-table/data-table-request';
|
|
import { DmpService } from '../../../../core/services/dmp/dmp.service';
|
|
import { MatDialog } from '@angular/material';
|
|
import { DmpUploadDialogue } from './upload-dialogue/dmp-upload-dialogue.component';
|
|
import { Observable } from 'rxjs';
|
|
import { ExternalSourceItemModel } from '../../../../core/model/external-sources/external-source-item';
|
|
import { ExternalSourcesService } from '../../../../core/services/external-sources/external-sources.service';
|
|
|
|
@Component({
|
|
selector: 'app-dmp-criteria-component',
|
|
templateUrl: './dmp-criteria.component.html',
|
|
styleUrls: ['./dmp-criteria.component.scss'],
|
|
})
|
|
export class DmpCriteriaComponent extends BaseCriteriaComponent implements OnInit {
|
|
|
|
@Input() showProject: boolean;
|
|
filteringProjectsAsync = false;
|
|
sizeError = false;
|
|
maxFileSize: number = 1048576;
|
|
filteringOrganisationsAsync = false;
|
|
filteredOrganisations: ExternalSourceItemModel[];
|
|
|
|
filteredProjects: ProjectListingModel[];
|
|
public formGroup = new FormBuilder().group({
|
|
like: new FormControl(),
|
|
projects: new FormControl(),
|
|
status: new FormControl(),
|
|
organisations: new FormControl()
|
|
});
|
|
|
|
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'],
|
|
titleFn: (item) => item['label']
|
|
};
|
|
|
|
organisationAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
|
|
filterFn: this.filterOrganisations.bind(this),
|
|
initialItems: (excludedItems: any[]) => this.filterOrganisations('').map(result => result.filter(resultItem => excludedItems.map(x => x.id).indexOf(resultItem.id) === -1)),
|
|
displayFn: (item) => item['name'],
|
|
titleFn: (item) => item['name']
|
|
}
|
|
|
|
constructor(
|
|
public language: TranslateService,
|
|
public projectService: ProjectService,
|
|
private dmpService: DmpService,
|
|
public formBuilder: FormBuilder,
|
|
private dialog: MatDialog,
|
|
private externalSourcesService: ExternalSourcesService
|
|
) {
|
|
super(new ValidationErrorModel());
|
|
}
|
|
|
|
ngOnInit() {
|
|
super.ngOnInit();
|
|
|
|
this.formGroup.get('organisations').valueChanges
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(x => this.controlModified());
|
|
this.formGroup.get('status').valueChanges
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(x => this.controlModified());
|
|
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());
|
|
//if (this.criteria == null) { this.criteria = new DataManagementPlanCriteria(); }
|
|
}
|
|
|
|
setCriteria(criteria: DmpCriteria): void {
|
|
this.formGroup.get('like').patchValue(criteria.like);
|
|
this.formGroup.get('projects').patchValue(criteria.projects);
|
|
this.formGroup.get('status').patchValue(criteria.status);
|
|
}
|
|
|
|
onCallbackError(error: any) {
|
|
this.setErrorModel(error.error);
|
|
}
|
|
|
|
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)
|
|
) {
|
|
setTimeout(() => this.refreshCallback());
|
|
}
|
|
}
|
|
|
|
filterProject(query: string) {
|
|
const fields: Array<string> = new Array<string>();
|
|
fields.push('asc');
|
|
const projectRequestItem: DataTableRequest<ProjectCriteria> = new DataTableRequest(0, null, { fields: fields });
|
|
projectRequestItem.criteria = new ProjectCriteria();
|
|
projectRequestItem.criteria.like = query;
|
|
return this.projectService.getPaged(projectRequestItem, "autocomplete").map(x => x.data);
|
|
}
|
|
|
|
filterOrganisations(value: string): Observable<ExternalSourceItemModel[]> {
|
|
this.filteredOrganisations = undefined;
|
|
this.filteringOrganisationsAsync = true;
|
|
|
|
return this.externalSourcesService.searchDMPOrganizations(value);
|
|
}
|
|
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
}
|