item-versions-notice.component.ts (dspace-angular-dspace-7.0) | : | item-versions-notice.component.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
import { Component, Input, OnInit } from '@angular/core'; | import { Component, Input, OnInit } from '@angular/core'; | |||
import { Item } from '../../../../core/shared/item.model'; | import { Item } from '../../../../core/shared/item.model'; | |||
import { PaginationComponentOptions } from '../../../pagination/pagination-compo | import { Observable } from 'rxjs'; | |||
nent-options.model'; | ||||
import { PaginatedSearchOptions } from '../../../search/paginated-search-options | ||||
.model'; | ||||
import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; | ||||
import { RemoteData } from '../../../../core/data/remote-data'; | import { RemoteData } from '../../../../core/data/remote-data'; | |||
import { VersionHistory } from '../../../../core/shared/version-history.model'; | import { VersionHistory } from '../../../../core/shared/version-history.model'; | |||
import { Version } from '../../../../core/shared/version.model'; | import { Version } from '../../../../core/shared/version.model'; | |||
import { hasValue, hasValueOperator } from '../../../empty.util'; | import { hasValue, hasValueOperator } from '../../../empty.util'; | |||
import { getAllSucceededRemoteData, getRemoteDataPayload } from '../../../../cor | import { | |||
e/shared/operators'; | getAllSucceededRemoteData, | |||
import { filter, map, startWith, switchMap } from 'rxjs/operators'; | getFirstSucceededRemoteDataPayload, | |||
import { followLink } from '../../../utils/follow-link-config.model'; | getRemoteDataPayload | |||
} from '../../../../core/shared/operators'; | ||||
import { map, startWith, switchMap } from 'rxjs/operators'; | ||||
import { VersionHistoryDataService } from '../../../../core/data/version-history -data.service'; | import { VersionHistoryDataService } from '../../../../core/data/version-history -data.service'; | |||
import { AlertType } from '../../../alert/aletr-type'; | import { AlertType } from '../../../alert/aletr-type'; | |||
import { getItemPageRoute } from '../../../../item-page/item-page-routing-paths' ; | import { getItemPageRoute } from '../../../../item-page/item-page-routing-paths' ; | |||
@Component({ | @Component({ | |||
selector: 'ds-item-versions-notice', | selector: 'ds-item-versions-notice', | |||
templateUrl: './item-versions-notice.component.html' | templateUrl: './item-versions-notice.component.html' | |||
}) | }) | |||
/** | /** | |||
* Component for displaying a warning notice when the item is not the latest ver sion within its version history | * Component for displaying a warning notice when the item is not the latest ver sion within its version history | |||
skipping to change at line 50 | skipping to change at line 51 | |||
/** | /** | |||
* The latest version of the item's version history | * The latest version of the item's version history | |||
*/ | */ | |||
latestVersion$: Observable<Version>; | latestVersion$: Observable<Version>; | |||
/** | /** | |||
* Is the item's version equal to the latest version from the version history? | * Is the item's version equal to the latest version from the version history? | |||
* This will determine whether or not to display a notice linking to the lates t version | * This will determine whether or not to display a notice linking to the lates t version | |||
*/ | */ | |||
isLatestVersion$: Observable<boolean>; | showLatestVersionNotice$: Observable<boolean>; | |||
/** | /** | |||
* Pagination options to fetch a single version on the first page (this is the latest version in the history) | * Pagination options to fetch a single version on the first page (this is the latest version in the history) | |||
*/ | */ | |||
latestVersionOptions = Object.assign(new PaginationComponentOptions(),{ | ||||
id: 'item-newest-version-options', | ||||
currentPage: 1, | ||||
pageSize: 1 | ||||
}); | ||||
/** | /** | |||
* The AlertType enumeration | * The AlertType enumeration | |||
* @type {AlertType} | * @type {AlertType} | |||
*/ | */ | |||
public AlertTypeEnum = AlertType; | public AlertTypeEnum = AlertType; | |||
constructor(private versionHistoryService: VersionHistoryDataService) { | constructor(private versionHistoryService: VersionHistoryDataService) { | |||
} | } | |||
/** | /** | |||
* Initialize the component's observables | * Initialize the component's observables | |||
*/ | */ | |||
ngOnInit(): void { | ngOnInit(): void { | |||
const latestVersionSearch = new PaginatedSearchOptions({pagination: this.lat estVersionOptions}); | ||||
if (hasValue(this.item.version)) { | if (hasValue(this.item.version)) { | |||
this.versionRD$ = this.item.version; | this.versionRD$ = this.item.version; | |||
this.versionHistoryRD$ = this.versionRD$.pipe( | this.versionHistoryRD$ = this.versionRD$.pipe( | |||
getAllSucceededRemoteData(), | getAllSucceededRemoteData(), | |||
getRemoteDataPayload(), | getRemoteDataPayload(), | |||
hasValueOperator(), | hasValueOperator(), | |||
switchMap((version: Version) => version.versionhistory) | switchMap((version: Version) => version.versionhistory) | |||
); | ); | |||
const versionHistory$ = this.versionHistoryRD$.pipe( | ||||
getAllSucceededRemoteData(), | this.latestVersion$ = this.versionHistoryRD$.pipe( | |||
getRemoteDataPayload(), | getFirstSucceededRemoteDataPayload(), | |||
); | switchMap((vh) => this.versionHistoryService.getLatestVersionFromHistory | |||
this.latestVersion$ = versionHistory$.pipe( | $(vh)) | |||
switchMap((versionHistory: VersionHistory) => | ||||
this.versionHistoryService.getVersions(versionHistory.id, latestVersio | ||||
nSearch, true, true, followLink('item'))), | ||||
getAllSucceededRemoteData(), | ||||
getRemoteDataPayload(), | ||||
hasValueOperator(), | ||||
filter((versions) => versions.page.length > 0), | ||||
map((versions) => versions.page[0]) | ||||
); | ); | |||
this.isLatestVersion$ = observableCombineLatest( | this.showLatestVersionNotice$ = this.versionRD$.pipe( | |||
this.versionRD$.pipe(getAllSucceededRemoteData(), getRemoteDataPayload() | getFirstSucceededRemoteDataPayload(), | |||
), this.latestVersion$ | switchMap((version) => this.versionHistoryService.isLatest$(version)), | |||
).pipe( | map((isLatest) => isLatest != null && !isLatest), | |||
map(([itemVersion, latestVersion]: [Version, Version]) => itemVersion.id | startWith(false), | |||
=== latestVersion.id), | ||||
startWith(true) | ||||
); | ); | |||
} | } | |||
} | } | |||
/** | /** | |||
* Get the item page url | * Get the item page url | |||
* @param item The item for which the url is requested | * @param item The item for which the url is requested | |||
*/ | */ | |||
getItemPage(item: Item): string { | getItemPage(item: Item): string { | |||
if (hasValue(item)) { | if (hasValue(item)) { | |||
End of changes. 7 change blocks. | ||||
36 lines changed or deleted | 18 lines changed or added |