Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1974 (pull request DSpace#2384)
Browse files Browse the repository at this point in the history
Task/dspace cris 2023 02 x/DSC-1974

Approved-by: Andrea Barbasso
  • Loading branch information
atarix83 authored and Andrea Barbasso committed Oct 17, 2024
2 parents 2efde9c + 27dc1ca commit 170f813
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 75 deletions.
2 changes: 0 additions & 2 deletions src/app/collection-page/collection-page-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { CollectionPageAdministratorGuard } from './collection-page-administrato
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';
import { ThemedCollectionPageComponent } from './themed-collection-page.component';
import { MenuItemType } from '../shared/menu/menu-item-type.model';
import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
import { CommunityBreadcrumbResolver } from '../core/breadcrumbs/community-breadcrumb.resolver';
import { EditCollectionResolver } from '../core/shared/resolvers/edit-collection.resolver';

Expand Down Expand Up @@ -56,7 +55,6 @@ import { EditCollectionResolver } from '../core/shared/resolvers/edit-collection
resolve: {
dso: CollectionPageResolver,
breadcrumb: CollectionBreadcrumbResolver,
menu: DSOEditMenuResolver
},
runGuardsAndResolvers: 'always',
children: [
Expand Down
2 changes: 0 additions & 2 deletions src/app/community-page/community-page-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { CommunityPageAdministratorGuard } from './community-page-administrator.
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';
import { ThemedCommunityPageComponent } from './themed-community-page.component';
import { MenuItemType } from '../shared/menu/menu-item-type.model';
import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver';

@NgModule({
Expand Down Expand Up @@ -48,7 +47,6 @@ import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.reso
resolve: {
dso: CommunityPageResolver,
breadcrumb: CommunityBreadcrumbResolver,
menu: DSOEditMenuResolver
},
runGuardsAndResolvers: 'always',
children: [
Expand Down
27 changes: 16 additions & 11 deletions src/app/core/browse/search-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import { DSpaceObject } from '../shared/dspace-object.model';
import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model';
import { SearchObjects } from '../../shared/search/models/search-objects.model';
import { SearchService } from '../shared/search/search.service';
import { WorkspaceItem } from '../submission/models/workspaceitem.model';
import { WorkflowItem } from '../submission/models/workflowitem.model';
import { hasValue } from '../../shared/empty.util';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { FollowAuthorityMetadata } from '../../../config/search-follow-metadata.interface';
import { MetadataValue } from '../shared/metadata.models';
import { Metadata } from '../shared/metadata.utils';
import isArray from 'lodash/isArray';
import { WORKSPACEITEM } from '../eperson/models/workspaceitem.resource-type';
import { WORKFLOWITEM } from '../eperson/models/workflowitem.resource-type';
import { ITEM } from '../shared/item.resource-type';

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

const items: Item[] = objects
.map((object) => {
if (object instanceof WorkspaceItem || object instanceof WorkflowItem) {
return object.item as Item;
}
if (object instanceof Item) {
.map((object: any) => {
if (object.type === ITEM.value) {
return object as Item;
} else if (object.type === WORKSPACEITEM.value || object.type === WORKFLOWITEM.value) {
return object?._embedded?.item as Item;
} else {
// Handle workflow task here, where the item is embedded in a workflowitem
return object?._embedded?.workflowitem?._embedded?.item as Item;
}

})
.filter((item) => hasValue(item));

Expand All @@ -127,12 +132,12 @@ export class SearchManager {
if (item.entityType === followMetadata.type) {
if (isArray(followMetadata.metadata)) {
followMetadata.metadata.forEach((metadata) => {
item.allMetadata(metadata)
Metadata.all(item.metadata, metadata)
.filter((metadataValue: MetadataValue) => Metadata.hasValidItemAuthority(metadataValue.authority))
.forEach((metadataValue: MetadataValue) => uuidMap[metadataValue.authority] = metadataValue);
});
} else {
item.allMetadata(followMetadata.metadata)
Metadata.all(item.metadata, followMetadata.metadata)
.filter((metadataValue: MetadataValue) => Metadata.hasValidItemAuthority(metadataValue.authority))
.forEach((metadataValue: MetadataValue) => uuidMap[metadataValue.authority] = metadataValue);
}
Expand Down
16 changes: 11 additions & 5 deletions src/app/core/browse/search.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { of } from 'rxjs';
import { MetadataValue } from '../shared/metadata.models';
import { v4 as uuidv4 } from 'uuid';
import { AUTHORITY_REFERENCE } from '../shared/metadata.utils';
import { ITEM } from '../shared/item.resource-type';

describe('SearchManager', () => {
let scheduler: TestScheduler;
Expand All @@ -31,7 +32,8 @@ describe('SearchManager', () => {
})

]
}
},
type: ITEM.value
});

const secondPublication = Object.assign(new Item(), {
Expand All @@ -44,7 +46,8 @@ describe('SearchManager', () => {
value: 'author2'
})
]
}
},
type: ITEM.value
});

const firstProject = Object.assign(new Item(), {
Expand All @@ -57,7 +60,8 @@ describe('SearchManager', () => {
value: 'author3'
})
]
}
},
type: ITEM.value
});

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

]
}
},
type: ITEM.value
});

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

]
}
},
type: ITEM.value
});

