Skip to content
Snippets Groups Projects
Commit 2317f1f3 authored by Art Lowel's avatar Art Lowel
Browse files

fixed an issue where changing the sort direction wouldn't work

parent c125f36f
Branches
Tags
No related merge requests found
......@@ -56,6 +56,10 @@
"detail": "{{ range }} of {{ total }}"
}
},
"sorting": {
"ASC": "Ascending",
"DESC": "Descending"
},
"title": "DSpace",
"404": {
"help": "We can't find the page you're looking for. The page may have been moved or deleted. You can use the button below to get back to the home page. ",
......
......@@ -10,7 +10,7 @@ import {
SearchFilterInitialExpandAction, SearchFilterResetPageAction,
SearchFilterToggleAction
} from './search-filter.actions';
import { hasValue, } from '../../../shared/empty.util';
import { hasValue, isEmpty, isNotEmpty, } from '../../../shared/empty.util';
import { SearchFilterConfig } from '../../search-service/search-filter-config.model';
import { SearchService } from '../../search-service/search.service';
import { RouteService } from '../../../shared/route.service';
......@@ -59,7 +59,9 @@ export class SearchFilterService {
getCurrentSort(): Observable<SortOptions> {
const sortDirection$ = this.routeService.getQueryParameterValue('sortDirection');
const sortField$ = this.routeService.getQueryParameterValue('sortField');
return Observable.combineLatest(sortDirection$, sortField$, (sortDirection, sortField) => new SortOptions(sortField || undefined, SortDirection[sortDirection]));
return Observable.combineLatest(sortDirection$, sortField$, (sortDirection, sortField) =>
new SortOptions(isNotEmpty(sortField) ? sortField : undefined, SortDirection[sortDirection])
);
}
getCurrentFilters() {
......
......@@ -5,7 +5,7 @@
<option *ngFor="let sortDirection of (sortDirections | dsKeys)"
[value]="sortDirection.value"
[selected]="sortDirection.value === direction? 'selected': null">
{{sortDirection.key}}
{{'sorting.' + sortDirection.key | translate}}
</option>
</select>
</div>
......
export enum SortDirection {
Ascending = 'ASC',
Descending = 'DESC'
ASC = 'ASC',
DESC = 'DESC'
}
export class SortOptions {
constructor(public field: string = 'dc.title', public direction: SortDirection = SortDirection.Ascending) {
constructor(public field: string = 'dc.title', public direction: SortDirection = SortDirection.ASC) {
}
}
......@@ -12,7 +12,7 @@
<h6 class="dropdown-header">{{ 'pagination.results-per-page' | translate}}</h6>
<button class="dropdown-item" *ngFor="let item of pageSizeOptions" (click)="doPageSizeChange(item)"><i [ngClass]="{'invisible': item != pageSize}" class="fa fa-check" aria-hidden="true"></i> {{item}} </button>
<h6 class="dropdown-header">{{ 'pagination.sort-direction' | translate}}</h6>
<button class="dropdown-item" *ngFor="let direction of (sortDirections | dsKeys)" (click)="doSortDirectionChange(direction.value)"><i [ngClass]="{'invisible': direction.value !== sortDirection}" class="fa fa-check" aria-hidden="true"></i> {{direction.key}} </button>
<button class="dropdown-item" *ngFor="let direction of (sortDirections | dsKeys)" (click)="doSortDirectionChange(direction.value)"><i [ngClass]="{'invisible': direction.value !== sortDirection}" class="fa fa-check" aria-hidden="true"></i> {{'sorting.' + direction.key | translate}} </button>
</div>
</div>
</div>
......
......@@ -144,7 +144,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
/**
* Direction in which to sort: ascending or descending
*/
public sortDirection: SortDirection = SortDirection.Ascending;
public sortDirection: SortDirection = SortDirection.ASC;
/**
* Name of the field that's used to sort by
......
......@@ -13,19 +13,19 @@ export class RouteService {
}
getQueryParameterValues(paramName: string): Observable<string[]> {
return this.route.queryParamMap.map((map) => [...map.getAll(paramName)]);
return this.route.queryParamMap.map((map) => [...map.getAll(paramName)]).distinctUntilChanged();
}
getQueryParameterValue(paramName: string): Observable<string> {
return this.route.queryParamMap.map((map) => map.get(paramName));
return this.route.queryParamMap.map((map) => map.get(paramName)).distinctUntilChanged();
}
hasQueryParam(paramName: string): Observable<boolean> {
return this.route.queryParamMap.map((map) => map.has(paramName));
return this.route.queryParamMap.map((map) => map.has(paramName)).distinctUntilChanged();
}
hasQueryParamWithValue(paramName: string, paramValue: string): Observable<boolean> {
return this.route.queryParamMap.map((map) => map.getAll(paramName).indexOf(paramValue) > -1);
return this.route.queryParamMap.map((map) => map.getAll(paramName).indexOf(paramValue) > -1).distinctUntilChanged();
}
getQueryParamsWithPrefix(prefix: string): Observable<Params> {
......@@ -38,6 +38,6 @@ export class RouteService {
params[key] = [...map.getAll(key)];
});
return params;
});
}).distinctUntilChanged();
}
}
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