Commit ef9c5b3e authored by Dimitri DI GUSTO's avatar Dimitri DI GUSTO
Browse files

Merge branch 'DOS0092078' into 'master'

Sorting by date only if no search string

See merge request !122
parents f35d10b2 1f556232
Pipeline #10431 passed with stage
in 6 minutes and 43 seconds
......@@ -94,7 +94,6 @@ export class ResultsComponent implements OnInit, OnDestroy {
// We need to make an initial request to get the aggregations and subaggregations
this._datasetResearchService.getResults().subscribe(() => {
// Create the ESOptions
const options = this._researchUrlService.getOptionsFromParameters(params);
this._datasetResearchService.elasticSearchOptions.setElasticsearchOptions(options);
// Force to recalculate the aggregate counts
......
import { Component, OnInit } from '@angular/core';
import {Component, OnDestroy, OnInit} from '@angular/core';
import { DatasetResearchService } from '../../services';
import { geosource } from '../../../../i18n/traductions';
import { Subscription } from 'rxjs';
interface IDropdownOptions {
'label': string;
......@@ -14,13 +15,15 @@ interface IDropdownOptions {
templateUrl: './sort.component.html',
styleUrls: ['./sort.component.scss'],
})
export class SortComponent implements OnInit {
export class SortComponent implements OnInit, OnDestroy {
// Options list for the sort dropdown
options: IDropdownOptions[];
// Selected value of the dropdown
selectedOption: IDropdownOptions;
searchChangeSubscription: Subscription;
dropDownFormatsToggle: boolean = false;
constructor(
......@@ -61,14 +64,20 @@ export class SortComponent implements OnInit {
}
ngOnInit() {
this.selectedOption = this.options.find(
e => (
e.value === this._datasetResearchService.sortOptions.value &&
e.order === this._datasetResearchService.sortOptions.order
),
this.selectedOption = this.getOptionFromValueAndOrder(this._datasetResearchService.sortOptions);
this.searchChangeSubscription = this._datasetResearchService.searchChange$.subscribe(
(sortOption: any) => {
if (sortOption && sortOption.value && sortOption.order) {
this.sortValueChanged(this.getOptionFromValueAndOrder(sortOption));
}
},
);
}
ngOnDestroy(): void {
this.searchChangeSubscription.unsubscribe();
}
sortValueChanged(option) {
this.selectedOption = option;
this._datasetResearchService.sortChanged({
......@@ -81,4 +90,12 @@ export class SortComponent implements OnInit {
return this._datasetResearchService.isLoading;
}
private getOptionFromValueAndOrder(sortOption) {
return this.options.find(
e => (
e.value === sortOption.value &&
e.order === sortOption.order
),
);
}
}
......@@ -463,6 +463,8 @@ export class DatasetResearchService {
this._elasticsearchOptions.searchString = value;
this._elasticsearchOptions.pageIndex = 0;
this._elasticsearchOptions.shouldAggregateResultCount = true;
this._elasticsearchOptions.sortOptions.value = (value && true) ? 'relevance' : 'date';
this._elasticsearchOptions.sortOptions.order = 'desc';
if (this._router.url.split('/').pop() !== AppRoutes.research.uri) {
if (value === '') {
this._router.navigate(['/', `${AppRoutes.research.uri}`]);
......@@ -472,7 +474,7 @@ export class DatasetResearchService {
}
this._researchUrlService.setParameter('q', value);
this._searchChangeSubject.next();
this._searchChangeSubject.next(this._elasticsearchOptions.sortOptions);
}
scopeChanged(scope: IScope) {
......
......@@ -66,7 +66,7 @@ export class ElasticsearchOptions {
// Need to be done in order to avoid object reference copy
this._sortOptions = {
value: 'date',
value: (data && data.searchString != null) ? 'relevance' : 'date',
order: 'desc',
};
if (data && data.sortOptions != null) {
......@@ -149,7 +149,7 @@ export class ElasticsearchOptions {
// Need to be done in order to avoid object reference copy
this._sortOptions = {
value: 'date',
value: (data && data.searchString != null) ? 'relevance' : 'date',
order: 'desc',
};
if (data && data.sortOptions != null) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment