print_designer icon indicating copy to clipboard operation
print_designer copied to clipboard

feat: add barcode option to show text

Open dj12djdjs opened this issue 2 years ago • 16 comments

add option to show text for non QR barcode types..

  • [x] Print Design and PDF Generation (Success)
  • [x] Patch existing gloablStyles
  • [ ] Patch elements (https://github.com/frappe/print_designer/pull/63#issuecomment-1732313025)

https://github.com/frappe/print_designer/assets/29856401/506f6918-eeeb-4200-bfb5-964e0b8d75ae

dj12djdjs avatar Sep 20 '23 19:09 dj12djdjs

@dj12djdjs can you please add more information about this pr in description?

maharshivpatel avatar Sep 21 '23 03:09 maharshivpatel

@maharshivpatel I've updated the description with video example

dj12djdjs avatar Sep 21 '23 14:09 dj12djdjs

let's make barcodeShowText boolean and set default as True! we can write patch for existing formats. I believe this is better in long run.

Edit: Also thank you for contributing i was going to add this and then completely forgot about it.

maharshivpatel avatar Sep 21 '23 16:09 maharshivpatel

@maharshivpatel I initially tried using a "Check" field, but it wouldn't render. That is why I used a Select field.

I tried searching the code base for existing "Check" usage on the panel but couldn't find any. Can you point me in the right direction to get that working?

dj12djdjs avatar Sep 21 '23 17:09 dj12djdjs

@dj12djdjs Select Field is fine just use formatValue to convert Yes/No to true/false.

maharshivpatel avatar Sep 22 '23 04:09 maharshivpatel

@maharshivpatel I've added this logic to convert "Yes" and "No" into bool. But it results in infinite loop. I'm not familiar with the inner workings of this. Do you have any suggestions?

formatValue(object, property) {
  const from = object[property];
  const to = from === "Yes";
  return to;
}

dj12djdjs avatar Sep 22 '23 15:09 dj12djdjs

@dj12djdjs you can do something like this:

// formatValue: is used to format value from state ( Pinia store ) to what PropertiesPanel need.

	formatValue: (object, property, isStyle) => {
		if (!object) return;
		return object[property] ? "Yes" : "No";
	},
// onChangeCallback: is called just after value is saved in state ( Pinia store ). 
// you can overwrite value based on requirement from here or trigger something when value changes.

	onChangeCallback: (value = null) => {
		if (value && MainStore.getCurrentElementsValues[0]) {
			MainStore.getCurrentElementsValues[0]["barcodeShowText"] = value === "Yes";
			MainStore.frappeControls[name].$input.blur();
		}
	},

you also need to change the logic as per true and false boolean instead of "Yes"/"No"

maharshivpatel avatar Sep 23 '23 11:09 maharshivpatel

@maharshivpatel Thank you, it seems to be working. I just need to figure out the patch. Let me know if there is anything else

dj12djdjs avatar Sep 23 '23 12:09 dj12djdjs

i am planning to write utils for patches as it will be quite complicated otherwise. i will share with you if i get time to write utils in few days else i will help you write a patch.

if you want to explore just check how ElementStore is used to save elements. There are two places elements and globalStyles that needs to be patched. Elements can also be nested inside if type is Rectangle.

maharshivpatel avatar Sep 23 '23 12:09 maharshivpatel

@maharshivpatel I think I've got the globalStyles, elements I'm going to need to look into

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))

dj12djdjs avatar Sep 23 '23 13:09 dj12djdjs

@dj12djdjs Patch utils are available now. you can read the patch file and check example here .

Incase you want i can also write patch 😄

maharshivpatel avatar Dec 08 '23 06:12 maharshivpatel

@maharshivpatel Awesome! I'll try to get some time this weekend to finish up this PR.

dj12djdjs avatar Dec 08 '23 16:12 dj12djdjs

Probably over the holiday break I'll get a chance to finish this up

dj12djdjs avatar Dec 20 '23 16:12 dj12djdjs

@dj12djdjs awesome, let me know if/whenever you need any help

maharshivpatel avatar Dec 20 '23 16:12 maharshivpatel

@dj12djdjs hey, did you got time to add patches 😅.

maharshivpatel avatar Jan 03 '24 06:01 maharshivpatel

how to adjust the sizes of the barcode?

classita avatar Aug 14 '24 07:08 classita