From 568b0124352f6d27df359e8c19a70d2dd1961e87 Mon Sep 17 00:00:00 2001 From: Artur Heinze Date: Sun, 18 Apr 2021 05:39:40 +0200 Subject: [PATCH] allow to define layout component previews via template strings --- modules/Cockpit/assets/components.js | 15 +++++++++++++++ .../Cockpit/assets/components/field-layout.tag | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/modules/Cockpit/assets/components.js b/modules/Cockpit/assets/components.js index a95cb5f0e..c220f6084 100755 --- a/modules/Cockpit/assets/components.js +++ b/modules/Cockpit/assets/components.js @@ -3182,6 +3182,21 @@ riot.tag2('field-layout', '
'+App.Utils.stripTags(component.settings.text)+'
':''; } diff --git a/modules/Cockpit/assets/components/field-layout.tag b/modules/Cockpit/assets/components/field-layout.tag index 09f8c67fd..2473cf0df 100644 --- a/modules/Cockpit/assets/components/field-layout.tag +++ b/modules/Cockpit/assets/components/field-layout.tag @@ -538,6 +538,21 @@ return; } + if (def.options && def.options.preview) { + + if (typeof(def.options.preview) == 'string') { + + try { + def.options.preview = new Function('$v', '$c', '$def', `return \`${def.options.preview}\`;`); + } catch(e) { + console.warn(e); + def.options.preview = null; + } + } + + return (def.options.preview && def.options.preview(component.settings || {}, component, def)) || ''; + } + if (['heading', 'button'].indexOf(component.component) > -1) { return component.settings.text ? '
'+App.Utils.stripTags(component.settings.text)+'
':''; }