Fix temp range display in show page and label templates

- Show page now displays temp ranges (min-max) instead of single values
- Fixed label template rendering to handle multiple tags in conditional blocks
- Added "not_set" translation key

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-14 23:59:54 -06:00
parent 10b98957b8
commit 46cc0656d6
3 changed files with 44 additions and 18 deletions

View File

@@ -254,7 +254,8 @@
"coaxial": "Coextruded", "coaxial": "Coextruded",
"longitudinal": "Longitudinal", "longitudinal": "Longitudinal",
"external_id": "External ID", "external_id": "External ID",
"spools": "Show Spools" "spools": "Show Spools",
"not_set": "Not Set"
}, },
"fields_help": { "fields_help": {
"name": "Filament name, to distinguish this filament type among others from the same manufacturer. Should contain the color for example.", "name": "Filament name, to distinguish this filament type among others from the same manufacturer. Should contain the color for example.",

View File

@@ -131,16 +131,20 @@ export const FilamentShow: React.FC<IResourceComponentsProps> = () => {
}} }}
/> />
<Title level={5}>{t("filament.fields.settings_extruder_temp")}</Title> <Title level={5}>{t("filament.fields.settings_extruder_temp")}</Title>
{!record?.settings_extruder_temp ? ( {!record?.settings_extruder_temp_min && !record?.settings_extruder_temp_max ? (
<TextField value="Not Set" /> <TextField value={t("filament.fields.not_set")} />
) : record?.settings_extruder_temp_min === record?.settings_extruder_temp_max || !record?.settings_extruder_temp_max ? (
<NumberFieldUnit value={record?.settings_extruder_temp_min ?? ""} unit="°C" />
) : ( ) : (
<NumberFieldUnit value={record?.settings_extruder_temp ?? ""} unit="°C" /> <TextField value={`${record?.settings_extruder_temp_min ?? "?"} - ${record?.settings_extruder_temp_max ?? "?"} °C`} />
)} )}
<Title level={5}>{t("filament.fields.settings_bed_temp")}</Title> <Title level={5}>{t("filament.fields.settings_bed_temp")}</Title>
{!record?.settings_bed_temp ? ( {!record?.settings_bed_temp_min && !record?.settings_bed_temp_max ? (
<TextField value="Not Set" /> <TextField value={t("filament.fields.not_set")} />
) : record?.settings_bed_temp_min === record?.settings_bed_temp_max || !record?.settings_bed_temp_max ? (
<NumberFieldUnit value={record?.settings_bed_temp_min ?? ""} unit="°C" />
) : ( ) : (
<NumberFieldUnit value={record?.settings_bed_temp ?? ""} unit="°C" /> <TextField value={`${record?.settings_bed_temp_min ?? "?"} - ${record?.settings_bed_temp_max ?? "?"} °C`} />
)} )}
<Title level={5}>{t("filament.fields.article_number")}</Title> <Title level={5}>{t("filament.fields.article_number")}</Title>
<TextField value={record?.article_number} /> <TextField value={record?.article_number} />

View File

@@ -102,24 +102,45 @@ function applyTextFormatting(text: string): ReactElement[] {
export function renderLabelContents(template: string, spool: ISpool): ReactElement { export function renderLabelContents(template: string, spool: ISpool): ReactElement {
// Find all {tags} in the template string and loop over them // Find all {tags} in the template string and loop over them
// let matches = [...template.matchAll(/(?:{(.*?))?{(.*?)}(.*?)(?:}(.*?))?/gs)];
let matches = [...template.matchAll(/{(?:[^}{]|{[^}{]*})*}/gs)]; let matches = [...template.matchAll(/{(?:[^}{]|{[^}{]*})*}/gs)];
let label_text = template; let label_text = template;
matches.forEach((match) => { matches.forEach((match) => {
if ((match[0].match(/{/g) || []).length == 1) { const braceCount = (match[0].match(/{/g) || []).length;
if (braceCount == 1) {
// Simple tag: {tag}
let tag = match[0].replace(/[{}]/g, ""); let tag = match[0].replace(/[{}]/g, "");
let tagValue = getTagValue(tag, spool); let tagValue = getTagValue(tag, spool);
label_text = label_text.replace(match[0], tagValue); label_text = label_text.replace(match[0], tagValue);
} else if ((match[0].match(/{/g) || []).length == 2) { } else if (braceCount >= 2) {
let structure = match[0].match(/{(.*?){(.*?)}(.*?)}/); // Conditional block with one or more inner tags: {prefix {tag1} middle {tag2} suffix}
if (structure != null) { // First, extract the outer content and find all inner tags
const tag = structure[2]; const outerContent = match[0].slice(1, -1); // Remove outer braces
let tagValue = getTagValue(tag, spool); const innerTagMatches = [...outerContent.matchAll(/{([^{}]+)}/g)];
if (tagValue == "?") {
label_text = label_text.replace(match[0], ""); if (innerTagMatches.length === 0) {
} else { // No inner tags found, leave as-is
label_text = label_text.replace(match[0], structure[1] + tagValue + structure[3]); return;
}
// Check if any inner tag resolves to "?" (missing value)
let allTagsValid = true;
let processedContent = outerContent;
for (const innerMatch of innerTagMatches) {
const tag = innerMatch[1];
const tagValue = getTagValue(tag, spool);
if (tagValue === "?" || tagValue === null || tagValue === undefined) {
allTagsValid = false;
break;
} }
processedContent = processedContent.replace(innerMatch[0], String(tagValue));
}
if (allTagsValid) {
label_text = label_text.replace(match[0], processedContent);
} else {
// If any tag is missing, remove the entire conditional block
label_text = label_text.replace(match[0], "");
} }
} }
}); });