107 lines
4.5 KiB
TypeScript
107 lines
4.5 KiB
TypeScript
|
import { Component, OnInit, ViewEncapsulation, Input, ViewChild, Output, EventEmitter } from '@angular/core';
|
||
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
||
|
import { BreadCrumbResolverService } from '../../../services/breadcrumb/breadcrumb-resolver.service';
|
||
|
import { Observable } from 'rxjs/Observable';
|
||
|
import { FacetSearchCriteriaModel } from '../../../models/facet-search/FacetSearchCriteriaModel';
|
||
|
import { ProjectStateType } from '../../../models/projects/ProjectStateType';
|
||
|
import { ProjectModel } from '../../../models/projects/ProjectModel';
|
||
|
import { ProjectService } from '../../../services/project/project.service';
|
||
|
import { ProjectCriteria } from '../../../models/criteria/project/ProjectCriteria';
|
||
|
import { DataTableRequest } from '../../../models/data-table/DataTableRequest';
|
||
|
import { ProjectListingModel } from '../../../models/projects/ProjectListingModel';
|
||
|
import { MatSelectionList, MatListOption, MatSelectionListChange } from '@angular/material';
|
||
|
import { SelectionModel } from '@angular/cdk/collections';
|
||
|
import { DatasetProfileService } from '../../../services/dataset-profile.service';
|
||
|
import { DatasetService } from '../../../services/dataset/dataset.service';
|
||
|
import { DatasetProfileModel } from '../../../models/datasetprofile/DatasetProfileModel';
|
||
|
import { RequestItem } from '../../../models/criteria/RequestItem';
|
||
|
import { ExternalSourcesService } from '../../../services/external-sources/external-sources.service';
|
||
|
import { ExternalSourcesItemModel } from '../../../models/external-sources/ExternalSourcesItemModel';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-facet',
|
||
|
templateUrl: './facet-search.component.html',
|
||
|
styleUrls: ['./facet-search.component.scss'],
|
||
|
encapsulation: ViewEncapsulation.None,
|
||
|
providers: [ProjectService]
|
||
|
})
|
||
|
export class FacetSearchComponent implements OnInit {
|
||
|
|
||
|
@Input()
|
||
|
facetCriteria = new FacetSearchCriteriaModel();
|
||
|
|
||
|
@Output()
|
||
|
facetCriteriaChange = new EventEmitter();
|
||
|
|
||
|
ProjectStateType = ProjectStateType;
|
||
|
projects: Observable<ProjectModel[]>
|
||
|
profiles: Observable<DatasetProfileModel[]>
|
||
|
dmpOrganisations: Observable<ExternalSourcesItemModel[]>
|
||
|
|
||
|
@ViewChild("project") selectionList: MatSelectionList
|
||
|
|
||
|
constructor(
|
||
|
public activatedRoute: ActivatedRoute,
|
||
|
public projectService: ProjectService,
|
||
|
public datasetProfileService: DatasetService,
|
||
|
public externalSourcesService: ExternalSourcesService
|
||
|
) {
|
||
|
}
|
||
|
|
||
|
ngOnInit() {
|
||
|
this.profiles = this.datasetProfileService.getDatasetProfiles()
|
||
|
this.selectionList.selectedOptions = new SelectionModel<MatListOption>(false);
|
||
|
this.dmpOrganisations = this.externalSourcesService.searchDMPOrganizations('')
|
||
|
}
|
||
|
|
||
|
public projectStatusChanged(event) {
|
||
|
this.facetCriteria.projectStatus = event.option.value
|
||
|
if (!event.option.selected) {
|
||
|
this.facetCriteria.projectStatus = null;
|
||
|
this.projects = Observable.of([])
|
||
|
this.facetCriteria.projects = []
|
||
|
}
|
||
|
if (event.option.selected) {
|
||
|
let projectCriteria = new ProjectCriteria()
|
||
|
projectCriteria.projectStateType = this.facetCriteria.projectStatus;
|
||
|
projectCriteria["length"] = 10;
|
||
|
let dataTableRequest: RequestItem<ProjectCriteria> = { criteria: projectCriteria };
|
||
|
this.projects = this.projectService.get(dataTableRequest);
|
||
|
this.facetCriteria.projects = []
|
||
|
}
|
||
|
this.facetCriteriaChange.emit(this.facetCriteria);
|
||
|
}
|
||
|
|
||
|
public projectChanged(event: any) {
|
||
|
let eventValue = event.option.value
|
||
|
if (event.option.selected) this.facetCriteria.projects.push(eventValue);
|
||
|
if (!event.option.selected) {
|
||
|
var index = this.facetCriteria.projects.indexOf(eventValue);
|
||
|
this.facetCriteria.projects.splice(index, 1);
|
||
|
}
|
||
|
this.facetCriteriaChange.emit(this.facetCriteria);
|
||
|
}
|
||
|
|
||
|
public profileChanged(event: any) {
|
||
|
let eventValue = event.option.value
|
||
|
if (event.option.selected) {
|
||
|
this.facetCriteria.datasetProfile.push(eventValue);
|
||
|
}
|
||
|
if (!event.option.selected) {
|
||
|
var index = this.facetCriteria.datasetProfile.indexOf(eventValue);
|
||
|
this.facetCriteria.datasetProfile.splice(index, 1);
|
||
|
}
|
||
|
this.facetCriteriaChange.emit(this.facetCriteria);
|
||
|
}
|
||
|
|
||
|
public dmpOrganisationChanged(event: any) {
|
||
|
let eventValue = event.option.value
|
||
|
if (event.option.selected) this.facetCriteria.dmpOrganisations.push(eventValue);
|
||
|
if (!event.option.selected) {
|
||
|
var index = this.facetCriteria.dmpOrganisations.indexOf(eventValue);
|
||
|
this.facetCriteria.dmpOrganisations.splice(index, 1);
|
||
|
}
|
||
|
this.facetCriteriaChange.emit(this.facetCriteria);
|
||
|
}
|
||
|
}
|