-
+
{{'browse.empty' | translate}}
diff --git a/src/app/shared/browse-by/browse-by.component.ts b/src/app/shared/browse-by/browse-by.component.ts
index 2e8d2447b1..01351fd030 100644
--- a/src/app/shared/browse-by/browse-by.component.ts
+++ b/src/app/shared/browse-by/browse-by.component.ts
@@ -129,6 +129,19 @@ export class BrowseByComponent implements OnInit, OnDestroy {
}
+ /**
+ * Used to set the back button label for metadata browsing.
+ */
+ backButtonType = 'metadata-browse';
+
+ /**
+ * Used for back navigation in metadata browse.
+ */
+ back = () => {
+ const page = +this.previousPage$.value > 1 ? +this.previousPage$.value : 1;
+ this.paginationService.updateRoute(this.paginationConfig.id, {page: page}, {[this.paginationConfig.id + '.return']: null, value: null, startsWith: null});
+ };
+
/**
* Go to the previous page
*/
diff --git a/src/app/shared/results-back-button/results-back-button.component.spec.ts b/src/app/shared/results-back-button/results-back-button.component.spec.ts
index 8536099d3a..4aceea289a 100644
--- a/src/app/shared/results-back-button/results-back-button.component.spec.ts
+++ b/src/app/shared/results-back-button/results-back-button.component.spec.ts
@@ -2,12 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ResultsBackButtonComponent } from './results-back-button.component';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { NO_ERRORS_SCHEMA } from '@angular/core';
-import { RouteService } from '../../core/services/route.service';
import { RouterTestingModule } from '@angular/router/testing';
-import { BehaviorSubject, Observable, of } from 'rxjs';
-import { Router } from '@angular/router';
-import { PaginationComponentOptions } from '../pagination/pagination-component-options.model';
-import { PaginationService } from '../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../testing/pagination-service.stub';
describe('ResultsBackButtonComponent', () => {
@@ -15,23 +10,7 @@ describe('ResultsBackButtonComponent', () => {
let component: ResultsBackButtonComponent;
let fixture: ComponentFixture;
let router;
- const paginationConfig = Object.assign(new PaginationComponentOptions(), {
- id: 'test-pagination',
- currentPage: 1,
- pageSizeOptions: [5, 10, 15, 20],
- pageSize: 15
- });
- const searchUrl = '/search?query=test&spc.page=2';
- const nonSearchUrl = '/item';
-
- function getMockRouteService(url) {
- return {
- getPreviousUrl(): Observable < string > {
- return of(url);
- }
- };
- }
router = jasmine.createSpyObj('router', {
navigateByUrl: jasmine.createSpy('navigateByUrl')
@@ -43,7 +22,6 @@ describe('ResultsBackButtonComponent', () => {
describe('back to results', () => {
- const mockRouteService = getMockRouteService(searchUrl);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
@@ -52,14 +30,10 @@ describe('ResultsBackButtonComponent', () => {
RouterTestingModule.withRoutes([])
],
providers: [
- { provide: RouteService, useValue: mockRouteService },
- { provide: PaginationService, useValue: paginationService},
- { provide: Router, useValue: router },
{ provide: TranslateService, useValue: translate }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
- spyOn(mockRouteService, 'getPreviousUrl').and.callThrough();
}));
describe('from a metadata browse list', () => {
@@ -67,8 +41,7 @@ describe('ResultsBackButtonComponent', () => {
beforeEach(waitForAsync(() => {
fixture = TestBed.createComponent(ResultsBackButtonComponent);
component = fixture.componentInstance;
- component.paginationConfig = paginationConfig;
- component.previousPage$ = new BehaviorSubject('1');
+ component.buttonType = 'metadata-browse';
fixture.detectChanges();
}));
@@ -76,8 +49,6 @@ describe('ResultsBackButtonComponent', () => {
expect(translate.get).toHaveBeenCalledWith('browse.back.all-results');
});
-
-
});
describe('from an item', () => {
@@ -92,11 +63,6 @@ describe('ResultsBackButtonComponent', () => {
expect(translate.get).toHaveBeenCalledWith('search.browse.item-back');
});
- it('should navigate to previous url', () => {
- component.back();
- expect(mockRouteService.getPreviousUrl).toHaveBeenCalled();
- expect(router.navigateByUrl).toHaveBeenCalledWith(searchUrl);
- });
});
});
diff --git a/src/app/shared/results-back-button/results-back-button.component.ts b/src/app/shared/results-back-button/results-back-button.component.ts
index 25a3f9476b..bea5c55b68 100644
--- a/src/app/shared/results-back-button/results-back-button.component.ts
+++ b/src/app/shared/results-back-button/results-back-button.component.ts
@@ -1,12 +1,6 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
-import { take } from 'rxjs/operators';
-import { RouteService } from '../../core/services/route.service';
-import { Router } from '@angular/router';
-import { PaginationService } from '../../core/pagination/pagination.service';
-import { PaginationComponentOptions } from '../pagination/pagination-component-options.model';
-import { BehaviorSubject, Observable } from 'rxjs';
+import { Observable } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';
-import { isNotEmpty } from '../empty.util';
@Component({
selector: 'ds-results-back-button',
@@ -20,52 +14,31 @@ import { isNotEmpty } from '../empty.util';
export class ResultsBackButtonComponent implements OnInit {
/**
- * Page number of the previous page
+ * The button type determines the button label.
*/
- @Input() previousPage$?: BehaviorSubject;
+ @Input() buttonType?: string;
/**
- * The pagination configuration used for the list
+ * The function used for back navigation.
*/
- @Input() paginationConfig?: PaginationComponentOptions;
+ @Input() back: () => void;
/**
- * The button text
+ * The button label translation.
*/
buttonLabel: Observable;
- constructor(protected routeService: RouteService,
- protected paginationService: PaginationService,
- protected router: Router,
- private translateService: TranslateService) {
+ constructor(private translateService: TranslateService) {
}
ngOnInit(): void {
- if (this.paginationConfig) {
+ // Set labels for metadata browse and item back buttons.
+ if (this.buttonType === 'metadata-browse') {
this.buttonLabel = this.translateService.get('browse.back.all-results');
} else {
this.buttonLabel = this.translateService.get('search.browse.item-back');
}
}
- /**
- * Navigate back from the item to the previous pagination list.
- */
- public back() {
- if (isNotEmpty(this.paginationConfig) && isNotEmpty(this.previousPage$)) {
- // if pagination configuration is provided use it to update the route to the previous browse page.
- const page = +this.previousPage$.value > 1 ? +this.previousPage$.value : 1;
- this.paginationService.updateRoute(this.paginationConfig.id, {page: page}, {[this.paginationConfig.id + '.return']: null, value: null, startsWith: null});
- } else {
- this.routeService.getPreviousUrl().pipe(
- take(1)
- ).subscribe(
- (url => {
- this.router.navigateByUrl(url);
- })
- );
- }
- }
-
}
diff --git a/src/app/shared/results-back-button/themed-results-back-button.component.ts b/src/app/shared/results-back-button/themed-results-back-button.component.ts
index 45ac86a605..2f569364bb 100644
--- a/src/app/shared/results-back-button/themed-results-back-button.component.ts
+++ b/src/app/shared/results-back-button/themed-results-back-button.component.ts
@@ -1,4 +1,4 @@
-import { Component } from '@angular/core';
+import { Component, Input } from '@angular/core';
import { ThemedComponent } from '../theme-support/themed.component';
import { ResultsBackButtonComponent } from './results-back-button.component';
@@ -9,6 +9,12 @@ import { ResultsBackButtonComponent } from './results-back-button.component';
})
export class ThemedResultsBackButtonComponent extends ThemedComponent {
+ @Input() buttonType?: string;
+
+ @Input() back: () => void;
+
+ protected inAndOutputNames: (keyof ResultsBackButtonComponent & keyof this)[] = ['back', 'buttonType'];
+
protected getComponentName(): string {
return 'ResultsBackButtonComponent';
}