Skip to content

Commit

Permalink
allow to define layout component previews via template strings
Browse files Browse the repository at this point in the history
  • Loading branch information
aheinze committed Apr 18, 2021
1 parent 3468b3b commit 568b012
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/Cockpit/assets/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -3182,6 +3182,21 @@ riot.tag2('field-layout', '<div class="uk-sortable layout-components {!items.len
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 ? '<div class="uk-text-truncate">'+App.Utils.stripTags(component.settings.text)+'</div>':'';
}
Expand Down
15 changes: 15 additions & 0 deletions modules/Cockpit/assets/components/field-layout.tag
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? '<div class="uk-text-truncate">'+App.Utils.stripTags(component.settings.text)+'</div>':'';
}
Expand Down

0 comments on commit 568b012

Please sign in to comment.