From 6e052af1f0bbb9d80670a20f5aa33e62bd69f2b4 Mon Sep 17 00:00:00 2001 From: Michael Spalti Date: Fri, 20 Jan 2023 16:11:56 -0800 Subject: [PATCH] moved view logic back to ItemComponent --- .../journal-issue.component.html | 2 +- .../journal-volume.component.html | 2 +- .../item-pages/journal/journal.component.html | 2 +- .../org-unit/org-unit.component.html | 2 +- .../item-pages/person/person.component.html | 2 +- .../item-pages/project/project.component.html | 2 +- .../publication/publication.component.html | 2 +- .../item-types/shared/item.component.spec.ts | 90 +++++++++++++++++++ .../item-types/shared/item.component.ts | 12 +++ .../untyped-item/untyped-item.component.html | 2 +- .../shared/browse-by/browse-by.component.html | 6 +- .../results-back-button.component.html | 2 +- .../results-back-button.component.spec.ts | 43 +-------- .../results-back-button.component.ts | 29 +----- 14 files changed, 115 insertions(+), 83 deletions(-) diff --git a/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.html b/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.html index 11d722f317..fee1751d93 100644 --- a/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.html +++ b/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.html @@ -1,4 +1,4 @@ - +
diff --git a/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.html b/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.html index 4475fbec8a..2cc653eba5 100644 --- a/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.html +++ b/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.html @@ -1,4 +1,4 @@ - +
diff --git a/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.html b/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.html index 1c079ed36f..b97aff326a 100644 --- a/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.html +++ b/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.html @@ -1,4 +1,4 @@ - +
diff --git a/src/app/entity-groups/research-entities/item-pages/org-unit/org-unit.component.html b/src/app/entity-groups/research-entities/item-pages/org-unit/org-unit.component.html index 87c9cc2fa1..8b29339211 100644 --- a/src/app/entity-groups/research-entities/item-pages/org-unit/org-unit.component.html +++ b/src/app/entity-groups/research-entities/item-pages/org-unit/org-unit.component.html @@ -1,4 +1,4 @@ - +
diff --git a/src/app/entity-groups/research-entities/item-pages/person/person.component.html b/src/app/entity-groups/research-entities/item-pages/person/person.component.html index 34c23ebf12..845f8127c0 100644 --- a/src/app/entity-groups/research-entities/item-pages/person/person.component.html +++ b/src/app/entity-groups/research-entities/item-pages/person/person.component.html @@ -1,4 +1,4 @@ - +
diff --git a/src/app/entity-groups/research-entities/item-pages/project/project.component.html b/src/app/entity-groups/research-entities/item-pages/project/project.component.html index bb49dc507a..e4475cc6f1 100644 --- a/src/app/entity-groups/research-entities/item-pages/project/project.component.html +++ b/src/app/entity-groups/research-entities/item-pages/project/project.component.html @@ -1,4 +1,4 @@ - +
diff --git a/src/app/item-page/simple/item-types/publication/publication.component.html b/src/app/item-page/simple/item-types/publication/publication.component.html index f418f5691e..56e118ca24 100644 --- a/src/app/item-page/simple/item-types/publication/publication.component.html +++ b/src/app/item-page/simple/item-types/publication/publication.component.html @@ -1,4 +1,4 @@ - +
{ ] }, }); + describe('back to results', () => { + let comp: ItemComponent; + let fixture: ComponentFixture; + let router: Router; + + const searchUrl = '/search?query=test&spc.page=2'; + const browseUrl = '/browse/title?scope=0cc&bbm.page=3'; + const recentSubmissionsUrl = '/collections/be7b8430-77a5-4016-91c9-90863e50583a?cp.page=3'; + + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + imports: [ + TranslateModule.forRoot({ + loader: { + provide: TranslateLoader, + useClass: TranslateLoaderMock + } + }), + RouterTestingModule, + ], + declarations: [ItemComponent, GenericItemPageFieldComponent, TruncatePipe ], + providers: [ + { provide: ItemDataService, useValue: {} }, + { provide: TruncatableService, useValue: {} }, + { provide: RelationshipDataService, useValue: {} }, + { provide: ObjectCacheService, useValue: {} }, + { provide: UUIDService, useValue: {} }, + { provide: Store, useValue: {} }, + { provide: RemoteDataBuildService, useValue: {} }, + { provide: CommunityDataService, useValue: {} }, + { provide: HALEndpointService, useValue: {} }, + { provide: HttpClient, useValue: {} }, + { provide: DSOChangeAnalyzer, useValue: {} }, + { provide: VersionHistoryDataService, useValue: {} }, + { provide: VersionDataService, useValue: {} }, + { provide: NotificationsService, useValue: {} }, + { provide: DefaultChangeAnalyzer, useValue: {} }, + { provide: BitstreamDataService, useValue: {} }, + { provide: WorkspaceitemDataService, useValue: {} }, + { provide: SearchService, useValue: {} }, + { provide: RouteService, useValue: mockRouteService }, + { provide: AuthorizationDataService, useValue: {} }, + { provide: ResearcherProfileDataService, useValue: {} } + ], + schemas: [NO_ERRORS_SCHEMA] + }).overrideComponent(ItemComponent, { + set: {changeDetection: ChangeDetectionStrategy.Default} + }); + })); + + beforeEach(waitForAsync(() => { + router = TestBed.inject(Router); + spyOn(router, 'navigateByUrl'); + TestBed.compileComponents(); + fixture = TestBed.createComponent(ItemComponent); + comp = fixture.componentInstance; + comp.object = mockItem; + fixture.detectChanges(); + })); + + it('should hide back button',() => { + spyOn(mockRouteService, 'getPreviousUrl').and.returnValue(observableOf('/item')); + comp.showBackButton.subscribe((val) => { + expect(val).toBeFalse(); + }); + }); + it('should show back button for search', () => { + spyOn(mockRouteService, 'getPreviousUrl').and.returnValue(observableOf(searchUrl)); + comp.ngOnInit(); + comp.showBackButton.subscribe((val) => { + expect(val).toBeTrue(); + }); + }); + it('should show back button for browse', () => { + spyOn(mockRouteService, 'getPreviousUrl').and.returnValue(observableOf(browseUrl)); + comp.ngOnInit(); + comp.showBackButton.subscribe((val) => { + expect(val).toBeTrue(); + }); + }); + it('should show back button for recent submissions', () => { + spyOn(mockRouteService, 'getPreviousUrl').and.returnValue(observableOf(recentSubmissionsUrl)); + comp.ngOnInit(); + comp.showBackButton.subscribe((val) => { + expect(val).toBeTrue(); + }); + }); + }); }); diff --git a/src/app/item-page/simple/item-types/shared/item.component.ts b/src/app/item-page/simple/item-types/shared/item.component.ts index 5d11dda8e9..b815ca0ddb 100644 --- a/src/app/item-page/simple/item-types/shared/item.component.ts +++ b/src/app/item-page/simple/item-types/shared/item.component.ts @@ -5,6 +5,7 @@ import { getItemPageRoute } from '../../../item-page-routing-paths'; import { RouteService } from '../../../../core/services/route.service'; import { Observable } from 'rxjs'; import { getDSpaceQuery, isIiifEnabled, isIiifSearchEnabled } from './item-iiif-utils'; +import { filter, map, take } from 'rxjs/operators'; @Component({ selector: 'ds-item', @@ -16,6 +17,11 @@ import { getDSpaceQuery, isIiifEnabled, isIiifSearchEnabled } from './item-iiif- export class ItemComponent implements OnInit { @Input() object: Item; + /** + * Used to show or hide the back to results button. + */ + showBackButton: Observable; + /** * Route to the item page */ @@ -42,6 +48,12 @@ export class ItemComponent implements OnInit { this.mediaViewer = environment.mediaViewer; } ngOnInit(): void { + + this.showBackButton = this.routeService.getPreviousUrl().pipe( + filter(url => /^(\/search|\/browse|\/collections|\/admin\/search|\/mydspace)/.test(url)), + take(1), + map(() => true) + ); this.itemPageRoute = getItemPageRoute(this.object); // check to see if iiif viewer is required. this.iiifEnabled = isIiifEnabled(this.object); diff --git a/src/app/item-page/simple/item-types/untyped-item/untyped-item.component.html b/src/app/item-page/simple/item-types/untyped-item/untyped-item.component.html index ef96eef620..462876736c 100644 --- a/src/app/item-page/simple/item-types/untyped-item/untyped-item.component.html +++ b/src/app/item-page/simple/item-types/untyped-item/untyped-item.component.html @@ -1,4 +1,4 @@ - +
+ [previousPage$]="previousPage$">
+ [previousPage$]="previousPage$">