Skip to content
Merged
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 @@ -89,6 +89,7 @@ describe('BrowseByDateComponent', () => {
getBrowseEntriesFor: (options: BrowseEntrySearchOptions) => toRemoteData([]),
getBrowseItemsFor: (value: string, options: BrowseEntrySearchOptions) => toRemoteData([firstItem]),
getFirstItemFor: (definition: string, scope?: string, sortDirection?: SortDirection) => null,
getConfiguredSortDirection: () => of(SortDirection.DESC),
};

const mockDsoService = {
Expand Down
34 changes: 14 additions & 20 deletions src/app/browse-by/browse-by-date/browse-by-date.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '@angular/core';
import {
ActivatedRoute,
Params,
Router,
} from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
Expand All @@ -21,8 +20,8 @@ import {
of,
} from 'rxjs';
import {
distinctUntilChanged,
map,
switchMap,
} from 'rxjs/operators';
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';

Expand All @@ -47,7 +46,6 @@ import {
isNotEmpty,
} from '../../shared/empty.util';
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { StartsWithType } from '../../shared/starts-with/starts-with-type';
import {
BrowseByMetadataComponent,
Expand Down Expand Up @@ -96,27 +94,23 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
this.loading$ = of(false);
return;
}
const sortConfig = new SortOptions('default', SortDirection.ASC);
this.browseId = this.route.snapshot.params.id;
this.startsWithType = StartsWithType.date;
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
const routeParams$: Observable<Params> = observableCombineLatest([
this.route.params,
this.route.queryParams,
]).pipe(
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
);

this.subs.push(
observableCombineLatest([
routeParams$,
this.scope$,
this.currentPagination$,
this.currentSort$,
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
this.browseService.getConfiguredSortDirection(this.browseId, SortDirection.ASC).pipe(
map((sortDir) => new SortOptions(this.browseId, sortDir)),
switchMap((sortConfig) => {
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig, false);
return observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.route.data, this.currentPagination$, this.currentSort$]).pipe(
map(([routeParams, queryParams, scope, data, currentPage, currentSort]) => ({
params: Object.assign({}, routeParams, queryParams, data), scope, currentPage, currentSort,
})));
})).subscribe(({ params, scope, currentPage, currentSort }) => {
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;
this.browseId = params.id;
this.startsWith = +params.startsWith || params.startsWith;
this.browseId = params.id;
const searchOptions = browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails);
this.updatePageWithItems(searchOptions, this.value, undefined);
this.updateStartsWithOptions(this.browseId, metadataKeys, params.scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('BrowseByMetadataComponent', () => {
const mockBrowseService = {
getBrowseEntriesFor: (options: BrowseEntrySearchOptions) => toRemoteData(mockEntries),
getBrowseItemsFor: (value: string, options: BrowseEntrySearchOptions) => toRemoteData(mockItems),
getConfiguredSortDirection: () => of(SortDirection.ASC),
};

const mockDsoService = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from '@angular/core';
import {
ActivatedRoute,
Params,
Router,
} from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
Expand All @@ -26,8 +25,8 @@ import {
Subscription,
} from 'rxjs';
import {
distinctUntilChanged,
map,
switchMap,
} from 'rxjs/operators';
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';

Expand Down Expand Up @@ -209,24 +208,18 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
this.loading$ = of(false);
return;
}
const sortConfig = new SortOptions('default', SortDirection.ASC);
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
const routeParams$: Observable<Params> = observableCombineLatest([
this.route.params,
this.route.queryParams,
]).pipe(
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.authority === curr.authority && prev.value === curr.value && prev.startsWith === curr.startsWith),
);
this.browseId = this.route.snapshot.params.id;
this.subs.push(
observableCombineLatest([
routeParams$,
this.scope$,
this.currentPagination$,
this.currentSort$,
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
this.browseId = params.id;
this.browseService.getConfiguredSortDirection(this.browseId, SortDirection.ASC).pipe(
map((sortDir) => new SortOptions(this.browseId, sortDir)),
switchMap((sortConfig) => {
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig, false);
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
return observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
map(([routeParams, queryParams, scope, currentPage, currentSort]) => ({
params: Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort,
})));
})).subscribe(({ params, scope, currentPage, currentSort }) => {
this.authority = params.authority;

if (typeof params.value === 'string') {
Expand All @@ -250,9 +243,8 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
} else {
this.updatePage(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, false));
}
this.updateStartsWithTextOptions();
}));
this.updateStartsWithTextOptions();

}

ngOnChanges(changes: SimpleChanges): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { of } from 'rxjs';
import { APP_CONFIG } from '../../../config/app-config.interface';
import { environment } from '../../../environments/environment';
import { BrowseService } from '../../core/browse/browse.service';
import { SortDirection } from '../../core/cache/models/sort-options.model';
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
import { ItemDataService } from '../../core/data/item-data.service';
import { PaginationService } from '../../core/pagination/pagination.service';
Expand Down Expand Up @@ -76,6 +77,7 @@ describe('BrowseByTitleComponent', () => {
const mockBrowseService = {
getBrowseItemsFor: () => toRemoteData(mockItems),
getBrowseEntriesFor: () => toRemoteData([]),
getConfiguredSortDirection: () => of(SortDirection.ASC),
};

const mockDsoService = {
Expand Down
36 changes: 14 additions & 22 deletions src/app/browse-by/browse-by-title/browse-by-title.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import {
Component,
OnInit,
} from '@angular/core';
import { Params } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import {
combineLatest as observableCombineLatest,
Observable,
of,
} from 'rxjs';
import {
distinctUntilChanged,
map,
switchMap,
} from 'rxjs/operators';

import { environment } from '../../../environments/environment';
Expand All @@ -25,7 +23,6 @@ import {
} from '../../core/cache/models/sort-options.model';
import { ThemedBrowseByComponent } from '../../shared/browse-by/themed-browse-by.component';
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import {
BrowseByMetadataComponent,
browseParamsToOptions,
Expand All @@ -52,28 +49,23 @@ export class BrowseByTitleComponent extends BrowseByMetadataComponent implements
this.loading$ = of(false);
return;
}
const sortConfig = new SortOptions('dc.title', SortDirection.ASC);
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
const routeParams$: Observable<Params> = observableCombineLatest([
this.route.params,
this.route.queryParams,
]).pipe(
map(([params, queryParams]: [Params, Params]) => Object.assign({}, params, queryParams)),
distinctUntilChanged((prev: Params, curr: Params) => prev.id === curr.id && prev.startsWith === curr.startsWith),
);
this.browseId = this.route.snapshot.params.id;
this.subs.push(
observableCombineLatest([
routeParams$,
this.scope$,
this.currentPagination$,
this.currentSort$,
]).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
this.browseService.getConfiguredSortDirection(this.browseId, SortDirection.ASC).pipe(
map((sortDir) => new SortOptions(this.browseId, sortDir)),
switchMap((sortConfig) => {
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig, false);
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
return observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
map(([routeParams, queryParams, scope, currentPage, currentSort]) => ({
params: Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort,
})),
);
})).subscribe(({ params, scope, currentPage, currentSort }) => {
this.startsWith = +params.startsWith || params.startsWith;
this.browseId = params.id;
this.updatePageWithItems(browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails), undefined, undefined);
this.updateStartsWithTextOptions();
}));
this.updateStartsWithTextOptions();
}

}
23 changes: 23 additions & 0 deletions src/app/core/browse/browse.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ export class BrowseService {
return this.hrefOnlyDataService.findListByHref<BrowseEntry>(href$);
}

