From d9c7d35e57e241f468aeeb8019e53811fb1b0b84 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Thu, 14 Dec 2023 18:14:57 +0200 Subject: [PATCH] [develop-filters | DONE | CHANGED]: Get 7 top values for each filter (minRef) and on view all click, query for top 100 for a specific filter. 1. searchResearchResults.service.ts & searchProjects.service.ts & searchOrganizations.service.ts & searchDataproviders.service.ts: In advanced search method added parameter minRef: boolean = false and if true, add in request url "&minRef=true" to query for top 7 values. 2. searchResearchResults.component.ts & searchProjects.component.ts & searchOrganizations.component.ts & searchDataProviders.component.ts: By default query filters with minRef=true | Added method "filterRequestedAll()" to be called on view all click of a filter. 3. searchHelperClasses.class.ts: Added in Filter public countAllValues?: number = -1; (-1: all filters not yet requested, 0: request failed) and public isOpen?: boolean = false; (checks if view all filter is clicked). 4. searchFilter.module.ts: Imported LoadingModule. 5. searchFilter.component.ts & searchFilter.component.html: Updated process on view all click. 6. newSearchPage.component.ts: Added method "filterToggled()". 7. newSearchPage.component.html: Bind filterToggled method to output. --- searchPages/searchDataProviders.component.ts | 46 +++++++++++++- searchPages/searchOrganizations.component.ts | 52 +++++++++++++-- searchPages/searchProjects.component.ts | 56 +++++++++++++++-- .../searchResearchResults.component.ts | 63 ++++++++++++++++++- .../searchUtils/newSearchPage.component.html | 1 + .../searchUtils/newSearchPage.component.ts | 12 +++- .../searchUtils/searchFilter.component.html | 56 ++++++++++------- .../searchUtils/searchFilter.component.ts | 24 +++++-- .../searchUtils/searchFilter.module.ts | 3 +- .../searchUtils/searchHelperClasses.class.ts | 2 + services/searchDataproviders.service.ts | 3 +- services/searchOrganizations.service.ts | 3 +- services/searchProjects.service.ts | 4 +- services/searchResearchResults.service.ts | 3 +- 14 files changed, 277 insertions(+), 51 deletions(-) diff --git a/searchPages/searchDataProviders.component.ts b/searchPages/searchDataProviders.component.ts index 7f698b42..4b8647cc 100644 --- a/searchPages/searchDataProviders.component.ts +++ b/searchPages/searchDataProviders.component.ts @@ -1,4 +1,4 @@ -import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core'; +import {ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {AdvancedField, Filter} from './searchUtils/searchHelperClasses.class'; import {SearchDataprovidersService} from '../services/searchDataproviders.service'; @@ -42,7 +42,8 @@ import {RefineFieldResultsService} from "../services/refineFieldResults.service" [simpleView]="simpleView" formPlaceholderText="Search by name, description, subject..." [showResultCount]="true" [showIndexInfo]="type!='deposit'" [tableViewLink]="tableViewLink" - [sort]="false" [showBreadcrumb]="showBreadcrumb" [basicMetaDescription]="metaDescription"> + [sort]="false" [showBreadcrumb]="showBreadcrumb" [basicMetaDescription]="metaDescription" + (filterRequestAll)="filterRequestedAll($event)"> @@ -166,6 +167,8 @@ export class SearchDataProvidersComponent { } this.getResults(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(params), this.searchUtils.page, this.searchUtils.size, refine, this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad)); firstLoad = false; + + this.refineQuery = this.searchPage.getSearchAPIQueryForRangeFields(params)+this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad); })); } ngOnDestroy() { @@ -187,7 +190,7 @@ export class SearchDataProvidersComponent { this.searchPageUpdates.emit({disableForms: this.disableForms, disableRefineForms: this.disableRefineForms, searchUtils: this.searchUtils}); let datasourceQueryPrefix = DatasourcesHelperClass.getQueryPrefix(this.type); - this.searchFiltersSub = this._searchDataProvidersService.advancedSearchDataproviders( datasourceQueryPrefix +(datasourceQueryPrefix.length > 0 && parameters.length > 0 ?' and (':'') + parameters +(datasourceQueryPrefix.length > 0 && parameters.length > 0 ?' ) ':''), page, size, this.properties, (refine /*&& (this.type=="all" || this.type == "deposit")*/) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery, (this.type == "deposit")) + this.searchFiltersSub = this._searchDataProvidersService.advancedSearchDataproviders( datasourceQueryPrefix +(datasourceQueryPrefix.length > 0 && parameters.length > 0 ?' and (':'') + parameters +(datasourceQueryPrefix.length > 0 && parameters.length > 0 ?' ) ':''), page, size, this.properties, (refine /*&& (this.type=="all" || this.type == "deposit")*/) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery, (this.type == "deposit"), true) //.switchMap( .subscribe( data => { @@ -333,4 +336,41 @@ export class SearchDataProvidersComponent { private handleError(message: string, error) { console.error(OpenaireEntities.DATASOURCES+" advanced Search Page: "+message, error); } + + public filterRequestedAll(oldFilter: Filter) { + let fieldsStr: string = "&fields=" + oldFilter.filterId+"&refine=true"; + + this.searchFiltersSub = this._searchDataProvidersService.advancedSearchDataproviders(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), 1, 0, properties, fieldsStr, [oldFilter.filterId], this.refineQuery).subscribe( + // this.searchFiltersSub = this._refineFieldsResultsService.getAllRefineFieldResultsByFieldName(oldFilter.filterId, this.entityType, this.properties, this.refineQuery).subscribe( + res => { + let filter: Filter = res[1][0]; + if(filter.values.length == 0) { + filter = oldFilter; + filter.countAllValues = 0; + } else { + filter.countAllValues = filter.values.length; + // console.log(filter); + for (let value of filter.values) { + for (let oldValue of oldFilter.values) { + if (oldValue.id == value.id && oldValue.selected) { + value.selected = true; + break; + } + } + } + } + + let index: number = this.filters.findIndex((fltr: Filter) => fltr.filterId == filter.filterId); + filter.isOpen = true; + this.filters[index] = filter; + this.cdr.detectChanges(); + }, + error => { + let index: number = this.filters.findIndex((fltr: Filter) => fltr.filterId == oldFilter.filterId); + oldFilter.countAllValues = 0; + this.filters[index] = oldFilter; + this.cdr.detectChanges(); + } + ) + } } diff --git a/searchPages/searchOrganizations.component.ts b/searchPages/searchOrganizations.component.ts index fdd49fea..46055ee4 100644 --- a/searchPages/searchOrganizations.component.ts +++ b/searchPages/searchOrganizations.component.ts @@ -1,4 +1,4 @@ -import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core'; +import {ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {AdvancedField, Filter} from './searchUtils/searchHelperClasses.class'; import {SearchOrganizationsService} from '../services/searchOrganizations.service'; @@ -9,6 +9,7 @@ import {SearchCustomFilter, SearchUtilsClass} from './searchUtils/searchUtils.cl import {EnvProperties} from '../utils/properties/env-properties'; import {NewSearchPageComponent, SearchForm} from "./searchUtils/newSearchPage.component"; import {properties} from "../../../environments/environment"; +import {RefineFieldResultsService} from "../services/refineFieldResults.service"; @Component({ @@ -36,7 +37,7 @@ import {properties} from "../../../environments/environment"; [simpleView]="simpleView" formPlaceholderText="Search by organization name..." [showSwitchSearchLink]="showSwitchSearchLink" [showBreadcrumb]="showBreadcrumb" - > + (filterRequestAll)="filterRequestedAll($event)"> ` }) @@ -79,7 +80,11 @@ export class SearchOrganizationsComponent { searchResultsSub: any; searchFiltersSub: any; - constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService ) { + private refineQuery: string = ""; + + constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService, + private _refineFieldsResultsService: RefineFieldResultsService, + private cdr: ChangeDetectorRef) { this.results =[]; this.errorCodes = new ErrorCodes(); this.errorMessages = new ErrorMessagesComponent(); @@ -135,6 +140,8 @@ export class SearchOrganizationsComponent { } this.getResults(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), this.searchUtils.page, this.searchUtils.size, refine, this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad)); firstLoad = false; + + this.refineQuery = this.searchPage.getSearchAPIQueryForRangeFields(params)+this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad); })); } ngOnDestroy() { @@ -154,7 +161,7 @@ export class SearchOrganizationsComponent { this.searchUtils.refineStatus = this.errorCodes.LOADING; this.disableRefineForms = true; this.searchPageUpdates.emit({disableForms: this.disableForms, disableRefineForms: this.disableRefineForms, searchUtils: this.searchUtils}); - this.searchFiltersSub = this._searchOrganizationsService.advancedSearchOrganizations(parameters, page, size, this.properties,(refine) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery) + this.searchFiltersSub = this._searchOrganizationsService.advancedSearchOrganizations(parameters, page, size, this.properties,(refine) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery, true) //.switchMap( .subscribe( data => { @@ -308,4 +315,41 @@ export class SearchOrganizationsComponent { private handleError(message: string, error) { console.error("Organizations advanced Search Page: "+message, error); } + + public filterRequestedAll(oldFilter: Filter) { + let fieldsStr: string = "&fields=" + oldFilter.filterId+"&refine=true"; + + this.searchFiltersSub = this._searchOrganizationsService.advancedSearchOrganizations(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), 1, 0, properties, fieldsStr, [oldFilter.filterId], this.refineQuery).subscribe( + // this.searchFiltersSub = this._refineFieldsResultsService.getAllRefineFieldResultsByFieldName(oldFilter.filterId, "organization", this.properties, this.refineQuery).subscribe( + res => { + let filter: Filter = res[1][0]; + if(filter.values.length == 0) { + filter = oldFilter; + filter.countAllValues = 0; + } else { + filter.countAllValues = filter.values.length; + // console.log(filter); + for (let value of filter.values) { + for (let oldValue of oldFilter.values) { + if (oldValue.id == value.id && oldValue.selected) { + value.selected = true; + break; + } + } + } + } + + let index: number = this.filters.findIndex((fltr: Filter) => fltr.filterId == filter.filterId); + filter.isOpen = true; + this.filters[index] = filter; + this.cdr.detectChanges(); + }, + error => { + let index: number = this.filters.findIndex((fltr: Filter) => fltr.filterId == oldFilter.filterId); + oldFilter.countAllValues = 0; + this.filters[index] = oldFilter; + this.cdr.detectChanges(); + } + ) + } } diff --git a/searchPages/searchProjects.component.ts b/searchPages/searchProjects.component.ts index 60429713..dd70ff8c 100644 --- a/searchPages/searchProjects.component.ts +++ b/searchPages/searchProjects.component.ts @@ -1,4 +1,4 @@ -import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core'; +import {ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {AdvancedField, Filter} from './searchUtils/searchHelperClasses.class'; import {SearchProjectsService} from '../services/searchProjects.service'; @@ -10,6 +10,7 @@ import {EnvProperties} from '../utils/properties/env-properties'; import {NewSearchPageComponent, SearchForm} from "./searchUtils/newSearchPage.component"; import {RangeFilter} from "../utils/rangeFilter/rangeFilterHelperClasses.class"; import {properties} from "../../../environments/environment"; +import {RefineFieldResultsService} from "../services/refineFieldResults.service"; @Component({ selector: 'search-projects', @@ -36,7 +37,7 @@ import {properties} from "../../../environments/environment"; [simpleView]="simpleView" formPlaceholderText="Search by title, acronym, project code..." [showSwitchSearchLink]="showSwitchSearchLink" [sort]="false" [showBreadcrumb]="showBreadcrumb" - > + (filterRequestAll)="filterRequestedAll($event)"> ` @@ -82,8 +83,12 @@ export class SearchProjectsComponent { subs: any[] = []; searchResultsSub: any; searchFiltersSub: any; - - constructor(private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService) { + + private refineQuery: string = ""; + + constructor(private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService, + private _refineFieldsResultsService: RefineFieldResultsService, + private cdr: ChangeDetectorRef) { this.results = []; this.errorCodes = new ErrorCodes(); this.errorMessages = new ErrorMessagesComponent(); @@ -136,6 +141,8 @@ export class SearchProjectsComponent { } this.getResults(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), this.searchUtils.page, this.searchUtils.size, refine, this.searchPage.getSearchAPIQueryForRangeFields(params) + this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad)); firstLoad = false; + + this.refineQuery = this.searchPage.getSearchAPIQueryForRangeFields(params)+this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad); })); } @@ -160,7 +167,7 @@ export class SearchProjectsComponent { disableRefineForms: this.disableRefineForms, searchUtils: this.searchUtils }); - this.searchFiltersSub = this._searchProjectsService.advancedSearchProjects(parameters, page, size, this.properties, (refine) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery) + this.searchFiltersSub = this._searchProjectsService.advancedSearchProjects(parameters, page, size, this.properties, (refine) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery, true) //.switchMap( .subscribe( data => { @@ -337,4 +344,41 @@ export class SearchProjectsComponent { private handleError(message: string, error) { console.error("Projects advanced Search Page: " + message, error); } -} + + public filterRequestedAll(oldFilter: Filter) { + let fieldsStr: string = "&fields=" + oldFilter.filterId+"&refine=true"; + + this.searchFiltersSub = this._searchProjectsService.advancedSearchProjects(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), 1, 0, properties, fieldsStr, [oldFilter.filterId], this.refineQuery).subscribe( + // this.searchFiltersSub = this._refineFieldsResultsService.getAllRefineFieldResultsByFieldName(oldFilter.filterId, "project", this.properties, this.refineQuery).subscribe( + res => { + let filter: Filter = res[1][0]; + if(filter.values.length == 0) { + filter = oldFilter; + filter.countAllValues = 0; + } else { + filter.countAllValues = filter.values.length; + // console.log(filter); + for (let value of filter.values) { + for (let oldValue of oldFilter.values) { + if (oldValue.id == value.id && oldValue.selected) { + value.selected = true; + break; + } + } + } + } + + let index: number = this.filters.findIndex((fltr: Filter) => fltr.filterId == filter.filterId); + filter.isOpen = true; + this.filters[index] = filter; + this.cdr.detectChanges(); + }, + error => { + let index: number = this.filters.findIndex((fltr: Filter) => fltr.filterId == oldFilter.filterId); + oldFilter.countAllValues = 0; + this.filters[index] = oldFilter; + this.cdr.detectChanges(); + } + ) + } +} \ No newline at end of file diff --git a/searchPages/searchResearchResults.component.ts b/searchPages/searchResearchResults.component.ts index 5da5794b..01433b9b 100644 --- a/searchPages/searchResearchResults.component.ts +++ b/searchPages/searchResearchResults.component.ts @@ -1,4 +1,4 @@ -import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core'; +import {ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {AdvancedField, Filter} from './searchUtils/searchHelperClasses.class'; import {SearchResearchResultsService} from '../services/searchResearchResults.service'; @@ -42,6 +42,7 @@ import {RefineFieldResultsService} from "../services/refineFieldResults.service" [includeOnlyResultsAndFilter]="includeOnlyResultsAndFilter" [showBreadcrumb]="showBreadcrumb" [showSwitchSearchLink]="showSwitchSearchLink" [stickyForm]="stickyForm" + (filterRequestAll)="filterRequestedAll($event)" > ` @@ -188,6 +189,8 @@ export class SearchResearchResultsComponent { } this._getResults(this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), this.searchUtils.page, this.searchUtils.size, this.searchUtils.sortBy, refine, this.searchPage.getSearchAPIQueryForRangeFields(params) + this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad)); firstLoad = false; + + this.refineQuery = this.searchPage.getSearchAPIQueryForRangeFields(params)+this.searchPage.getSearchAPIQueryForRefineFields(params, firstLoad); })); } @@ -496,4 +499,62 @@ export class SearchResearchResultsComponent { public getEntityFileName(entityType: string) { return StringUtils.getEntityFileName(entityType); } + + public filterRequestedAll(oldFilter: Filter) { + let fieldsStr: string = "&fields=" + oldFilter.filterId+"&refine=true"; + + this.searchFiltersSub = this._searchResearchResultsService.advancedSearchResults(this.resultType, this.searchPage.getSearchAPIQueryForAdvancedSearhFields(), 1, 0, null, properties, fieldsStr, [oldFilter.filterId], this.refineQuery).subscribe( + // this.searchFiltersSub = this._refineFieldsResultsService.getAllRefineFieldResultsByFieldName(oldFilter.filterId, this.resultType, this.properties, this.refineQuery).subscribe( + res => { + // let filter: Filter = res[1][0]; + let filter: Filter = res[2][0]; + if(filter.values.length == 0) { + filter = oldFilter; + filter.countAllValues = 0; + } else { + filter.countAllValues = filter.values.length; + for (let value of filter.values) { + for (let oldValue of oldFilter.values) { + if (oldValue.id == value.id && oldValue.selected) { + value.selected = true; + break; + } + } + } + } + + let index: number = this.filters.findIndex((fltr: Filter) => fltr.filterId == filter.filterId); + filter.isOpen = true; + filter.countSelectedValues = oldFilter.countSelectedValues; + filter.radioValue = oldFilter.radioValue; + this.filters[index] = filter; + // this.updateOrderedFilter(filter); + + this.cdr.detectChanges(); + }, + error => { + let index: number = this.filters.findIndex((fltr: Filter) => fltr.filterId == oldFilter.filterId); + oldFilter.countAllValues = 0; + this.filters[index] = oldFilter; + // this.updateOrderedFilter(oldFilter); + + this.cdr.detectChanges(); + } + ) + } + + // public updateOrderedFilter(filter: Filter) { + // if(this.orderedFilters) { + // let groupIndex = 0; + // let index; + // for(let group of this.orderedFilters) { + // index = group.values.findIndex((fltr: Filter) => fltr.filterId == filter.filterId); + // if(index != -1) { + // break; + // } + // groupIndex++; + // } + // this.orderedFilters[groupIndex].values[index] = filter; + // } + // } } diff --git a/searchPages/searchUtils/newSearchPage.component.html b/searchPages/searchUtils/newSearchPage.component.html index 8eaee58b..dcc2398b 100644 --- a/searchPages/searchUtils/newSearchPage.component.html +++ b/searchPages/searchUtils/newSearchPage.component.html @@ -99,6 +99,7 @@ [isDisabled]="disabled" [filter]="filter" [showResultCount]=showResultCount (onFilterChange)="filterChanged($event)" + (onFilterToggle)="filterToggled($event)" [actionRoute]="true"> diff --git a/searchPages/searchUtils/newSearchPage.component.ts b/searchPages/searchUtils/newSearchPage.component.ts index 75f1dc19..3335bf93 100644 --- a/searchPages/searchUtils/newSearchPage.component.ts +++ b/searchPages/searchUtils/newSearchPage.component.ts @@ -1,11 +1,11 @@ import { ChangeDetectorRef, Component, - ElementRef, Inject, + ElementRef, EventEmitter, Inject, Input, OnChanges, OnDestroy, - OnInit, PLATFORM_ID, + OnInit, Output, PLATFORM_ID, SimpleChanges, ViewChild } from '@angular/core'; @@ -157,6 +157,8 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges { isServer: boolean; searchTerm: string = null; advancedSearchTerms: number = 0; + + @Output() filterRequestAll = new EventEmitter(); constructor(private route: ActivatedRoute, private location: Location, @@ -454,7 +456,7 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges { var fields: string[] = []; for (var i = 0; i < this.refineFields.length; i++) { var dependentTo = this.searchFieldsHelper.DEPENDENT_FIELDS[this.refineFields[i]]; - + // TODO check again the checks //if filter is not marked as hidden OR it is hidden but it is dependent to a field that it IS selected if (this.searchFieldsHelper.HIDDEN_FIELDS.indexOf(this.refineFields[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) || (selected_filters.indexOf(this.refineFields[i]) != -1) @@ -773,6 +775,10 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges { this.goTo(1); } + + filterToggled($event) { + this.filterRequestAll.emit($event) + } /** * if there is a change in the values of the quick filter, this function has to be run, to also update the quickFilter diff --git a/searchPages/searchUtils/searchFilter.component.html b/searchPages/searchUtils/searchFilter.component.html index fe68a0fd..c797bb2c 100644 --- a/searchPages/searchUtils/searchFilter.component.html +++ b/searchPages/searchUtils/searchFilter.component.html @@ -10,33 +10,41 @@ -
+
- View all - View less + View all + View less -
-
-
Top 100 values are shown in the filters
-
-
-
+
+
+ +
+
+ An error occured. Please try again. +
+ +
+
Top 100 values are shown in the filters
+
+
+
+
-
-
- -
- -
-
- -
- No filters available with that term -
-
-
+
+ +
+ +
+
+ +
+ No filters available with that term +
+
+
+
diff --git a/searchPages/searchUtils/searchFilter.component.ts b/searchPages/searchUtils/searchFilter.component.ts index d43ceb57..896cc360 100644 --- a/searchPages/searchUtils/searchFilter.component.ts +++ b/searchPages/searchUtils/searchFilter.component.ts @@ -26,6 +26,7 @@ export class SearchFilterComponent implements OnInit, OnChanges { @Input() addShowMore: boolean = true; @Input() showMoreInline: boolean = true; @Input() filterValuesNum: number = 6; + public hasMoreValues: boolean = false; public showAll: boolean = false; public _maxCharacters: number = 28; @@ -33,6 +34,7 @@ export class SearchFilterComponent implements OnInit, OnChanges { @Output() modalChange = new EventEmitter(); @Output() onFilterChange = new EventEmitter(); + @Output() onFilterToggle = new EventEmitter(); keyword = ""; sortBy: "name" | "num" = "name"; sortByOptions: Option[] = [{label: 'Results number', value: 'num'}, {label: 'Name', value: 'name'}]; @@ -41,7 +43,7 @@ export class SearchFilterComponent implements OnInit, OnChanges { @Input() actionRoute: boolean = false; @Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string }; sub; - public isOpen: boolean = false; + @Input() isOpen: boolean = false; sortedValues; hasMatch: boolean = false; @@ -58,11 +60,12 @@ export class SearchFilterComponent implements OnInit, OnChanges { ngOnInit() { if(this.filterValuesNum == 0){ - this.isOpen = true; + this.filter.isOpen = true; this.sortBy = "num"; - }else{ - this.isOpen = false; } + // else{ + // this.filter.isOpen = false; + // } this.sub = this.route.queryParams.subscribe(params => { this.queryParams = Object.assign({}, params); this.paramPosition = SearchFields.getParameterOrder(this.filter.filterId, this.getEntries(params)); @@ -81,6 +84,7 @@ export class SearchFilterComponent implements OnInit, OnChanges { ngOnChanges(changes: SimpleChanges) { if (changes.filter) { + this.hasMoreValues = this.filter.values.length > this.filterValuesNum; // this.filter.values = this.filter.values.filter(value => !value.name.toLowerCase().includes('unknown') && !value.name.toLowerCase().includes('not available')); this.filter.values = this.filter.values.filter(value => value && value.name != "unidentified" && value.name != "Undetermined" && !value.name.toLowerCase().includes('unknown') && !value.name.toLowerCase().includes('not available')); @@ -268,8 +272,18 @@ export class SearchFilterComponent implements OnInit, OnChanges { } toggle(event) { - this.isOpen = !this.isOpen; + this.filter.isOpen = !this.filter.isOpen; event.stopPropagation(); + this.toggleWithoutUpdate(); + } + + toggleWithoutUpdate() { + if(this.filter.countAllValues == 0) { + this.filter.countAllValues = -1; // if request failed, try again automatically if toggled again + } + if(this.filter.isOpen && this.filter.countAllValues < 0) { + this.onFilterToggle.emit(this.filter); + } } disabled(value) { diff --git a/searchPages/searchUtils/searchFilter.module.ts b/searchPages/searchUtils/searchFilter.module.ts index 6f8bc92b..5f014308 100644 --- a/searchPages/searchUtils/searchFilter.module.ts +++ b/searchPages/searchUtils/searchFilter.module.ts @@ -8,11 +8,12 @@ import {ModalModule} from '../../utils/modal/modal.module'; import {RouterModule} from "@angular/router"; import {InputModule} from '../../sharedComponents/input/input.module'; import {IconsModule} from "../../utils/icons/icons.module"; +import {LoadingModule} from "../../utils/loading/loading.module"; @NgModule({ imports: [ CommonModule, FormsModule, ModalModule, RouterModule, - InputModule, IconsModule + InputModule, IconsModule, LoadingModule ], declarations: [ SearchFilterComponent, SearchFilterModalComponent diff --git a/searchPages/searchUtils/searchHelperClasses.class.ts b/searchPages/searchUtils/searchHelperClasses.class.ts index 4663be5f..01a68404 100644 --- a/searchPages/searchUtils/searchHelperClasses.class.ts +++ b/searchPages/searchUtils/searchHelperClasses.class.ts @@ -11,6 +11,8 @@ export class Filter{ public type?: string = "keyword"; public radioValue?: string = ""; // public uniqueValueIdSelected: string; + public countAllValues?: number = -1; // -1: not yet requested, 0: request failed, >0 OK + public isOpen?: boolean = false; } export class Value{ diff --git a/services/searchDataproviders.service.ts b/services/searchDataproviders.service.ts index af05a7f1..1ae052b5 100644 --- a/services/searchDataproviders.service.ts +++ b/services/searchDataproviders.service.ts @@ -31,7 +31,7 @@ export class SearchDataprovidersService { .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource", usedBy)])); } - advancedSearchDataproviders (params: string, page: number, size: number, properties: EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null, depositQuery:boolean = false ):any { + advancedSearchDataproviders (params: string, page: number, size: number, properties: EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null, depositQuery:boolean = false, minRef: boolean = false):any { let url = properties.searchAPIURLLAst+"resources"+(depositQuery?'':2)+"/?format=json"; if(params!= null && params != '' ) { @@ -45,6 +45,7 @@ export class SearchDataprovidersService { url += "&" + refineQuery; } url += "&page="+(page-1)+"&size="+size; + url += minRef ? "&minRef=true" : ""; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .pipe(map(res => [res['meta'].total, this.parseResults(res['results']), RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")])); diff --git a/services/searchOrganizations.service.ts b/services/searchOrganizations.service.ts index d35f9f97..b4b51c15 100644 --- a/services/searchOrganizations.service.ts +++ b/services/searchOrganizations.service.ts @@ -55,7 +55,7 @@ export class SearchOrganizationsService { //.map(res => res.json()) .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "organization")])); } - advancedSearchOrganizations (params: string, page: number, size: number, properties:EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null ):any { + advancedSearchOrganizations (params: string, page: number, size: number, properties:EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null, minRef: boolean = false):any { // &type=organizations let url = properties.searchAPIURLLAst+"resources2/?format=json"; var basicQuery = "(reldatasourcecompatibilityid exact driver or reldatasourcecompatibilityid exact driver-openaire2.0 or " + @@ -76,6 +76,7 @@ export class SearchOrganizationsService { url += "&" + refineQuery; } url += "&page="+(page-1)+"&size="+size; + url += minRef ? "&minRef=true" : ""; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) //.map(res => res.json()) diff --git a/services/searchProjects.service.ts b/services/searchProjects.service.ts index b513b737..8e2fa14d 100644 --- a/services/searchProjects.service.ts +++ b/services/searchProjects.service.ts @@ -49,7 +49,7 @@ export class SearchProjectsService { //.map(res => res.json()) .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])])); } - advancedSearchProjects (params: string, page: number, size: number, properties:EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null ):any { + advancedSearchProjects (params: string, page: number, size: number, properties:EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null, minRef: boolean = false):any { // &type=projects let url = properties.searchAPIURLLAst+"resources2/?format=json"; // var basicQuery = "(oaftype exact project) " @@ -67,6 +67,8 @@ export class SearchProjectsService { url += "&" + refineQuery; } url += "&page="+(page-1)+"&size="+size; + url += minRef ? "&minRef=true" : ""; + // url += "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) //.map(res => res.json()) diff --git a/services/searchResearchResults.service.ts b/services/searchResearchResults.service.ts index d81981e1..4c76bf90 100644 --- a/services/searchResearchResults.service.ts +++ b/services/searchResearchResults.service.ts @@ -109,7 +109,7 @@ export class SearchResearchResultsService { .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties), RefineResultsUtils.parse(res['refineResults'], refineFields, "publication")])); } - advancedSearchResults(resultType: string, params: string, page: number, size: number, sortBy: string, properties: EnvProperties, refineParams: string = null, refineFields: string[] = null, refineQuery: string = null): any { + advancedSearchResults(resultType: string, params: string, page: number, size: number, sortBy: string, properties: EnvProperties, refineParams: string = null, refineFields: string[] = null, refineQuery: string = null, minRef: boolean = false): any { let url = properties.searchAPIURLLAst + "resources2/?format=json"; if (params != null && params != '') { url += "&query=(" + params + ")"; @@ -126,6 +126,7 @@ export class SearchResearchResultsService { } url += "&page=" + (page - 1) + "&size=" + size; + url += minRef ? "&minRef=true" : ""; // url += "&format=json"; return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)