From d09f5297a1f4e36071494bd89dc462b7538b3474 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Wed, 14 Aug 2024 22:46:14 +0200 Subject: [PATCH 1/2] 117287: Removed method calls returning observables from the item versions overview --- .../versions/item-versions.component.html | 257 +++++++++--------- .../versions/item-versions.component.ts | 44 +-- 2 files changed, 158 insertions(+), 143 deletions(-) diff --git a/src/app/item-page/versions/item-versions.component.html b/src/app/item-page/versions/item-versions.component.html index 176c1f0cde6..93e65e26298 100644 --- a/src/app/item-page/versions/item-versions.component.html +++ b/src/app/item-page/versions/item-versions.component.html @@ -1,145 +1,148 @@ -
-
-
-

{{"item.version.history.head" | translate}}

- - {{ "item.version.history.selected.alert" | translate : {version: itemVersion.version} }} - - - - - - - - - - - - - - + + +
{{"item.version.history.table.version" | translate}}{{"item.version.history.table.editor" | translate}}{{"item.version.history.table.date" | translate}}{{"item.version.history.table.summary" | translate}}
- - - +
+
+

{{ "item.version.history.head" | translate }}

+ + {{ "item.version.history.selected.alert" | translate : { version: itemVersion.version } }} + + + + + + + + + + + + + + - - - + + + - - -
{{ "item.version.history.table.version" | translate }}{{ "item.version.history.table.editor" | translate }}{{ "item.version.history.table.date" | translate }}{{ "item.version.history.table.summary" | translate }}
+ + + -
+
- - - {{version.version}} - - - {{version.version}} - - * + + + {{ versionDTO.version.version }} + + + {{ versionDTO.version.version }} + + * - + {{ "item.version.history.table.workspaceItem" | translate }} - + {{ "item.version.history.table.workflowItem" | translate }} -
+
-
+
-
- - + + + - - - - - - - - -
- + + + + +
- - -
- {{version?.submitterName}} - - {{version?.created | date : 'yyyy-MM-dd HH:mm:ss'}} - -
- - {{version?.summary}} - - - -
- -
- - - - - - - - - -
+ + + +
+ {{ versionDTO.version.submitterName }} + + {{ versionDTO.version.created | date : 'yyyy-MM-dd HH:mm:ss' }} + +
+ + {{ versionDTO.version.summary }} + + + +
-
-
* {{"item.version.history.selected" | translate}}
-
- -
+
+ + + + + + + + + +
+
+
* {{ "item.version.history.selected" | translate }}
+
+ + + + diff --git a/src/app/item-page/versions/item-versions.component.ts b/src/app/item-page/versions/item-versions.component.ts index 700a35552c2..df42dc9bb71 100644 --- a/src/app/item-page/versions/item-versions.component.ts +++ b/src/app/item-page/versions/item-versions.component.ts @@ -3,7 +3,6 @@ import { Item } from '../../core/shared/item.model'; import { Version } from '../../core/shared/version.model'; import { RemoteData } from '../../core/data/remote-data'; import { - BehaviorSubject, combineLatest, Observable, of, @@ -49,6 +48,17 @@ import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-da import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service'; import { ConfigurationDataService } from '../../core/data/configuration-data.service'; +interface VersionsDTO { + totalElements: number; + versionDTOs: VersionDTO[]; +} + +interface VersionDTO { + version: Version; + canEditVersion: Observable; + canDeleteVersion: Observable; +} + @Component({ selector: 'ds-item-versions', templateUrl: './item-versions.component.html', @@ -109,16 +119,15 @@ export class ItemVersionsComponent implements OnDestroy, OnInit { versionHistory$: Observable; /** - * The version history's list of versions + * The version history information that is used to render the HTML */ - versionsRD$: BehaviorSubject>> = new BehaviorSubject>>(null); + versionsDTO$: Observable; /** * Verify if the list of versions has at least one e-person to display * Used to hide the "Editor" column when no e-persons are present to display */ hasEpersons$: Observable; - /** * Verify if there is an inprogress submission in the version history * Used to disable the "Create version" button @@ -421,16 +430,23 @@ export class ItemVersionsComponent implements OnDestroy, OnInit { */ getAllVersions(versionHistory$: Observable): void { const currentPagination = this.paginationService.getCurrentPagination(this.options.id, this.options); - combineLatest([versionHistory$, currentPagination]).pipe( + this.versionsDTO$ = combineLatest([versionHistory$, currentPagination]).pipe( switchMap(([versionHistory, options]: [VersionHistory, PaginationComponentOptions]) => { return this.versionHistoryService.getVersions(versionHistory.id, new PaginatedSearchOptions({pagination: Object.assign({}, options, {currentPage: options.currentPage})}), false, true, followLink('item'), followLink('eperson')); }), getFirstCompletedRemoteData(), - ).subscribe((res: RemoteData>) => { - this.versionsRD$.next(res); - }); + getRemoteDataPayload(), + map((versions: PaginatedList) => ({ + totalElements: versions.totalElements, + versionDTOs: (versions?.page ?? []).map((version: Version) => ({ + version: version, + canEditVersion: this.canEditVersion$(version), + canDeleteVersion: this.canDeleteVersion$(version), + })), + })), + ); } /** @@ -509,16 +525,12 @@ export class ItemVersionsComponent implements OnDestroy, OnInit { ); this.getAllVersions(this.versionHistory$); - this.hasEpersons$ = this.versionsRD$.pipe( - getAllSucceededRemoteData(), - getRemoteDataPayload(), - hasValueOperator(), - map((versions: PaginatedList) => versions.page.filter((version: Version) => version.eperson !== undefined).length > 0), + this.hasEpersons$ = this.versionsDTO$.pipe( + map((versionsDTO: VersionsDTO) => versionsDTO.versionDTOs.filter((versionDTO: VersionDTO) => versionDTO.version.eperson !== undefined).length > 0), startWith(false) ); - this.itemPageRoutes$ = this.versionsRD$.pipe( - getAllSucceededRemoteDataPayload(), - switchMap((versions) => combineLatest(versions.page.map((version) => version.item.pipe(getAllSucceededRemoteDataPayload())))), + this.itemPageRoutes$ = this.versionsDTO$.pipe( + switchMap((versionsDTO: VersionsDTO) => combineLatest(versionsDTO.versionDTOs.map((versionDTO: VersionDTO) => versionDTO.version.item.pipe(getAllSucceededRemoteDataPayload())))), map((versions) => { const itemPageRoutes = {}; versions.forEach((item) => itemPageRoutes[item.uuid] = getItemPageRoute(item)); From 04bbaf9cb930cc823668076e858b0ab4703f4568 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Wed, 14 Aug 2024 23:43:44 +0200 Subject: [PATCH 2/2] 117287: Simplified the if conditions on the edit/save/discard buttons on item versions --- .../versions/item-versions.component.html | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/app/item-page/versions/item-versions.component.html b/src/app/item-page/versions/item-versions.component.html index e35acff55f6..ce5107aaa25 100644 --- a/src/app/item-page/versions/item-versions.component.html +++ b/src/app/item-page/versions/item-versions.component.html @@ -49,35 +49,31 @@

{{"item.version.history.head" | translate}}<

-
- - - + + - - + + - - +
- -