Skip to content

Commit 170f813

Browse files
atarix83Andrea Barbasso
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-1974 (pull request DSpace#2384)
Task/dspace cris 2023 02 x/DSC-1974 Approved-by: Andrea Barbasso
2 parents 2efde9c + 27dc1ca commit 170f813

21 files changed

Lines changed: 152 additions & 75 deletions

src/app/collection-page/collection-page-routing.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { CollectionPageAdministratorGuard } from './collection-page-administrato
2121
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';
2222
import { ThemedCollectionPageComponent } from './themed-collection-page.component';
2323
import { MenuItemType } from '../shared/menu/menu-item-type.model';
24-
import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
2524
import { CommunityBreadcrumbResolver } from '../core/breadcrumbs/community-breadcrumb.resolver';
2625
import { EditCollectionResolver } from '../core/shared/resolvers/edit-collection.resolver';
2726

@@ -56,7 +55,6 @@ import { EditCollectionResolver } from '../core/shared/resolvers/edit-collection
5655
resolve: {
5756
dso: CollectionPageResolver,
5857
breadcrumb: CollectionBreadcrumbResolver,
59-
menu: DSOEditMenuResolver
6058
},
6159
runGuardsAndResolvers: 'always',
6260
children: [

src/app/community-page/community-page-routing.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { CommunityPageAdministratorGuard } from './community-page-administrator.
1414
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';
1515
import { ThemedCommunityPageComponent } from './themed-community-page.component';
1616
import { MenuItemType } from '../shared/menu/menu-item-type.model';
17-
import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
1817
import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver';
1918

2019
@NgModule({
@@ -48,7 +47,6 @@ import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.reso
4847
resolve: {
4948
dso: CommunityPageResolver,
5049
breadcrumb: CommunityBreadcrumbResolver,
51-
menu: DSOEditMenuResolver
5250
},
5351
runGuardsAndResolvers: 'always',
5452
children: [

src/app/core/browse/search-manager.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import { DSpaceObject } from '../shared/dspace-object.model';
1414
import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model';
1515
import { SearchObjects } from '../../shared/search/models/search-objects.model';
1616
import { SearchService } from '../shared/search/search.service';
17-
import { WorkspaceItem } from '../submission/models/workspaceitem.model';
18-
import { WorkflowItem } from '../submission/models/workflowitem.model';
19-
import { hasValue } from '../../shared/empty.util';
17+
import { hasValue, isNotEmpty } from '../../shared/empty.util';
2018
import { FollowAuthorityMetadata } from '../../../config/search-follow-metadata.interface';
2119
import { MetadataValue } from '../shared/metadata.models';
2220
import { Metadata } from '../shared/metadata.utils';
2321
import isArray from 'lodash/isArray';
22+
import { WORKSPACEITEM } from '../eperson/models/workspaceitem.resource-type';
23+
import { WORKFLOWITEM } from '../eperson/models/workflowitem.resource-type';
24+
import { ITEM } from '../shared/item.resource-type';
2425

2526
/**
2627
* The service aims to manage browse requests and subsequent extra fetch requests.
@@ -84,7 +85,8 @@ export class SearchManager {
8485
protected completeSearchObjectsWithExtraData<T extends DSpaceObject>() {
8586
return switchMap((searchObjectsRD: RemoteData<SearchObjects<T>>) => {
8687
if (searchObjectsRD.isSuccess) {
87-
const items: Item[] = searchObjectsRD.payload.page.map((searchResult) => searchResult.indexableObject) as any;
88+
const items: Item[] = searchObjectsRD.payload.page
89+
.map((searchResult) => isNotEmpty(searchResult?._embedded?.indexableObject) ? searchResult._embedded.indexableObject : searchResult.indexableObject) as any;
8890
return this.fetchExtraData(items).pipe(map(() => {
8991
return searchObjectsRD;
9092
}));
@@ -96,13 +98,16 @@ export class SearchManager {
9698
protected fetchExtraData<T extends DSpaceObject>(objects: T[]): Observable<any> {
9799

98100
const items: Item[] = objects
99-
.map((object) => {
100-
if (object instanceof WorkspaceItem || object instanceof WorkflowItem) {
101-
return object.item as Item;
102-
}
103-
if (object instanceof Item) {
101+
.map((object: any) => {
102+
if (object.type === ITEM.value) {
104103
return object as Item;
104+
} else if (object.type === WORKSPACEITEM.value || object.type === WORKFLOWITEM.value) {
105+
return object?._embedded?.item as Item;
106+
} else {
107+
// Handle workflow task here, where the item is embedded in a workflowitem
108+
return object?._embedded?.workflowitem?._embedded?.item as Item;
105109
}
110+
106111
})
107112
.filter((item) => hasValue(item));
108113

@@ -127,12 +132,12 @@ export class SearchManager {
127132
if (item.entityType === followMetadata.type) {
128133
if (isArray(followMetadata.metadata)) {
129134
followMetadata.metadata.forEach((metadata) => {
130-
item.allMetadata(metadata)
135+
Metadata.all(item.metadata, metadata)
131136
.filter((metadataValue: MetadataValue) => Metadata.hasValidItemAuthority(metadataValue.authority))
132137
.forEach((metadataValue: MetadataValue) => uuidMap[metadataValue.authority] = metadataValue);
133138
});
134139
} else {
135-
item.allMetadata(followMetadata.metadata)
140+
Metadata.all(item.metadata, followMetadata.metadata)
136141
.filter((metadataValue: MetadataValue) => Metadata.hasValidItemAuthority(metadataValue.authority))
137142
.forEach((metadataValue: MetadataValue) => uuidMap[metadataValue.authority] = metadataValue);
138143
}

src/app/core/browse/search.manager.spec.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { of } from 'rxjs';
1212
import { MetadataValue } from '../shared/metadata.models';
1313
import { v4 as uuidv4 } from 'uuid';
1414
import { AUTHORITY_REFERENCE } from '../shared/metadata.utils';
15+
import { ITEM } from '../shared/item.resource-type';
1516

1617
describe('SearchManager', () => {
1718
let scheduler: TestScheduler;
@@ -31,7 +32,8 @@ describe('SearchManager', () => {
3132
})
3233

3334
]
34-
}
35+
},
36+
type: ITEM.value
3537
});
3638

3739
const secondPublication = Object.assign(new Item(), {
@@ -44,7 +46,8 @@ describe('SearchManager', () => {
4446
value: 'author2'
4547
})
4648
]
47-
}
49+
},
50+
type: ITEM.value
4851
});
4952

5053
const firstProject = Object.assign(new Item(), {
@@ -57,7 +60,8 @@ describe('SearchManager', () => {
5760
value: 'author3'
5861
})
5962
]
60-
}
63+
},
64+
type: ITEM.value
6165
});
6266

6367
const thirdPublication = Object.assign(new Item(), {
@@ -70,7 +74,8 @@ describe('SearchManager', () => {
7074
})
7175

7276
]
73-
}
77+
},
78+
type: ITEM.value
7479
});
7580

7681
const invalidAuthorityPublication = Object.assign(new Item(), {
@@ -84,7 +89,8 @@ describe('SearchManager', () => {
8489
})
8590

8691
]
87-
}
92+
},
93+
type: ITEM.value
8894
});
8995

9096
const mockBrowseService: any = {

src/app/core/data/entity-type-data.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class EntityTypeDataService extends BaseDataService<ItemType> implements
8383
*/
8484
hasMoreThanOneAuthorized(): Observable<boolean> {
8585
const findListOptions: FindListOptions = {
86-
elementsPerPage: 2,
86+
elementsPerPage: 10,
8787
currentPage: 1
8888
};
8989
return this.getAllAuthorizedRelationshipType(findListOptions).pipe(
@@ -117,7 +117,7 @@ export class EntityTypeDataService extends BaseDataService<ItemType> implements
117117
*/
118118
hasMoreThanOneAuthorizedImport(): Observable<boolean> {
119119
const findListOptions: FindListOptions = {
120-
elementsPerPage: 2,
120+
elementsPerPage: 10,
121121
currentPage: 1
122122
};
123123
return this.getAllAuthorizedRelationshipTypeImport(findListOptions).pipe(

src/app/cris-item-page/cris-item-page.resolver.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Observable } from 'rxjs';
33
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
44
import { RemoteData } from '../core/data/remote-data';
55
import { ItemDataService } from '../core/data/item-data.service';
6-
import { followLink } from '../shared/utils/follow-link-config.model';
76
import { Item } from '../core/shared/item.model';
87
import { getFirstCompletedRemoteData } from '../core/shared/operators';
8+
import { ITEM_PAGE_LINKS_TO_FOLLOW } from '../item-page/item.resolver';
99

1010
/**
1111
* This class represents a resolver that requests a specific item before the route is activated
@@ -25,13 +25,9 @@ export class CrisItemPageResolver implements Resolve<RemoteData<Item>> {
2525
* or an error if something went wrong
2626
*/
2727
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> {
28-
// TODO temporary disable cache to have always an update item, check if after update with 7.3, it's only necessary to invalidate a cache on edit item saving
2928
return this.itemService.findById(route.params.id,
30-
false, true,
31-
followLink('owningCollection'),
32-
followLink('bundles'),
33-
followLink('relationships'),
34-
followLink('version', {}, followLink('versionhistory')),
29+
true, true,
30+
...ITEM_PAGE_LINKS_TO_FOLLOW
3531
).pipe(
3632
getFirstCompletedRemoteData()
3733
);

src/app/item-page/item-page-routing.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { REQUEST_COPY_MODULE_PATH } from '../app-routing-paths';
1919
import { CrisItemPageTabResolver } from './cris-item-page-tab.resolver';
2020
import { OrcidPageComponent } from './orcid-page/orcid-page.component';
2121
import { OrcidPageGuard } from './orcid-page/orcid-page.guard';
22-
import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
2322

2423
@NgModule({
2524
imports: [
@@ -29,7 +28,6 @@ import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
2928
resolve: {
3029
dso: ItemPageResolver,
3130
breadcrumb: ItemBreadcrumbResolver,
32-
menu: DSOEditMenuResolver
3331
},
3432
runGuardsAndResolvers: 'always',
3533
children: [

src/app/item-page/item.resolver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ export class ItemResolver implements Resolve<RemoteData<Item>> {
4545
* or an error if something went wrong
4646
*/
4747
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> {
48+
// Fetch item with cache disabled to have always a fresh item object
4849
const itemRD$ = this.itemService.findById(route.params.id,
4950
false,
50-
false,
51+
true,
5152
...ITEM_PAGE_LINKS_TO_FOLLOW
5253
).pipe(
5354
getFirstCompletedRemoteData(),

src/app/shared/browse-most-elements/abstract-browse-elements.component.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { followLink } from '../utils/follow-link-config.model';
22
import { CollectionElementLinkType } from '../object-collection/collection-element-link.type';
3-
import { TopSection } from '../../core/layout/models/section.model';
43
import { Component, Input, OnChanges, OnInit, PLATFORM_ID, inject } from '@angular/core';
54
import { isPlatformServer } from '@angular/common';
65

@@ -31,17 +30,42 @@ export abstract class AbstractBrowseElementsComponent implements OnInit, OnChang
3130
protected readonly platformId = inject(PLATFORM_ID);
3231
protected readonly searchService = inject(SearchService);
3332

34-
protected followThumbnailLink: boolean; // to be overridden
33+
protected abstract followMetricsLink: boolean; // to be overridden
34+
protected abstract followThumbnailLink: boolean; // to be overridden
3535

36+
/**
37+
* The context of listable object
38+
*/
39+
@Input() context: Context;
40+
41+
/**
42+
* The pagination options
43+
*/
3644
@Input() paginatedSearchOptions: PaginatedSearchOptions;
3745

38-
@Input() context: Context;
46+
/**
47+
* Optional projection to use during the search
48+
*/
49+
@Input() projection = 'preventMetadataSecurity';
50+
51+
/**
52+
* Whether to show the badge label or not
53+
*/
54+
@Input() showLabel: boolean;
3955

40-
@Input() topSection: TopSection;
56+
/**
57+
* Whether to show the metrics badges
58+
*/
59+
@Input() showMetrics = this.appConfig.browseBy.showMetrics;
60+
61+
/**
62+
* Whether to show the thumbnail preview
63+
*/
64+
@Input() showThumbnails = this.appConfig.browseBy.showThumbnails;
4165

4266
public collectionElementLinkTypeEnum = CollectionElementLinkType;
4367

44-
paginatedSearchOptionsBS: BehaviorSubject<PaginatedSearchOptions>;
68+
paginatedSearchOptions$: BehaviorSubject<PaginatedSearchOptions>;
4569

4670
searchResults$: Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>;
4771

@@ -51,13 +75,23 @@ export abstract class AbstractBrowseElementsComponent implements OnInit, OnChang
5175
if (isPlatformServer(this.platformId)) {
5276
return;
5377
}
54-
this.paginatedSearchOptionsBS?.next(this.paginatedSearchOptions);
78+
this.paginatedSearchOptions$?.next(this.paginatedSearchOptions);
5579
}
5680

5781
ngOnInit() {
58-
const followLinks = this.followThumbnailLink ? [followLink('thumbnail'), followLink('metrics')] : [followLink('metrics')];
59-
this.paginatedSearchOptionsBS = new BehaviorSubject<PaginatedSearchOptions>(this.paginatedSearchOptions);
60-
this.searchResults$ = this.paginatedSearchOptionsBS.asObservable().pipe(
82+
const followLinks = [];
83+
if (this.followThumbnailLink) {
84+
followLinks.push(followLink('thumbnail'));
85+
}
86+
if (this.followMetricsLink) {
87+
followLinks.push(followLink('metrics'));
88+
}
89+
90+
this.paginatedSearchOptions = Object.assign(new PaginatedSearchOptions({}), this.paginatedSearchOptions, {
91+
projection: this.projection
92+
});
93+
this.paginatedSearchOptions$ = new BehaviorSubject<PaginatedSearchOptions>(this.paginatedSearchOptions);
94+
this.searchResults$ = this.paginatedSearchOptions$.asObservable().pipe(
6195
mergeMap((paginatedSearchOptions) =>
6296
this.searchService.search(paginatedSearchOptions, null, true, true, ...followLinks),
6397
),

src/app/shared/browse-most-elements/browse-most-elements.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<ng-container *ngSwitchDefault>
44
<ds-themed-default-browse-elements
55
[showMetrics]="showMetrics"
6-
[showThumbnails]="topSection.showThumbnails"
6+
[showThumbnails]="showThumbnails ?? topSection.showThumbnails"
77
[topSection]="topSection"
88
[showLabel]="showLabel"
9-
[paginatedSearchOptions]="paginatedSearchOptionsBS.asObservable() | async"
9+
[paginatedSearchOptions]="paginatedSearchOptions$.asObservable() | async"
1010
[context]="context"
1111
></ds-themed-default-browse-elements>
1212
</ng-container>

0 commit comments

Comments
 (0)