Skip to content

Commit 615d02e

Browse files
[DSC-2309] make default async, fix lint
1 parent 5193d3b commit 615d02e

4 files changed

Lines changed: 45 additions & 33 deletions

File tree

src/app/core/shared/image.utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { Observable, of } from 'rxjs';
1+
import {
2+
Observable,
3+
of,
4+
} from 'rxjs';
25
import { map } from 'rxjs/operators';
36

47
export const getDefaultImageUrlByEntityType = (entityType: string): Observable<string> => {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<ds-thumbnail *ngIf="(initialized | async)" data-test="thumbnail"
22
[thumbnail]="thumbnail$ | async"
3-
[defaultImage]="default">
3+
[defaultImage]="default$ | async">
44
</ds-thumbnail>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/thumbnail/thumbnail.component.spec.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ describe('ThumbnailComponent', () => {
152152
expect(thumbnail).toBeTruthy();
153153
}));
154154

155-
it('should show default thumbnail', () => {
156-
expect(component.default).toBe('assets/images/file-placeholder.svg');
155+
it('should show default thumbnail', (done) => {
156+
component.default$.subscribe(image => {
157+
expect(image).toBe('assets/images/file-placeholder.svg');
158+
done();
159+
});
157160
});
158-
159161
});
160162

161163
describe('When bitstreams are only original', () => {
@@ -172,10 +174,12 @@ describe('ThumbnailComponent', () => {
172174
expect(thumbnail).toBeTruthy();
173175
}));
174176

175-
it('should show default thumbnail', () => {
176-
expect(component.default).toBe('assets/images/file-placeholder.svg');
177+
it('should show default thumbnail', (done) => {
178+
component.default$.subscribe(image => {
179+
expect(image).toBe('assets/images/file-placeholder.svg');
180+
done();
181+
});
177182
});
178-
179183
});
180184

181185
describe('When bitstreams are only thumbnail', () => {
@@ -239,10 +243,12 @@ describe('ThumbnailComponent', () => {
239243
expect(thumbnail).toBeTruthy();
240244
});
241245

242-
it('should show default thumbnail', () => {
243-
expect(component.default).toBe('assets/images/file-placeholder.svg');
246+
it('should show default thumbnail', (done) => {
247+
component.default$.subscribe(image => {
248+
expect(image).toBe('assets/images/file-placeholder.svg');
249+
done();
250+
});
244251
});
245-
246252
});
247253

248254
describe('When bitstreams are only original without the right metadata information', () => {
@@ -254,8 +260,11 @@ describe('ThumbnailComponent', () => {
254260
fixture.detectChanges();
255261
});
256262

257-
it('should not show bitstream content image src but the default image', () => {
258-
expect(component.default).toBe('assets/images/file-placeholder.svg');
263+
it('should not show bitstream content image src but the default image', (done) => {
264+
component.default$.subscribe(image => {
265+
expect(image).toBe('assets/images/file-placeholder.svg');
266+
done();
267+
});
259268
});
260269

261270
});
@@ -269,10 +278,12 @@ describe('ThumbnailComponent', () => {
269278
fixture.detectChanges();
270279
});
271280

272-
it('should not show thumbnail content image src but the default image', () => {
273-
expect(component.default).toBe('assets/images/file-placeholder.svg');
281+
it('should not show thumbnail content image src but the default image', (done) => {
282+
component.default$.subscribe(image => {
283+
expect(image).toBe('assets/images/file-placeholder.svg');
284+
done();
285+
});
274286
});
275-
276287
});
277288

278289
describe('When bitstreams are only original with the right metadata information', () => {
@@ -284,8 +295,11 @@ describe('ThumbnailComponent', () => {
284295
fixture.detectChanges();
285296
});
286297

287-
it('should not show thumbnail content image src but the default image', () => {
288-
expect(component.default).toBe('assets/images/file-placeholder.svg');
298+
it('should not show thumbnail content image src but the default image', (done) => {
299+
component.default$.subscribe(image => {
300+
expect(image).toBe('assets/images/file-placeholder.svg');
301+
done();
302+
});
289303
});
290304

291305
});

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/thumbnail/thumbnail.component.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Inject, OnInit } from '@angular/core';
22

3-
import { BehaviorSubject, of as observableOf } from 'rxjs';
3+
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
44
import { map, switchMap, take } from 'rxjs/operators';
55
import { TranslateService } from '@ngx-translate/core';
66

@@ -35,7 +35,7 @@ export class ThumbnailComponent extends BitstreamRenderingModelComponent impleme
3535
/**
3636
* Default image to be shown in the thumbnail
3737
*/
38-
default: string;
38+
default$: Observable<string>;
3939

4040
/**
4141
* Item rendering initialization state
@@ -62,9 +62,14 @@ export class ThumbnailComponent extends BitstreamRenderingModelComponent impleme
6262
* Get the thumbnail information from api for this item
6363
*/
6464
ngOnInit(): void {
65-
this.setDefaultImage();
66-
this.getBitstreamsByItem().pipe(
67-
map((bitstreamList: PaginatedList<Bitstream>) => bitstreamList.page),
65+
const eType = this.item.firstMetadataValue('dspace.entity.type');
66+
this.default$ = getDefaultImageUrlByEntityType(eType);
67+
68+
combineLatest([
69+
this.default$,
70+
this.getBitstreamsByItem(),
71+
]).pipe(
72+
map(([_, bitstreamList]: [string, PaginatedList<Bitstream>]) => bitstreamList.page),
6873
switchMap((filteredBitstreams: Bitstream[]) => {
6974
if (filteredBitstreams.length > 0) {
7075
if (isEmpty(filteredBitstreams[0].thumbnail)) {
@@ -92,14 +97,4 @@ export class ThumbnailComponent extends BitstreamRenderingModelComponent impleme
9297
this.initialized.next(true);
9398
});
9499
}
95-
96-
/**
97-
* Set the default image src depending on item entity type
98-
*/
99-
setDefaultImage(): void {
100-
const eType = this.item.firstMetadataValue('dspace.entity.type');
101-
getDefaultImageUrlByEntityType(eType).pipe(take(1)).subscribe((url) => {
102-
this.default = url;
103-
});
104-
}
105100
}

0 commit comments

Comments
 (0)