Skip to content

Commit d62b4c6

Browse files
[DSC-2309] make default async, fix lint
1 parent 8c5b648 commit d62b4c6

5 files changed

Lines changed: 49 additions & 37 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
@@ -169,10 +169,12 @@ describe('', () => {
169169
expect(thumbnail).toBeTruthy();
170170
}));
171171

172-
it('should show default thumbnail', () => {
173-
expect(component.default).toBe('assets/images/file-placeholder.svg');
172+
it('should show default thumbnail', (done) => {
173+
component.default$.subscribe(image => {
174+
expect(image).toBe('assets/images/file-placeholder.svg');
175+
done();
176+
});
174177
});
175-
176178
});
177179

178180
describe('When bitstreams are only original', () => {
@@ -189,10 +191,12 @@ describe('', () => {
189191
expect(thumbnail).toBeTruthy();
190192
}));
191193

192-
it('should show default thumbnail', () => {
193-
expect(component.default).toBe('assets/images/file-placeholder.svg');
194+
it('should show default thumbnail', (done) => {
195+
component.default$.subscribe(image => {
196+
expect(image).toBe('assets/images/file-placeholder.svg');
197+
done();
198+
});
194199
});
195-
196200
});
197201

198202
describe('When bitstreams are only thumbnail', () => {
@@ -263,10 +267,12 @@ describe('', () => {
263267
expect(thumbnail).toBeTruthy();
264268
});
265269

266-
it('should show default thumbnail', () => {
267-
expect(component.default).toBe('assets/images/file-placeholder.svg');
270+
it('should show default thumbnail', (done) => {
271+
component.default$.subscribe(image => {
272+
expect(image).toBe('assets/images/file-placeholder.svg');
273+
done();
274+
});
268275
});
269-
270276
});
271277

272278
describe('When bitstreams are only original without the right metadata information', () => {
@@ -278,8 +284,11 @@ describe('', () => {
278284
fixture.detectChanges();
279285
});
280286

281-
it('should not show bitstream content image src but the default image', () => {
282-
expect(component.default).toBe('assets/images/file-placeholder.svg');
287+
it('should not show bitstream content image src but the default image', (done) => {
288+
component.default$.subscribe(image => {
289+
expect(image).toBe('assets/images/file-placeholder.svg');
290+
done();
291+
});
283292
});
284293

285294
});
@@ -293,10 +302,12 @@ describe('', () => {
293302
fixture.detectChanges();
294303
});
295304

296-
it('should not show thumbnail content image src but the default image', () => {
297-
expect(component.default).toBe('assets/images/file-placeholder.svg');
305+
it('should not show thumbnail content image src but the default image', (done) => {
306+
component.default$.subscribe(image => {
307+
expect(image).toBe('assets/images/file-placeholder.svg');
308+
done();
309+
});
298310
});
299-
300311
});
301312

302313
describe('When bitstreams are only original with the right metadata information', () => {
@@ -308,8 +319,11 @@ describe('', () => {
308319
fixture.detectChanges();
309320
});
310321

311-
it('should not show thumbnail content image src but the default image', () => {
312-
expect(component.default).toBe('assets/images/file-placeholder.svg');
322+
it('should not show thumbnail content image src but the default image', (done) => {
323+
component.default$.subscribe(image => {
324+
expect(image).toBe('assets/images/file-placeholder.svg');
325+
done();
326+
});
313327
});
314328

315329
});

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ import {
1010
import { TranslateService } from '@ngx-translate/core';
1111
import {
1212
BehaviorSubject,
13+
combineLatest,
14+
Observable,
1315
of as observableOf,
1416
} from 'rxjs';
1517
import {
1618
map,
1719
switchMap,
18-
take
1920
} from 'rxjs/operators';
2021

2122
import { BitstreamDataService } from '../../../../../../../core/data/bitstream-data.service';
2223
import { PaginatedList } from '../../../../../../../core/data/paginated-list.model';
2324
import { LayoutField } from '../../../../../../../core/layout/models/box.model';
2425
import { Bitstream } from '../../../../../../../core/shared/bitstream.model';
26+
import { getDefaultImageUrlByEntityType } from '../../../../../../../core/shared/image.utils';
2527
import { Item } from '../../../../../../../core/shared/item.model';
2628
import { getFirstCompletedRemoteData } from '../../../../../../../core/shared/operators';
2729
import {
28-
hasValue,
2930
isEmpty,
3031
isNotEmpty,
3132
} from '../../../../../../../shared/empty.util';
3233
import { ThemedThumbnailComponent } from '../../../../../../../thumbnail/themed-thumbnail.component';
3334
import { BitstreamRenderingModelComponent } from '../bitstream-rendering-model';
34-
import { getDefaultImageUrlByEntityType } from '../../../../../../../core/shared/image.utils';
3535

3636
@Component({
3737
// eslint-disable-next-line @angular-eslint/component-selector, dspace-angular-ts/themed-component-selectors
@@ -58,7 +58,7 @@ export class ThumbnailRenderingComponent extends BitstreamRenderingModelComponen
5858
/**
5959
* Default image to be shown in the thumbnail
6060
*/
61-
default: string;
61+
default$: Observable<string>;
6262

6363
/**
6464
* Item rendering initialization state
@@ -85,9 +85,14 @@ export class ThumbnailRenderingComponent extends BitstreamRenderingModelComponen
8585
* Get the thumbnail information from api for this item
8686
*/
8787
ngOnInit(): void {
88-
this.setDefaultImage();
89-
this.getBitstreamsByItem().pipe(
90-
map((bitstreamList: PaginatedList<Bitstream>) => bitstreamList.page),
88+
const eType = this.item.firstMetadataValue('dspace.entity.type');
89+
this.default$ = getDefaultImageUrlByEntityType(eType);
90+
91+
combineLatest([
92+
this.default$,
93+
this.getBitstreamsByItem(),
94+
]).pipe(
95+
map(([_, bitstreamList]: [string, PaginatedList<Bitstream>]) => bitstreamList.page),
9196
switchMap((filteredBitstreams: Bitstream[]) => {
9297
if (filteredBitstreams.length > 0) {
9398
if (isEmpty(filteredBitstreams[0].thumbnail)) {
@@ -115,14 +120,4 @@ export class ThumbnailRenderingComponent extends BitstreamRenderingModelComponen
115120
this.initialized.next(true);
116121
});
117122
}
118-
119-
/**
120-
* Set the default image src depending on item entity type
121-
*/
122-
setDefaultImage(): void {
123-
const eType = this.item.firstMetadataValue('dspace.entity.type');
124-
getDefaultImageUrlByEntityType(eType).pipe(take(1)).subscribe((url) => {
125-
this.default = url;
126-
});
127-
}
128123
}

src/app/shared/metadata-link-view/metadata-link-view-avatar-popover/metadata-link-view-avatar-popover.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {
99
OnInit,
1010
} from '@angular/core';
1111
import { TranslateModule } from '@ngx-translate/core';
12-
import { ThumbnailComponent } from 'src/app/thumbnail/thumbnail.component';
13-
import { getDefaultImageUrlByEntityType } from '../../../core/shared/image.utils';
1412
import { Observable } from 'rxjs';
13+
import { ThumbnailComponent } from 'src/app/thumbnail/thumbnail.component';
1514

15+
import { getDefaultImageUrlByEntityType } from '../../../core/shared/image.utils';
1616
import { ThemedLoadingComponent } from '../../loading/themed-loading.component';
1717
import { SafeUrlPipe } from '../../utils/safe-url-pipe';
1818
import { VarDirective } from '../../utils/var.directive';

0 commit comments

Comments
 (0)