Skip to content

Commit 53bb38f

Browse files
committed
Merge remote-tracking branch 'ybnd/fix-versioning-button-7.6' into fix-versioning-button
2 parents 591cf03 + adb2e31 commit 53bb38f

14 files changed

Lines changed: 72 additions & 76 deletions

File tree

src/app/core/data/version-history-data.service.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ import { ObjectCacheService } from '../cache/object-cache.service';
66
import { HALEndpointService } from '../shared/hal-endpoint.service';
77
import { HttpHeaders } from '@angular/common/http';
88
import { PostRequest } from './request.models';
9-
import { Observable, of } from 'rxjs';
9+
import { combineLatest, Observable, of as observableOf } from 'rxjs';
1010
import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model';
1111
import { RemoteData } from './remote-data';
1212
import { PaginatedList } from './paginated-list.model';
1313
import { Version } from '../shared/version.model';
14-
import { filter, map, switchMap, take } from 'rxjs/operators';
14+
import { filter, find, map, switchMap, take } from 'rxjs/operators';
1515
import { VERSION_HISTORY } from '../shared/version-history.resource-type';
1616
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
1717
import { VersionDataService } from './version-data.service';
1818
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
1919
import { getAllSucceededRemoteData, getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload, getRemoteDataPayload } from '../shared/operators';
2020
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
21-
import { hasValueOperator } from '../../shared/empty.util';
21+
import { hasValue, hasValueOperator } from '../../shared/empty.util';
2222
import { Item } from '../shared/item.model';
2323
import { FindListOptions } from './find-list-options.model';
24-
import { sendRequest } from '../shared/request.operators';
25-
import { RestRequest } from './rest-request.model';
2624
import { IdentifiableDataService } from './base/identifiable-data.service';
2725
import { dataService } from './base/data-service.decorator';
2826

