59695: Arrow-navigation enabled by default + support for entries

This commit is contained in:
Kristof De Langhe
2019-02-19 08:57:37 +01:00
parent 5288f817b0
commit 25b65d840c
5 changed files with 47 additions and 32 deletions

View File

@@ -7,7 +7,7 @@
[sortConfig]="sortConfig" [sortConfig]="sortConfig"
[type]="startsWithType" [type]="startsWithType"
[startsWithOptions]="startsWithOptions" [startsWithOptions]="startsWithOptions"
[enableArrows]="startsWith" [enableArrows]="true"
(prev)="goPrev()" (prev)="goPrev()"
(next)="goNext()" (next)="goNext()"
(pageSizeChange)="pageSizeChange($event)" (pageSizeChange)="pageSizeChange($event)"

View File

@@ -168,18 +168,30 @@ export class BrowseByMetadataPageComponent implements OnInit {
* Navigate to the previous page * Navigate to the previous page
*/ */
goPrev() { goPrev() {
this.items$.pipe(take(1)).subscribe((items) => { if (this.items$) {
this.items$ = this.browseService.getPrevBrowseItems(items); this.items$.pipe(take(1)).subscribe((items) => {
}); this.items$ = this.browseService.getPrevBrowseItems(items);
});
} else if (this.browseEntries$) {
this.browseEntries$.pipe(take(1)).subscribe((entries) => {
this.browseEntries$ = this.browseService.getPrevBrowseEntries(entries);
});
}
} }
/** /**
* Navigate to the next page * Navigate to the next page
*/ */
goNext() { goNext() {
this.items$.pipe(take(1)).subscribe((items) => { if (this.items$) {
this.items$ = this.browseService.getNextBrowseItems(items); this.items$.pipe(take(1)).subscribe((items) => {
}); this.items$ = this.browseService.getNextBrowseItems(items);
});
} else if (this.browseEntries$) {
this.browseEntries$.pipe(take(1)).subscribe((entries) => {
this.browseEntries$ = this.browseService.getNextBrowseEntries(entries);
});
}
} }
/** /**

View File

@@ -41,8 +41,8 @@ describe('BrowseByTitlePageComponent', () => {
}) })
]; ];
const mockItemDataService = { const mockBrowseService = {
findAll: () => toRemoteData(mockItems) getBrowseItemsFor: () => toRemoteData(mockItems)
}; };
const mockDsoService = { const mockDsoService = {
@@ -59,10 +59,9 @@ describe('BrowseByTitlePageComponent', () => {
declarations: [BrowseByTitlePageComponent, EnumKeysPipe], declarations: [BrowseByTitlePageComponent, EnumKeysPipe],
providers: [ providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: BrowseService, useValue: {} }, { provide: BrowseService, useValue: mockBrowseService },
{ provide: DSpaceObjectDataService, useValue: mockDsoService }, { provide: DSpaceObjectDataService, useValue: mockDsoService },
{ provide: Router, useValue: new MockRouter() }, { provide: Router, useValue: new MockRouter() }
{ provide: ItemDataService, useValue: mockItemDataService }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); }).compileComponents();

View File

@@ -25,8 +25,7 @@ export class BrowseByTitlePageComponent extends BrowseByMetadataPageComponent {
public constructor(protected route: ActivatedRoute, public constructor(protected route: ActivatedRoute,
protected browseService: BrowseService, protected browseService: BrowseService,
protected dsoService: DSpaceObjectDataService, protected dsoService: DSpaceObjectDataService,
protected router: Router, protected router: Router) {
protected itemDataService: ItemDataService) {
super(route, browseService, dsoService, router); super(route, browseService, dsoService, router);
} }
@@ -43,27 +42,12 @@ export class BrowseByTitlePageComponent extends BrowseByMetadataPageComponent {
}) })
.subscribe((params) => { .subscribe((params) => {
this.metadata = params.metadata || this.defaultMetadata; this.metadata = params.metadata || this.defaultMetadata;
this.updatePage(browseParamsToOptions(params, this.paginationConfig, this.sortConfig)); this.updatePageWithItems(browseParamsToOptions(params, this.paginationConfig, this.sortConfig, this.metadata), undefined);
this.updateParent(params.scope) this.updateParent(params.scope)
})); }));
this.startsWithOptions = []; this.startsWithOptions = [];
} }
/**
* Updates the current page with searchOptions
* @param searchOptions Options to narrow down your search:
* { pagination: PaginationComponentOptions,
* sort: SortOptions }
*/
updatePage(searchOptions: BrowseEntrySearchOptions) {
this.items$ = this.itemDataService.findAll({
currentPage: searchOptions.pagination.currentPage,
elementsPerPage: searchOptions.pagination.pageSize,
sort: searchOptions.sort,
scopeID: searchOptions.scope
});
}
ngOnDestroy(): void { ngOnDestroy(): void {
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe()); this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
} }

View File

@@ -194,7 +194,7 @@ export class BrowseService {
} }
/** /**
* Get the previous page using the paginated list's prev link * Get the previous page of items using the paginated list's prev link
* @param items * @param items
*/ */
getPrevBrowseItems(items: RemoteData<PaginatedList<Item>>): Observable<RemoteData<PaginatedList<Item>>> { getPrevBrowseItems(items: RemoteData<PaginatedList<Item>>): Observable<RemoteData<PaginatedList<Item>>> {
@@ -204,7 +204,7 @@ export class BrowseService {
} }
/** /**
* Get the next page using the paginated list's next link * Get the next page of items using the paginated list's next link
* @param items * @param items
*/ */
getNextBrowseItems(items: RemoteData<PaginatedList<Item>>): Observable<RemoteData<PaginatedList<Item>>> { getNextBrowseItems(items: RemoteData<PaginatedList<Item>>): Observable<RemoteData<PaginatedList<Item>>> {
@@ -213,6 +213,26 @@ export class BrowseService {
); );
} }
/**
* Get the previous page of browse-entries using the paginated list's prev link
* @param entries
*/
getPrevBrowseEntries(entries: RemoteData<PaginatedList<BrowseEntry>>): Observable<RemoteData<PaginatedList<BrowseEntry>>> {
return observableOf(entries.payload.prev).pipe(
getBrowseEntriesFor(this.requestService, this.responseCache, this.rdb)
);
}
/**
* Get the next page of browse-entries using the paginated list's next link
* @param entries
*/
getNextBrowseEntries(entries: RemoteData<PaginatedList<BrowseEntry>>): Observable<RemoteData<PaginatedList<BrowseEntry>>> {
return observableOf(entries.payload.next).pipe(
getBrowseEntriesFor(this.requestService, this.responseCache, this.rdb)
);
}
/** /**
* Get the browse URL by providing a metadatum key and linkPath * Get the browse URL by providing a metadatum key and linkPath
* @param metadatumKey * @param metadatumKey