version-data.service.ts (dspace-angular-dspace-7.0) | : | version-data.service.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
skipping to change at line 13 | skipping to change at line 13 | |||
import { Version } from '../shared/version.model'; | import { Version } from '../shared/version.model'; | |||
import { RequestService } from './request.service'; | import { RequestService } from './request.service'; | |||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv ice'; | import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv ice'; | |||
import { Store } from '@ngrx/store'; | import { Store } from '@ngrx/store'; | |||
import { CoreState } from '../core.reducers'; | import { CoreState } from '../core.reducers'; | |||
import { ObjectCacheService } from '../cache/object-cache.service'; | import { ObjectCacheService } from '../cache/object-cache.service'; | |||
import { HALEndpointService } from '../shared/hal-endpoint.service'; | import { HALEndpointService } from '../shared/hal-endpoint.service'; | |||
import { NotificationsService } from '../../shared/notifications/notifications.s ervice'; | import { NotificationsService } from '../../shared/notifications/notifications.s ervice'; | |||
import { HttpClient } from '@angular/common/http'; | import { HttpClient } from '@angular/common/http'; | |||
import { DefaultChangeAnalyzer } from './default-change-analyzer.service'; | import { DefaultChangeAnalyzer } from './default-change-analyzer.service'; | |||
import { FindListOptions } from './request.models'; | import { EMPTY, Observable } from 'rxjs'; | |||
import { Observable } from 'rxjs'; | ||||
import { dataService } from '../cache/builders/build-decorators'; | import { dataService } from '../cache/builders/build-decorators'; | |||
import { VERSION } from '../shared/version.resource-type'; | import { VERSION } from '../shared/version.resource-type'; | |||
import { VersionHistory } from '../shared/version-history.model'; | ||||
import { followLink } from '../../shared/utils/follow-link-config.model'; | ||||
import { getFirstSucceededRemoteDataPayload } from '../shared/operators'; | ||||
import { map, switchMap } from 'rxjs/operators'; | ||||
import { isNotEmpty } from '../../shared/empty.util'; | ||||
/** | /** | |||
* Service responsible for handling requests related to the Version object | * Service responsible for handling requests related to the Version object | |||
*/ | */ | |||
@Injectable() | @Injectable() | |||
@dataService(VERSION) | @dataService(VERSION) | |||
export class VersionDataService extends DataService<Version> { | export class VersionDataService extends DataService<Version> { | |||
protected linkPath = 'versions'; | protected linkPath = 'versions'; | |||
constructor( | constructor( | |||
skipping to change at line 39 | skipping to change at line 43 | |||
protected store: Store<CoreState>, | protected store: Store<CoreState>, | |||
protected objectCache: ObjectCacheService, | protected objectCache: ObjectCacheService, | |||
protected halService: HALEndpointService, | protected halService: HALEndpointService, | |||
protected notificationsService: NotificationsService, | protected notificationsService: NotificationsService, | |||
protected http: HttpClient, | protected http: HttpClient, | |||
protected comparator: DefaultChangeAnalyzer<Version>) { | protected comparator: DefaultChangeAnalyzer<Version>) { | |||
super(); | super(); | |||
} | } | |||
/** | /** | |||
* Get the endpoint for browsing versions | * Get the version history for the given version | |||
* @param version | ||||
* @param useCachedVersionIfAvailable If this is true, the request will only b | ||||
e sent if there's | ||||
* no valid cached version. Defaults to tru | ||||
e | ||||
* @param reRequestOnStale Whether or not the request should automa | ||||
tically be re- | ||||
* requested after the response becomes sta | ||||
le | ||||
*/ | */ | |||
getBrowseEndpoint(options: FindListOptions = {}, linkPath?: string): Observabl | getHistoryFromVersion(version: Version, useCachedVersionIfAvailable = false, r | |||
e<string> { | eRequestOnStale = true): Observable<VersionHistory> { | |||
return this.halService.getEndpoint(this.linkPath); | return isNotEmpty(version) ? this.findById(version.id, useCachedVersionIfAva | |||
ilable, reRequestOnStale, followLink('versionhistory')).pipe( | ||||
getFirstSucceededRemoteDataPayload(), | ||||
switchMap((res: Version) => res.versionhistory), | ||||
getFirstSucceededRemoteDataPayload(), | ||||
) : EMPTY; | ||||
} | } | |||
/** | ||||
* Get the ID of the version history for the given version | ||||
* @param version | ||||
*/ | ||||
getHistoryIdFromVersion(version: Version): Observable<string> { | ||||
return this.getHistoryFromVersion(version).pipe( | ||||
map((versionHistory: VersionHistory) => versionHistory.id), | ||||
); | ||||
} | ||||
} | } | |||
End of changes. 5 change blocks. | ||||
6 lines changed or deleted | 35 lines changed or added |