@@ -86,29 +84,31 @@ export class VersionHistoryDataService extends IdentifiableDataService<VersionHi
8684
* @param summary the summary of the new version
8785
*/
8886
createVersion(itemHref: string, summary: string): Observable<RemoteData<Version>> {
87+
const requestId = this.requestService.generateRequestId();
8988
const requestOptions: HttpOptions = Object.create({});
9089
let requestHeaders = new HttpHeaders();
9190
requestHeaders = requestHeaders.append('Content-Type', 'text/uri-list');
9291
requestOptions.headers = requestHeaders;
9392

94-
const response$ = this.halService.getEndpoint(this.versionsEndpoint).pipe(
93+
this.halService.getEndpoint(this.versionsEndpoint).pipe(
9594
take(1),
9695
map((endpointUrl: string) => (summary?.length > 0) ? `${endpointUrl}?summary=${summary}` : `${endpointUrl}`),
97-
map((endpointURL: string) => new PostRequest(this.requestService.generateRequestId(), endpointURL, itemHref, requestOptions)),
98-
sendRequest(this.requestService),
99-
switchMap((restRequest: RestRequest) => this.rdbService.buildFromRequestUUID(restRequest.uuid)),
100-
getFirstCompletedRemoteData()
101-
) as Observable<RemoteData<Version>>;
102-
103-
response$.subscribe((versionRD: RemoteData<Version>) => {
104-
// invalidate version history
105-
// note: we should do this regardless of whether the request succeeds,
106-
// because it may have failed due to cached data that is out of date
107-
this.requestService.setStaleByHrefSubstring(versionRD.payload._links.self.href);
108-
this.requestService.setStaleByHrefSubstring(versionRD.payload._links.versionhistory.href);
96+
find((href: string) => hasValue(href)),
97+
).subscribe((href) => {
98+
const request = new PostRequest(requestId, href, itemHref, requestOptions);
99+
if (hasValue(this.responseMsToLive)) {
100+
request.responseMsToLive = this.responseMsToLive;
101+
}
102+
103+
this.requestService.send(request);
109104
});
110105

111-
return response$;
106+
return this.rdbService.buildFromRequestUUIDAndAwait<Version>(requestId, (versionRD) => combineLatest([
107+
this.requestService.setStaleByHrefSubstring(versionRD.payload._links.self.href),
108+
this.requestService.setStaleByHrefSubstring(versionRD.payload._links.versionhistory.href),
109+
])).pipe(
110+
getFirstCompletedRemoteData(),
111+
);
112112
}
113113

114114
/**
@@ -147,7 +147,7 @@ export class VersionHistoryDataService extends IdentifiableDataService<VersionHi
147147
switchMap((res) => res.versionhistory),
148148
getFirstSucceededRemoteDataPayload(),
149149
switchMap((versionHistoryRD) => this.getLatestVersionFromHistory$(versionHistoryRD)),
150-
) : of(null);
150+
) : observableOf(null);
151151
}
152152

153153
/**
@@ -158,8 +158,8 @@ export class VersionHistoryDataService extends IdentifiableDataService<VersionHi
158158
isLatest$(version: Version): Observable<boolean> {
159159
return version ? this.getLatestVersion$(version).pipe(
160160
take(1),
161-
switchMap((latestVersion) => of(version.version === latestVersion.version))
162-
) : of(null);
161+
switchMap((latestVersion) => observableOf(version.version === latestVersion.version))
162+
) : observableOf(null);
163163
}
164164

165165
/**
@@ -170,21 +170,20 @@ export class VersionHistoryDataService extends IdentifiableDataService<VersionHi
170170
hasDraftVersion$(versionHref: string): Observable<boolean> {
171171
return this.versionDataService.findByHref(versionHref, false, true, followLink('versionhistory')).pipe(
172172
getFirstCompletedRemoteData(),
173-
switchMap((res) => {
174-
if (res.hasSucceeded && !res.hasNoContent) {
175-
return res.payload.versionhistory.pipe(
173+
switchMap((versionRD: RemoteData<Version>) => {
174+
if (versionRD.hasSucceeded && !versionRD.hasNoContent) {
175+
return versionRD.payload.versionhistory.pipe(
176176
getFirstCompletedRemoteData(),
177-
map((versionHistoryRD) => {
178-
if (res.hasSucceeded) {
179-
const versionHistory = versionHistoryRD.payload;
180-
return versionHistory ? versionHistory.draftVersion : false;
177+
map((versionHistoryRD: RemoteData<VersionHistory>) => {
178+
if (versionHistoryRD.hasSucceeded && !versionHistoryRD.hasNoContent) {
179+
return versionHistoryRD.payload.draftVersion;
181180
} else {
182181
return false;
183182
}
184183
}),
185184
);
186185
} else {
187-
return of(false);
186+
return observableOf(false);
188187
}
189188
}),
190189
);

src/app/shared/dso-page/dso-versioning-modal-service/dso-versioning-modal.service.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
22
import { RemoteData } from '../../../core/data/remote-data';
33
import { Version } from '../../../core/shared/version.model';
4-
import { map, startWith, switchMap, tap } from 'rxjs/operators';
4+
import { map, switchMap, tap } from 'rxjs/operators';
55
import { Item } from '../../../core/shared/item.model';
66
import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model';
77
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
@@ -13,9 +13,7 @@ import { ItemDataService } from '../../../core/data/item-data.service';
1313
import { Injectable } from '@angular/core';
1414
import { Observable, of } from 'rxjs';
1515
import { ItemVersionsSharedService } from '../../../item-page/versions/item-versions-shared.service';
16-
import {
17-
ItemVersionsSummaryModalComponent
18-
} from '../../../item-page/versions/item-versions-summary-modal/item-versions-summary-modal.component';
16+
import { ItemVersionsSummaryModalComponent } from '../../../item-page/versions/item-versions-summary-modal/item-versions-summary-modal.component';
1917

2018
/**
2119
* Service to take care of all the functionality related to the version creation modal
@@ -86,7 +84,6 @@ export class DsoVersioningModalService {
8684
// button is disabled if hasDraftVersion = true, and enabled if hasDraftVersion = false or null
8785
// (hasDraftVersion is null when a version history does not exist)
8886
map((res) => Boolean(res)),
89-
startWith(true),
9087
);
9188
}
9289

src/assets/i18n/bn.json5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,7 +3121,7 @@
31213121
// "item.page.version.create": "Create new version",
31223122
"item.page.version.create": "নতুন সংস্করণ তৈরি করুন",
31233123

3124-
// "item.page.version.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3124+
// "item.page.version.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
31253125
"item.page.version.hasDraft": "একটি নতুন সংস্করণ তৈরি করা যাচ্ছে না কারণ ভার্সন হিস্ট্রিতে একটি জমা ইনপ্রগ্রেসস অবস্থাই রয়েছে",
31263126

31273127
// "item.preview.dc.identifier.uri": "Identifier:",
@@ -3250,7 +3250,7 @@
32503250
// "item.version.history.table.action.deleteVersion": "Delete version",
32513251
"item.version.history.table.action.deleteVersion": "মুছে ফেলুন সংস্করণ",
32523252

3253-
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3253+
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
32543254
"item.version.history.table.action.hasDraft": "একটি নতুন সংস্করণ তৈরি করা যাচ্ছে না কারণ ভার্সন হিস্ট্রিতে একটি জমা ইনপ্রগ্রেসস অবস্থাই রয়েছে",
32553255

32563256

@@ -3291,7 +3291,7 @@
32913291
// "item.version.create.notification.failure" : "New version has not been created",
32923292
"item.version.create.notification.failure": "নতুন সংস্করণ তৈরি করা হয়নি",
32933293

3294-
// "item.version.create.notification.inProgress" : "A new version cannot be created because there is an inprogress submission in the version history",
3294+
// "item.version.create.notification.inProgress" : "A new version cannot be created because there is an in-progress submission in the version history",
32953295
"item.version.create.notification.inProgress": "একটি নতুন সংস্করণ তৈরি করা যাবে না কারণ ভার্সন হিস্ট্রিতে একটি জমা ইনপ্রগ্রেসস অবস্থাই রয়েছে",
32963296

32973297

src/assets/i18n/ca.json5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,7 +3376,7 @@
33763376
// "item.page.version.create": "Create new version",
33773377
"item.page.version.create": "Crear una nova versió",
33783378

3379-
// "item.page.version.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3379+
// "item.page.version.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
33803380
"item.page.version.hasDraft": "No es pot crear una nova versió perquè a l'historial de versions hi ha un enviament en curs",
33813381

33823382
// "item.page.claim.button": "Claim",
@@ -3535,7 +3535,7 @@
35353535
// "item.version.history.table.action.deleteVersion": "Delete version",
35363536
"item.version.history.table.action.deleteVersion": "Esborrar versió",
35373537

3538-
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3538+
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
35393539
"item.version.history.table.action.hasDraft": "No és possible crear una nova versió ja que existeix a l'historial de versions un enviament pendent",
35403540

35413541

@@ -3582,7 +3582,7 @@
35823582
// "item.version.create.notification.failure" : "New version has not been created",
35833583
"item.version.create.notification.failure": "No s'ha creat una nova versió",
35843584

3585-
// "item.version.create.notification.inProgress" : "A new version cannot be created because there is an inprogress submission in the version history",
3585+
// "item.version.create.notification.inProgress" : "A new version cannot be created because there is an in-progress submission in the version history",
35863586
"item.version.create.notification.inProgress": "No és possible crear una nova versió ja que existeix a l'historial de versions un enviament pendent",
35873587

35883588

src/assets/i18n/en.json5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,7 @@
24722472

24732473
"item.page.version.create": "Create new version",
24742474

2475-
"item.page.version.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
2475+
"item.page.version.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
24762476

24772477
"item.page.claim.button": "Claim",
24782478

@@ -2582,7 +2582,7 @@
25822582

25832583
"item.version.history.table.action.deleteVersion": "Delete version",
25842584

2585-
"item.version.history.table.action.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
2585+
"item.version.history.table.action.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
25862586

25872587
"item.version.notice": "This is not the latest version of this item. The latest version can be found <a href='{{destination}}'>here</a>.",
25882588

@@ -2612,7 +2612,7 @@
26122612

26132613
"item.version.create.notification.failure": "New version has not been created",
26142614

2615-
"item.version.create.notification.inProgress": "A new version cannot be created because there is an inprogress submission in the version history",
2615+
"item.version.create.notification.inProgress": "A new version cannot be created because there is an in-progress submission in the version history",
26162616

26172617
"item.version.delete.modal.header": "Delete version",
26182618

src/assets/i18n/es.json5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,7 +3660,7 @@
36603660
// "item.page.version.create": "Create new version",
36613661
"item.page.version.create": "Crear una nueva version",
36623662

3663-
// "item.page.version.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3663+
// "item.page.version.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
36643664
"item.page.version.hasDraft": "No se puede crear una nueva versión porque en el historial de versiones hay un envío en curso",
36653665

36663666
// "item.page.claim.button": "Claim",
@@ -3819,7 +3819,7 @@
38193819
// "item.version.history.table.action.deleteVersion": "Delete version",
38203820
"item.version.history.table.action.deleteVersion": "Borrar versión",
38213821

3822-
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3822+
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
38233823
"item.version.history.table.action.hasDraft": "No es posible crear una nueva versión puesto que existe en el historial de versiones un envío pendiente",
38243824

38253825
// "item.version.notice": "This is not the latest version of this item. The latest version can be found <a href='{{destination}}'>here</a>.",
@@ -3864,7 +3864,7 @@
38643864
// "item.version.create.notification.failure": "New version has not been created",
38653865
"item.version.create.notification.failure": "No se ha creado una nueva versión",
38663866

3867-
// "item.version.create.notification.inProgress": "A new version cannot be created because there is an inprogress submission in the version history",
3867+
// "item.version.create.notification.inProgress": "A new version cannot be created because there is an in-progress submission in the version history",
38683868
"item.version.create.notification.inProgress": "No es posible crear una nueva versión puesto que existe en el historial de versiones un envío pendiente",
38693869

38703870
// "item.version.delete.modal.header": "Delete version",

src/assets/i18n/fr.json5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,7 +3108,7 @@
31083108
// "item.page.version.create": "Create new version",
31093109
"item.page.version.create": "Créer une nouvelle version",
31103110

3111-
// "item.page.version.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3111+
// "item.page.version.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
31123112
"item.page.version.hasDraft": "Une nouvelle version ne peut être créée car il y a une soumission en cours dans l'historique des versions",
31133113

31143114
// "item.preview.dc.identifier.uri": "Identifier:",
@@ -3234,7 +3234,7 @@
32343234
// "item.version.history.table.action.deleteVersion": "Delete version",
32353235
"item.version.history.table.action.deleteVersion": "Supprimer la version",
32363236

3237-
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3237+
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
32383238
"item.version.history.table.action.hasDraft": "Une nouvelle version ne peut pas être créée parce qu'il y a une soumission en cours dans l'historique des versions.",
32393239

32403240
// "item.version.notice": "This is not the latest version of this item. The latest version can be found <a href='{{destination}}'>here</a>.",
@@ -3273,7 +3273,7 @@
32733273
// "item.version.create.notification.failure": "New version has not been created",
32743274
"item.version.create.notification.failure": "La nouvelle version n'a pas été créée",
32753275

3276-
// "item.version.create.notification.inProgress": "A new version cannot be created because there is an inprogress submission in the version history",
3276+
// "item.version.create.notification.inProgress": "A new version cannot be created because there is an in-progress submission in the version history",
32773277
"item.version.create.notification.inProgress": "Une nouvelle version ne peut pas être créée parce qu'il y a une soumission en cours dans l'historique des versions.",
32783278

32793279
// "item.version.delete.modal.header": "Delete version",

src/assets/i18n/gd.json5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,7 +3106,7 @@
31063106
// "item.page.version.create": "Create new version",
31073107
"item.page.version.create": "Cruthaich dreach ùr",
31083108

3109-
// "item.page.version.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3109+
// "item.page.version.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
31103110
"item.page.version.hasDraft": "Cha ghabh dreach ùr a chruthachadh oir tha cur-a-steach a' tachairt ann an eachdraidh nan dreachan",
31113111

31123112
// "item.preview.dc.identifier.uri": "Identifier:",
@@ -3235,7 +3235,7 @@
32353235
// "item.version.history.table.action.deleteVersion": "Delete version",
32363236
"item.version.history.table.action.deleteVersion": "Dubh às dreach",
32373237

3238-
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
3238+
// "item.version.history.table.action.hasDraft": "A new version cannot be created because there is an in-progress submission in the version history",
32393239
"item.version.history.table.action.hasDraft": "Cha ghabh dreach ùr a chruthachadh oir tha cur-a-steach a' tachairt ann an eachdraidh nan dreachan",
32403240

32413241

@@ -3276,7 +3276,7 @@
32763276
// "item.version.create.notification.failure" : "New version has not been created",
32773277
"item.version.create.notification.failure": "Cha deach dreach ùr a chruthachadh",
32783278

3279-
// "item.version.create.notification.inProgress" : "A new version cannot be created because there is an inprogress submission in the version history",
3279+
// "item.version.create.notification.inProgress" : "A new version cannot be created because there is an in-progress submission in the version history",
32803280
"item.version.create.notification.inProgress": "Cha ghabh dreach ùr a chruthachadh oir tha cur-a-steach a' tachairt ann an eachdraidh nan dreachan",
32813281

32823282

0 commit comments

Comments
 (0)