mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Fixed issue while retrieve undefined item's bitstreams on ItemDetailPreviewComponent
This commit is contained in:
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
|
|||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
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 { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||||
import { dataService } from '../cache/builders/build-decorators';
|
import { dataService } from '../cache/builders/build-decorators';
|
||||||
@@ -72,7 +72,7 @@ export class BitstreamDataService extends DataService<Bitstream> {
|
|||||||
public getThumbnailFor(item: Item): Observable<RemoteData<Bitstream>> {
|
public getThumbnailFor(item: Item): Observable<RemoteData<Bitstream>> {
|
||||||
return this.bundleService.findByItemAndName(item, 'THUMBNAIL').pipe(
|
return this.bundleService.findByItemAndName(item, 'THUMBNAIL').pipe(
|
||||||
switchMap((bundleRD: RemoteData<Bundle>) => {
|
switchMap((bundleRD: RemoteData<Bundle>) => {
|
||||||
if (hasValue(bundleRD.payload)) {
|
if (isNotEmpty(bundleRD.payload)) {
|
||||||
return this.findAllByBundle(bundleRD.payload, { elementsPerPage: 1 }).pipe(
|
return this.findAllByBundle(bundleRD.payload, { elementsPerPage: 1 }).pipe(
|
||||||
map((bitstreamRD: RemoteData<PaginatedList<Bitstream>>) => {
|
map((bitstreamRD: RemoteData<PaginatedList<Bitstream>>) => {
|
||||||
if (hasValue(bitstreamRD.payload) && hasValue(bitstreamRD.payload.page)) {
|
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>> {
|
public getMatchingThumbnail(item: Item, bitstreamInOriginal: Bitstream): Observable<RemoteData<Bitstream>> {
|
||||||
return this.bundleService.findByItemAndName(item, 'THUMBNAIL').pipe(
|
return this.bundleService.findByItemAndName(item, 'THUMBNAIL').pipe(
|
||||||
switchMap((bundleRD: RemoteData<Bundle>) => {
|
switchMap((bundleRD: RemoteData<Bundle>) => {
|
||||||
if (hasValue(bundleRD.payload)) {
|
if (isNotEmpty(bundleRD.payload)) {
|
||||||
return this.findAllByBundle(bundleRD.payload, { elementsPerPage: Number.MAX_SAFE_INTEGER }).pipe(
|
return this.findAllByBundle(bundleRD.payload, { elementsPerPage: Number.MAX_SAFE_INTEGER }).pipe(
|
||||||
map((bitstreamRD: RemoteData<PaginatedList<Bitstream>>) => {
|
map((bitstreamRD: RemoteData<PaginatedList<Bitstream>>) => {
|
||||||
if (hasValue(bitstreamRD.payload) && hasValue(bitstreamRD.payload.page)) {
|
if (hasValue(bitstreamRD.payload) && hasValue(bitstreamRD.payload.page)) {
|
||||||
|
@@ -10,9 +10,9 @@
|
|||||||
<div class="row mb-1">
|
<div class="row mb-1">
|
||||||
<div class="col-xs-12 col-md-4">
|
<div class="col-xs-12 col-md-4">
|
||||||
<ds-metadata-field-wrapper>
|
<ds-metadata-field-wrapper>
|
||||||
<ds-thumbnail [thumbnail]="thumbnail$ | async"></ds-thumbnail>
|
<ds-thumbnail [thumbnail]="this.getThumbnail() | async"></ds-thumbnail>
|
||||||
</ds-metadata-field-wrapper>
|
</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)">
|
<ds-metadata-field-wrapper [label]="('item.page.files' | translate)">
|
||||||
<div *ngIf="bitstreams?.length > 0" class="file-section">
|
<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)">
|
<button class="btn btn-link" *ngFor="let file of bitstreams; let last=last;" (click)="downloadBitstreamFile(file?.uuid)">
|
||||||
|
@@ -5,8 +5,8 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { of as observableOf } from 'rxjs';
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
|
||||||
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
|
||||||
import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
|
import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
|
||||||
import { BitstreamDataService } from '../../../../core/data/bitstream-data.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 { createSuccessfulRemoteDataObject$ } from '../../../testing/utils';
|
||||||
import { FileSizePipe } from '../../../utils/file-size-pipe';
|
import { FileSizePipe } from '../../../utils/file-size-pipe';
|
||||||
import { FollowLinkConfig } from '../../../utils/follow-link-config.model';
|
import { FollowLinkConfig } from '../../../utils/follow-link-config.model';
|
||||||
|
|
||||||
import { TruncatePipe } from '../../../utils/truncate.pipe';
|
import { TruncatePipe } from '../../../utils/truncate.pipe';
|
||||||
import { VarDirective } from '../../../utils/var.directive';
|
import { VarDirective } from '../../../utils/var.directive';
|
||||||
import { ItemDetailPreviewFieldComponent } from './item-detail-preview-field/item-detail-preview-field.component';
|
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', () => {
|
it('should get item thumbnail', (done) => {
|
||||||
expect(component.thumbnail$).toBeDefined();
|
component.getThumbnail().subscribe((thumbnail) => {
|
||||||
expect(component.bitstreams$).toBeDefined();
|
expect(thumbnail).toBeDefined();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get item bitstreams', (done) => {
|
||||||
|
component.getFiles().subscribe((bitstreams) => {
|
||||||
|
expect(bitstreams).toBeDefined();
|
||||||
|
done();
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,17 +1,13 @@
|
|||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { first, map } from 'rxjs/operators';
|
import { first } from 'rxjs/operators';
|
||||||
import { BitstreamDataService } from '../../../../core/data/bitstream-data.service';
|
import { BitstreamDataService } from '../../../../core/data/bitstream-data.service';
|
||||||
import { RemoteData } from '../../../../core/data/remote-data';
|
|
||||||
|
|
||||||
import { Item } from '../../../../core/shared/item.model';
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
import {
|
import {
|
||||||
getAllSucceededRemoteListPayload,
|
|
||||||
getFirstSucceededRemoteDataPayload,
|
getFirstSucceededRemoteDataPayload,
|
||||||
getFirstSucceededRemoteListPayload,
|
getFirstSucceededRemoteListPayload
|
||||||
getRemoteDataPayload,
|
|
||||||
getSucceededRemoteData
|
|
||||||
} from '../../../../core/shared/operators';
|
} from '../../../../core/shared/operators';
|
||||||
import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type';
|
import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type';
|
||||||
import { fadeInOut } from '../../../animations/fade';
|
import { fadeInOut } from '../../../animations/fade';
|
||||||
@@ -71,20 +67,13 @@ export class ItemDetailPreviewComponent {
|
|||||||
*
|
*
|
||||||
* @param {FileService} fileService
|
* @param {FileService} fileService
|
||||||
* @param {HALEndpointService} halService
|
* @param {HALEndpointService} halService
|
||||||
|
* @param {BitstreamDataService} bitstreamDataService
|
||||||
*/
|
*/
|
||||||
constructor(private fileService: FileService,
|
constructor(private fileService: FileService,
|
||||||
private halService: HALEndpointService,
|
private halService: HALEndpointService,
|
||||||
private bitstreamDataService: BitstreamDataService) {
|
private bitstreamDataService: BitstreamDataService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize all instance variables
|
|
||||||
*/
|
|
||||||
ngOnInit() {
|
|
||||||
this.thumbnail$ = this.getThumbnail();
|
|
||||||
this.bitstreams$ = this.getFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform bitstream download
|
* 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
|
// 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(
|
return this.bitstreamDataService.getThumbnailFor(this.item).pipe(
|
||||||
getFirstSucceededRemoteDataPayload()
|
getFirstSucceededRemoteDataPayload()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO refactor this method to return RemoteData, and the template to deal with loading and errors
|
// 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
|
return this.bitstreamDataService
|
||||||
.findAllByItemAndBundleName(this.item, 'ORIGINAL', { elementsPerPage: Number.MAX_SAFE_INTEGER })
|
.findAllByItemAndBundleName(this.item, 'ORIGINAL', { elementsPerPage: Number.MAX_SAFE_INTEGER })
|
||||||
.pipe(
|
.pipe(
|
||||||
|
Reference in New Issue
Block a user