Fixed issue while retrieve undefined item's bitstreams on ItemDetailPreviewComponent

This commit is contained in:
Giuseppe Digilio
2020-03-03 12:09:33 +01:00
parent 401065dba2
commit 64c96c78f0
4 changed files with 24 additions and 27 deletions

View File

@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/internal/Observable';
import { map, switchMap } from 'rxjs/operators';
import { hasValue } from '../../shared/empty.util';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { dataService } from '../cache/builders/build-decorators';
@@ -72,7 +72,7 @@ export class BitstreamDataService extends DataService<Bitstream> {
public getThumbnailFor(item: Item): Observable<RemoteData<Bitstream>> {
return this.bundleService.findByItemAndName(item, 'THUMBNAIL').pipe(
switchMap((bundleRD: RemoteData<Bundle>) => {
if (hasValue(bundleRD.payload)) {
if (isNotEmpty(bundleRD.payload)) {
return this.findAllByBundle(bundleRD.payload, { elementsPerPage: 1 }).pipe(
map((bitstreamRD: RemoteData<PaginatedList<Bitstream>>) => {
if (hasValue(bitstreamRD.payload) && hasValue(bitstreamRD.payload.page)) {
@@ -108,7 +108,7 @@ export class BitstreamDataService extends DataService<Bitstream> {
public getMatchingThumbnail(item: Item, bitstreamInOriginal: Bitstream): Observable<RemoteData<Bitstream>> {
return this.bundleService.findByItemAndName(item, 'THUMBNAIL').pipe(
switchMap((bundleRD: RemoteData<Bundle>) => {
if (hasValue(bundleRD.payload)) {
if (isNotEmpty(bundleRD.payload)) {
return this.findAllByBundle(bundleRD.payload, { elementsPerPage: Number.MAX_SAFE_INTEGER }).pipe(
map((bitstreamRD: RemoteData<PaginatedList<Bitstream>>) => {
if (hasValue(bitstreamRD.payload) && hasValue(bitstreamRD.payload.page)) {

View File

@@ -10,9 +10,9 @@
<div class="row mb-1">
<div class="col-xs-12 col-md-4">
<ds-metadata-field-wrapper>
<ds-thumbnail [thumbnail]="thumbnail$ | async"></ds-thumbnail>
<ds-thumbnail [thumbnail]="this.getThumbnail() | async"></ds-thumbnail>
</ds-metadata-field-wrapper>
<ng-container *ngVar="(bitstreams$ | async) as bitstreams">
<ng-container *ngVar="(getFiles() | async) as bitstreams">
<ds-metadata-field-wrapper [label]="('item.page.files' | translate)">
<div *ngIf="bitstreams?.length > 0" class="file-section">
<button class="btn btn-link" *ngFor="let file of bitstreams; let last=last;" (click)="downloadBitstreamFile(file?.uuid)">

View File

@@ -5,8 +5,8 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Store } from '@ngrx/store';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs';
import { Observable } from 'rxjs/internal/Observable';
import { Observable, of as observableOf } from 'rxjs';
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
import { BitstreamDataService } from '../../../../core/data/bitstream-data.service';
@@ -28,7 +28,6 @@ import { HALEndpointServiceStub } from '../../../testing/hal-endpoint-service-st
import { createSuccessfulRemoteDataObject$ } from '../../../testing/utils';
import { FileSizePipe } from '../../../utils/file-size-pipe';
import { FollowLinkConfig } from '../../../utils/follow-link-config.model';
import { TruncatePipe } from '../../../utils/truncate.pipe';
import { VarDirective } from '../../../utils/var.directive';
import { ItemDetailPreviewFieldComponent } from './item-detail-preview-field/item-detail-preview-field.component';
@@ -127,8 +126,17 @@ describe('ItemDetailPreviewComponent', () => {
}));
it('should init thumbnail and bitstreams on init', () => {
expect(component.thumbnail$).toBeDefined();
expect(component.bitstreams$).toBeDefined();
it('should get item thumbnail', (done) => {
component.getThumbnail().subscribe((thumbnail) => {
expect(thumbnail).toBeDefined();
done();
});
});
it('should get item bitstreams', (done) => {
component.getFiles().subscribe((bitstreams) => {
expect(bitstreams).toBeDefined();
done();
})
});
});

View File

@@ -1,17 +1,13 @@
import { Component, Input } from '@angular/core';
import { Observable } from 'rxjs';
import { first, map } from 'rxjs/operators';
import { first } from 'rxjs/operators';
import { BitstreamDataService } from '../../../../core/data/bitstream-data.service';
import { RemoteData } from '../../../../core/data/remote-data';
import { Item } from '../../../../core/shared/item.model';
import {
getAllSucceededRemoteListPayload,
getFirstSucceededRemoteDataPayload,
getFirstSucceededRemoteListPayload,
getRemoteDataPayload,
getSucceededRemoteData
getFirstSucceededRemoteListPayload
} from '../../../../core/shared/operators';
import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type';
import { fadeInOut } from '../../../animations/fade';
@@ -71,20 +67,13 @@ export class ItemDetailPreviewComponent {
*
* @param {FileService} fileService
* @param {HALEndpointService} halService
* @param {BitstreamDataService} bitstreamDataService
*/
constructor(private fileService: FileService,
private halService: HALEndpointService,
private bitstreamDataService: BitstreamDataService) {
}
/**
* Initialize all instance variables
*/
ngOnInit() {
this.thumbnail$ = this.getThumbnail();
this.bitstreams$ = this.getFiles();
}
/**
* Perform bitstream download
*/
@@ -98,14 +87,14 @@ export class ItemDetailPreviewComponent {
}
// TODO refactor this method to return RemoteData, and the template to deal with loading and errors
getThumbnail(): Observable<Bitstream> {
public getThumbnail(): Observable<Bitstream> {
return this.bitstreamDataService.getThumbnailFor(this.item).pipe(
getFirstSucceededRemoteDataPayload()
);
}
// TODO refactor this method to return RemoteData, and the template to deal with loading and errors
getFiles(): Observable<Bitstream[]> {
public getFiles(): Observable<Bitstream[]> {
return this.bitstreamDataService
.findAllByItemAndBundleName(this.item, 'ORIGINAL', { elementsPerPage: Number.MAX_SAFE_INTEGER })
.pipe(