Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
web-et-numerique
web-et-numerique-internet
data.grandlyon.com
web-portal
components
custom-apps
web-app
Commits
ef9c5b3e
Commit
ef9c5b3e
authored
Jan 19, 2021
by
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
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/app/datasets/components/results/results.component.ts
View file @
ef9c5b3e
...
...
@@ -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
...
...
src/app/datasets/components/sort/sort.component.ts
View file @
ef9c5b3e
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
),
);
}
}
src/app/datasets/services/dataset-research.service.ts
View file @
ef9c5b3e
...
...
@@ -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
)
{
...
...
src/app/elasticsearch/models/elasticsearch-options.model.ts
View file @
ef9c5b3e
...
...
@@ -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
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment