Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add barcode option to show text #63

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dj12djdjs
Copy link

@dj12djdjs dj12djdjs commented Sep 20, 2023

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

Barcode.Show.Text.mp4

@maharshivpatel
Copy link
Collaborator

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

@dj12djdjs
Copy link
Author

@maharshivpatel I've updated the description with video example

@maharshivpatel
Copy link
Collaborator

maharshivpatel commented Sep 21, 2023

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.

@dj12djdjs
Copy link
Author

@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?

@maharshivpatel
Copy link
Collaborator

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

@dj12djdjs
Copy link
Author

@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;
}

@maharshivpatel
Copy link
Collaborator

maharshivpatel commented Sep 23, 2023

@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"

@dj12djdjs
Copy link
Author

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

@maharshivpatel
Copy link
Collaborator

maharshivpatel commented Sep 23, 2023

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.

@dj12djdjs
Copy link
Author

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

@maharshivpatel
Copy link
Collaborator

maharshivpatel commented Dec 8, 2023

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

Incase you want i can also write patch 😄

@dj12djdjs
Copy link
Author

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

@dj12djdjs
Copy link
Author

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

@maharshivpatel
Copy link
Collaborator

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

@maharshivpatel
Copy link
Collaborator

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

@dj12djdjs dj12djdjs force-pushed the feat-show-barcode-text branch from 9e142f4 to 424a260 Compare March 16, 2024 21:01
@classita
Copy link

how to adjust the sizes of the barcode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants