Skip to content

Commit 9286001

Browse files
author
Andrea Barbasso
committed
[UXP-141] add longhtml and longmarkdown rendering components
1 parent 57c536b commit 9286001

12 files changed

Lines changed: 271 additions & 10 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div [class]="field.styleValue">
2+
<ds-truncatable [id]="truncatableId">
3+
<ds-truncatable-part [id]="truncatableId" [minLines]="8">
4+
<span [innerHTML]="processHtml(metadataValue.value)" class="text-value"></span>
5+
</ds-truncatable-part>
6+
</ds-truncatable>
7+
</div>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/longhtml/longhtml.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3+
import { By } from '@angular/platform-browser';
4+
5+
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
6+
7+
import { LonghtmlComponent } from './longhtml.component';
8+
import { Item } from '../../../../../../../core/shared/item.model';
9+
import { TranslateLoaderMock } from '../../../../../../../shared/mocks/translate-loader.mock';
10+
import { DsDatePipe } from '../../../../../../pipes/ds-date.pipe';
11+
import { LayoutField } from '../../../../../../../core/layout/models/box.model';
12+
import { MetadataValue } from '../../../../../../../core/shared/metadata.models';
13+
14+
describe('LonghtmlComponent', () => {
15+
let component: LonghtmlComponent;
16+
let fixture: ComponentFixture<LonghtmlComponent>;
17+
18+
const metadataValue = Object.assign(new MetadataValue(), {
19+
'value': 'test item title',
20+
'language': null,
21+
'authority': null,
22+
'confidence': -1,
23+
'place': 0
24+
});
25+
26+
const testItem = Object.assign(new Item(),
27+
{
28+
type: 'item',
29+
metadata: {
30+
'dc.title': [metadataValue]
31+
},
32+
uuid: 'test-item-uuid',
33+
}
34+
);
35+
36+
37+
const mockField: LayoutField = {
38+
'metadata': 'dc.title',
39+
'label': 'Title',
40+
'rendering': 'html',
41+
'fieldType': 'METADATA',
42+
'style': null,
43+
'styleLabel': 'test-style-label',
44+
'styleValue': 'test-style-value',
45+
'labelAsHeading': false,
46+
'valuesInline': true
47+
};
48+
49+
beforeEach(waitForAsync(() => {
50+
TestBed.configureTestingModule({
51+
imports: [TranslateModule.forRoot({
52+
loader: {
53+
provide: TranslateLoader,
54+
useClass: TranslateLoaderMock
55+
}
56+
}), BrowserAnimationsModule],
57+
providers: [
58+
{ provide: 'fieldProvider', useValue: mockField },
59+
{ provide: 'itemProvider', useValue: testItem },
60+
{ provide: 'metadataValueProvider', useValue: metadataValue },
61+
{ provide: 'renderingSubTypeProvider', useValue: '' },
62+
{ provide: 'tabNameProvider', useValue: '' },
63+
],
64+
declarations: [LonghtmlComponent, DsDatePipe]
65+
})
66+
.compileComponents();
67+
}));
68+
69+
beforeEach(() => {
70+
fixture = TestBed.createComponent(LonghtmlComponent);
71+
component = fixture.componentInstance;
72+
fixture.detectChanges();
73+
});
74+
75+
it('should create', () => {
76+
expect(component).toBeTruthy();
77+
});
78+
79+
it('check metadata rendering', (done) => {
80+
const spanValueFound = fixture.debugElement.queryAll(By.css('span.text-value'));
81+
expect(spanValueFound.length).toBe(1);
82+
expect(spanValueFound[0].nativeElement.textContent).toContain(metadataValue.value);
83+
done();
84+
});
85+
86+
it('check value style', (done) => {
87+
const spanValueFound = fixture.debugElement.queryAll(By.css('.test-style-value'));
88+
expect(spanValueFound.length).toBe(1);
89+
done();
90+
});
91+
92+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
import { FieldRenderingType, MetadataBoxFieldRendering } from '../metadata-box.decorator';
4+
import { RenderingTypeValueModelComponent } from '../rendering-type-value.model';
5+
6+
/**
7+
* This component renders the text metadata fields with a show more button
8+
*/
9+
@Component({
10+
// eslint-disable-next-line @angular-eslint/component-selector
11+
selector: 'span[ds-longhtml]',
12+
templateUrl: './longhtml.component.html',
13+
styleUrls: ['./longhtml.component.scss']
14+
})
15+
@MetadataBoxFieldRendering(FieldRenderingType.LONGHTML)
16+
export class LonghtmlComponent extends RenderingTypeValueModelComponent implements OnInit {
17+
18+
/**
19+
* Id for truncatable component
20+
*/
21+
truncatableId: string;
22+
23+
ngOnInit(): void {
24+
this.truncatableId = `${this.item.id}_${this.field.metadata}_html`;
25+
}
26+
27+
/**
28+
* If the metadata value does not contain HTML tags then replace newline character with <br>
29+
* @param text
30+
*/
31+
processHtml(text: string): string {
32+
const htmlTagRegex = /<.*?>/;
33+
return htmlTagRegex.test(text) ? text.replace(/\n/, '<br>') : text;
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div class="mb-2">
2+
<div class="{{field.styleValue}}">
3+
<ds-truncatable [id]="truncatableId">
4+
<ds-truncatable-part [id]="truncatableId" [minLines]="8">
5+
<ds-markdown-viewer [value]="metadataValue.value"></ds-markdown-viewer>
6+
</ds-truncatable-part>
7+
</ds-truncatable>
8+
</div>
9+
</div>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/longmarkdown/longmarkdown.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3+
import { By } from '@angular/platform-browser';
4+
5+
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
6+
7+
import { LongmarkdownComponent } from './longmarkdown.component';
8+
import { Item } from '../../../../../../../core/shared/item.model';
9+
import { TranslateLoaderMock } from '../../../../../../../shared/mocks/translate-loader.mock';
10+
import { LayoutField } from '../../../../../../../core/layout/models/box.model';
11+
import { MetadataValue } from '../../../../../../../core/shared/metadata.models';
12+
13+
describe('LongmarkdownComponent', () => {
14+
let component: LongmarkdownComponent;
15+
let fixture: ComponentFixture<LongmarkdownComponent>;
16+
17+
const metadataValue = Object.assign(new MetadataValue(), {
18+
'value': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.',
19+
'language': null,
20+
'authority': null,
21+
'confidence': -1,
22+
'place': 0
23+
});
24+
25+
const testItem = Object.assign(new Item(),
26+
{
27+
type: 'item',
28+
metadata: {
29+
'dc.abstract': [metadataValue]
30+
},
31+
uuid: 'test-item-uuid',
32+
}
33+
);
34+
35+
36+
const mockField: LayoutField = {
37+
'metadata': 'dc.abstract',
38+
'label': 'Preferred name',
39+
'rendering': 'markdown',
40+
'fieldType': 'METADATA',
41+
'style': null,
42+
'styleLabel': 'test-style-label',
43+
'styleValue': 'test-style-value',
44+
'labelAsHeading': false,
45+
'valuesInline': true
46+
};
47+
48+
beforeEach(waitForAsync(() => {
49+
TestBed.configureTestingModule({
50+
imports: [TranslateModule.forRoot({
51+
loader: {
52+
provide: TranslateLoader,
53+
useClass: TranslateLoaderMock
54+
}
55+
}), BrowserAnimationsModule],
56+
providers: [
57+
{ provide: 'fieldProvider', useValue: mockField },
58+
{ provide: 'itemProvider', useValue: testItem },
59+
{ provide: 'metadataValueProvider', useValue: metadataValue },
60+
{ provide: 'renderingSubTypeProvider', useValue: '' },
61+
{ provide: 'tabNameProvider', useValue: '' },
62+
],
63+
declarations: [LongmarkdownComponent]
64+
})
65+
.compileComponents();
66+
}));
67+
68+
beforeEach(() => {
69+
fixture = TestBed.createComponent(LongmarkdownComponent);
70+
component = fixture.componentInstance;
71+
fixture.detectChanges();
72+
});
73+
74+
it('should create', () => {
75+
expect(component).toBeTruthy();
76+
});
77+
78+
it('check metadata rendering', (done) => {
79+
const spanValueFound = fixture.debugElement.queryAll(By.css('ds-markdown-viewer'));
80+
expect(spanValueFound.length).toBe(1);
81+
done();
82+
});
83+
84+
it('check value style', (done) => {
85+
const spanValueFound = fixture.debugElement.queryAll(By.css('.test-style-value'));
86+
expect(spanValueFound.length).toBe(1);
87+
done();
88+
});
89+
90+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
import { FieldRenderingType, MetadataBoxFieldRendering } from '../metadata-box.decorator';
4+
import { RenderingTypeValueModelComponent } from '../rendering-type-value.model';
5+
6+
/**
7+
* This component renders the markdown metadata fields with a show more button
8+
*/
9+
@Component({
10+
// eslint-disable-next-line @angular-eslint/component-selector
11+
selector: 'div[ds-longmarkdown]',
12+
templateUrl: './longmarkdown.component.html',
13+
styleUrls: ['./longmarkdown.component.scss']
14+
})
15+
@MetadataBoxFieldRendering(FieldRenderingType.LONGMARKDOWN)
16+
export class LongmarkdownComponent extends RenderingTypeValueModelComponent implements OnInit {
17+
18+
/**
19+
* Id for truncable component
20+
*/
21+
truncatableId: string;
22+
23+
ngOnInit(): void {
24+
this.truncatableId = `${this.item.id}_${this.field.metadata}_md`;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="mb-2">
2-
<div class="{{field.styleValue}}">
2+
<div class="{{field.styleValue}}">
33
<ds-markdown-viewer [value]="metadataValue.value"></ds-markdown-viewer>
44
</div>
55
</div>

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,4 @@ import { RenderingTypeValueModelComponent } from '../rendering-type-value.model'
1515
@MetadataBoxFieldRendering(FieldRenderingType.MARKDOWN)
1616
export class MarkdownComponent extends RenderingTypeValueModelComponent {
1717

18-
/**
19-
* Id for truncable component
20-
*/
21-
truncableId: string;
22-
23-
ngOnInit(): void {
24-
this.truncableId = `${this.item.id}_${this.field.metadata}`;
25-
}
2618
}

0 commit comments

Comments
 (0)