From a7415c4c73cf45a384a2869644f68c7968c02902 Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Wed, 20 Sep 2023 15:05:43 -0400 Subject: [PATCH 1/5] feat: add barcode option to show text. (cherry picked from commit 39cbee473fd024400bcd90f7a8a5aaf5d228b17f) --- .../page/print_designer/jinja/main.html | 3 +- .../page/print_designer/print_designer.py | 6 +- .../js/print_designer/PropertiesPanelState.js | 88 +++++++++++++------ .../components/base/BaseBarcode.vue | 4 +- .../layout/AppBarcodePreviewModal.vue | 5 +- .../js/print_designer/defaultObjects.js | 4 +- 6 files changed, 75 insertions(+), 35 deletions(-) diff --git a/print_designer/print_designer/page/print_designer/jinja/main.html b/print_designer/print_designer/page/print_designer/jinja/main.html index bd4bc9f..41b8443 100644 --- a/print_designer/print_designer/page/print_designer/jinja/main.html +++ b/print_designer/print_designer/page/print_designer/jinja/main.html @@ -75,6 +75,7 @@ style="width:100%;height:100%; {{convert_css(element.style)}}" class="barcode {{ element.classes | join(' ') }}" >{% if value %}{{get_barcode(element.barcodeFormat, value|string, { + "show_text": element.barcodeShowText or "Yes", "module_color": element.barcodeColor or "#000000", "foreground": element.barcodeColor or "#ffffff", "background": element.barcodeBackgroundColor or "#ffffff", @@ -274,4 +275,4 @@ .flexDirectionColumn .baseSpanTag .valueSpanTag { display: block; } - \ No newline at end of file + diff --git a/print_designer/print_designer/page/print_designer/print_designer.py b/print_designer/print_designer/page/print_designer/print_designer.py index e97bddf..9ed0f50 100644 --- a/print_designer/print_designer/page/print_designer/print_designer.py +++ b/print_designer/print_designer/page/print_designer/print_designer.py @@ -218,7 +218,6 @@ def get_barcode( return get_qrcode(barcode_value, options, png_base64) from io import BytesIO - import barcode from barcode.writer import ImageWriter, SVGWriter @@ -263,7 +262,8 @@ def _init(self, code): ) stream = BytesIO() - barcode.write(stream, options) + show_text = options.pop("show_text") + barcode.write(stream, options, text="" if show_text == "No" else None) barcode_value = stream.getvalue().decode("utf-8") stream.close() @@ -302,4 +302,4 @@ def get_qrcode(barcode_value, options=None, png_base64=False): qrcode_svg = stream.getvalue().decode("utf-8") stream.close() - return {"type": "png_base64" if png_base64 else "svg", "value": qrcode_svg} + return {"type": "png_base64" if png_base64 else "svg", "value": qrcode_svg} \ No newline at end of file diff --git a/print_designer/public/js/print_designer/PropertiesPanelState.js b/print_designer/public/js/print_designer/PropertiesPanelState.js index 4624b9c..1d2c82d 100644 --- a/print_designer/public/js/print_designer/PropertiesPanelState.js +++ b/print_designer/public/js/print_designer/PropertiesPanelState.js @@ -1203,34 +1203,70 @@ export const createPropertiesPanel = () => { (MainStore.getCurrentElementsId.length === 1 && MainStore.getCurrentElementsValues[0].type === "barcode"), fields: [ - { - label: "Barcode Format", - name: "barcodeFormat", - isLabelled: true, - condtional: null, - frappeControl: (ref, name) => { - const MainStore = useMainStore(); - const { barcodeFormats } = storeToRefs(MainStore); - makeFeild({ - name: name, - ref: ref, - fieldtype: "Autocomplete", - requiredData: [ - barcodeFormats, - MainStore.getCurrentElementsValues[0] || - MainStore.globalStyles["barcode"], - ], - options: () => barcodeFormats.value, - reactiveObject: () => { - return ( + [ + { + label: "Barcode Format", + name: "barcodeFormat", + isLabelled: true, + condtional: null, + frappeControl: (ref, name) => { + const MainStore = useMainStore(); + const { barcodeFormats } = storeToRefs(MainStore); + makeFeild({ + name: name, + ref: ref, + fieldtype: "Autocomplete", + requiredData: [ + barcodeFormats, MainStore.getCurrentElementsValues[0] || - MainStore.globalStyles["barcode"] - ); - }, - propertyName: "barcodeFormat", - }); + MainStore.globalStyles["barcode"], + ], + options: () => barcodeFormats.value, + reactiveObject: () => { + return ( + MainStore.getCurrentElementsValues[0] || + MainStore.globalStyles["barcode"] + ); + }, + propertyName: "barcodeFormat", + }); + }, }, - }, + ], + [ + { + label: "Show Text", + name: "barcodeShowText", + isLabelled: true, + condtional: () => { + return MainStore.getCurrentElementsValues[0].barcodeFormat !== "qrcode"; + }, + frappeControl: (ref, name) => { + const MainStore = useMainStore(); + console.log(MainStore.getCurrentElementsValues); + makeFeild({ + name: name, + ref: ref, + fieldtype: "Select", + requiredData: [ + MainStore.getCurrentElementsValues[0] || + MainStore.globalStyles["barcode"], + ], + options: () => ([ + { label: "Yes", value: "Yes" }, + { label: "No", value: "No" }, + ]), + reactiveObject: () => { + return ( + MainStore.getCurrentElementsValues[0] || + MainStore.globalStyles["barcode"] + ); + }, + propertyName: "barcodeShowText", + }); + }, + } + ], [ colorStyleFrappeControl("Color", "barcodeColor", "barcodeColor", false, false), colorStyleFrappeControl( diff --git a/print_designer/public/js/print_designer/components/base/BaseBarcode.vue b/print_designer/public/js/print_designer/components/base/BaseBarcode.vue index 8bacc9d..1997700 100644 --- a/print_designer/public/js/print_designer/components/base/BaseBarcode.vue +++ b/print_designer/public/js/print_designer/components/base/BaseBarcode.vue @@ -61,7 +61,7 @@ const { value, dynamicContent, barcodeFormat, - barcodeColor, + barcodeShowText,barcodeColor, barcodeBackgroundColor, startX, startY, @@ -133,7 +133,7 @@ watch( options["module_color"] = barcodeColor.value || "#000000"; } else { options["foreground"] = barcodeColor.value || "#000000"; - } + options["show_text"] = barcodeShowText.value || "Yes";} let finalValue = value.value; if (finalValue != "") { try { diff --git a/print_designer/public/js/print_designer/components/layout/AppBarcodePreviewModal.vue b/print_designer/public/js/print_designer/components/layout/AppBarcodePreviewModal.vue index 3b8905e..caf5bb3 100644 --- a/print_designer/public/js/print_designer/components/layout/AppBarcodePreviewModal.vue +++ b/print_designer/public/js/print_designer/components/layout/AppBarcodePreviewModal.vue @@ -121,7 +121,7 @@ const setLabel = (value) => { label.value = value; } }; -const { barcodeColor, barcodeBackgroundColor, isDynamic, barcodeFormat, style } = toRefs( +const { barcodeColor, barcodeBackgroundColor, isDynamic, barcodeFormat, barcodeShowText, style } = toRefs( MainStore.getCurrentElementsValues[0] ); onMounted(() => { @@ -195,6 +195,7 @@ const setBarcode = async () => { options["module_color"] = barcodeColor.value || "#000000"; } else { options["foreground"] = barcodeColor.value || "#000000"; + options["show_text"] = barcodeShowText.value || "Yes"; } let value = props.fieldnames[0].value; if (props.fieldnames[0].parseJinja && value != "") { @@ -227,7 +228,7 @@ const setBarcode = async () => { }; watch( - () => [props.fieldnames, barcodeFormat.value, MainStore.mainParsedJinjaData], + () => [props.fieldnames, barcodeFormat.value, barcodeShowText.value, MainStore.mainParsedJinjaData], () => setBarcode(), { deep: true, immediate: true } ); diff --git a/print_designer/public/js/print_designer/defaultObjects.js b/print_designer/public/js/print_designer/defaultObjects.js index 2b64547..4ea237b 100644 --- a/print_designer/public/js/print_designer/defaultObjects.js +++ b/print_designer/public/js/print_designer/defaultObjects.js @@ -100,6 +100,7 @@ export const createBarcode = (cordinates, parent = null) => { id: id, type: "barcode", barcodeFormat: MainStore.globalStyles["barcode"].barcodeFormat || "qrcode", + barcodeShowText: MainStore.globalStyles["barcode"].barcodeShowText || "Yes", barcodeColor: "#000000", barcodeBackgroundColor: "#ffffff", DOMRef: null, @@ -441,4 +442,5 @@ export const barcodeFormats = [ { label: "ITF", value: "itf" }, { label: "GS1", value: "gs1" }, { label: "Gs1_128", value: "gs1_128" }, -]; +] +; \ No newline at end of file From 8b0f6fc763b1b7d462e7a5c0f254935f2b9f0a5c Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Sat, 23 Sep 2023 08:27:40 -0400 Subject: [PATCH 2/5] chore: remove console.log --- print_designer/public/js/print_designer/PropertiesPanelState.js | 1 - 1 file changed, 1 deletion(-) diff --git a/print_designer/public/js/print_designer/PropertiesPanelState.js b/print_designer/public/js/print_designer/PropertiesPanelState.js index 1d2c82d..51245ad 100644 --- a/print_designer/public/js/print_designer/PropertiesPanelState.js +++ b/print_designer/public/js/print_designer/PropertiesPanelState.js @@ -1243,7 +1243,6 @@ export const createPropertiesPanel = () => { }, frappeControl: (ref, name) => { const MainStore = useMainStore(); - console.log(MainStore.getCurrentElementsValues); makeFeild({ name: name, ref: ref, From ad211c324cddce9982e393fbbd2d778af0abad7c Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Sat, 23 Sep 2023 08:52:38 -0400 Subject: [PATCH 3/5] fix: barcodeShowText format between boolean and text Co-authored-by: Maharshi Patel --- .../public/js/print_designer/PropertiesPanelState.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/print_designer/public/js/print_designer/PropertiesPanelState.js b/print_designer/public/js/print_designer/PropertiesPanelState.js index 51245ad..4b8100d 100644 --- a/print_designer/public/js/print_designer/PropertiesPanelState.js +++ b/print_designer/public/js/print_designer/PropertiesPanelState.js @@ -1262,6 +1262,16 @@ export const createPropertiesPanel = () => { ); }, propertyName: "barcodeShowText", + formatValue: (object, property) => { + if (!object) return; + return (object[property] === undefined || object[property]) ? "Yes" : "No"; + }, + onChangeCallback: (value = null) => { + if (value && MainStore.getCurrentElementsValues[0]) { + MainStore.getCurrentElementsValues[0]["barcodeShowText"] = value !== "No" + MainStore.frappeControls["barcodeShowText"].$input.blur(); + } + }, }); }, } From 798bcc0763fbef0467089fbb40a3ec8b61522367 Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Sat, 23 Sep 2023 08:53:29 -0400 Subject: [PATCH 4/5] fix: convert barcodeShowText usages to boolean --- .../print_designer/page/print_designer/jinja/main.html | 2 +- .../print_designer/page/print_designer/print_designer.py | 2 +- .../public/js/print_designer/components/base/BaseBarcode.vue | 2 +- .../print_designer/components/layout/AppBarcodePreviewModal.vue | 2 +- print_designer/public/js/print_designer/defaultObjects.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/print_designer/print_designer/page/print_designer/jinja/main.html b/print_designer/print_designer/page/print_designer/jinja/main.html index 41b8443..14c92f0 100644 --- a/print_designer/print_designer/page/print_designer/jinja/main.html +++ b/print_designer/print_designer/page/print_designer/jinja/main.html @@ -75,7 +75,7 @@ style="width:100%;height:100%; {{convert_css(element.style)}}" class="barcode {{ element.classes | join(' ') }}" >{% if value %}{{get_barcode(element.barcodeFormat, value|string, { - "show_text": element.barcodeShowText or "Yes", + "show_text": element.barcodeShowText, "module_color": element.barcodeColor or "#000000", "foreground": element.barcodeColor or "#ffffff", "background": element.barcodeBackgroundColor or "#ffffff", diff --git a/print_designer/print_designer/page/print_designer/print_designer.py b/print_designer/print_designer/page/print_designer/print_designer.py index 9ed0f50..e90cbc1 100644 --- a/print_designer/print_designer/page/print_designer/print_designer.py +++ b/print_designer/print_designer/page/print_designer/print_designer.py @@ -263,7 +263,7 @@ def _init(self, code): stream = BytesIO() show_text = options.pop("show_text") - barcode.write(stream, options, text="" if show_text == "No" else None) + barcode.write(stream, options, text="" if not show_text else None) barcode_value = stream.getvalue().decode("utf-8") stream.close() diff --git a/print_designer/public/js/print_designer/components/base/BaseBarcode.vue b/print_designer/public/js/print_designer/components/base/BaseBarcode.vue index 1997700..aa79360 100644 --- a/print_designer/public/js/print_designer/components/base/BaseBarcode.vue +++ b/print_designer/public/js/print_designer/components/base/BaseBarcode.vue @@ -133,7 +133,7 @@ watch( options["module_color"] = barcodeColor.value || "#000000"; } else { options["foreground"] = barcodeColor.value || "#000000"; - options["show_text"] = barcodeShowText.value || "Yes";} + options["show_text"] = barcodeShowText.value;} let finalValue = value.value; if (finalValue != "") { try { diff --git a/print_designer/public/js/print_designer/components/layout/AppBarcodePreviewModal.vue b/print_designer/public/js/print_designer/components/layout/AppBarcodePreviewModal.vue index caf5bb3..e2f7b10 100644 --- a/print_designer/public/js/print_designer/components/layout/AppBarcodePreviewModal.vue +++ b/print_designer/public/js/print_designer/components/layout/AppBarcodePreviewModal.vue @@ -195,7 +195,7 @@ const setBarcode = async () => { options["module_color"] = barcodeColor.value || "#000000"; } else { options["foreground"] = barcodeColor.value || "#000000"; - options["show_text"] = barcodeShowText.value || "Yes"; + options["show_text"] = barcodeShowText.value; } let value = props.fieldnames[0].value; if (props.fieldnames[0].parseJinja && value != "") { diff --git a/print_designer/public/js/print_designer/defaultObjects.js b/print_designer/public/js/print_designer/defaultObjects.js index 4ea237b..3cd0c21 100644 --- a/print_designer/public/js/print_designer/defaultObjects.js +++ b/print_designer/public/js/print_designer/defaultObjects.js @@ -100,7 +100,7 @@ export const createBarcode = (cordinates, parent = null) => { id: id, type: "barcode", barcodeFormat: MainStore.globalStyles["barcode"].barcodeFormat || "qrcode", - barcodeShowText: MainStore.globalStyles["barcode"].barcodeShowText || "Yes", + barcodeShowText: MainStore.globalStyles["barcode"].barcodeShowText === undefined || MainStore.globalStyles["barcode"].barcodeShowText === "Yes", barcodeColor: "#000000", barcodeBackgroundColor: "#ffffff", DOMRef: null, From 424a260e319ba0d5b3901ad06f0752663d93b49b Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Sat, 23 Sep 2023 09:07:57 -0400 Subject: [PATCH 5/5] fix: patch globalStyles with barcodeShowText --- print_designer/patches.txt | 3 ++- print_designer/patches/barcode_show_text.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 print_designer/patches/barcode_show_text.py diff --git a/print_designer/patches.txt b/print_designer/patches.txt index 1bd155f..dfade81 100644 --- a/print_designer/patches.txt +++ b/print_designer/patches.txt @@ -4,4 +4,5 @@ print_designer.patches.introduce_jinja print_designer.patches.introduce_schema_versioning print_designer.patches.rerun_introduce_jinja print_designer.patches.introduce_table_alt_row_styles -print_designer.patches.introduce_column_style \ No newline at end of file +print_designer.patches.introduce_column_style +print_designer.patches.barcode_show_text diff --git a/print_designer/patches/barcode_show_text.py b/print_designer/patches/barcode_show_text.py new file mode 100644 index 0000000..2360a42 --- /dev/null +++ b/print_designer/patches/barcode_show_text.py @@ -0,0 +1,9 @@ +import frappe + + +def execute(): + for name, print_format in frappe.get_all("Print Format", filters={"print_designer": 1}, fields=["name", "print_designer_settings"], as_list=1): + print_format = frappe.parse_json(print_format) + if print_format and "barcode" in print_format["globalStyles"]: + print_format["globalStyles"]["barcode"]["showBarcodeText"] = True + frappe.set_value("Print Format", name, "print_designer_settings", frappe.as_json(print_format))