diff --git a/src/app/+collection-page/collection-page.component.ts b/src/app/+collection-page/collection-page.component.ts index de7e9a72d4..4a935b73b9 100644 --- a/src/app/+collection-page/collection-page.component.ts +++ b/src/app/+collection-page/collection-page.component.ts @@ -3,7 +3,7 @@ import { ActivatedRoute } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { Subscription } from 'rxjs/Subscription'; -import { SortOptions } from '../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; import { CollectionDataService } from '../core/data/collection-data.service'; import { ItemDataService } from '../core/data/item-data.service'; import { PaginatedList } from '../core/data/paginated-list'; @@ -48,7 +48,7 @@ export class CollectionPageComponent implements OnInit, OnDestroy { this.paginationConfig.id = 'collection-page-pagination'; this.paginationConfig.pageSize = 5; this.paginationConfig.currentPage = 1; - this.sortConfig = new SortOptions(); + this.sortConfig = new SortOptions('dc.title', SortDirection.ASC); } ngOnInit(): void { diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts b/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts index 1b71220382..8fca66ea79 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; import { Observable } from 'rxjs/Observable'; -import { SortOptions } from '../../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { CommunityDataService } from '../../core/data/community-data.service'; import { PaginatedList } from '../../core/data/paginated-list'; @@ -27,7 +27,7 @@ export class TopLevelCommunityListComponent { this.config.id = 'top-level-pagination'; this.config.pageSize = 5; this.config.currentPage = 1; - this.sortConfig = new SortOptions(); + this.sortConfig = new SortOptions('dc.title', SortDirection.ASC); this.updatePage({ page: this.config.currentPage, diff --git a/src/app/+search-page/search-filters/search-filter/search-filter.service.ts b/src/app/+search-page/search-filters/search-filter/search-filter.service.ts index cbe6d79dfc..890b32b2f0 100644 --- a/src/app/+search-page/search-filters/search-filter/search-filter.service.ts +++ b/src/app/+search-page/search-filters/search-filter/search-filter.service.ts @@ -60,8 +60,12 @@ export class SearchFilterService { getCurrentSort(): Observable { const sortDirection$ = this.routeService.getQueryParameterValue('sortDirection'); const sortField$ = this.routeService.getQueryParameterValue('sortField'); - return Observable.combineLatest(sortDirection$, sortField$, (sortDirection, sortField) => - new SortOptions(isNotEmpty(sortField) ? sortField : undefined, SortDirection[sortDirection]) + return Observable.combineLatest(sortDirection$, sortField$, (sortDirection, sortField) => { + if (isNotEmpty(sortField)) { + const direction = SortDirection[sortDirection]; + return new SortOptions(sortField, direction ? direction : SortDirection.ASC) + } + } ); } @@ -87,7 +91,7 @@ export class SearchFilterService { defaults, { pagination: pagination, - sort: sort, + sort: sort || defaults.sort, view: view, scope: scope || defaults.scope, query: query, @@ -108,7 +112,7 @@ export class SearchFilterService { defaults, { view: view, - scope: scope, + scope: scope || defaults.scope, query: query, filters: filters }) diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 95ff8f498f..4f50723ced 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { flatMap, } from 'rxjs/operators'; -import { SortOptions } from '../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; import { CommunityDataService } from '../core/data/community-data.service'; import { PaginatedList } from '../core/data/paginated-list'; import { RemoteData } from '../core/data/remote-data'; @@ -42,6 +42,7 @@ export class SearchPageComponent implements OnInit { id: 'search-results-pagination', pageSize: 10 }, + sort: new SortOptions('score', SortDirection.DESC), query: '', scope: '' }; diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 2e1a6d5a6d..0351a9a54c 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -7,7 +7,7 @@ import { Observable } from 'rxjs/Observable'; import { flatMap, map, tap } from 'rxjs/operators'; import { ViewMode } from '../../+search-page/search-options.model'; import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service'; -import { SortOptions } from '../../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { FacetConfigSuccessResponse, FacetValueSuccessResponse, @@ -61,7 +61,7 @@ export class SearchService implements OnDestroy { pagination.id = 'search-results-pagination'; pagination.currentPage = 1; pagination.pageSize = 10; - const sort: SortOptions = new SortOptions(); + const sort: SortOptions = new SortOptions('score', SortDirection.DESC); this.searchOptions = Object.assign(new SearchOptions(), { pagination: pagination, sort: sort }); } diff --git a/src/app/core/cache/models/sort-options.model.ts b/src/app/core/cache/models/sort-options.model.ts index b2380cbaf3..247504a63a 100644 --- a/src/app/core/cache/models/sort-options.model.ts +++ b/src/app/core/cache/models/sort-options.model.ts @@ -4,7 +4,7 @@ export enum SortDirection { } export class SortOptions { - constructor(public field: string = 'dc.title', public direction: SortDirection = SortDirection.ASC) { + constructor(public field: string, public direction: SortDirection) { } } diff --git a/src/app/shared/pagination/pagination.component.spec.ts b/src/app/shared/pagination/pagination.component.spec.ts index ad05f0cdfe..48767cf582 100644 --- a/src/app/shared/pagination/pagination.component.spec.ts +++ b/src/app/shared/pagination/pagination.component.spec.ts @@ -41,7 +41,7 @@ import { MockRouter } from '../mocks/mock-router'; import { HostWindowService } from '../host-window.service'; import { EnumKeysPipe } from '../utils/enum-keys-pipe'; -import { SortOptions } from '../../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { GLOBAL_CONFIG, ENV_CONFIG } from '../../../config'; @@ -349,7 +349,7 @@ class TestComponent { collection: string[] = []; collectionSize: number; paginationOptions = new PaginationComponentOptions(); - sortOptions = new SortOptions(); + sortOptions = new SortOptions('dc.title', SortDirection.ASC); constructor() { this.collection = Array.from(new Array(100), (x, i) => `item ${i + 1}`);