mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge pull request #3412 from alexandrevryghem/w2p-117287_fix-item-version-performance-issues_contribute-8_x
[Port dspace-8_x] Fixed Edit Item's Version History crashing
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
<div *ngVar="(versionsRD$ | async)?.payload as versions">
|
||||
<div *ngVar="(versionRD$ | async)?.payload as itemVersion">
|
||||
<div class="mb-2" *ngIf="versions?.page?.length > 0 || displayWhenEmpty">
|
||||
<div *ngIf="(versionsDTO$ | async) as versionsDTO; else noItemVersion" class="mb-2">
|
||||
<div *ngIf="(versionRD$ | async)?.payload as itemVersion">
|
||||
<h2 *ngIf="displayTitle" class="h4">{{"item.version.history.head" | translate}}</h2>
|
||||
<ds-alert [type]="AlertTypeEnum.Info" *ngIf="itemVersion">
|
||||
<ds-alert [type]="AlertTypeEnum.Info">
|
||||
{{ "item.version.history.selected.alert" | translate : { version: itemVersion.version } }}
|
||||
</ds-alert>
|
||||
<ds-pagination *ngIf="versions?.page?.length > 0"
|
||||
<ds-pagination *ngIf="versionsDTO.versionDTOs.length > 0"
|
||||
(paginationChange)="onPageChange()"
|
||||
[hideGear]="true"
|
||||
[hidePagerWhenSinglePage]="true"
|
||||
[paginationOptions]="options"
|
||||
[collectionSize]="versions?.totalElements"
|
||||
[collectionSize]="versionsDTO.totalElements"
|
||||
[retainScrollPosition]="true">
|
||||
<table class="table table-striped table-bordered align-middle my-2">
|
||||
<thead>
|
||||
@@ -22,10 +21,10 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<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">
|
||||
<ds-item-versions-row-element-version [hasDraftVersion]="hasDraftVersion$ | async"
|
||||
[version]="version"
|
||||
[version]="versionDTO.version"
|
||||
[item]="item" [displayActions]="displayActions"
|
||||
[itemVersion]="itemVersion"
|
||||
[versionBeingEditedNumber]="versionBeingEditedNumber"
|
||||
@@ -33,15 +32,16 @@
|
||||
></ds-item-versions-row-element-version>
|
||||
</td>
|
||||
<td class="version-row-element-editor" *ngIf="(showSubmitter$ | async)">
|
||||
{{version?.submitterName}}
|
||||
{{ versionDTO.version.submitterName }}
|
||||
</td>
|
||||
<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 class="version-row-element-summary">
|
||||
<div class="float-left">
|
||||
<ng-container *ngIf="isThisBeingEdited(version); then editSummary else showSummary"></ng-container>
|
||||
<ng-template #showSummary>{{version?.summary}}</ng-template>
|
||||
<ng-container
|
||||
*ngIf="isThisBeingEdited(versionDTO.version); then editSummary else showSummary"></ng-container>
|
||||
<ng-template #showSummary>{{ versionDTO.version.summary }}</ng-template>
|
||||
<ng-template #editSummary>
|
||||
<input [attr.aria-label]="'item.version.history.table.action.editSummary' | translate"
|
||||
[(ngModel)]="versionBeingEditedSummary" (keyup.enter)="onSummarySubmit()"
|
||||
@@ -49,43 +49,42 @@
|
||||
</ng-template>
|
||||
</div>
|
||||
|
||||
<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 && versionDTO.canEditVersion | async">
|
||||
<ng-container *ngIf="isThisBeingEdited(versionDTO.version); else notThisBeingEdited">
|
||||
<!--DISCARD EDIT-->
|
||||
<ng-container *ngIf="(canEditVersion$(version) | async) && isThisBeingEdited(version)">
|
||||
<button class="btn btn-sm"
|
||||
[ngClass]="isThisBeingEdited(version) ? 'btn-outline-warning' : 'btn-outline-primary'"
|
||||
<button class="btn btn-sm btn-outline-warning"
|
||||
(click)="disableVersionEditing()"
|
||||
title="{{'item.version.history.table.action.discardSummary' | translate}}">
|
||||
<i class="fas fa-undo-alt fa-fw"></i>
|
||||
</button>
|
||||
</ng-container>
|
||||
<!--EDIT / SAVE-->
|
||||
<ng-container *ngIf="canEditVersion$(version) | async">
|
||||
<button class="btn btn-outline-primary btn-sm version-row-element-edit"
|
||||
*ngIf="!isThisBeingEdited(version)"
|
||||
[disabled]="isAnyBeingEdited()"
|
||||
(click)="enableVersionEditing(version)"
|
||||
title="{{'item.version.history.table.action.editSummary' | translate}}">
|
||||
<i class="fas fa-edit fa-fw"></i>
|
||||
</button>
|
||||
<!--SAVE-->
|
||||
<button class="btn btn-outline-success btn-sm"
|
||||
*ngIf="isThisBeingEdited(version)"
|
||||
(click)="onSummarySubmit()"
|
||||
title="{{'item.version.history.table.action.saveSummary' | translate}}">
|
||||
<i class="fas fa-check fa-fw"></i>
|
||||
</button>
|
||||
</ng-container>
|
||||
<ng-template #notThisBeingEdited>
|
||||
<!--EDIT-->
|
||||
<button class="btn btn-outline-primary btn-sm version-row-element-edit"
|
||||
[disabled]="isAnyBeingEdited()"
|
||||
(click)="enableVersionEditing(versionDTO.version)"
|
||||
title="{{'item.version.history.table.action.editSummary' | translate}}">
|
||||
<i class="fas fa-edit fa-fw"></i>
|
||||
</button>
|
||||
</ng-template>
|
||||
</div>
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div>* {{"item.version.history.selected" | translate}}</div>
|
||||
</ds-pagination>
|
||||
<ds-alert *ngIf="!itemVersion || versions?.page?.length === 0" [content]="'item.version.history.empty'"
|
||||
[type]="AlertTypeEnum.Info"></ds-alert>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ng-template #noItemVersion>
|
||||
<ds-alert *ngIf="displayWhenEmpty"
|
||||
[content]="'item.version.history.empty'"
|
||||
[type]="AlertTypeEnum.Info">
|
||||
</ds-alert>
|
||||
</ng-template>
|
||||
|
@@ -18,7 +18,6 @@ import {
|
||||
TranslateService,
|
||||
} from '@ngx-translate/core';
|
||||
import {
|
||||
BehaviorSubject,
|
||||
combineLatest,
|
||||
Observable,
|
||||
Subscription,
|
||||
@@ -64,6 +63,16 @@ import { VarDirective } from '../../shared/utils/var.directive';
|
||||
import { getItemPageRoute } from '../item-page-routing-paths';
|
||||
import { ItemVersionsRowElementVersionComponent } from './item-versions-row-element-version/item-versions-row-element-version.component';
|
||||
|
||||
interface VersionsDTO {
|
||||
totalElements: number;
|
||||
versionDTOs: VersionDTO[];
|
||||
}
|
||||
|
||||
interface VersionDTO {
|
||||
version: Version;
|
||||
canEditVersion: Observable<boolean>;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'ds-item-versions',
|
||||
templateUrl: './item-versions.component.html',
|
||||
@@ -126,16 +135,15 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
|
||||
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
|
||||
* Used to hide the "Editor" column when no e-persons are present to display
|
||||
*/
|
||||
hasEpersons$: Observable<boolean>;
|
||||
|
||||
/**
|
||||
* Verify if there is an inprogress submission in the version history
|
||||
* Used to disable the "Create version" button
|
||||
@@ -186,9 +194,6 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
|
||||
*/
|
||||
versionBeingEditedSummary: string;
|
||||
|
||||
canCreateVersion$: Observable<boolean>;
|
||||
createVersionTitle$: Observable<string>;
|
||||
|
||||
constructor(private versionHistoryService: VersionHistoryDataService,
|
||||
private versionService: VersionDataService,
|
||||
private paginationService: PaginationService,
|
||||
@@ -305,16 +310,22 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
|
||||
*/
|
||||
getAllVersions(versionHistory$: Observable<VersionHistory>): 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<PaginatedList<Version>>) => {
|
||||
this.versionsRD$.next(res);
|
||||
});
|
||||
getRemoteDataPayload(),
|
||||
map((versions: PaginatedList<Version>) => ({
|
||||
totalElements: versions.totalElements,
|
||||
versionDTOs: (versions?.page ?? []).map((version: Version) => ({
|
||||
version: version,
|
||||
canEditVersion: this.canEditVersion$(version),
|
||||
})),
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -348,16 +359,12 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
|
||||
);
|
||||
|
||||
this.getAllVersions(this.versionHistory$);
|
||||
this.hasEpersons$ = this.versionsRD$.pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
hasValueOperator(),
|
||||
map((versions: PaginatedList<Version>) => 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));
|
||||
|
Reference in New Issue
Block a user