[CST-4320] fixed item version component initialization

This commit is contained in:
Alessandro Martelli
2021-07-07 16:09:19 +02:00
parent f5cd878096
commit 3d6cacadff

View File

@@ -16,7 +16,7 @@ import { VersionHistoryDataService } from '../../../core/data/version-history-da
import { PaginatedSearchOptions } from '../../search/paginated-search-options.model'; import { PaginatedSearchOptions } from '../../search/paginated-search-options.model';
import { AlertType } from '../../alert/aletr-type'; import { AlertType } from '../../alert/aletr-type';
import { followLink } from '../../utils/follow-link-config.model'; import { followLink } from '../../utils/follow-link-config.model';
import { hasValueOperator } from '../../empty.util'; import { hasValue, hasValueOperator } from '../../empty.util';
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
import { getItemPageRoute } from '../../../+item-page/item-page-routing-paths'; import { getItemPageRoute } from '../../../+item-page/item-page-routing-paths';
@@ -110,41 +110,43 @@ export class ItemVersionsComponent implements OnInit {
* Initialize all observables * Initialize all observables
*/ */
ngOnInit(): void { ngOnInit(): void {
this.versionRD$ = this.item.version; if (hasValue(this.item.version)) {
this.versionHistoryRD$ = this.versionRD$.pipe( this.versionRD$ = this.item.version;
getAllSucceededRemoteData(), this.versionHistoryRD$ = this.versionRD$.pipe(
getRemoteDataPayload(), getAllSucceededRemoteData(),
hasValueOperator(), getRemoteDataPayload(),
switchMap((version: Version) => version.versionhistory) hasValueOperator(),
); switchMap((version: Version) => version.versionhistory)
const versionHistory$ = this.versionHistoryRD$.pipe( );
getAllSucceededRemoteData(), const versionHistory$ = this.versionHistoryRD$.pipe(
getRemoteDataPayload(), getAllSucceededRemoteData(),
hasValueOperator(), getRemoteDataPayload(),
); hasValueOperator(),
const currentPagination = this.paginationService.getCurrentPagination(this.options.id, this.options); );
this.versionsRD$ = observableCombineLatest(versionHistory$, currentPagination).pipe( const currentPagination = this.paginationService.getCurrentPagination(this.options.id, this.options);
switchMap(([versionHistory, options]: [VersionHistory, PaginationComponentOptions]) => this.versionsRD$ = observableCombineLatest(versionHistory$, currentPagination).pipe(
this.versionHistoryService.getVersions(versionHistory.id, switchMap(([versionHistory, options]: [VersionHistory, PaginationComponentOptions]) =>
new PaginatedSearchOptions({pagination: Object.assign({}, options, { currentPage: options.currentPage })}), this.versionHistoryService.getVersions(versionHistory.id,
true, true, followLink('item'), followLink('eperson'))) new PaginatedSearchOptions({pagination: Object.assign({}, options, { currentPage: options.currentPage })}),
); true, true, followLink('item'), followLink('eperson')))
this.hasEpersons$ = this.versionsRD$.pipe( );
getAllSucceededRemoteData(), this.hasEpersons$ = this.versionsRD$.pipe(
getRemoteDataPayload(), getAllSucceededRemoteData(),
hasValueOperator(), getRemoteDataPayload(),
map((versions: PaginatedList<Version>) => versions.page.filter((version: Version) => version.eperson !== undefined).length > 0), hasValueOperator(),
startWith(false) map((versions: PaginatedList<Version>) => versions.page.filter((version: Version) => version.eperson !== undefined).length > 0),
); startWith(false)
this.itemPageRoutes$ = this.versionsRD$.pipe( );
getAllSucceededRemoteDataPayload(), this.itemPageRoutes$ = this.versionsRD$.pipe(
switchMap((versions) => observableCombineLatest(...versions.page.map((version) => version.item.pipe(getAllSucceededRemoteDataPayload())))), getAllSucceededRemoteDataPayload(),
map((versions) => { switchMap((versions) => observableCombineLatest(...versions.page.map((version) => version.item.pipe(getAllSucceededRemoteDataPayload())))),
const itemPageRoutes = {}; map((versions) => {
versions.forEach((item) => itemPageRoutes[item.uuid] = getItemPageRoute(item)); const itemPageRoutes = {};
return itemPageRoutes; versions.forEach((item) => itemPageRoutes[item.uuid] = getItemPageRoute(item));
}) return itemPageRoutes;
); })
);
}
} }
ngOnDestroy(): void { ngOnDestroy(): void {