Skip to content

Commit 584a8ac

Browse files
davide-negrettialisaismailati
authored andcommitted
[UXP-138] Port of [CST-14002] new "image" rendering type
1 parent 89091ba commit 584a8ac

7 files changed

Lines changed: 79 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!--<div *ngIf="(imageUrl$ | async) as url" [style.background-image]="backgroundImageUrl(url)"></div>-->
2+
<img *ngIf="(imageUrl$ | async) as url" [src]="url">
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,25 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ImageComponent } from './image.component';
4+
5+
describe('ImageComponent', () => {
6+
let component: ImageComponent;
7+
let fixture: ComponentFixture<ImageComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ ImageComponent ]
12+
})
13+
.compileComponents();
14+
});
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(ImageComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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, tap } 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+
import { HALLink } from '../../../../../../../core/shared/hal-link.model';
10+
11+
@Component({
12+
// eslint-disable-next-line @angular-eslint/component-selector
13+
selector: 'div[ds-image]',
14+
templateUrl: './image.component.html',
15+
styleUrls: ['./image.component.scss'],
16+
})
17+
@MetadataBoxFieldRendering(FieldRenderingType.IMAGE, true)
18+
export class ImageComponent extends BitstreamRenderingModelComponent implements OnInit {
19+
20+
bitstream = new BehaviorSubject<Bitstream>(null);
21+
22+
imageUrl$: Observable<string>;
23+
24+
ngOnInit(): void {
25+
this.getBitstreamsByItem().pipe(
26+
getPaginatedListPayload(),
27+
map((filteredBitstreams: Bitstream[]) => filteredBitstreams.length > 0 ? filteredBitstreams[0] : null)
28+
).subscribe((image) => {
29+
this.bitstream.next(image);
30+
});
31+
32+
this.imageUrl$ = this.bitstream.asObservable().pipe(
33+
map((bitstream) => bitstream?._links?.content?.href),
34+
);
35+
36+
}
37+
38+
backgroundImageUrl(url: string) {
39+
return `url('${url}')`;
40+
}
41+
42+
}

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ import { OpenStreetMapModule } from '../shared/open-street-map/open-street-map.m
152152
import { OpenStreetMapRenderingComponent } from './cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/open-street-map/open-street-map-rendering.component';
153153
import { GooglemapsGroupComponent } from './cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/metadataGroup/googlemaps-group/googlemaps-group.component';
154154
import { OpenstreetmapGroupComponent } from './cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/metadataGroup/openstreetmap-group/openstreetmap-group.component';
155+
import { ImageComponent } from './cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/image/image.component';
155156

156157
const ENTRY_COMPONENTS = [
157158
// put only entry components that use custom decorator
@@ -189,6 +190,7 @@ const ENTRY_COMPONENTS = [
189190
SearchComponent,
190191
TagSearchComponent,
191192
CrisLayoutMediaBoxComponent,
193+
ImageComponent,
192194
GooglemapsGroupComponent,
193195
OpenstreetmapGroupComponent,
194196
];
@@ -218,6 +220,7 @@ const ENTRY_COMPONENTS = [
218220
MarkdownComponent,
219221
BitstreamAttachmentComponent,
220222
AttachmentRenderComponent,
223+
ImageComponent,
221224
],
222225
providers:[ LoadMoreService, NgbActiveModal ],
223226
imports: [

0 commit comments

Comments
 (0)