Merge branch 'w2p-117287_fix-item-version-performance-issues_contribute-7.6' into w2p-117287_fix-item-version-performance-issues_contribute-7_x

# Conflicts:
#	src/app/item-page/versions/item-versions.component.html
This commit is contained in:
Alexandre Vryghem
2024-09-29 00:19:11 +02:00
2 changed files with 159 additions and 143 deletions

View File

@@ -1,44 +1,46 @@
<div *ngVar="(versionsRD$ | async)?.payload as versions"> <div *ngIf="(versionsDTO$ | async) as versionsDTO; else noItemVersion" class="mb-2">
<div *ngVar="(versionRD$ | async)?.payload as itemVersion"> <div *ngIf="(versionRD$ | async)?.payload as itemVersion">
<div class="mb-2" *ngIf="versions?.page?.length > 0 || displayWhenEmpty"> <h2 *ngIf="displayTitle" class="h4">{{ "item.version.history.head" | translate }}</h2>
<h2 *ngIf="displayTitle" class="h4">{{"item.version.history.head" | translate}}</h2> <ds-alert [type]="AlertTypeEnum.Info">
<ds-alert [type]="AlertTypeEnum.Info" *ngIf="itemVersion"> {{ "item.version.history.selected.alert" | translate : { version: itemVersion.version } }}
{{ "item.version.history.selected.alert" | translate : {version: itemVersion.version} }}
</ds-alert> </ds-alert>
<ds-pagination *ngIf="versions?.page?.length > 0" <ds-pagination *ngIf="versionsDTO.versionDTOs.length > 0"
(paginationChange)="onPageChange()" (paginationChange)="onPageChange()"
[hideGear]="true" [hideGear]="true"
[hidePagerWhenSinglePage]="true" [hidePagerWhenSinglePage]="true"
[paginationOptions]="options" [paginationOptions]="options"
[collectionSize]="versions?.totalElements" [collectionSize]="versionsDTO.totalElements"
[retainScrollPosition]="true"> [retainScrollPosition]="true">
<table class="table table-striped table-bordered align-middle my-2"> <table class="table table-striped table-bordered align-middle my-2">
<thead> <thead>
<tr> <tr>
<th scope="col">{{"item.version.history.table.version" | translate}}</th> <th scope="col">{{ "item.version.history.table.version" | translate }}</th>
<th scope="col" *ngIf="(showSubmitter() | async)">{{"item.version.history.table.editor" | translate}}</th> <th scope="col" *ngIf="(showSubmitter() | async)">{{ "item.version.history.table.editor" | translate }}</th>
<th scope="col">{{"item.version.history.table.date" | translate}}</th> <th scope="col">{{ "item.version.history.table.date" | translate }}</th>
<th scope="col">{{"item.version.history.table.summary" | translate}}</th> <th scope="col">{{ "item.version.history.table.summary" | translate }}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let version of versions?.page" [id]="'version-row-' + version.id"> <tr *ngFor="let versionDTO of versionsDTO.versionDTOs" [id]="'version-row-' + versionDTO.version.id">
<td class="version-row-element-version"> <td class="version-row-element-version">
<!-- Get the ID of the workspace/workflow item (`undefined` if they don't exist). <!-- Get the ID of the workspace/workflow item (`undefined` if they don't exist).
Conditionals inside *ngVar are needed in order to avoid useless calls. --> Conditionals inside *ngVar are needed in order to avoid useless calls. -->
<ng-container *ngVar="((hasDraftVersion$ | async) ? getWorkspaceId(version?.item) : undefined) as workspaceId$"> <ng-container
<ng-container *ngVar=" ((workspaceId$ | async) ? undefined : getWorkflowId(version?.item)) as workflowId$"> *ngVar="((hasDraftVersion$ | async) ? getWorkspaceId(versionDTO.version.item) : undefined) as workspaceId$">
<ng-container
*ngVar=" ((workspaceId$ | async) ? undefined : getWorkflowId(versionDTO.version.item)) as workflowId$">
<div class="left-column"> <div class="left-column">
<span *ngIf="(workspaceId$ | async) || (workflowId$ | async); then versionNumberWithoutLink else versionNumberWithLink"></span> <span
*ngIf="(workspaceId$ | async) || (workflowId$ | async); then versionNumberWithoutLink else versionNumberWithLink"></span>
<ng-template #versionNumberWithLink> <ng-template #versionNumberWithLink>
<a [routerLink]="getVersionRoute(version.id)">{{version.version}}</a> <a [routerLink]="getVersionRoute(versionDTO.version.id)">{{ versionDTO.version.version }}</a>
</ng-template> </ng-template>
<ng-template #versionNumberWithoutLink> <ng-template #versionNumberWithoutLink>
{{version.version}} {{ versionDTO.version.version }}
</ng-template> </ng-template>
<span *ngIf="version?.id === itemVersion?.id">*</span> <span *ngIf="versionDTO.version.id === itemVersion?.id">*</span>
<span *ngIf="workspaceId$ | async" class="text-light badge badge-primary ml-3"> <span *ngIf="workspaceId$ | async" class="text-light badge badge-primary ml-3">
{{ "item.version.history.table.workspaceItem" | translate }} {{ "item.version.history.table.workspaceItem" | translate }}
@@ -64,17 +66,17 @@
<ng-container *ngIf="canCreateVersion$ | async"> <ng-container *ngIf="canCreateVersion$ | async">
<button class="btn btn-outline-primary btn-sm version-row-element-create" <button class="btn btn-outline-primary btn-sm version-row-element-create"
[disabled]="isAnyBeingEdited() || (hasDraftVersion$ | async)" [disabled]="isAnyBeingEdited() || (hasDraftVersion$ | async)"
(click)="createNewVersion(version)" (click)="createNewVersion(versionDTO.version)"
title="{{createVersionTitle$ | async | translate }}"> title="{{createVersionTitle$ | async | translate }}">
<i class="fas fa-code-branch fa-fw"></i> <i class="fas fa-code-branch fa-fw"></i>
</button> </button>
</ng-container> </ng-container>
<!--DELETE--> <!--DELETE-->
<ng-container *ngIf="canDeleteVersion$(version) | async"> <ng-container *ngIf="versionDTO.canDeleteVersion">
<button class="btn btn-sm version-row-element-delete" <button class="btn btn-sm version-row-element-delete"
[ngClass]="isAnyBeingEdited() ? 'btn-outline-primary' : 'btn-outline-danger'" [ngClass]="isAnyBeingEdited() ? 'btn-outline-primary' : 'btn-outline-danger'"
[disabled]="isAnyBeingEdited()" [disabled]="isAnyBeingEdited()"
(click)="deleteVersion(version, version.id==itemVersion.id)" (click)="deleteVersion(versionDTO.version, versionDTO.version.id==itemVersion.id)"
title="{{'item.version.history.table.action.deleteVersion' | translate}}"> title="{{'item.version.history.table.action.deleteVersion' | translate}}">
<i class="fas fa-trash fa-fw"></i> <i class="fas fa-trash fa-fw"></i>
</button> </button>
@@ -87,15 +89,16 @@
</ng-container> </ng-container>
</td> </td>
<td class="version-row-element-editor" *ngIf="(showSubmitter() | async)"> <td class="version-row-element-editor" *ngIf="(showSubmitter() | async)">
{{version?.submitterName}} {{ versionDTO.version.submitterName }}
</td> </td>
<td class="version-row-element-date"> <td class="version-row-element-date">
{{version?.created | date : 'yyyy-MM-dd HH:mm:ss'}} {{ versionDTO.version.created | date : 'yyyy-MM-dd HH:mm:ss' }}
</td> </td>
<td class="version-row-element-summary"> <td class="version-row-element-summary">
<div class="float-left"> <div class="float-left">
<ng-container *ngIf="isThisBeingEdited(version); then editSummary else showSummary"></ng-container> <ng-container
<ng-template #showSummary>{{version?.summary}}</ng-template> *ngIf="isThisBeingEdited(versionDTO.version); then editSummary else showSummary"></ng-container>
<ng-template #showSummary>{{ versionDTO.version.summary }}</ng-template>
<ng-template #editSummary> <ng-template #editSummary>
<input [attr.aria-label]="'item.version.history.table.action.editSummary' | translate" <input [attr.aria-label]="'item.version.history.table.action.editSummary' | translate"
[(ngModel)]="versionBeingEditedSummary" (keyup.enter)="onSummarySubmit()" [(ngModel)]="versionBeingEditedSummary" (keyup.enter)="onSummarySubmit()"
@@ -105,41 +108,42 @@
<div class="float-right btn-group edit-field space-children-mr" *ngIf="displayActions"> <div class="float-right btn-group edit-field space-children-mr" *ngIf="displayActions">
<!--DISCARD EDIT --> <!--DISCARD EDIT -->
<ng-container *ngIf="(canEditVersion$(version) | async) && isThisBeingEdited(version)"> <ng-container *ngIf="(versionDTO.canEditVersion | async) && isThisBeingEdited(versionDTO.version)">
<button class="btn btn-sm" <button class="btn btn-sm"
[ngClass]="isThisBeingEdited(version) ? 'btn-outline-warning' : 'btn-outline-primary'" [ngClass]="isThisBeingEdited(versionDTO.version) ? 'btn-outline-warning' : 'btn-outline-primary'"
(click)="disableVersionEditing()" (click)="disableVersionEditing()"
title="{{'item.version.history.table.action.discardSummary' | translate}}"> title="{{'item.version.history.table.action.discardSummary' | translate}}">
<i class="fas fa-undo-alt fa-fw"></i> <i class="fas fa-undo-alt fa-fw"></i>
</button> </button>
</ng-container> </ng-container>
<!--EDIT / SAVE--> <!--EDIT / SAVE-->
<ng-container *ngIf="canEditVersion$(version) | async"> <ng-container *ngIf="versionDTO.canEditVersion | async">
<button class="btn btn-outline-primary btn-sm version-row-element-edit" <button class="btn btn-outline-primary btn-sm version-row-element-edit"
*ngIf="!isThisBeingEdited(version)" *ngIf="!isThisBeingEdited(versionDTO.version)"
[disabled]="isAnyBeingEdited()" [disabled]="isAnyBeingEdited()"
(click)="enableVersionEditing(version)" (click)="enableVersionEditing(versionDTO.version)"
title="{{'item.version.history.table.action.editSummary' | translate}}"> title="{{'item.version.history.table.action.editSummary' | translate}}">
<i class="fas fa-edit fa-fw"></i> <i class="fas fa-edit fa-fw"></i>
</button> </button>
<button class="btn btn-outline-success btn-sm" <button class="btn btn-outline-success btn-sm"
*ngIf="isThisBeingEdited(version)" *ngIf="isThisBeingEdited(versionDTO.version)"
(click)="onSummarySubmit()" (click)="onSummarySubmit()"
title="{{'item.version.history.table.action.saveSummary' | translate}}"> title="{{'item.version.history.table.action.saveSummary' | translate}}">
<i class="fas fa-check fa-fw"></i> <i class="fas fa-check fa-fw"></i>
</button> </button>
</ng-container> </ng-container>
</div> </div>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div>*&nbsp;{{"item.version.history.selected" | translate}}</div> <div>*&nbsp;{{ "item.version.history.selected" | translate }}</div>
</ds-pagination> </ds-pagination>
<ds-alert *ngIf="!itemVersion || versions?.page?.length === 0" [content]="'item.version.history.empty'"
[type]="AlertTypeEnum.Info"></ds-alert>
</div>
</div> </div>
</div> </div>
<ng-template #noItemVersion>
<ds-alert *ngIf="displayWhenEmpty"
[content]="'item.version.history.empty'"
[type]="AlertTypeEnum.Info">
</ds-alert>
</ng-template>

