Skip to content

Commit

Permalink
chore: generate image at the end for performance (#236)
Browse files Browse the repository at this point in the history
as generating the image is a slow operation, we should do it at the end
  • Loading branch information
maharshivpatel authored Apr 16, 2024
1 parent 6b1bc8b commit 08a6285
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions print_designer/public/js/print_designer/store/ElementStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,12 @@ export const useElementStore = defineStore("ElementStore", {
r = JSON.parse(xhr.responseText);
if (r.message.doctype === "File") {
file_url = r.message.file_url;
// if format is not saved then update the preview image value with it
if (MainStore.isFormatSaving) {
MainStore.print_designer_preview_img = file_url;
} else {
// if format is already saved then update the print_designer_preview_img field
frappe.db.set_value(
"Print Format",
MainStore.printDesignName,
"print_designer_preview_img",
file_url
);
}
frappe.db.set_value(
"Print Format",
MainStore.printDesignName,
"print_designer_preview_img",
file_url
);
}
} catch (e) {
r = xhr.responseText;
Expand Down Expand Up @@ -254,23 +248,20 @@ export const useElementStore = defineStore("ElementStore", {
css: css,
};
const PrintFormatData = this.getPrintFormatData({ header, body, footer });
MainStore.isFormatSaving = true;
await this.generatePreview();

objectToSave.print_designer_print_format = PrintFormatData;
objectToSave.print_designer_preview_img = MainStore.print_designer_preview_img;
if (MainStore.isOlderSchema("1.1.0")) {
await this.printFormatCopyOnOlderSchema(objectToSave);
} else {
await frappe.db.set_value("Print Format", MainStore.printDesignName, objectToSave);
MainStore.isFormatSaving = false;
frappe.show_alert(
{
message: `Print Format Saved Successfully`,
indicator: "green",
},
5
);
await this.generatePreview();
}
},
checkIfAnyTableIsEmpty() {
Expand Down

0 comments on commit 08a6285

Please sign in to comment.