Better rendering for parameter table (#4943)

- Use trueFalseLabel
This commit is contained in:
Oliver 2023-06-01 20:30:53 +10:00 committed by GitHub
parent 46a808c064
commit 037654610e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -37,6 +37,8 @@
/* exported /* exported
makeIcon, makeIcon,
trueFalseLabel,
yesNoLabel,
*/ */
@ -87,6 +89,14 @@ function yesNoLabel(value, options={}) {
} }
function trueFalseLabel(value, options={}) {
options.pass = '{% trans "True" %}';
options.fail = '{% trans "False" %}';
return yesNoLabel(value, options);
}
function editButton(url, text='{% trans "Edit" %}') { function editButton(url, text='{% trans "Edit" %}') {
return `<button class='btn btn-success edit-button btn-sm' type='button' url='${url}'>${text}</button>`; return `<button class='btn btn-success edit-button btn-sm' type='button' url='${url}'>${text}</button>`;
} }

View File

@ -44,6 +44,7 @@
showMessage, showMessage,
showModalSpinner, showModalSpinner,
thumbnailImage, thumbnailImage,
trueFalseLabel,
updateFieldValue, updateFieldValue,
withTitle, withTitle,
wrapButtons, wrapButtons,
@ -1468,10 +1469,7 @@ function loadPartParameterTable(table, options) {
let template = row.template_detail; let template = row.template_detail;
if (template.checkbox) { if (template.checkbox) {
return yesNoLabel(value, { return trueFalseLabel(value);
pass: '{% trans "True" %}',
fail: '{% trans "False" %}',
});
} }
if (row.data_numeric && row.template_detail.units) { if (row.data_numeric && row.template_detail.units) {
@ -2019,6 +2017,18 @@ function loadParametricPartTable(table, options={}) {
template_name += ` [${template.units}]`; template_name += ` [${template.units}]`;
} }
let fmt_func = null;
if (template.checkbox) {
fmt_func = function(value) {
if (value == null) {
return null;
} else {
return trueFalseLabel(value);
}
}
}
columns.push({ columns.push({
field: `parameter_${template.pk}`, field: `parameter_${template.pk}`,
title: template_name, title: template_name,
@ -2026,6 +2036,7 @@ function loadParametricPartTable(table, options={}) {
sortable: true, sortable: true,
filterControl: 'input', filterControl: 'input',
visible: false, visible: false,
formatter: fmt_func,
}); });
} }
} }