From c3d0ab5f9a4ef4c961bf11e7574fb2175bc7d3a7 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Fri, 18 Aug 2023 11:04:31 +0530 Subject: [PATCH] feat: add html template for comparator --- .../document_comparator.html | 74 +++++++++++++++++++ .../document_comparator.js | 35 +++++++++ 2 files changed, 109 insertions(+) create mode 100644 frappe/core/doctype/document_comparator/document_comparator.html create mode 100644 frappe/core/doctype/document_comparator/document_comparator.js diff --git a/frappe/core/doctype/document_comparator/document_comparator.html b/frappe/core/doctype/document_comparator/document_comparator.html new file mode 100644 index 0000000000..3b4950adea --- /dev/null +++ b/frappe/core/doctype/document_comparator/document_comparator.html @@ -0,0 +1,74 @@ +
+ +
+ {% if documents.length > 1 %} +

Documents to Compare : {{ documents.length }}

+ {% else %} +

Documents to Compare : {{ documents.length - 1 }}

+ {% endif %} +
+ + {% var field_keys = Object.keys(changed).sort(); %} + {% if field_keys.length > 0 %} +
+
Changes
+ + + + {% for doc in documents %} + + {% endfor %} + + + {% for fieldname in field_keys %} + + + {% var values = changed[fieldname] %} + + {% for value in values %} + + {% endfor %} + + {% endfor %} + +
Fields {{ doc }}
{{ fieldname }} {{ value }}
+
+ {% endif %} + + {% var tables = Object.keys(row_changed).sort(); %} + {% if tables.length > 0 %} +
+
Rows Updated
+ + + + {% for doc in documents %} + + {% endfor %} + + + {% for table in tables %} + + + {% var row_index = row_changed[table]["index"] %} + + {% var fields = Object.keys(row_changed[table]).sort(); %} + {% for field in fields %} + {% if field != "index" %} + + + {% var values = row_changed[table][field] %} + {% for value in values %} + + {% endfor %} + + {% endfor %} + {% endfor %} + + {% endfor %} + +
Fields {{ doc }}
{{ table }}
idx : {{ row_index }}
{{ field }} {{ value }}
+
+ {% endif %} + +
\ No newline at end of file diff --git a/frappe/core/doctype/document_comparator/document_comparator.js b/frappe/core/doctype/document_comparator/document_comparator.js new file mode 100644 index 0000000000..22e73a848f --- /dev/null +++ b/frappe/core/doctype/document_comparator/document_comparator.js @@ -0,0 +1,35 @@ +// Copyright (c) 2023, Frappe Technologies and contributors +// For license information, please see license.txt + +frappe.ui.form.on("Document Comparator", { + refresh(frm) { + frm.disable_save(); + + frm.set_query("doctype_name", () => { + return { + filters: { + track_changes: 1, + }, + }; + }); + + frm.page.set_primary_action("Compare", () => { + frm.call({ + doc: frm.doc, + method: "compare_document", + callback: function (r) { + let document_names = r.message[0]; + let changed_fields = r.message[1]; + let render_dict = { + documents: document_names, + changed: changed_fields.changed, + row_changed: changed_fields.row_changed, + }; + $(frappe.render_template("document_comparator", render_dict)).appendTo( + frm.fields_dict.version_table.$wrapper.empty() + ); + }, + }); + }); + }, +});