From 9bdcb596ce100e679729e580eb63a3f3c04a9327 Mon Sep 17 00:00:00 2001 From: "Julien (jula)" Date: Fri, 7 Jul 2023 12:02:22 +0000 Subject: [PATCH] [IMP] tools: make arch diff viewer prettier When investigating an issue on a customer database, the diff view modal can be pretty useful. However it is not very good looking and therefore poorly readable. This PR improves the CSS styling of that modal so that it resemble more the diff view of GitHub. This is done by: - Increasing the width of the modal - Aligning the text to the top of the table cell, that way there is no text floating in the middle of two lines - Lightly coloring the whole line when there is a change on it while the actual change is on a darker background - Putting in red all types of change on the left and in green on the right (instead of mixing green, red and orange together) This commit is improving the tool that was made at [`96d3fa4`](https://github.com/odoo/odoo/commit/96d3fa4e01bf8afc35dbf0b7301ce75c6bf3a5c7) closes odoo/odoo#127765 X-original-commit: bf412f6920b10376a979c9f95c4508dedfec5d5f Signed-off-by: Romain Derie (rde) --- odoo/addons/base/models/ir_ui_view.py | 2 ++ odoo/tools/misc.py | 33 +++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index cb3440a111e..3dc8833b932 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -2333,6 +2333,8 @@ class ResetViewArchWizard(models.TransientModel): view.arch_diff = get_diff( (view_arch, get_table_name(view.view_id) if view.reset_mode == 'other_view' else _("Current Arch")), (diff_to, diff_to_name), + custom_style=False, + dark_color_scheme=request and request.httprequest.cookies.get('color_scheme') == 'dark', ) view.has_diff = view_arch != diff_to diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index 0af82222db2..5c068c11fb0 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -1669,16 +1669,17 @@ class DotDict(dict): return DotDict(val) if type(val) is dict else val -def get_diff(data_from, data_to, custom_style=False): +def get_diff(data_from, data_to, custom_style=False, dark_color_scheme=False): """ Return, in an HTML table, the diff between two texts. :param tuple data_from: tuple(text, name), name will be used as table header :param tuple data_to: tuple(text, name), name will be used as table header :param tuple custom_style: string, style css including - ''' + ''' % colors return html_diff diff = HtmlDiff(tabsize=2).make_table( @@ -1711,7 +1724,7 @@ def get_diff(data_from, data_to, custom_style=False): context=True, # Show only diff lines, not all the code numlines=3, ) - return handle_style(diff, custom_style) + return handle_style(diff, custom_style, dark_color_scheme) def hmac(env, scope, message, hash_function=hashlib.sha256):