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

This commit is contained in:
Art Lowel
2018-04-20 14:19:18 +02:00
parent c125f36f43
commit 2317f1f3a3
7 changed files with 19 additions and 13 deletions

View File

@@ -56,6 +56,10 @@
"detail": "{{ range }} of {{ total }}" "detail": "{{ range }} of {{ total }}"
} }
}, },
"sorting": {
"ASC": "Ascending",
"DESC": "Descending"
},
"title": "DSpace", "title": "DSpace",
"404": { "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. ", "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. ",

View File

@@ -10,7 +10,7 @@ import {
SearchFilterInitialExpandAction, SearchFilterResetPageAction, SearchFilterInitialExpandAction, SearchFilterResetPageAction,
SearchFilterToggleAction SearchFilterToggleAction
} from './search-filter.actions'; } 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 { SearchFilterConfig } from '../../search-service/search-filter-config.model';
import { SearchService } from '../../search-service/search.service'; import { SearchService } from '../../search-service/search.service';
import { RouteService } from '../../../shared/route.service'; import { RouteService } from '../../../shared/route.service';
@@ -59,7 +59,9 @@ export class SearchFilterService {
getCurrentSort(): Observable<SortOptions> { getCurrentSort(): Observable<SortOptions> {
const sortDirection$ = this.routeService.getQueryParameterValue('sortDirection'); const sortDirection$ = this.routeService.getQueryParameterValue('sortDirection');
const sortField$ = this.routeService.getQueryParameterValue('sortField'); 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() { getCurrentFilters() {

View File

@@ -5,7 +5,7 @@
<option *ngFor="let sortDirection of (sortDirections | dsKeys)" <option *ngFor="let sortDirection of (sortDirections | dsKeys)"
[value]="sortDirection.value" [value]="sortDirection.value"
[selected]="sortDirection.value === direction? 'selected': null"> [selected]="sortDirection.value === direction? 'selected': null">
{{sortDirection.key}} {{'sorting.' + sortDirection.key | translate}}
</option> </option>
</select> </select>
</div> </div>

View File

@@ -1,10 +1,10 @@
export enum SortDirection { export enum SortDirection {
Ascending = 'ASC', ASC = 'ASC',
Descending = 'DESC' DESC = 'DESC'
} }
export class SortOptions { 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) {
} }
} }

View File

@@ -12,7 +12,7 @@
<h6 class="dropdown-header">{{ 'pagination.results-per-page' | translate}}</h6> <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> <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> <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> </div>
</div> </div>

View File

@@ -144,7 +144,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
/** /**
* Direction in which to sort: ascending or descending * 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 * Name of the field that's used to sort by

View File

@@ -13,19 +13,19 @@ export class RouteService {
} }
getQueryParameterValues(paramName: string): Observable<string[]> { 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> { 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> { 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> { 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> { getQueryParamsWithPrefix(prefix: string): Observable<Params> {
@@ -38,6 +38,6 @@ export class RouteService {
params[key] = [...map.getAll(key)]; params[key] = [...map.getAll(key)];
}); });
return params; return params;
}); }).distinctUntilChanged();
} }
} }