Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public class EsSearchManager implements ISearchManager {
// Elasticsearch scripted field to get the first overview url. Scripted fields must return single values.
.put("overview", "return params['_source'].overview == null ? [] : params['_source'].overview.stream().map(f -> f.url).findFirst().orElse('');")
.put("overview_data", "return params['_source'].overview == null ? [] : params['_source'].overview.stream().map(f -> f.data).filter(Objects::nonNull).findFirst().orElse('');")
.put("lastResourceDate", "return params['_source'].resourceDate == null ? null : params['_source'].resourceDate.stream().map(d -> d.date).filter(date -> date != null).max(String::compareTo).orElse(null);")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@
"$http",
"$q",
function ($http, $q) {
this.sortByField = function (records, sortBy) {
if (!sortBy || !records) {
return records;
}

var descOrder = sortBy.startsWith("-");
var sortField = descOrder ? sortBy.substring(1) : sortBy;
records.sort(function (a, b) {
var aProperty = a[sortField] || (a.properties && a.properties[sortField]);
var bProperty = b[sortField] || (b.properties && b.properties[sortField]);

if (!aProperty && !bProperty) {
return 0;
}
if (!aProperty) {
return 1;
}
if (!bProperty) {
return -1;
}

var comparison = String(aProperty).localeCompare(String(bProperty));
return descOrder ? -comparison : comparison;
});

return records;
};

this.get = function (uuidOrId, types, approved) {
var canceller = $q.defer();
var request = $http({
Expand Down Expand Up @@ -962,7 +990,8 @@
]);

module.directive("gnRelatedWithStats", [
function () {
"gnRelatedService",
function (gnRelatedService) {
return {
restrict: "A",
templateUrl: function (elem, attrs) {
Expand Down Expand Up @@ -1025,11 +1054,7 @@
}

function sort() {
if (scope.sortBy) {
scope.displayedRecords.sort(function (a, b) {
return a[scope.sortBy] && a[scope.sortBy].localeCompare(b[scope.sortBy]);
});
}
gnRelatedService.sortByField(scope.displayedRecords, scope.sortBy);
}

function reset() {
Expand Down Expand Up @@ -1196,8 +1221,9 @@

module.directive("gnRecordsTable", [
"Metadata",
"gnConfigService",
"gnRelatedService",
function (Metadata, gnRelatedService) {
function (Metadata, gnConfigService, gnRelatedService) {
return {
restrict: "A",
templateUrl: function (elem, attrs) {
Expand All @@ -1214,6 +1240,7 @@
// * links by type eg. link:OGC
columns: "@",
labels: "@",
sortBy: "@",
agg: "="
},
link: function (scope, element, attrs, controller) {
Expand Down Expand Up @@ -1262,10 +1289,7 @@
});

function sort() {
scope.displayedRecords.sort(function (a, b) {
var sortBy = scope.columnsConfig[0];
return a[sortBy] && a[sortBy].localeCompare(b[sortBy]);
});
gnRelatedService.sortByField(scope.displayedRecords, scope.sortBy);
}

function reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
? mdView.current.record.related.aggregations_children
:mdView.current.record.related.aggregations_siblings"
data-type="'blocks'"
data-sort-by="resourceTitle"
data-sort-by="-lastResourceDate"
data-title="{{'seriesComposedOf' | translate}}"
></div>

Expand All @@ -69,6 +69,7 @@
:mdView.current.record.related.aggregations_siblings"
labels="{{::viewConfig.collectionTableConfig.labels}}"
columns="{{::viewConfig.collectionTableConfig.columns}}"
data-sort-by="-lastResourceDate"
></div>
</div>
</div>
Expand Down
Loading