View File

@@ -3,7 +3,6 @@ import { Item } from '../../core/shared/item.model';
import { Version } from '../../core/shared/version.model'; import { Version } from '../../core/shared/version.model';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
import { import {
BehaviorSubject,
combineLatest, combineLatest,
Observable, Observable,
of, of,
@@ -49,6 +48,17 @@ import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-da
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service'; import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
import { ConfigurationDataService } from '../../core/data/configuration-data.service'; import { ConfigurationDataService } from '../../core/data/configuration-data.service';
interface VersionsDTO {
totalElements: number;
versionDTOs: VersionDTO[];
}
interface VersionDTO {
version: Version;
canEditVersion: Observable<boolean>;
canDeleteVersion: Observable<boolean>;
}
@Component({ @Component({
selector: 'ds-item-versions', selector: 'ds-item-versions',
templateUrl: './item-versions.component.html', templateUrl: './item-versions.component.html',
@@ -109,16 +119,15 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
versionHistory$: Observable<VersionHistory>; versionHistory$: Observable<VersionHistory>;
/** /**
* The version history's list of versions * The version history information that is used to render the HTML
*/ */
versionsRD$: BehaviorSubject<RemoteData<PaginatedList<Version>>> = new BehaviorSubject<RemoteData<PaginatedList<Version>>>(null); versionsDTO$: Observable<VersionsDTO>;
/** /**
* Verify if the list of versions has at least one e-person to display * 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 * Used to hide the "Editor" column when no e-persons are present to display
*/ */
hasEpersons$: Observable<boolean>; hasEpersons$: Observable<boolean>;
/** /**
* Verify if there is an inprogress submission in the version history * Verify if there is an inprogress submission in the version history
* Used to disable the "Create version" button * Used to disable the "Create version" button
@@ -421,16 +430,23 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
*/ */
getAllVersions(versionHistory$: Observable<VersionHistory>): void { getAllVersions(versionHistory$: Observable<VersionHistory>): void {
const currentPagination = this.paginationService.getCurrentPagination(this.options.id, this.options); 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]) => { switchMap(([versionHistory, options]: [VersionHistory, PaginationComponentOptions]) => {
return this.versionHistoryService.getVersions(versionHistory.id, return this.versionHistoryService.getVersions(versionHistory.id,
new PaginatedSearchOptions({pagination: Object.assign({}, options, {currentPage: options.currentPage})}), new PaginatedSearchOptions({pagination: Object.assign({}, options, {currentPage: options.currentPage})}),
false, true, followLink('item'), followLink('eperson')); false, true, followLink('item'), followLink('eperson'));
}), }),
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
).subscribe((res: RemoteData<PaginatedList<Version>>) => { getRemoteDataPayload(),
this.versionsRD$.next(res); map((versions: PaginatedList<Version>) => ({
}); 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.getAllVersions(this.versionHistory$);
this.hasEpersons$ = this.versionsRD$.pipe( this.hasEpersons$ = this.versionsDTO$.pipe(
getAllSucceededRemoteData(), map((versionsDTO: VersionsDTO) => versionsDTO.versionDTOs.filter((versionDTO: VersionDTO) => versionDTO.version.eperson !== undefined).length > 0),
getRemoteDataPayload(),
hasValueOperator(),
map((versions: PaginatedList<Version>) => versions.page.filter((version: Version) => version.eperson !== undefined).length > 0),
startWith(false) startWith(false)
); );
this.itemPageRoutes$ = this.versionsRD$.pipe( this.itemPageRoutes$ = this.versionsDTO$.pipe(
getAllSucceededRemoteDataPayload(), switchMap((versionsDTO: VersionsDTO) => combineLatest(versionsDTO.versionDTOs.map((versionDTO: VersionDTO) => versionDTO.version.item.pipe(getAllSucceededRemoteDataPayload())))),
switchMap((versions) => combineLatest(versions.page.map((version) => version.item.pipe(getAllSucceededRemoteDataPayload())))),
map((versions) => { map((versions) => {
const itemPageRoutes = {}; const itemPageRoutes = {};
versions.forEach((item) => itemPageRoutes[item.uuid] = getItemPageRoute(item)); versions.forEach((item) => itemPageRoutes[item.uuid] = getItemPageRoute(item));