const mockBrowseService: any = {
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/data/entity-type-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class EntityTypeDataService extends BaseDataService<ItemType> implements
*/
hasMoreThanOneAuthorized(): Observable<boolean> {
const findListOptions: FindListOptions = {
elementsPerPage: 2,
elementsPerPage: 10,
currentPage: 1
};
return this.getAllAuthorizedRelationshipType(findListOptions).pipe(
Expand Down Expand Up @@ -117,7 +117,7 @@ export class EntityTypeDataService extends BaseDataService<ItemType> implements
*/
hasMoreThanOneAuthorizedImport(): Observable<boolean> {
const findListOptions: FindListOptions = {
elementsPerPage: 2,
elementsPerPage: 10,
currentPage: 1
};
return this.getAllAuthorizedRelationshipTypeImport(findListOptions).pipe(
Expand Down
10 changes: 3 additions & 7 deletions src/app/cris-item-page/cris-item-page.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Observable } from 'rxjs';
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { RemoteData } from '../core/data/remote-data';
import { ItemDataService } from '../core/data/item-data.service';
import { followLink } from '../shared/utils/follow-link-config.model';
import { Item } from '../core/shared/item.model';
import { getFirstCompletedRemoteData } from '../core/shared/operators';
import { ITEM_PAGE_LINKS_TO_FOLLOW } from '../item-page/item.resolver';

/**
* This class represents a resolver that requests a specific item before the route is activated
Expand All @@ -25,13 +25,9 @@ export class CrisItemPageResolver implements Resolve<RemoteData<Item>> {
* or an error if something went wrong
*/
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> {
// 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
return this.itemService.findById(route.params.id,
false, true,
followLink('owningCollection'),
followLink('bundles'),
followLink('relationships'),
followLink('version', {}, followLink('versionhistory')),
true, true,
...ITEM_PAGE_LINKS_TO_FOLLOW
).pipe(
getFirstCompletedRemoteData()
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/item-page/item-page-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { REQUEST_COPY_MODULE_PATH } from '../app-routing-paths';
import { CrisItemPageTabResolver } from './cris-item-page-tab.resolver';
import { OrcidPageComponent } from './orcid-page/orcid-page.component';
import { OrcidPageGuard } from './orcid-page/orcid-page.guard';
import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';

@NgModule({
imports: [
Expand All @@ -29,7 +28,6 @@ import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
resolve: {
dso: ItemPageResolver,
breadcrumb: ItemBreadcrumbResolver,
menu: DSOEditMenuResolver
},
runGuardsAndResolvers: 'always',
children: [
Expand Down
3 changes: 2 additions & 1 deletion src/app/item-page/item.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ export class ItemResolver implements Resolve<RemoteData<Item>> {
* or an error if something went wrong
*/
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> {
// Fetch item with cache disabled to have always a fresh item object
const itemRD$ = this.itemService.findById(route.params.id,
false,
false,
true,
...ITEM_PAGE_LINKS_TO_FOLLOW
).pipe(
getFirstCompletedRemoteData(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { followLink } from '../utils/follow-link-config.model';
import { CollectionElementLinkType } from '../object-collection/collection-element-link.type';
import { TopSection } from '../../core/layout/models/section.model';
import { Component, Input, OnChanges, OnInit, PLATFORM_ID, inject } from '@angular/core';
import { isPlatformServer } from '@angular/common';

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

protected followThumbnailLink: boolean; // to be overridden
protected abstract followMetricsLink: boolean; // to be overridden
protected abstract followThumbnailLink: boolean; // to be overridden

/**
* The context of listable object
*/
@Input() context: Context;

/**
* The pagination options
*/
@Input() paginatedSearchOptions: PaginatedSearchOptions;

@Input() context: Context;
/**
* Optional projection to use during the search
*/
@Input() projection = 'preventMetadataSecurity';

/**
* Whether to show the badge label or not
*/
@Input() showLabel: boolean;

@Input() topSection: TopSection;
/**
* Whether to show the metrics badges
*/
@Input() showMetrics = this.appConfig.browseBy.showMetrics;

/**
* Whether to show the thumbnail preview
*/
@Input() showThumbnails = this.appConfig.browseBy.showThumbnails;

public collectionElementLinkTypeEnum = CollectionElementLinkType;

paginatedSearchOptionsBS: BehaviorSubject<PaginatedSearchOptions>;
paginatedSearchOptions$: BehaviorSubject<PaginatedSearchOptions>;

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

Expand All @@ -51,13 +75,23 @@ export abstract class AbstractBrowseElementsComponent implements OnInit, OnChang
if (isPlatformServer(this.platformId)) {
return;
}
this.paginatedSearchOptionsBS?.next(this.paginatedSearchOptions);
this.paginatedSearchOptions$?.next(this.paginatedSearchOptions);
}

ngOnInit() {
const followLinks = this.followThumbnailLink ? [followLink('thumbnail'), followLink('metrics')] : [followLink('metrics')];
this.paginatedSearchOptionsBS = new BehaviorSubject<PaginatedSearchOptions>(this.paginatedSearchOptions);
this.searchResults$ = this.paginatedSearchOptionsBS.asObservable().pipe(
const followLinks = [];
if (this.followThumbnailLink) {
followLinks.push(followLink('thumbnail'));
}
if (this.followMetricsLink) {
followLinks.push(followLink('metrics'));
}

this.paginatedSearchOptions = Object.assign(new PaginatedSearchOptions({}), this.paginatedSearchOptions, {
projection: this.projection
});
this.paginatedSearchOptions$ = new BehaviorSubject<PaginatedSearchOptions>(this.paginatedSearchOptions);
this.searchResults$ = this.paginatedSearchOptions$.asObservable().pipe(
mergeMap((paginatedSearchOptions) =>
this.searchService.search(paginatedSearchOptions, null, true, true, ...followLinks),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<ng-container *ngSwitchDefault>
<ds-themed-default-browse-elements
[showMetrics]="showMetrics"
[showThumbnails]="topSection.showThumbnails"
[showThumbnails]="showThumbnails ?? topSection.showThumbnails"
[topSection]="topSection"
[showLabel]="showLabel"
[paginatedSearchOptions]="paginatedSearchOptionsBS.asObservable() | async"
[paginatedSearchOptions]="paginatedSearchOptions$.asObservable() | async"
[context]="context"
></ds-themed-default-browse-elements>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TopSection, TopSectionTemplateType } from './../../core/layout/models/section.model';
import { TopSection, TopSectionTemplateType } from '../../core/layout/models/section.model';
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
import { Context } from '../../core/shared/context.model';
Expand All @@ -12,19 +12,42 @@ import { BehaviorSubject } from 'rxjs';

export class BrowseMostElementsComponent implements OnInit, OnChanges {

/**
* The pagination options
*/
@Input() paginatedSearchOptions: PaginatedSearchOptions;

/**
* The context of listable object
*/
@Input() context: Context;

showLabel: boolean;

showMetrics = true;

/**
* Optional projection to use during the search
*/
@Input() projection = 'preventMetadataSecurity';

/**
* Whether to show the badge label or not
*/
@Input() showLabel: boolean;

/**
* Whether to show the metrics badges
*/
@Input() showMetrics: boolean;

/**
* Whether to show the thumbnail preview
*/
@Input() showThumbnails: boolean;

/*
* The top section object
*/
@Input() topSection: TopSection;

paginatedSearchOptionsBS = new BehaviorSubject<PaginatedSearchOptions>(null);

templateTypeEnum = TopSectionTemplateType;
paginatedSearchOptions$ = new BehaviorSubject<PaginatedSearchOptions>(null);

sectionTemplateType: TopSectionTemplateType;

Expand All @@ -33,6 +56,6 @@ export class BrowseMostElementsComponent implements OnInit, OnChanges {
}

ngOnChanges() { // trigger change detection on child components
this.paginatedSearchOptionsBS.next(this.paginatedSearchOptions);
this.paginatedSearchOptions$.next(this.paginatedSearchOptions);
}
}
Loading

0 comments on commit 170f813

Please sign in to comment.