diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 41875a0..22410a9 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -254,7 +254,8 @@ "coaxial": "Coextruded", "longitudinal": "Longitudinal", "external_id": "External ID", - "spools": "Show Spools" + "spools": "Show Spools", + "not_set": "Not Set" }, "fields_help": { "name": "Filament name, to distinguish this filament type among others from the same manufacturer. Should contain the color for example.", diff --git a/client/src/pages/filaments/show.tsx b/client/src/pages/filaments/show.tsx index 7561366..ace7e84 100644 --- a/client/src/pages/filaments/show.tsx +++ b/client/src/pages/filaments/show.tsx @@ -131,16 +131,20 @@ export const FilamentShow: React.FC = () => { }} /> {t("filament.fields.settings_extruder_temp")} - {!record?.settings_extruder_temp ? ( - + {!record?.settings_extruder_temp_min && !record?.settings_extruder_temp_max ? ( + + ) : record?.settings_extruder_temp_min === record?.settings_extruder_temp_max || !record?.settings_extruder_temp_max ? ( + ) : ( - + )} {t("filament.fields.settings_bed_temp")} - {!record?.settings_bed_temp ? ( - + {!record?.settings_bed_temp_min && !record?.settings_bed_temp_max ? ( + + ) : record?.settings_bed_temp_min === record?.settings_bed_temp_max || !record?.settings_bed_temp_max ? ( + ) : ( - + )} {t("filament.fields.article_number")} diff --git a/client/src/pages/printing/printing.tsx b/client/src/pages/printing/printing.tsx index 10147ab..d15deb1 100644 --- a/client/src/pages/printing/printing.tsx +++ b/client/src/pages/printing/printing.tsx @@ -102,24 +102,45 @@ function applyTextFormatting(text: string): ReactElement[] { export function renderLabelContents(template: string, spool: ISpool): ReactElement { // Find all {tags} in the template string and loop over them - // let matches = [...template.matchAll(/(?:{(.*?))?{(.*?)}(.*?)(?:}(.*?))?/gs)]; let matches = [...template.matchAll(/{(?:[^}{]|{[^}{]*})*}/gs)]; let label_text = template; 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 tagValue = getTagValue(tag, spool); label_text = label_text.replace(match[0], tagValue); - } else if ((match[0].match(/{/g) || []).length == 2) { - let structure = match[0].match(/{(.*?){(.*?)}(.*?)}/); - if (structure != null) { - const tag = structure[2]; - let tagValue = getTagValue(tag, spool); - if (tagValue == "?") { - label_text = label_text.replace(match[0], ""); - } else { - label_text = label_text.replace(match[0], structure[1] + tagValue + structure[3]); + } else if (braceCount >= 2) { + // Conditional block with one or more inner tags: {prefix {tag1} middle {tag2} suffix} + // First, extract the outer content and find all inner tags + const outerContent = match[0].slice(1, -1); // Remove outer braces + const innerTagMatches = [...outerContent.matchAll(/{([^{}]+)}/g)]; + + if (innerTagMatches.length === 0) { + // No inner tags found, leave as-is + 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], ""); } } });