/*
* Get the sort direction for a browse index based on its unique id
* @param browseId The unique id of the browse index
* @param defaultDirection The default sort direction to return if the browse index has no sort direction configured
* @returns {Observable<SortDirection>} The sort direction of the browse index
*/
getConfiguredSortDirection(browseId: string, defaultDirection: SortDirection): Observable<SortDirection> {
return this.getBrowseDefinitions().pipe(
getRemoteDataPayload(),
getPaginatedListPayload(),
map((browseDefinitions: BrowseDefinition[]) => browseDefinitions
.find((def: BrowseDefinition) => def.id === browseId),
),
map((browseDef: BrowseDefinition) => {
if (browseDef.order === SortDirection.ASC || browseDef.order === SortDirection.DESC) {
return browseDef.order;
} else {
return defaultDirection;
}
}),
);
}

/**
* Get all items linked to a certain metadata value
* @param {string} filterValue metadata value to filter by (e.g. author's name)
Expand Down
4 changes: 4 additions & 0 deletions src/app/core/shared/browse-definition.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

import { BrowseByDataType } from '../../browse-by/browse-by-switcher/browse-by-data-type';
import { CacheableObject } from '../cache/cacheable-object.model';
import { SortDirection } from '../cache/models/sort-options.model';

/**
* Base class for BrowseDefinition models
Expand All @@ -17,6 +18,9 @@ export abstract class BrowseDefinition extends CacheableObject {
@autoserializeAs('metadata')
metadataKeys: string[];

@autoserialize
order: SortDirection;

/**
* Get the render type of the BrowseDefinition model
*/
Expand Down
Loading