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
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" %}') {
return `<button class='btn btn-success edit-button btn-sm' type='button' url='${url}'>${text}</button>`;
}

View File

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