[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 <search-filter> output.
This commit is contained in:
Konstantina Galouni 2023-12-14 18:14:57 +02:00
parent 0768248bde
commit d9c7d35e57
14 changed files with 277 additions and 51 deletions

View File

@ -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)">
</new-search-page>
@ -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();
}
)
}
}

View File

@ -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)">
</new-search-page>
`
})
@ -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();
}
)
}
}

View File

@ -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)">
</new-search-page>
`
@ -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();
}
)
}
}

View File

@ -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)"
>
</new-search-page>
`
@ -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;
// }
// }
}

View File

@ -99,6 +99,7 @@
[isDisabled]="disabled"
[filter]="filter" [showResultCount]=showResultCount
(onFilterChange)="filterChanged($event)"
(onFilterToggle)="filterToggled($event)"
[actionRoute]="true"></search-filter>
</ng-template>

View File

@ -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

View File

@ -10,33 +10,41 @@
<ng-container *ngTemplateOutlet="input_label_wrapper; context: {filter: filter, value: value}"></ng-container>
</div>
</div>
<div *ngIf="addShowMore && (filter.values.length) > filterValuesNum">
<div *ngIf="addShowMore && hasMoreValues">
<a *ngIf="filterValuesNum > 0 " class="uk-text-small view-more-less-link uk-margin-small-top" [ngClass]="((isDisabled)?'uk-disabled uk-link-muted ':'')" (click)="toggle($event)">
<span *ngIf="!isOpen">View all</span>
<span *ngIf="isOpen">View less </span>
<span *ngIf="!filter.isOpen">View all</span>
<span *ngIf="filter.isOpen">View less </span>
</a>
<div *ngIf="isOpen" class="uk-text-small uk-margin-small-top uk-margin-small-bottom">
<div class="uk-margin-small-left">
<div class="uk-text-meta">Top 100 values are shown in the filters</div>
<div class="uk-flex uk-flex-bottom uk-margin-top">
<div input class="uk-width-1-2@m uk-margin-right" [placeholder]="{label: 'Search', static: true}" inputClass="inner small" [(value)]="keyword" (valueChange)="initMatching()"></div>
<div *ngIf="showResultCount === true" input type="select" class="uk-width-expand" placeholder="Sort by"
inputClass="border-bottom" [(value)]="sortBy" [options]="sortByOptions" (valueChange)="sort()"></div>
<div *ngIf="filter.isOpen" class="uk-text-small uk-margin-small-top uk-margin-small-bottom">
<div *ngIf="filter.countAllValues == -1">
<loading class="uk-height-small uk-display-block" size="medium"></loading>
</div>
<div *ngIf="filter.countAllValues == 0">
<span class="uk-text-warning">An error occured. </span><span><a class="uk-button-link" (click)="toggleWithoutUpdate()">Please try again</a>.</span>
</div>
<ng-container *ngIf="(!filter.countAllValues && filter.countAllValues != 0) || filter.countAllValues > 0">
<div class="uk-margin-small-left">
<div class="uk-text-meta">Top 100 values are shown in the filters</div>
<div class="uk-flex uk-flex-bottom uk-margin-top">
<div input class="uk-width-1-2@m uk-margin-right" [placeholder]="{label: 'Search', static: true}" inputClass="inner small" [(value)]="keyword" (valueChange)="initMatching()"></div>
<div *ngIf="showResultCount === true" input type="select" class="uk-width-expand" placeholder="Sort by"
inputClass="border-bottom" [(value)]="sortBy" [options]="sortByOptions" (valueChange)="sort()"></div>
</div>
</div>
</div>
<div class="uk-overflow-auto uk-height-max-small uk-margin-small-left uk-margin-small-right uk-margin-top">
<ng-container *ngFor="let value of this.sortedValues">
<div *ngIf="filterKeywords(value.name)" title="{{value.name}}"
class="uk-animation-fade uk-text-small">
<ng-container *ngTemplateOutlet="input_label_wrapper; context: {filter: filter, value: value}"></ng-container>
</div>
</ng-container>
<ng-container *ngIf="!hasMatch">
<div class="uk-padding-small uk-text-meta">
No filters available with that term
</div>
</ng-container>
</div>
<div class="uk-overflow-auto uk-height-max-small uk-margin-small-left uk-margin-small-right uk-margin-top">
<ng-container *ngFor="let value of this.sortedValues">
<div *ngIf="filterKeywords(value.name)" title="{{value.name}}"
class="uk-animation-fade uk-text-small">
<ng-container *ngTemplateOutlet="input_label_wrapper; context: {filter: filter, value: value}"></ng-container>
</div>
</ng-container>
<ng-container *ngIf="!hasMatch">
<div class="uk-padding-small uk-text-meta">
No filters available with that term
</div>
</ng-container>
</div>
</ng-container>
</div>
</div>
</div>

View File

@ -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) {

View File

@ -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

View File

@ -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{

View File

@ -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")]));

View File

@ -55,7 +55,7 @@ export class SearchOrganizationsService {
//.map(res => <any> 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 => <any> res.json())

View File

@ -49,7 +49,7 @@ export class SearchProjectsService {
//.map(res => <any> 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 => <any> res.json())

View File

@ -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)