mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
[CST-4499] Version history (WIP) - Authorization features - Deleting not working
This commit is contained in:
@@ -21,4 +21,7 @@ export enum FeatureID {
|
|||||||
CanManagePolicies = 'canManagePolicies',
|
CanManagePolicies = 'canManagePolicies',
|
||||||
CanMakePrivate = 'canMakePrivate',
|
CanMakePrivate = 'canMakePrivate',
|
||||||
CanMove = 'canMove',
|
CanMove = 'canMove',
|
||||||
|
CanEditVersion = 'canEditVersion',
|
||||||
|
CanDeleteVersion = 'canDeleteVersion',
|
||||||
|
CanCreateVersion = 'canCreateVersion',
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@ import { PaginatedSearchOptions } from '../../shared/search/paginated-search-opt
|
|||||||
import { RemoteData } from './remote-data';
|
import { RemoteData } from './remote-data';
|
||||||
import { PaginatedList } from './paginated-list.model';
|
import { PaginatedList } from './paginated-list.model';
|
||||||
import { Version } from '../shared/version.model';
|
import { Version } from '../shared/version.model';
|
||||||
import { filter, map, switchMap, take } from 'rxjs/operators';
|
import { filter, map, startWith, switchMap, take } from 'rxjs/operators';
|
||||||
import { dataService } from '../cache/builders/build-decorators';
|
import { dataService } from '../cache/builders/build-decorators';
|
||||||
import { VERSION_HISTORY } from '../shared/version-history.resource-type';
|
import { VERSION_HISTORY } from '../shared/version-history.resource-type';
|
||||||
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||||
@@ -127,16 +127,30 @@ export class VersionHistoryDataService extends DataService<VersionHistory> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO move to versionDataService
|
||||||
|
getHistoryIdFromVersion$(version: Version): Observable<string> {
|
||||||
|
return this.getHistoryFromVersion$(version).pipe(
|
||||||
|
map((versionHistory) => versionHistory.id),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO move to versionDataService
|
||||||
|
getHistoryFromVersion$(version: Version): Observable<VersionHistory> {
|
||||||
|
return this.versionDataService.findById(version.id, false, true, followLink('versionhistory')).pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
switchMap((res) => res.versionhistory),
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO move to versionDataService
|
||||||
getLatestVersion$(version: Version): Observable<Version> {
|
getLatestVersion$(version: Version): Observable<Version> {
|
||||||
// retrieve again version, including with versionHistory
|
// retrieve again version, including with versionHistory
|
||||||
return this.versionDataService.findById(version.id, false, true, followLink('versionhistory')).pipe(
|
return this.versionDataService.findById(version.id, false, true, followLink('versionhistory')).pipe(
|
||||||
getFirstSucceededRemoteDataPayload(),
|
getFirstSucceededRemoteDataPayload(),
|
||||||
switchMap((res) => res.versionhistory),
|
switchMap((res) => res.versionhistory),
|
||||||
getFirstSucceededRemoteDataPayload(),
|
getFirstSucceededRemoteDataPayload(),
|
||||||
switchMap((versionHistoryRD) => {
|
switchMap((versionHistoryRD) => this.getLatestVersionFromHistory$(versionHistoryRD)),
|
||||||
return this.getLatestVersionFromHistory$(versionHistoryRD);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,4 +161,16 @@ export class VersionHistoryDataService extends DataService<VersionHistory> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a worskpace item exists in the version history
|
||||||
|
* @param versionHref the href of the version
|
||||||
|
*/
|
||||||
|
hasDraftVersion$(versionHref: string): Observable<boolean> {
|
||||||
|
return this.versionDataService.findByHref(versionHref, true, true, followLink('versionhistory')).pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
switchMap((version) => this.getHistoryFromVersion$(version)),
|
||||||
|
map((versionHistory) => versionHistory.draftVersion),
|
||||||
|
startWith(false),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import { link, typedObject } from '../cache/builders/build-decorators';
|
|||||||
import { DSpaceObject } from './dspace-object.model';
|
import { DSpaceObject } from './dspace-object.model';
|
||||||
import { HALLink } from './hal-link.model';
|
import { HALLink } from './hal-link.model';
|
||||||
import { VERSION } from './version.resource-type';
|
import { VERSION } from './version.resource-type';
|
||||||
|
import { ResourceType } from './resource-type';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing a DSpace Version History
|
* Class representing a DSpace Version History
|
||||||
@@ -22,6 +23,7 @@ export class VersionHistory extends DSpaceObject {
|
|||||||
_links: {
|
_links: {
|
||||||
self: HALLink;
|
self: HALLink;
|
||||||
versions: HALLink;
|
versions: HALLink;
|
||||||
|
draftVersion: HALLink;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,6 +44,12 @@ export class VersionHistory extends DSpaceObject {
|
|||||||
@autoserialize
|
@autoserialize
|
||||||
submitterName: string;
|
submitterName: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether exist a workspace item
|
||||||
|
*/
|
||||||
|
@autoserialize
|
||||||
|
draftVersion: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of versions within this history
|
* The list of versions within this history
|
||||||
*/
|
*/
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
{{'publication.page.titleprefix' | translate}}<ds-metadata-values [mdValues]="object?.allMetadata(['dc.title'])"></ds-metadata-values>
|
{{'publication.page.titleprefix' | translate}}<ds-metadata-values [mdValues]="object?.allMetadata(['dc.title'])"></ds-metadata-values>
|
||||||
</h2>
|
</h2>
|
||||||
<div class="pl-2">
|
<div class="pl-2">
|
||||||
<ds-dso-page-version-button (newVersionEvent)="createNewVersion()" [dso]="object" [tooltipMsg]="'item.page.version'"></ds-dso-page-version-button>
|
|
||||||
<ds-dso-page-edit-button [pageRoute]="itemPageRoute" [dso]="object" [tooltipMsg]="'publication.page.edit'"></ds-dso-page-edit-button>
|
<ds-dso-page-edit-button [pageRoute]="itemPageRoute" [dso]="object" [tooltipMsg]="'publication.page.edit'"></ds-dso-page-edit-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -3,7 +3,9 @@
|
|||||||
<ds-metadata-values [mdValues]="object?.allMetadata(['dc.title'])"></ds-metadata-values>
|
<ds-metadata-values [mdValues]="object?.allMetadata(['dc.title'])"></ds-metadata-values>
|
||||||
</h2>
|
</h2>
|
||||||
<div class="pl-2">
|
<div class="pl-2">
|
||||||
<ds-dso-page-version-button (newVersionEvent)="createNewVersion()" [dso]="object" [tooltipMsg]="'item.page.version'"></ds-dso-page-version-button>
|
<ds-dso-page-version-button (newVersionEvent)="createNewVersion()" [dso]="object"
|
||||||
|
[tooltipMsgCreate]="'item.page.version.create'"
|
||||||
|
[tooltipMsgHasDraft]="'item.page.version.hasDraft'"></ds-dso-page-version-button>
|
||||||
<ds-dso-page-edit-button [pageRoute]="itemPageRoute" [dso]="object" [tooltipMsg]="'item.page.edit'"></ds-dso-page-edit-button>
|
<ds-dso-page-edit-button [pageRoute]="itemPageRoute" [dso]="object" [tooltipMsg]="'item.page.edit'"></ds-dso-page-edit-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
<button *ngIf="isAuthorized$ | async"
|
<button *ngIf="isAuthorized$ | async"
|
||||||
class="edit-button btn btn-dark btn-sm"
|
class="edit-button btn btn-dark btn-sm"
|
||||||
(click)="createNewVersion()"
|
(click)="createNewVersion()"
|
||||||
[ngbTooltip]="tooltipMsg | translate"
|
[disabled]="hasDraftVersion$ | async"
|
||||||
role="button" [title]="tooltipMsg |translate" [attr.aria-label]="tooltipMsg |translate">
|
[ngbTooltip]="tooltipMsg$ | async | translate"
|
||||||
|
role="button" [title]="tooltipMsg$ | async |translate" [attr.aria-label]="tooltipMsg$ | async | translate">
|
||||||
<i class="fas fa-code-branch fa-fw"></i>
|
<i class="fas fa-code-branch fa-fw"></i>
|
||||||
</button>
|
</button>
|
||||||
|
@@ -1,8 +1,12 @@
|
|||||||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
|
||||||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
||||||
|
import { VersionHistoryDataService } from '../../../core/data/version-history-data.service';
|
||||||
|
import { Item } from '../../../core/shared/item.model';
|
||||||
|
import { switchMap } from 'rxjs/operators';
|
||||||
|
import { VersionDataService } from '../../../core/data/version-data.service';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dso-page-version-button',
|
selector: 'ds-dso-page-version-button',
|
||||||
@@ -14,15 +18,21 @@ import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
|||||||
*/
|
*/
|
||||||
export class DsoPageVersionButtonComponent implements OnInit {
|
export class DsoPageVersionButtonComponent implements OnInit {
|
||||||
/**
|
/**
|
||||||
* The DSpaceObject to display a button to the edit page for
|
* The item for which display a button to create a new version
|
||||||
*/
|
*/
|
||||||
@Input() dso: DSpaceObject;
|
@Input() dso: Item;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A message for the tooltip on the button
|
* A message for the tooltip on the button
|
||||||
* Supports i18n keys
|
* Supports i18n keys
|
||||||
*/
|
*/
|
||||||
@Input() tooltipMsg: string;
|
@Input() tooltipMsgCreate: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A message for the tooltip on the button (when is disabled)
|
||||||
|
* Supports i18n keys
|
||||||
|
*/
|
||||||
|
@Input() tooltipMsgHasDraft: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emits an event that triggers the creation of the new version
|
* Emits an event that triggers the creation of the new version
|
||||||
@@ -34,7 +44,14 @@ export class DsoPageVersionButtonComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
isAuthorized$: Observable<boolean>;
|
isAuthorized$: Observable<boolean>;
|
||||||
|
|
||||||
constructor(protected authorizationService: AuthorizationDataService) {
|
hasDraftVersion$: Observable<boolean>;
|
||||||
|
|
||||||
|
tooltipMsg$: Observable<string>;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
protected authorizationService: AuthorizationDataService,
|
||||||
|
protected versionHistoryService: VersionHistoryDataService,
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,8 +62,11 @@ export class DsoPageVersionButtonComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// TODO show if user can view history
|
this.isAuthorized$ = this.authorizationService.isAuthorized(FeatureID.CanCreateVersion, this.dso.self);
|
||||||
this.isAuthorized$ = this.authorizationService.isAuthorized(FeatureID.CanEditMetadata, this.dso.self);
|
this.hasDraftVersion$ = this.versionHistoryService.hasDraftVersion$(this.dso._links.version.href);
|
||||||
|
this.tooltipMsg$ = this.hasDraftVersion$.pipe(
|
||||||
|
switchMap((hasDraftVersion) => of(hasDraftVersion ? this.tooltipMsgHasDraft : this.tooltipMsgCreate)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -46,41 +46,50 @@
|
|||||||
<td class="version-row-element-actions" *ngIf="displayActions">
|
<td class="version-row-element-actions" *ngIf="displayActions">
|
||||||
<div class="btn-group edit-field">
|
<div class="btn-group edit-field">
|
||||||
<!--EDIT / SAVE-->
|
<!--EDIT / SAVE-->
|
||||||
<button class="btn btn-outline-primary btn-sm"
|
<ng-container *ngIf="canEditVersion$(version) | async">
|
||||||
*ngIf="!isThisBeingEdited(version)"
|
<button class="btn btn-outline-primary btn-sm"
|
||||||
[disabled]="isAnyBeingEdited()"
|
*ngIf="!isThisBeingEdited(version)"
|
||||||
(click)="enableVersionEditing(version)"
|
[disabled]="isAnyBeingEdited()"
|
||||||
title="{{'item.version.history.table.action.editSummary' | translate}}">
|
(click)="enableVersionEditing(version)"
|
||||||
<i class="fas fa-edit fa-fw"></i>
|
title="{{'item.version.history.table.action.editSummary' | translate}}">
|
||||||
</button>
|
<i class="fas fa-edit fa-fw"></i>
|
||||||
<button class="btn btn-outline-success btn-sm"
|
</button>
|
||||||
*ngIf="isThisBeingEdited(version)"
|
<button class="btn btn-outline-success btn-sm"
|
||||||
(click)="onSummarySubmit()"
|
*ngIf="isThisBeingEdited(version)"
|
||||||
title="{{'item.version.history.table.action.saveSummary' | translate}}">
|
(click)="onSummarySubmit()"
|
||||||
<i class="fas fa-check fa-fw"></i>
|
title="{{'item.version.history.table.action.saveSummary' | translate}}">
|
||||||
</button>
|
<i class="fas fa-check fa-fw"></i>
|
||||||
|
</button>
|
||||||
|
</ng-container>
|
||||||
<!--CREATE-->
|
<!--CREATE-->
|
||||||
<button class="btn btn-outline-primary btn-sm"
|
<ng-container *ngIf="canCreateVersion$ | async">
|
||||||
[disabled]="isAnyBeingEdited()"
|
<button class="btn btn-outline-primary btn-sm"
|
||||||
(click)="createNewVersion(version)"
|
[disabled]="isAnyBeingEdited() || (hasDraftVersion$ | async)"
|
||||||
title="{{'item.version.history.table.action.newVersion' | translate}}">
|
(click)="createNewVersion(version)"
|
||||||
<i class="fas fa-code-branch fa-fw"></i>
|
title="{{createVersionTitle$ | async | translate }}">
|
||||||
</button>
|
<i class="fas fa-code-branch fa-fw"></i>
|
||||||
|
</button>
|
||||||
|
</ng-container>
|
||||||
<!--DELETE-->
|
<!--DELETE-->
|
||||||
<button class="btn btn-sm"
|
<ng-container *ngIf="canDeleteVersion$(version) | async">
|
||||||
[ngClass]="isAnyBeingEdited() ? 'btn-outline-primary' : 'btn-outline-danger'"
|
<button class="btn btn-sm"
|
||||||
[disabled]="isAnyBeingEdited()"
|
[ngClass]="isAnyBeingEdited() ? 'btn-outline-primary' : 'btn-outline-danger'"
|
||||||
(click)="deleteVersion(version, itemVersion)"
|
[disabled]="isAnyBeingEdited()"
|
||||||
title="{{'item.version.history.table.action.deleteVersion' | translate}}">
|
(click)="deleteVersion(version, itemVersion)"
|
||||||
<i class="fas fa-trash fa-fw"></i>
|
title="{{'item.version.history.table.action.deleteVersion' | translate}}">
|
||||||
</button>
|
<i class="fas fa-trash fa-fw"></i>
|
||||||
<button class="btn btn-sm"
|
</button>
|
||||||
[ngClass]="isThisBeingEdited(version) ? 'btn-outline-warning' : 'btn-outline-primary'"
|
</ng-container>
|
||||||
[disabled]="!isAnyBeingEdited() || !isThisBeingEdited(version)"
|
<!--DISCARD EDIT -->
|
||||||
(click)="disableSummaryEditing()"
|
<ng-container *ngIf="canEditVersion$(version) | async">
|
||||||
title="{{'item.version.history.table.action.discardSummary' | translate}}">
|
<button class="btn btn-sm"
|
||||||
<i class="fas fa-undo-alt fa-fw"></i>
|
[ngClass]="isThisBeingEdited(version) ? 'btn-outline-warning' : 'btn-outline-primary'"
|
||||||
</button>
|
[disabled]="!isAnyBeingEdited()"
|
||||||
|
(click)="disableSummaryEditing()"
|
||||||
|
title="{{'item.version.history.table.action.discardSummary' | translate}}">
|
||||||
|
<i class="fas fa-undo-alt fa-fw"></i>
|
||||||
|
</button>
|
||||||
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@@ -2,7 +2,14 @@ import { Component, Input, OnInit } from '@angular/core';
|
|||||||
import { Item } from '../../../core/shared/item.model';
|
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 { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
|
import {
|
||||||
|
BehaviorSubject,
|
||||||
|
combineLatest,
|
||||||
|
combineLatest as observableCombineLatest,
|
||||||
|
Observable,
|
||||||
|
of,
|
||||||
|
Subscription
|
||||||
|
} from 'rxjs';
|
||||||
import { VersionHistory } from '../../../core/shared/version-history.model';
|
import { VersionHistory } from '../../../core/shared/version-history.model';
|
||||||
import {
|
import {
|
||||||
getAllSucceededRemoteData,
|
getAllSucceededRemoteData,
|
||||||
@@ -12,7 +19,7 @@ import {
|
|||||||
getFirstSucceededRemoteDataPayload,
|
getFirstSucceededRemoteDataPayload,
|
||||||
getRemoteDataPayload
|
getRemoteDataPayload
|
||||||
} from '../../../core/shared/operators';
|
} from '../../../core/shared/operators';
|
||||||
import { map, startWith, switchMap, take } from 'rxjs/operators';
|
import { map, mergeMap, startWith, switchMap, take } from 'rxjs/operators';
|
||||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||||
import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';
|
||||||
import { VersionHistoryDataService } from '../../../core/data/version-history-data.service';
|
import { VersionHistoryDataService } from '../../../core/data/version-history-data.service';
|
||||||
@@ -35,6 +42,8 @@ import { ItemVersionsDeleteModalComponent } from './item-versions-delete-modal/i
|
|||||||
import { VersionDataService } from '../../../core/data/version-data.service';
|
import { VersionDataService } from '../../../core/data/version-data.service';
|
||||||
import { ItemDataService } from '../../../core/data/item-data.service';
|
import { ItemDataService } from '../../../core/data/item-data.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||||
|
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-item-versions',
|
selector: 'ds-item-versions',
|
||||||
@@ -101,6 +110,12 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
hasEpersons$: Observable<boolean>;
|
hasEpersons$: Observable<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify if there is an inprogress submission in the version history
|
||||||
|
* Used to disable the "Create version" button
|
||||||
|
*/
|
||||||
|
hasDraftVersion$: Observable<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The amount of versions to display per page
|
* The amount of versions to display per page
|
||||||
*/
|
*/
|
||||||
@@ -151,6 +166,9 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
versionBeingEditedSummary: string;
|
versionBeingEditedSummary: string;
|
||||||
|
|
||||||
|
canCreateVersion$: Observable<boolean>;
|
||||||
|
createVersionTitle$: Observable<string>;
|
||||||
|
|
||||||
constructor(private versionHistoryService: VersionHistoryDataService,
|
constructor(private versionHistoryService: VersionHistoryDataService,
|
||||||
private versionService: VersionDataService,
|
private versionService: VersionDataService,
|
||||||
private itemService: ItemDataService,
|
private itemService: ItemDataService,
|
||||||
@@ -160,6 +178,7 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
private notificationsService: NotificationsService,
|
private notificationsService: NotificationsService,
|
||||||
private translateService: TranslateService,
|
private translateService: TranslateService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
|
protected authorizationService: AuthorizationDataService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,9 +269,113 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
activeModal.componentInstance.versionNumber = version.version;
|
activeModal.componentInstance.versionNumber = version.version;
|
||||||
activeModal.componentInstance.firstVersion = false;
|
activeModal.componentInstance.firstVersion = false;
|
||||||
|
|
||||||
|
|
||||||
|
// OLD
|
||||||
|
const versionHistory$ = this.versionHistoryService.getHistoryIdFromVersion$(version).pipe(
|
||||||
|
take(1),
|
||||||
|
switchMap((res) => this.versionHistoryService.findById(res)),
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
);
|
||||||
|
|
||||||
// On modal submit/dismiss
|
// On modal submit/dismiss
|
||||||
activeModal.result.then(() => {
|
activeModal.result.then(() => {
|
||||||
console.log('Deleting item...');
|
|
||||||
|
/*const versionHistory$ = this.versionHistoryService.getHistoryIdFromVersion$(version).pipe(
|
||||||
|
take(1),
|
||||||
|
map((versionHistoryId) => {
|
||||||
|
console.log('Version history ID = ' + versionHistoryId);
|
||||||
|
return versionHistoryId;
|
||||||
|
}),
|
||||||
|
switchMap((res) => this.versionHistoryService.findById(res)),
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
);*/
|
||||||
|
|
||||||
|
/*const deleteResultWithVersionHistory$ = versionHistory$.pipe(
|
||||||
|
switchMap((versionHisory) => combineLatest([
|
||||||
|
versionItem$.pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload<Item>(),
|
||||||
|
switchMap((itemBeingDeleted) => this.itemService.delete(itemBeingDeleted.id)),
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
map((deleteItemRes) => deleteItemRes.hasSucceeded),
|
||||||
|
),
|
||||||
|
of(versionHisory)
|
||||||
|
])
|
||||||
|
)
|
||||||
|
);*/
|
||||||
|
|
||||||
|
/*const deleteResultWithNewLatestVersion = deleteResultWithVersionHistory$.pipe(
|
||||||
|
switchMap( ([deleteHasSucceeded, versionHisory]) => [
|
||||||
|
of(deleteHasSucceeded),
|
||||||
|
of(versionHisory).pipe(
|
||||||
|
switchMap((vh) => this.versionHistoryService.getLatestVersionFromHistory$(vh)),
|
||||||
|
switchMap((newLatestVersion) => newLatestVersion.item),
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
).subscribe(([deleteHasSucceeded, newLatestVersionItem] ) => {
|
||||||
|
if (deleteHasSucceeded) {
|
||||||
|
this.notificationsService.success(null, this.translateService.get(successMessageKey, {'version': versionNumber}));
|
||||||
|
} else {
|
||||||
|
this.notificationsService.error(null, this.translateService.get(failureMessageKey, {'version': versionNumber}));
|
||||||
|
}
|
||||||
|
console.log('LATEST VERSION = ' + newLatestVersionItem.uuid);
|
||||||
|
if (redirectToLatest) {
|
||||||
|
const tmpPath = getItemEditVersionhistoryRoute(newLatestVersionItem);
|
||||||
|
console.log('PATH = ' + tmpPath);
|
||||||
|
this.router.navigateByUrl(tmpPath);
|
||||||
|
}
|
||||||
|
return this.versionHistoryService.getLatestVersion$(version);
|
||||||
|
});*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 1. recuperare version history
|
||||||
|
* 2. successivamente eliminare l'item
|
||||||
|
* 3. dopo aver eliminato l'item, recuperare la nuova versione
|
||||||
|
* 4. fare il redirect
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*versionItem$.pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload<Item>(),
|
||||||
|
map((item) => item.id),
|
||||||
|
mergeMap((itemId) => combineLatest([
|
||||||
|
of(itemId).pipe(
|
||||||
|
// BEGIN DELETE
|
||||||
|
switchMap((id) => this.itemService.delete(id)),
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
map((deleteItemRes) => deleteItemRes.hasSucceeded),
|
||||||
|
// END DELETE
|
||||||
|
),
|
||||||
|
|
||||||
|
this.versionHistoryService.getHistoryIdFromVersion$(version).pipe(
|
||||||
|
take(1),
|
||||||
|
map((versionHistoryId) => {
|
||||||
|
console.log('Version history ID = ' + versionHistoryId);
|
||||||
|
return versionHistoryId;
|
||||||
|
}),
|
||||||
|
switchMap((res) => this.versionHistoryService.findById(res)),
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
switchMap((vh) => this.versionHistoryService.getLatestVersionFromHistory$(vh)),
|
||||||
|
switchMap((newLatestVersion) => newLatestVersion.item),
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
mergeMap((deleteHasSucceeded) => combineLatest([]))
|
||||||
|
)
|
||||||
|
|
||||||
|
])
|
||||||
|
),
|
||||||
|
).subscribe(([deleteHasSucceeded, newLatestVersionItem]) => {
|
||||||
|
if (deleteHasSucceeded) {
|
||||||
|
this.notificationsService.success(null, this.translateService.get(successMessageKey, {'version': versionNumber}));
|
||||||
|
} else {
|
||||||
|
this.notificationsService.error(null, this.translateService.get(failureMessageKey, {'version': versionNumber}));
|
||||||
|
}
|
||||||
|
console.log('LATEST VERSION = ' + newLatestVersionItem.uuid);
|
||||||
|
if (redirectToLatest) {
|
||||||
|
const tmpPath = getItemEditVersionhistoryRoute(newLatestVersionItem);
|
||||||
|
console.log('PATH = ' + tmpPath);
|
||||||
|
this.router.navigateByUrl(tmpPath);
|
||||||
|
}
|
||||||
|
return this.versionHistoryService.getLatestVersion$(version);
|
||||||
|
});*/
|
||||||
|
|
||||||
versionItem$.pipe(
|
versionItem$.pipe(
|
||||||
getFirstSucceededRemoteDataPayload<Item>(),
|
getFirstSucceededRemoteDataPayload<Item>(),
|
||||||
@@ -260,82 +383,30 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
switchMap((itemId) => this.itemService.delete(itemId)),
|
switchMap((itemId) => this.itemService.delete(itemId)),
|
||||||
getFirstCompletedRemoteData(),
|
getFirstCompletedRemoteData(),
|
||||||
map((deleteItemRes) => deleteItemRes.hasSucceeded),
|
map((deleteItemRes) => deleteItemRes.hasSucceeded),
|
||||||
switchMap((deleteHasSucceeded) => {
|
mergeMap((deleteHasSucceeded) => combineLatest([
|
||||||
if (deleteHasSucceeded) {
|
of(deleteHasSucceeded),
|
||||||
this.notificationsService.success(null, this.translateService.get(successMessageKey, {'version': versionNumber}));
|
versionHistory$.pipe(
|
||||||
} else {
|
switchMap((vh) => this.versionHistoryService.getLatestVersionFromHistory$(vh)),
|
||||||
this.notificationsService.error(null, this.translateService.get(failureMessageKey, {'version': versionNumber}));
|
switchMap((newLatestVersion) => newLatestVersion.item),
|
||||||
}
|
getFirstSucceededRemoteDataPayload()
|
||||||
return this.versionHistoryService.getLatestVersion$(version);
|
)
|
||||||
}),
|
])
|
||||||
switchMap((latestVersion) => latestVersion.item),
|
),
|
||||||
getFirstSucceededRemoteDataPayload(),
|
).subscribe(([deleteHasSucceeded, newLatestVersionItem]) => {
|
||||||
).subscribe((latestVersionItem) => {
|
if (deleteHasSucceeded) {
|
||||||
console.log('LATEST VERSION = ' + latestVersionItem.uuid);
|
this.notificationsService.success(null, this.translateService.get(successMessageKey, {'version': versionNumber}));
|
||||||
|
} else {
|
||||||
|
this.notificationsService.error(null, this.translateService.get(failureMessageKey, {'version': versionNumber}));
|
||||||
|
}
|
||||||
|
console.log('LATEST VERSION = ' + newLatestVersionItem.uuid);
|
||||||
if (redirectToLatest) {
|
if (redirectToLatest) {
|
||||||
const tmpPath = getItemEditVersionhistoryRoute(latestVersionItem);
|
const tmpPath = getItemEditVersionhistoryRoute(newLatestVersionItem);
|
||||||
console.log('PATH = ' + tmpPath);
|
console.log('PATH = ' + tmpPath);
|
||||||
this.router.navigateByUrl(tmpPath);
|
this.router.navigateByUrl(tmpPath);
|
||||||
}
|
}
|
||||||
|
return this.versionHistoryService.getLatestVersion$(version);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
const itemVersion$ = item.version;
|
|
||||||
const isLatest$ = item.version.pipe(
|
|
||||||
getFirstSucceededRemoteDataPayload(),
|
|
||||||
map( (itemVersion) => this.versionHistoryService.isLatest$(itemVersion))
|
|
||||||
);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*map((item) => {
|
|
||||||
item.version.pipe(
|
|
||||||
getFirstSucceededRemoteDataPayload(),
|
|
||||||
switchMap( (itemVersion) => this.versionHistoryService.isLatest$(itemVersion)),
|
|
||||||
).subscribe((isLatestVersion) => {
|
|
||||||
isDeletingLatestVersion = isLatestVersion;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return item;
|
|
||||||
}),*/
|
|
||||||
/*mergeMap((versionItem) => combineLatest([
|
|
||||||
of(versionItem).pipe(
|
|
||||||
map((item) => item.id),
|
|
||||||
switchMap((itemId) => this.itemService.delete(itemId)),
|
|
||||||
getFirstCompletedRemoteData()
|
|
||||||
),
|
|
||||||
versionHistory$.pipe(
|
|
||||||
getFirstSucceededRemoteDataPayload(),
|
|
||||||
)
|
|
||||||
])),*/
|
|
||||||
|
|
||||||
|
|
||||||
// FUNZIONANTE:
|
|
||||||
|
|
||||||
/*version.item.pipe(getFirstSucceededRemoteDataPayload()).subscribe((getItemRes) => {
|
|
||||||
const itemId = getItemRes.id;
|
|
||||||
|
|
||||||
const isLatest$ = this.itemService.findById(itemId, true,true, followLink('version')).pipe(
|
|
||||||
getFirstSucceededRemoteDataPayload(),
|
|
||||||
switchMap( (item) => item.version ),
|
|
||||||
getFirstSucceededRemoteDataPayload(),
|
|
||||||
map( (itemVersion) => this.versionHistoryService.isLatest$(itemVersion))
|
|
||||||
);
|
|
||||||
|
|
||||||
this.itemService.delete(itemId).pipe(getFirstCompletedRemoteData()).subscribe(
|
|
||||||
(deleteItemRes) => {
|
|
||||||
console.log(JSON.stringify(deleteItemRes));
|
|
||||||
if (deleteItemRes.hasSucceeded) {
|
|
||||||
this.notificationsService.success(null, this.translateService.get(successMessageKey, {'version': versionNumber}));
|
|
||||||
this.refreshSubject.next(null);
|
|
||||||
} else {
|
|
||||||
this.notificationsService.error(null, this.translateService.get(failureMessageKey, {'version': versionNumber}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});*/
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,6 +443,33 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO eliminare
|
||||||
|
/*hasDraftVersion$(versionItem: Observable<RemoteData<Item>>): Observable<boolean> {
|
||||||
|
return versionItem.pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
map((res) => res._links.version.href ),
|
||||||
|
switchMap( (res) => this.versionHistoryService.hasDraftVersion$(res))
|
||||||
|
);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
canEditVersion$(versionItem: Version) {
|
||||||
|
return this.authorizationService.isAuthorized(FeatureID.CanEditVersion, versionItem.self);
|
||||||
|
}
|
||||||
|
|
||||||
|
canDeleteVersion$(versionItem: Version) {
|
||||||
|
return this.authorizationService.isAuthorized(FeatureID.CanDeleteVersion, versionItem.self);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO eliminare (usa item anziché vrsion)
|
||||||
|
/*canDeleteVersion$(version: Version) {
|
||||||
|
return version.item.pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
map((item) => item.self),
|
||||||
|
switchMap((url) => this.authorizationService.isAuthorized(FeatureID.CanDeleteVersion, url)),
|
||||||
|
take(1),
|
||||||
|
);
|
||||||
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize all observables
|
* Initialize all observables
|
||||||
*/
|
*/
|
||||||
@@ -384,6 +482,15 @@ export class ItemVersionsComponent implements OnInit {
|
|||||||
hasValueOperator(),
|
hasValueOperator(),
|
||||||
switchMap((version: Version) => version.versionhistory)
|
switchMap((version: Version) => version.versionhistory)
|
||||||
);
|
);
|
||||||
|
this.hasDraftVersion$ = this.versionHistoryRD$.pipe(
|
||||||
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
map((res) => res.draftVersion)
|
||||||
|
);
|
||||||
|
this.canCreateVersion$ = this.authorizationService.isAuthorized(FeatureID.CanCreateVersion, this.item.self);
|
||||||
|
this.createVersionTitle$ = this.hasDraftVersion$.pipe(
|
||||||
|
take(1),
|
||||||
|
switchMap((res) => of(res ? 'item.version.history.table.action.hasDraft' : 'item.version.history.table.action.newVersion'))
|
||||||
|
);
|
||||||
const versionHistory$ = this.versionHistoryRD$.pipe(
|
const versionHistory$ = this.versionHistoryRD$.pipe(
|
||||||
getAllSucceededRemoteData(),
|
getAllSucceededRemoteData(),
|
||||||
getRemoteDataPayload(),
|
getRemoteDataPayload(),
|
||||||
|
@@ -1910,7 +1910,9 @@
|
|||||||
|
|
||||||
"item.page.return": "Back",
|
"item.page.return": "Back",
|
||||||
|
|
||||||
"item.page.version": "Create new version",
|
"item.page.version.create": "Create new version",
|
||||||
|
|
||||||
|
"item.page.version.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
|
||||||
|
|
||||||
"item.preview.dc.identifier.uri": "Identifier:",
|
"item.preview.dc.identifier.uri": "Identifier:",
|
||||||
|
|
||||||
@@ -1992,6 +1994,8 @@
|
|||||||
|
|
||||||
"item.version.history.table.action.deleteVersion": "Delete version",
|
"item.version.history.table.action.deleteVersion": "Delete version",
|
||||||
|
|
||||||
|
"item.version.history.table.action.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
|
||||||
|
|
||||||
|
|
||||||
"item.version.notice": "This is not the latest version of this item. The latest version can be found <a href='{{destination}}'>here</a>.",
|
"item.version.notice": "This is not the latest version of this item. The latest version can be found <a href='{{destination}}'>here</a>.",
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user