mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 06:53:03 +00:00
Merge branch 'search-backend' into w2p-49440_Date-widget
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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,
|
||||
|
@@ -60,11 +60,14 @@ export class SearchFilterService {
|
||||
});
|
||||
}
|
||||
|
||||
getCurrentSort(): Observable<SortOptions> {
|
||||
getCurrentSort(defaultSort: SortOptions): Observable<SortOptions> {
|
||||
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) => {
|
||||
const field = sortField || defaultSort.field;
|
||||
const direction = SortDirection[sortDirection] || defaultSort.direction;
|
||||
return new SortOptions(field, direction)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,28 +82,28 @@ export class SearchFilterService {
|
||||
getPaginatedSearchOptions(defaults: any = {}): Observable<PaginatedSearchOptions> {
|
||||
return Observable.combineLatest(
|
||||
this.getCurrentPagination(defaults.pagination),
|
||||
this.getCurrentSort(),
|
||||
this.getCurrentSort(defaults.sort),
|
||||
this.getCurrentView(),
|
||||
this.getCurrentScope(),
|
||||
this.getCurrentQuery(),
|
||||
this.getCurrentFilters()).pipe(
|
||||
distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
|
||||
map(([pagination, sort, view, scope, query, filters]) => {
|
||||
return Object.assign(new PaginatedSearchOptions(),
|
||||
defaults,
|
||||
{
|
||||
pagination: pagination,
|
||||
sort: sort,
|
||||
view: view,
|
||||
scope: scope || defaults.scope,
|
||||
query: query,
|
||||
filters: filters
|
||||
})
|
||||
})
|
||||
)
|
||||
distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
|
||||
map(([pagination, sort, view, scope, query, filters]) => {
|
||||
return Object.assign(new PaginatedSearchOptions(),
|
||||
defaults,
|
||||
{
|
||||
pagination: pagination,
|
||||
sort: sort,
|
||||
view: view,
|
||||
scope: scope || defaults.scope,
|
||||
query: query,
|
||||
filters: filters
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
getSearchOptions(defaults: any = {}): Observable<SearchOptions> {
|
||||
getSearchOptions(defaults: any = {}): Observable<SearchOptions> {
|
||||
return Observable.combineLatest(
|
||||
this.getCurrentView(),
|
||||
this.getCurrentScope(),
|
||||
@@ -111,7 +114,7 @@ export class SearchFilterService {
|
||||
defaults,
|
||||
{
|
||||
view: view,
|
||||
scope: scope,
|
||||
scope: scope || defaults.scope,
|
||||
query: query,
|
||||
filters: filters
|
||||
})
|
||||
|
@@ -8,10 +8,8 @@ import { cold, hot } from 'jasmine-marbles';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
||||
import { CommunityDataService } from '../core/data/community-data.service';
|
||||
import { Community } from '../core/shared/community.model';
|
||||
import { HostWindowService } from '../shared/host-window.service';
|
||||
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
||||
import { PaginatedSearchOptions } from './paginated-search-options.model';
|
||||
import { SearchPageComponent } from './search-page.component';
|
||||
import { SearchService } from './search-service/search.service';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
@@ -35,7 +33,7 @@ describe('SearchPageComponent', () => {
|
||||
pagination.id = 'search-results-pagination';
|
||||
pagination.currentPage = 1;
|
||||
pagination.pageSize = 10;
|
||||
const sort: SortOptions = new SortOptions();
|
||||
const sort: SortOptions = new SortOptions('score', SortDirection.DESC);
|
||||
const mockResults = Observable.of(['test', 'data']);
|
||||
const searchServiceStub = jasmine.createSpyObj('SearchService', {
|
||||
search: mockResults,
|
||||
|
@@ -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: ''
|
||||
};
|
||||
|
@@ -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 });
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { SearchSettingsComponent } from './search-settings.component';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
|
||||
import { SortOptions } from '../../core/cache/models/sort-options.model';
|
||||
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
@@ -22,7 +22,7 @@ describe('SearchSettingsComponent', () => {
|
||||
pagination.id = 'search-results-pagination';
|
||||
pagination.currentPage = 1;
|
||||
pagination.pageSize = 10;
|
||||
const sort: SortOptions = new SortOptions();
|
||||
const sort: SortOptions = new SortOptions('score', SortDirection.DESC);
|
||||
const mockResults = [ 'test', 'data' ];
|
||||
const searchServiceStub = {
|
||||
searchOptions: { pagination: pagination, sort: sort },
|
||||
|
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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}`);
|
||||
|
Reference in New Issue
Block a user