Skip to content

Commit

Permalink
Merge remote-tracking branch 'ybnd/fix-versioning-button-7.6' into fi…
Browse files Browse the repository at this point in the history
…x-versioning-button
  • Loading branch information
ybnd committed Feb 7, 2024
2 parents 591cf03 + 9f39358 commit 48b1458
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions src/app/core/data/version-history-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ import { ObjectCacheService } from '../cache/object-cache.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { HttpHeaders } from '@angular/common/http';
import { PostRequest } from './request.models';
import { Observable, of } from 'rxjs';
import { combineLatest, Observable, of as observableOf } from 'rxjs';
import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model';
import { RemoteData } from './remote-data';
import { PaginatedList } from './paginated-list.model';
import { Version } from '../shared/version.model';
import { filter, map, switchMap, take } from 'rxjs/operators';
import { filter, find, map, switchMap, take } from 'rxjs/operators';
import { VERSION_HISTORY } from '../shared/version-history.resource-type';
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { VersionDataService } from './version-data.service';
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
import { getAllSucceededRemoteData, getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload, getRemoteDataPayload } from '../shared/operators';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { hasValueOperator } from '../../shared/empty.util';
import { hasValue, hasValueOperator } from '../../shared/empty.util';
import { Item } from '../shared/item.model';
import { FindListOptions } from './find-list-options.model';
import { sendRequest } from '../shared/request.operators';
import { RestRequest } from './rest-request.model';
import { IdentifiableDataService } from './base/identifiable-data.service';
import { dataService } from './base/data-service.decorator';

Expand Down Expand Up @@ -86,29 +84,31 @@ export class VersionHistoryDataService extends IdentifiableDataService<VersionHi
* @param summary the summary of the new version
*/
createVersion(itemHref: string, summary: string): Observable<RemoteData<Version>> {
const requestId = this.requestService.generateRequestId();

Check warning on line 87 in src/app/core/data/version-history-data.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L87 was not covered by tests
const requestOptions: HttpOptions = Object.create({});
let requestHeaders = new HttpHeaders();
requestHeaders = requestHeaders.append('Content-Type', 'text/uri-list');
requestOptions.headers = requestHeaders;

const response$ = this.halService.getEndpoint(this.versionsEndpoint).pipe(
this.halService.getEndpoint(this.versionsEndpoint).pipe(

Check warning on line 93 in src/app/core/data/version-history-data.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L93 was not covered by tests
take(1),
map((endpointUrl: string) => (summary?.length > 0) ? `${endpointUrl}?summary=${summary}` : `${endpointUrl}`),
map((endpointURL: string) => new PostRequest(this.requestService.generateRequestId(), endpointURL, itemHref, requestOptions)),
sendRequest(this.requestService),
switchMap((restRequest: RestRequest) => this.rdbService.buildFromRequestUUID(restRequest.uuid)),
getFirstCompletedRemoteData()
) as Observable<RemoteData<Version>>;

response$.subscribe((versionRD: RemoteData<Version>) => {
// invalidate version history
// note: we should do this regardless of whether the request succeeds,
// because it may have failed due to cached data that is out of date
this.requestService.setStaleByHrefSubstring(versionRD.payload._links.self.href);
this.requestService.setStaleByHrefSubstring(versionRD.payload._links.versionhistory.href);
find((href: string) => hasValue(href)),

Check warning on line 96 in src/app/core/data/version-history-data.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L96 was not covered by tests
).subscribe((href) => {
const request = new PostRequest(requestId, href, itemHref, requestOptions);

Check warning on line 98 in src/app/core/data/version-history-data.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L98 was not covered by tests
if (hasValue(this.responseMsToLive)) {
request.responseMsToLive = this.responseMsToLive;

Check warning on line 100 in src/app/core/data/version-history-data.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L100 was not covered by tests
}

this.requestService.send(request);

Check warning on line 103 in src/app/core/data/version-history-data.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L103 was not covered by tests
});

return response$;
return this.rdbService.buildFromRequestUUIDAndAwait<Version>(requestId, (versionRD) => combineLatest([

Check warning on line 106 in src/app/core/data/version-history-data.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L106 was not covered by tests
this.requestService.setStaleByHrefSubstring(versionRD.payload._links.self.href),
this.requestService.setStaleByHrefSubstring(versionRD.payload._links.versionhistory.href),
])).pipe(
getFirstCompletedRemoteData(),
);
}

/**
Expand Down Expand Up @@ -147,7 +147,7 @@ export class VersionHistoryDataService extends IdentifiableDataService<VersionHi
switchMap((res) => res.versionhistory),
getFirstSucceededRemoteDataPayload(),
switchMap((versionHistoryRD) => this.getLatestVersionFromHistory$(versionHistoryRD)),
) : of(null);
) : observableOf(null);
}

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

/**
Expand All @@ -170,21 +170,20 @@ export class VersionHistoryDataService extends IdentifiableDataService<VersionHi
hasDraftVersion$(versionHref: string): Observable<boolean> {
return this.versionDataService.findByHref(versionHref, false, true, followLink('versionhistory')).pipe(
getFirstCompletedRemoteData(),
switchMap((res) => {
if (res.hasSucceeded && !res.hasNoContent) {
return res.payload.versionhistory.pipe(
switchMap((versionRD: RemoteData<Version>) => {
if (versionRD.hasSucceeded && !versionRD.hasNoContent) {
return versionRD.payload.versionhistory.pipe(
getFirstCompletedRemoteData(),
map((versionHistoryRD) => {
if (res.hasSucceeded) {
const versionHistory = versionHistoryRD.payload;
return versionHistory ? versionHistory.draftVersion : false;
map((versionHistoryRD: RemoteData<VersionHistory>) => {
if (versionHistoryRD.hasSucceeded && !versionHistoryRD.hasNoContent) {
return versionHistoryRD.payload.draftVersion;
} else {
return false;

Check warning on line 181 in src/app/core/data/version-history-data.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L181 was not covered by tests
}
}),
);
} else {
return of(false);
return observableOf(false);

Check warning on line 186 in src/app/core/data/version-history-data.service.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L186 was not covered by tests
}
}),
);
Expand Down

0 comments on commit 48b1458

Please sign in to comment.