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: default template import export #208

Conversation

maharshivpatel
Copy link
Collaborator

@maharshivpatel maharshivpatel commented Apr 1, 2024

  • Added Custom Field for Print Designer Template Location

  • Added Hook to define folder location for Print Designer Templates ( location fallbacks to default_templates if not defined in hooks for export )

  • when print designer is installed, loop over all apps and import standard templates.

  • when any new app is installed, check if it has print designer templates and install them. - it also checks print_designer app for new templates and installs them.

  • Modified export functionality for print formats that are made using print_designer. - it will export print format in custom directory if defined in hooks else in default_templates folder.

  • user / developer can define app where print format should be exported in print_designer_template_app field.

depends on : frappe/frappe#25752

TODO: Add template grid view for users so they can explore formats.

  • All of the logic is already implemented
  • figure out how to use vue-router inside desk
  • current implementation is hacky and not a good experience so not added.
Screenshot 2024-04-01 at 1 36 49 PM

- Added Custom Field for Print Designer Template Location
- Added Hook to define folder location for Print Designer Templates
( location fallbacks to default_templates if not defined in hooks for export )

- when print designer is installed, loop over all apps and import standard templates.
- when any new app is installed, check if it has print designer templates and install them.
    - it also checks print_designer app for new templates and installs them.

- Modified export functionality for print formats that are made using print_designer.
    - it will export print format in custom directory if defined in hooks else in default_templates folder.
    - user / developer can define app where print format should be exported in print_designer_template_app field.
added new custom field "print_designer_preview_img" to store the format preview image.
added html2canvas
on save
- make copy of main-container dom and convert to canvas using html2canvas.
- create file instance and pass blob to it from canvas.toBlob()
- send file to /api/method/upload_file , client side function is just modified version of FileUploader.
- remove old format preview image after new one is uploaded successfully.

This will be used to display the format preview in the format Grid View.
dynamic text value is fetched from db so there is no need to save it as part of format.
we have to consider and load metaFields from db so remove it from Print Format JSON.
- if standard is set to true, remove static file urls as it can't be used across site.
- only try to load file if url value exists for the file.
    - This doesn't check if image file exists or not.
As standard field returns Yes or No, update the logic to compare string instead of boolean.

update preview image url in print_designer_preview_img field
First check if table exists before trying to load childfield meta
Copy the image to the export directory so that it can be used for preview while installing the format.
when print_designer format is saved in developer mode and format is standard.
preview images and " File " document is exported as per the location defined in the selected app's hook.
after install once the formats are imported, copy the file to private/files folder and update the file path in the format.
After merging relative containers when this in this PR conflicts were manually resolved.
There were some incorrect conflict resolutions, which are fixed in this commit.

Also, removed multiple updates for print format document caused by updating file_url.
instead get latest file_url from the file document else set to null.
@maharshivpatel maharshivpatel force-pushed the feat-default-template-import-export-develop branch from 15d10e0 to bbe07f9 Compare April 1, 2024 20:41
while refactoring the code, by mistake it was changed to an array. This commit fixes it.
unintended cssRules were removed by mistake so until that can be fixed removing deleteRule code.
@maharshivpatel maharshivpatel force-pushed the feat-default-template-import-export-develop branch from e21640a to 6e8469a Compare April 2, 2024 04:22
image upload sometime happen before the format is saved and sometimes after.
handled both cases based on isFormatSaving flag.
maharshivpatel added a commit to maharshivpatel/print_designer that referenced this pull request Apr 2, 2024
This 2 templates will be installed if erpnext is present in the system.
depends on frappe#208
when we create copy when user updates the formats with old schema.
it was implicitly setting the name with copy + number suffix.
now we set that name as default and prompt user if they want to change the name.
@maharshivpatel maharshivpatel force-pushed the feat-default-template-import-export-develop branch from 35bb2bd to 6afc817 Compare April 3, 2024 05:44
@maharshivpatel maharshivpatel force-pushed the feat-default-template-import-export-develop branch from 6085370 to f911516 Compare April 3, 2024 07:22
@maharshivpatel maharshivpatel merged commit bdf3e7c into frappe:develop Apr 3, 2024
2 checks passed
@maharshivpatel
Copy link
Collaborator Author

🎉 This PR is included in version 1.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants