fix: save_changes in to workflow_data field
This commit is contained in:
parent
a10cf8d8e8
commit
3d0af4b9c6
2 changed files with 47 additions and 1 deletions
|
|
@ -18,7 +18,15 @@ export const useStore = defineStore("workflow-builder-store", () => {
|
|||
workflow_doc.value = frappe.get_doc("Workflow", workflow_name.value);
|
||||
await frappe.model.with_doctype(workflow_doc.value.document_type);
|
||||
|
||||
workflow.value.elements = get_workflow_elements(workflow_doc.value);
|
||||
if (
|
||||
workflow_doc.value.workflow_data &&
|
||||
JSON.parse(workflow_doc.value.workflow_data).length &&
|
||||
typeof workflow_doc.value.workflow_data == "string"
|
||||
) {
|
||||
workflow.value.elements = JSON.parse(workflow_doc.value.workflow_data);
|
||||
} else {
|
||||
workflow.value.elements = get_workflow_elements(workflow_doc.value);
|
||||
}
|
||||
|
||||
setup_undo_redo();
|
||||
}
|
||||
|
|
@ -27,6 +35,22 @@ export const useStore = defineStore("workflow-builder-store", () => {
|
|||
fetch();
|
||||
}
|
||||
|
||||
async function save_changes() {
|
||||
frappe.dom.freeze(__("Saving..."));
|
||||
|
||||
try {
|
||||
let doc = workflow_doc.value;
|
||||
doc.workflow_data = JSON.stringify(workflow.value.elements);
|
||||
await frappe.call("frappe.client.save", { doc });
|
||||
frappe.toast("Workflow is updated successfully");
|
||||
fetch();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
frappe.dom.unfreeze();
|
||||
}
|
||||
}
|
||||
|
||||
let undo_redo_keyboard_event = onKeyDown(true, (e) => {
|
||||
if (!ref_history.value) return;
|
||||
if (e.ctrlKey || e.metaKey) {
|
||||
|
|
@ -50,6 +74,7 @@ export const useStore = defineStore("workflow-builder-store", () => {
|
|||
ref_history,
|
||||
fetch,
|
||||
reset_changes,
|
||||
save_changes,
|
||||
setup_undo_redo,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,9 +16,30 @@ class WorkflowBuilder {
|
|||
// set page title
|
||||
this.page.set_title(__("Editing {0}", [this.workflow]));
|
||||
|
||||
this.setup_page_actions();
|
||||
this.setup_app();
|
||||
}
|
||||
|
||||
setup_page_actions() {
|
||||
// clear actions
|
||||
this.page.clear_actions();
|
||||
this.page.clear_menu();
|
||||
this.page.clear_custom_actions();
|
||||
|
||||
// setup page actions
|
||||
this.primary_btn = this.page.set_primary_action(__("Save"), () =>
|
||||
this.store.save_changes()
|
||||
);
|
||||
|
||||
this.reset_changes_btn = this.page.add_button(__("Reset Changes"), () => {
|
||||
this.store.reset_changes();
|
||||
});
|
||||
|
||||
this.go_to_doctype_btn = this.page.add_menu_item(__("Go to Workflow"), () =>
|
||||
frappe.set_route("Form", "Workflow", this.workflow)
|
||||
);
|
||||
}
|
||||
|
||||
setup_app() {
|
||||
// create a pinia instance
|
||||
let pinia = createPinia();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue