mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
AAE-42908 Evaluate expressions for rich-text-display list types (#11726)
This commit is contained in:
+106
@@ -467,5 +467,111 @@ describe('DisplayRichTextWidgetComponent', () => {
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
describe('list block type', () => {
|
||||
it('should resolve expressions in unordered list blocks', () => {
|
||||
const form = new FormModel({
|
||||
fields: [
|
||||
{
|
||||
id: 'richText1',
|
||||
type: 'display-rich-text',
|
||||
value: {
|
||||
time: 1658154611110,
|
||||
blocks: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'list',
|
||||
data: {
|
||||
style: 'unordered',
|
||||
items: [{ content: 'Hello ${field.name}', items: [] }]
|
||||
}
|
||||
}
|
||||
],
|
||||
version: 1
|
||||
}
|
||||
},
|
||||
{ id: 'name', type: 'text', value: 'Yngwie' }
|
||||
]
|
||||
});
|
||||
|
||||
widget.field = form.getFieldById('richText1');
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(widget.field.value.blocks[0].data.items[0].content).toBe('Hello Yngwie');
|
||||
});
|
||||
|
||||
it('should resolve expressions in ordered list blocks', () => {
|
||||
const form = new FormModel({
|
||||
fields: [
|
||||
{
|
||||
id: 'richText1',
|
||||
type: 'display-rich-text',
|
||||
value: {
|
||||
time: 1658154611110,
|
||||
blocks: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'list',
|
||||
data: {
|
||||
style: 'ordered',
|
||||
items: [
|
||||
{ content: 'First: ${field.firstName}', items: [] },
|
||||
{ content: 'Last: ${field.lastName}', items: [] }
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
version: 1
|
||||
}
|
||||
},
|
||||
{ id: 'firstName', type: 'text', value: 'Mike' },
|
||||
{ id: 'lastName', type: 'text', value: 'Watt' }
|
||||
]
|
||||
});
|
||||
|
||||
widget.field = form.getFieldById('richText1');
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(widget.field.value.blocks[0].data.items[0].content).toBe('First: Mike');
|
||||
expect(widget.field.value.blocks[0].data.items[1].content).toBe('Last: Watt');
|
||||
});
|
||||
|
||||
it('should resolve expressions in checklists', () => {
|
||||
const form = new FormModel({
|
||||
fields: [
|
||||
{
|
||||
id: 'richText1',
|
||||
type: 'display-rich-text',
|
||||
value: {
|
||||
time: 1658154611110,
|
||||
blocks: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'paragraph',
|
||||
data: { text: 'Hello ${field.name}' }
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: 'list',
|
||||
data: {
|
||||
style: 'checklist',
|
||||
items: [{ content: 'Item for ${field.name}', items: [] }]
|
||||
}
|
||||
}
|
||||
],
|
||||
version: 1
|
||||
}
|
||||
},
|
||||
{ id: 'name', type: 'text', value: 'Yngwie' }
|
||||
]
|
||||
});
|
||||
|
||||
widget.field = form.getFieldById('richText1');
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(widget.field.value.blocks[0].data.text).toBe('Hello Yngwie');
|
||||
expect(widget.field.value.blocks[1].data.items[0].content).toBe('Item for Yngwie');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+7
-1
@@ -90,7 +90,13 @@ export class DisplayRichTextWidgetComponent extends BaseDisplayTextWidgetCompone
|
||||
|
||||
private applyExpressionsToBlocks(value: any): void {
|
||||
for (const block of value.blocks) {
|
||||
block.data.text = this.resolveExpressions(block.data.text, true);
|
||||
if (block.type === 'list') {
|
||||
for (const item of block.data.items) {
|
||||
item.content = this.resolveExpressions(item.content, true);
|
||||
}
|
||||
} else {
|
||||
block.data.text = this.resolveExpressions(block.data.text, true);
|
||||
}
|
||||
}
|
||||
this.field.value = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user