From d852ca0816199e8af502e5a6a1e2e5a20f6eb9b0 Mon Sep 17 00:00:00 2001
From: Andrea Barbasso <´andrea.barbasso@4science.com´>
Date: Wed, 18 Jan 2023 09:58:33 +0100
Subject: [PATCH] CST-8165 show logo when browsing collections
---
.../browse-by-date-page.component.ts | 1 +
.../browse-by-metadata-page.component.html | 5 +++
.../browse-by-metadata-page.component.spec.ts | 7 ++++
.../browse-by-metadata-page.component.ts | 33 +++++++++++++++++--
.../browse-by-title-page.component.ts | 1 +
5 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/src/app/browse-by/browse-by-date-page/browse-by-date-page.component.ts b/src/app/browse-by/browse-by-date-page/browse-by-date-page.component.ts
index c4a67349a57..ffa7e882af7 100644
--- a/src/app/browse-by/browse-by-date-page/browse-by-date-page.component.ts
+++ b/src/app/browse-by/browse-by-date-page/browse-by-date-page.component.ts
@@ -65,6 +65,7 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
const searchOptions = browseParamsToOptions(params, currentPage, currentSort, this.browseId, this.fetchThumbnails);
this.updatePageWithItems(searchOptions, this.value, undefined);
this.updateParent(params.scope);
+ this.updateLogo();
this.updateStartsWithOptions(this.browseId, metadataKeys, params.scope);
}));
}
diff --git a/src/app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component.html b/src/app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component.html
index 227fa8aa788..b68f498771e 100644
--- a/src/app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component.html
+++ b/src/app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component.html
@@ -5,6 +5,11 @@
+
+
+
{
route.params = observableOf(paramsWithValue);
comp.ngOnInit();
+ comp.updateParent('fake-scope');
+ comp.updateLogo();
+ fixture.detectChanges();
});
it('should fetch items', () => {
@@ -151,6 +154,10 @@ describe('BrowseByMetadataPageComponent', () => {
expect(result.payload.page).toEqual(mockItems);
});
});
+
+ it('should fetch the logo', () => {
+ expect(comp.logo$).toBeTruthy();
+ });
});
describe('when calling browseParamsToOptions', () => {
diff --git a/src/app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component.ts b/src/app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component.ts
index 4cfe332da10..5de6c7d8567 100644
--- a/src/app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component.ts
+++ b/src/app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component.ts
@@ -15,7 +15,11 @@ import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.serv
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { StartsWithType } from '../../shared/starts-with/starts-with-decorator';
import { PaginationService } from '../../core/pagination/pagination.service';
-import { map } from 'rxjs/operators';
+import { filter, map, mergeMap } from 'rxjs/operators';
+import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
+import { Bitstream } from '../../core/shared/bitstream.model';
+import { Collection } from '../../core/shared/collection.model';
+import { Community } from '../../core/shared/community.model';
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
export const BBM_PAGINATION_ID = 'bbm';
@@ -48,6 +52,11 @@ export class BrowseByMetadataPageComponent implements OnInit, OnDestroy {
*/
parent$: Observable>;
+ /**
+ * The logo of the current Community or Collection
+ */
+ logo$: Observable>;
+
/**
* The pagination config used to display the values
*/
@@ -151,6 +160,7 @@ export class BrowseByMetadataPageComponent implements OnInit, OnDestroy {
this.updatePage(browseParamsToOptions(params, currentPage, currentSort, this.browseId, false));
}
this.updateParent(params.scope);
+ this.updateLogo();
}));
this.updateStartsWithTextOptions();
@@ -196,12 +206,31 @@ export class BrowseByMetadataPageComponent implements OnInit, OnDestroy {
*/
updateParent(scope: string) {
if (hasValue(scope)) {
- this.parent$ = this.dsoService.findById(scope).pipe(
+ const linksToFollow = () => {
+ return [followLink('logo')];
+ };
+ this.parent$ = this.dsoService.findById(scope,
+ true,
+ true,
+ ...linksToFollow() as FollowLinkConfig[]).pipe(
getFirstSucceededRemoteData()
);
}
}
+ /**
+ * Update the parent Community or Collection logo
+ */
+ updateLogo() {
+ if (hasValue(this.parent$)) {
+ this.logo$ = this.parent$.pipe(
+ map((rd: RemoteData) => rd.payload),
+ filter((collectionOrCommunity: Collection | Community) => hasValue(collectionOrCommunity.logo)),
+ mergeMap((collectionOrCommunity: Collection | Community) => collectionOrCommunity.logo)
+ );
+ }
+ }
+
/**
* Navigate to the previous page
*/
diff --git a/src/app/browse-by/browse-by-title-page/browse-by-title-page.component.ts b/src/app/browse-by/browse-by-title-page/browse-by-title-page.component.ts
index 5320d7bb48b..3e9af2197cc 100644
--- a/src/app/browse-by/browse-by-title-page/browse-by-title-page.component.ts
+++ b/src/app/browse-by/browse-by-title-page/browse-by-title-page.component.ts
@@ -49,6 +49,7 @@ export class BrowseByTitlePageComponent extends BrowseByMetadataPageComponent {
this.browseId = params.id || this.defaultBrowseId;
this.updatePageWithItems(browseParamsToOptions(params, currentPage, currentSort, this.browseId, this.fetchThumbnails), undefined, undefined);
this.updateParent(params.scope);
+ this.updateLogo();
}));
this.updateStartsWithTextOptions();
}