Skip to content

Commit 9886cb0

Browse files
alisaismailatiFrancescoMolinaro
authored andcommitted
Merged in task/ux-plus-2023_02_x/UXP-138 (pull request #16)
Task/ux plus 2023 02 x/UXP-138 Approved-by: Francesco Molinaro
2 parents f1d6844 + deccdc9 commit 9886cb0

7 files changed

Lines changed: 162 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div [class]="field.styleValue">
2+
<img *ngIf="(imageUrl$ | async) as url" [src]="url">
3+
</div>
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
img {
2+
width: 100%;
3+
max-width: 900px;
4+
max-height: 600px;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import {ComponentFixture, TestBed} from '@angular/core/testing';
2+
3+
import {ImageComponent} from './image.component';
4+
import {LayoutField} from '../../../../../../../core/layout/models/box.model';
5+
import {FieldRenderingType} from '../metadata-box.decorator';
6+
import {Item} from '../../../../../../../core/shared/item.model';
7+
import {Observable, of} from 'rxjs';
8+
import {BitstreamDataService} from '../../../../../../../core/data/bitstream-data.service';
9+
import {TranslateLoader, TranslateModule, TranslateService} from '@ngx-translate/core';
10+
import {RemoteData} from '../../../../../../../core/data/remote-data';
11+
import {Bitstream} from '../../../../../../../core/shared/bitstream.model';
12+
import {createSuccessfulRemoteDataObject$} from '../../../../../../../shared/remote-data.utils';
13+
import {TranslateLoaderMock} from '../../../../../../../shared/mocks/translate-loader.mock';
14+
import {createPaginatedList} from '../../../../../../../shared/testing/utils.test';
15+
16+
describe('ImageComponent', () => {
17+
let component: ImageComponent;
18+
let fixture: ComponentFixture<ImageComponent>;
19+
20+
const mockField: LayoutField = {
21+
metadata: '',
22+
label: 'Files',
23+
rendering: FieldRenderingType.IMAGE,
24+
fieldType: 'BITSTREAM',
25+
style: null,
26+
styleLabel: 'test-style-label',
27+
styleValue: 'test-style-value',
28+
labelAsHeading: false,
29+
valuesInline: true,
30+
bitstream: {
31+
bundle: 'ORIGINAL',
32+
metadataField: null,
33+
metadataValue: null
34+
}
35+
};
36+
37+
const testItem = Object.assign(new Item(), {
38+
bundles: of({}),
39+
metadata: {
40+
'dc.identifier.doi': [
41+
{
42+
value: 'doi:10.1392/dironix'
43+
}
44+
]
45+
},
46+
_links: {
47+
self: {href: 'obj-selflink'}
48+
},
49+
uuid: 'item-uuid',
50+
});
51+
52+
const mockBitstreamDataService: any = jasmine.createSpyObj('BitstreamDataService', {
53+
getThumbnailFor(item: Item): Observable<RemoteData<Bitstream>> {
54+
return createSuccessfulRemoteDataObject$(new Bitstream());
55+
},
56+
findAllByItemAndBundleName: jasmine.createSpy('findAllByItemAndBundleName'),
57+
findByItem: of(createPaginatedList([new Bitstream()])),
58+
});
59+
const langList = ['en', 'xx', 'de'];
60+
const translateServiceStub: any = {
61+
getLangs: () => {
62+
return langList;
63+
},
64+
getBrowserLang: () => {
65+
return langList;
66+
},
67+
// eslint-disable-next-line @typescript-eslint/no-empty-function
68+
use: (param: string) => {
69+
}
70+
};
71+
72+
beforeEach(async () => {
73+
await TestBed.configureTestingModule({
74+
declarations: [ImageComponent],
75+
imports: [
76+
TranslateModule.forRoot({
77+
loader: {
78+
provide: TranslateLoader,
79+
useClass: TranslateLoaderMock
80+
}
81+
}),
82+
],
83+
providers: [
84+
{provide: 'fieldProvider', useValue: mockField},
85+
{provide: 'itemProvider', useValue: testItem},
86+
{provide: 'renderingSubTypeProvider', useValue: ''},
87+
{provide: 'tabNameProvider', useValue: ''},
88+
{provide: BitstreamDataService, useValue: mockBitstreamDataService},
89+
{provide: TranslateService, useValue: translateServiceStub},
90+
]
91+
})
92+
.compileComponents();
93+
});
94+
95+
beforeEach(() => {
96+
fixture = TestBed.createComponent(ImageComponent);
97+
component = fixture.componentInstance;
98+
fixture.detectChanges();
99+
});
100+
101+
it('should create', () => {
102+
expect(component).toBeTruthy();
103+
});
104+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { FieldRenderingType, MetadataBoxFieldRendering } from '../metadata-box.decorator';
3+
4+
import { BitstreamRenderingModelComponent } from '../bitstream-rendering-model';
5+
import { map } from 'rxjs/operators';
6+
import { Bitstream } from '../../../../../../../core/shared/bitstream.model';
7+
import { BehaviorSubject, Observable } from 'rxjs';
8+
import { getPaginatedListPayload } from '../../../../../../../core/shared/operators';
9+
10+
@Component({
11+
// eslint-disable-next-line @angular-eslint/component-selector
12+
selector: 'div[ds-image]',
13+
templateUrl: './image.component.html',
14+
styleUrls: ['./image.component.scss'],
15+
})
16+
@MetadataBoxFieldRendering(FieldRenderingType.IMAGE, true)
17+
export class ImageComponent extends BitstreamRenderingModelComponent implements OnInit {
18+
19+
bitstream = new BehaviorSubject<Bitstream>(null);
20+
21+
imageUrl$: Observable<string>;
22+
23+
ngOnInit(): void {
24+
this.getBitstreamsByItem().pipe(
25+
getPaginatedListPayload(),
26+
map((filteredBitstreams: Bitstream[]) => filteredBitstreams.length > 0 ? filteredBitstreams[0] : null)
27+
).subscribe((image) => {
28+
this.bitstream.next(image);
29+
});
30+
31+
this.imageUrl$ = this.bitstream.asObservable().pipe(
32+
map((bitstream) => bitstream?._links?.content?.href),
33+
);
34+
35+
}
36+
37+
backgroundImageUrl(url: string) {
38+
return `url('${url}')`;
39+
}
40+
41+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export enum FieldRenderingType {
1010
IDENTIFIER = 'IDENTIFIER',
1111
CRISREF = 'CRISREF',
1212
THUMBNAIL = 'THUMBNAIL',
13+
IMAGE = 'IMAGE',
1314
ATTACHMENT = 'ATTACHMENT',
1415
TABLE = 'TABLE',
1516
INLINE = 'INLINE',

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/row/metadata-container/metadata-container.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export class MetadataContainerComponent implements OnInit {
164164
const rendering = this.computeRendering(this.field);
165165
if (this.field.fieldType === LayoutFieldType.BITSTREAM
166166
&& (rendering.toLocaleLowerCase() === FieldRenderingType.ATTACHMENT.toLocaleLowerCase()
167+
|| rendering.toLocaleLowerCase() === FieldRenderingType.IMAGE.toLocaleLowerCase()
167168
|| rendering.toLocaleLowerCase() === FieldRenderingType.ADVANCEDATTACHMENT.toLocaleLowerCase())) {
168169
this.hasBitstream().pipe(take(1)).subscribe((hasBitstream: boolean) => {
169170
if (hasBitstream) {

src/app/cris-layout/cris-layout.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ import {
158158
import {
159159
LonghtmlComponent
160160
} from './cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/longhtml/longhtml.component';
161+
import {
162+
ImageComponent
163+
} from './cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/image/image.component';
161164

162165
const ENTRY_COMPONENTS = [
163166
// put only entry components that use custom decorator
@@ -199,6 +202,7 @@ const ENTRY_COMPONENTS = [
199202
CrisLayoutMediaBoxComponent,
200203
GooglemapsGroupComponent,
201204
OpenstreetmapGroupComponent,
205+
ImageComponent
202206
];
203207

204208
@NgModule({
@@ -225,6 +229,8 @@ const ENTRY_COMPONENTS = [
225229
MetadataRenderComponent,
226230
BitstreamAttachmentComponent,
227231
AttachmentRenderComponent,
232+
MarkdownComponent,
233+
ImageComponent
228234
],
229235
providers:[ LoadMoreService, NgbActiveModal ],
230236
imports: [

0 commit comments

Comments
 (0)