argos/dmp-frontend/src/app/ui/explore-dmp/dmp-explore-filters/explore-dmp-filters.compone...

348 lines
13 KiB
TypeScript
Raw Normal View History

2019-09-23 10:17:03 +02:00
2019-05-13 17:41:40 +02:00
import { AfterViewInit, Component, EventEmitter, Input, OnInit, Output, ViewChild } from "@angular/core";
2019-09-23 10:17:03 +02:00
import { MatAccordion } from "@angular/material/expansion";
2019-04-26 16:05:15 +02:00
import { ActivatedRoute } from "@angular/router";
import { GrantStateType } from '@app/core/common/enum/grant-state-type';
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile';
import { GrantListingModel } from '@app/core/model/grant/grant-listing';
import { OrganizationModel } from '@app/core/model/organisation/organization';
import { DatasetProfileCriteria } from '@app/core/query/dataset-profile/dataset-profile-criteria';
import { ExploreDmpCriteriaModel } from '@app/core/query/explore-dmp/explore-dmp-criteria';
import { GrantCriteria } from '@app/core/query/grant/grant-criteria';
import { OrganisationCriteria } from '@app/core/query/organisation/organisation-criteria';
import { AuthService } from '@app/core/services/auth/auth.service';
import { DatasetService } from '@app/core/services/dataset/dataset.service';
import { DmpService } from '@app/core/services/dmp/dmp.service';
import { ExternalSourcesService } from '@app/core/services/external-sources/external-sources.service';
import { GrantService } from '@app/core/services/grant/grant.service';
import { OrganisationService } from '@app/core/services/organisation/organisation.service';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { BaseCriteriaComponent } from '@app/ui/misc/criteria/base-criteria.component';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
2019-04-26 16:05:15 +02:00
import { TranslateService } from "@ngx-translate/core";
import { Observable, of as observableOf } from 'rxjs';
import { map } from 'rxjs/operators';
2019-04-26 16:05:15 +02:00
@Component({
selector: 'app-explore-dmp-filters-component',
templateUrl: './explore-dmp-filters.component.html',
styleUrls: ['./explore-dmp-filters.component.scss']
})
2019-05-13 17:41:40 +02:00
export class ExploreDmpFiltersComponent extends BaseCriteriaComponent implements OnInit, AfterViewInit {
2019-04-26 16:05:15 +02:00
@Input() facetCriteria = new ExploreDmpCriteriaModel();
@Output() facetCriteriaChange = new EventEmitter();
2019-05-13 17:41:40 +02:00
@Input() displayTitleFunc: (value) => string;
GrantStateType = GrantStateType;
grants: Observable<GrantListingModel[]>;
2019-04-26 16:05:15 +02:00
profiles: Observable<DatasetProfileModel[]>;
dmpOrganisations: Observable<OrganizationModel[]>;
grantOptions: Observable<GrantListingModel[]>;
grantStateOptions: Observable<any[]>;
2019-05-13 17:41:40 +02:00
filteringOrganisationsAsync = false;
filteredOrganisations: OrganizationModel[];
status: GrantStateType;
2019-05-13 17:41:40 +02:00
IsChecked: boolean;
IsIndeterminate: boolean;
LabelAlign: string;
IsDisabled: boolean;
Active: string;
Inactive: string;
2019-09-23 10:17:03 +02:00
@ViewChild('facetAccordion', { static: false }) accordion: MatAccordion;
2019-04-26 16:05:15 +02:00
displayGrantStateValue = (option) => option['value'];
displayGrantStateLabel = (option) => option['label'];
2019-04-26 16:05:15 +02:00
displayGrantValue = (option) => option['id'];
displayGrantLabel = (option) => option['label'];
2019-04-26 16:05:15 +02:00
displayProfileValue = (option) => option['id'];
displayProfileLabel = (option) => option['label'];
displayDmpOrganisationsValue = (option) => option['id'];
displayDmpOrganisationsLabel = (option) => option['name'];
2019-05-13 17:41:40 +02:00
profileAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
filterFn: this.filterProfile.bind(this),
initialItems: (excludedItems: any[]) =>
this.filterProfile('').pipe(
map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
2019-05-13 17:41:40 +02:00
displayFn: (item) => item['label'],
titleFn: (item) => item['label']
};
organizationAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
filterFn: this.filterOrganisation.bind(this),
initialItems: (excludedItems: any[]) =>
2019-09-23 10:17:03 +02:00
this.getOrganisations().pipe(
map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
2019-05-13 17:41:40 +02:00
displayFn: (item) => item['name'],
titleFn: (item) => item['name']
}
grantAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
filterFn: this.filterGrant.bind(this),
2019-05-13 17:41:40 +02:00
initialItems: (excludedItems: any[]) =>
2019-09-23 10:17:03 +02:00
this.filterGrant('').pipe(
map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
2019-05-13 17:41:40 +02:00
displayFn: (item) => item['label'],
titleFn: (item) => item['label']
}
2019-04-26 16:05:15 +02:00
constructor(
public activatedRoute: ActivatedRoute,
public languageService: TranslateService,
public grantService: GrantService,
private authentication: AuthService,
2019-04-26 16:05:15 +02:00
public datasetProfileService: DatasetService,
2019-05-13 17:41:40 +02:00
public organisationService: OrganisationService,
2019-04-26 16:05:15 +02:00
public externalSourcesService: ExternalSourcesService,
2019-05-13 17:41:40 +02:00
private dmpService: DmpService
) {
super(new ValidationErrorModel());
this.IsChecked = false;
this.IsIndeterminate = false;
this.LabelAlign = 'after';
this.IsDisabled = false;
this.Active = "0";
this.Inactive = "1";
}
2019-04-26 16:05:15 +02:00
ngOnInit() {
setTimeout(x => {
2019-09-23 10:17:03 +02:00
this.grantStateOptions = observableOf(
2019-04-26 16:05:15 +02:00
[
{ label: this.languageService.instant('FACET-SEARCH.GRANT-STATUS.OPTIONS.INACTIVE'), value: GrantStateType.Finished },
{ label: this.languageService.instant('FACET-SEARCH.GRANT-STATUS.OPTIONS.ACTIVE'), value: GrantStateType.OnGoing },
2019-04-26 16:05:15 +02:00
]);
});
//this.profiles = this.datasetProfileService.getDatasetProfiles();
const fields: Array<string> = new Array<string>();
fields.push('asc');
2019-09-23 10:17:03 +02:00
this.dmpOrganisations = this.organisationService.searchPublicOrganisations(new DataTableRequest<OrganisationCriteria>(0, null, { fields: fields })).pipe(map(x => x.data));
2019-04-26 16:05:15 +02:00
}
ngAfterViewInit(): void {
2019-05-13 17:41:40 +02:00
// this.accordion.openAll();
}
OnChange($event) {
2019-05-13 17:41:40 +02:00
console.log($event);
}
OnIndeterminateChange($event) {
console.log($event);
2019-04-26 16:05:15 +02:00
}
controlModified() {
this.facetCriteriaChange.emit(this.facetCriteria);
}
grantSearch(value: string): Observable<GrantListingModel[]> {
const grantCriteria = new GrantCriteria();
grantCriteria.grantStateType = this.facetCriteria.grantStatus;
grantCriteria['length'] = 10;
grantCriteria.like = value;
2019-04-26 16:05:15 +02:00
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dataTableRequest: DataTableRequest<GrantCriteria> = new DataTableRequest(0, null, { fields: fields });
dataTableRequest.criteria = grantCriteria;
2019-09-23 10:17:03 +02:00
return this.grantService.getPublicPaged(dataTableRequest).pipe(map(x => x.data));
2019-04-26 16:05:15 +02:00
}
grantStatusChanged(event) {
this.facetCriteria.grantStatus = event.value;
// this.facetCriteria.grantStatus = +event.source.ariaLabel; // For checkboxes
// this.facetCriteria.grantStatus = event.option.value.value; // For <app-explore-dmp-filter-item-component>
// if (!event.source.checked) {
if (event.value === 'null') {
this.facetCriteria.grantStatus = null;
2019-09-23 10:17:03 +02:00
this.grants = observableOf([]);
this.facetCriteria.grants = [];
2019-04-26 16:05:15 +02:00
}
2019-05-13 17:41:40 +02:00
// if (event.checked) {
// if (event.option.selected) {
// if (event.source.checked) {
else {
2019-04-26 16:05:15 +02:00
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dataTableRequest: DataTableRequest<GrantCriteria> = new DataTableRequest(0, null, { fields: fields });
dataTableRequest.criteria = new GrantCriteria();
dataTableRequest.criteria.grantStateType = this.facetCriteria.grantStatus;
2019-04-26 16:05:15 +02:00
dataTableRequest.criteria['length'] = 10;
2019-09-23 10:17:03 +02:00
this.grants = this.grantService.getPublicPaged(dataTableRequest).pipe(map(x => x.data));
this.facetCriteria.grants = [];
2019-04-26 16:05:15 +02:00
}
this.facetCriteriaChange.emit(this.facetCriteria);
}
grantChanged(event: any) {
2019-04-26 16:05:15 +02:00
const eventValue = event.option.value.id;
if (event.option.selected) { this.facetCriteria.grants.push(eventValue); }
2019-04-26 16:05:15 +02:00
if (!event.option.selected) {
const index = this.facetCriteria.grants.indexOf(eventValue);
this.facetCriteria.grants.splice(index, 1);
2019-04-26 16:05:15 +02:00
}
this.facetCriteriaChange.emit(this.facetCriteria);
}
removeGrant(grant) {
this.facetCriteria.grants.splice(this.facetCriteria.grants.indexOf(grant), 1);
2019-04-26 16:05:15 +02:00
this.facetCriteriaChange.emit(this.facetCriteria);
}
onProfileOptionSelected(items: DatasetProfileModel) {
//this.facetCriteria.datasetProfile.splice(0);
this.facetCriteria.datasetProfile.push(items.id);
2019-05-13 17:41:40 +02:00
this.facetCriteriaChange.emit(this.facetCriteria);
}
onProfileOptionRemoved(item: DatasetProfileModel) {
const index = this.facetCriteria.datasetProfile.indexOf(item.id);
if (index >= 0) {
this.facetCriteria.datasetProfile.splice(index, 1);
this.facetCriteriaChange.emit(this.facetCriteria);
}
}
2019-04-26 16:05:15 +02:00
profileChanged(event: any) {
const eventValue = event.option.value.id;
if (event.option.selected) {
this.facetCriteria.datasetProfile.push(eventValue);
}
if (!event.option.selected) {
const index = this.facetCriteria.datasetProfile.indexOf(eventValue);
this.facetCriteria.datasetProfile.splice(index, 1);
}
this.facetCriteriaChange.emit(this.facetCriteria);
}
removeProfile(profile) {
this.facetCriteria.datasetProfile.splice(this.facetCriteria.datasetProfile.indexOf(profile), 1);
this.facetCriteriaChange.emit(this.facetCriteria);
}
onOrganizationOptionSelected(item: OrganizationModel) {
this.facetCriteria.dmpOrganisations.push(item.id);
2019-05-13 17:41:40 +02:00
this.facetCriteriaChange.emit(this.facetCriteria);
}
onOrganizationOptionRemoved(item: OrganizationModel) {
const index = this.facetCriteria.dmpOrganisations.indexOf(item.id);
if (index >= 0) {
this.facetCriteria.dmpOrganisations.splice(index, 1);
this.facetCriteriaChange.emit(this.facetCriteria);
}
}
onGrantOptionSelected(item: GrantListingModel) {
this.facetCriteria.grants.push(item.id);
2019-05-13 17:41:40 +02:00
this.facetCriteriaChange.emit(this.facetCriteria);
}
onGrantOptionRemoved(item: GrantListingModel) {
const index = this.facetCriteria.grants.indexOf(item.id);
2019-05-13 17:41:40 +02:00
if (index >= 0) {
this.facetCriteria.grants.splice(index, 1);
2019-05-13 17:41:40 +02:00
this.facetCriteriaChange.emit(this.facetCriteria);
}
}
public roleChanged(event: any) {
this.facetCriteria.role = event.value;
if (event.value === 'null') {
this.facetCriteria.role = null;
}
this.facetCriteriaChange.emit(this.facetCriteria);
}
2019-04-26 16:05:15 +02:00
dmpOrganisationChanged(event: any) {
const eventValue = event.option.value.id;
if (event.option.selected) { this.facetCriteria.dmpOrganisations.push(eventValue); }
if (!event.option.selected) {
const index = this.facetCriteria.dmpOrganisations.indexOf(eventValue);
this.facetCriteria.dmpOrganisations.splice(index, 1);
}
this.facetCriteriaChange.emit(this.facetCriteria);
}
// profileSearch(value: string) {
// return this.datasetProfileService.getDatasetProfiles();
// }
2019-04-26 16:05:15 +02:00
dmpOrganisationSearch(value: string): Observable<OrganizationModel[]> {
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dataTableRequest: DataTableRequest<OrganisationCriteria> = new DataTableRequest(0, null, { fields: fields });
dataTableRequest.criteria = new OrganisationCriteria();
dataTableRequest.criteria.labelLike = value;
2019-09-23 10:17:03 +02:00
return this.organisationService.searchPublicOrganisations(dataTableRequest).pipe(map(x => x.data));
2019-04-26 16:05:15 +02:00
}
removeOrganisation(organisation) {
this.facetCriteria.dmpOrganisations.splice(this.facetCriteria.dmpOrganisations.indexOf(organisation), 1);
this.facetCriteriaChange.emit(this.facetCriteria);
}
2019-05-13 17:41:40 +02:00
// getProfiles() {
// return this.datasetProfileService.getDatasetProfiles();
// }
2019-05-13 17:41:40 +02:00
getOrganisations() {
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dataTableRequest: DataTableRequest<OrganisationCriteria> = new DataTableRequest(0, null, { fields: fields });
dataTableRequest.criteria = new OrganisationCriteria();
dataTableRequest.criteria.labelLike = '';
2019-09-23 10:17:03 +02:00
return this.organisationService.searchPublicOrganisations(dataTableRequest).pipe(map(x => x.data));
2019-05-13 17:41:40 +02:00
}
filterGrant(query: string) {
2019-05-13 17:41:40 +02:00
const fields: Array<string> = new Array<string>();
fields.push('asc');
const grantRequestItem: DataTableRequest<GrantCriteria> = new DataTableRequest(0, null, { fields: fields });
grantRequestItem.criteria = new GrantCriteria();
grantRequestItem.criteria.like = query;
2019-09-23 10:17:03 +02:00
return this.grantService.getPublicPaged(grantRequestItem).pipe(map(x => x.data));
2019-05-13 17:41:40 +02:00
}
filterProfile(query: string) {
const fields: Array<string> = new Array<string>();
fields.push('asc');
const profileRequestItem: DataTableRequest<DatasetProfileCriteria> = new DataTableRequest(0, null, { fields: fields });
profileRequestItem.criteria = new DatasetProfileCriteria();
2019-05-13 17:41:40 +02:00
profileRequestItem.criteria.like = query;
return this.datasetProfileService.getDatasetProfiles(profileRequestItem);
2019-05-13 17:41:40 +02:00
}
filterOrganisation(value: string) {
this.filteringOrganisationsAsync = true;
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dataTableRequest: DataTableRequest<OrganisationCriteria> = new DataTableRequest(0, null, { fields: fields });
dataTableRequest.criteria = new OrganisationCriteria();
dataTableRequest.criteria.labelLike = value;
2019-09-23 10:17:03 +02:00
return this.organisationService.searchPublicOrganisations(dataTableRequest).pipe(map(x => x.data));
2019-05-13 17:41:40 +02:00
}
displayLabel(value) {
return this.displayTitleFunc ? this.displayTitleFunc(value) : value;
}
isOptionSelected(profile: any) {
return this.formGroup.value.map(x => x.id).indexOf(profile.id) !== -1;
}
public isAuthenticated(): boolean {
return !(!this.authentication.current());
}
2019-04-26 16:05:15 +02:00
}