[debug_toolbar] add a uicfg content panel

authorLaurent Peuch <cortex@worlddomination.be>
changeset25611c5925a9
branchdefault
phasedraft
hiddenno
parent revision#d9292ce0698f [debug_toolbar] add a uicfg declarations panel
child revision<not specified>
files modified by this revision
cubicweb/pyramid/debug_toolbar_templates/uicfg_content.dbtmako
cubicweb/pyramid/debugtoolbar_panels.py
# HG changeset patch
# User Laurent Peuch <cortex@worlddomination.be>
# Date 1611742840 -3600
# Wed Jan 27 11:20:40 2021 +0100
# Node ID 25611c5925a9a2d30fd4801c2c4bd14e58bb1f80
# Parent d9292ce0698ff4124389cb4edc9e273d632aa3fc
[debug_toolbar] add a uicfg content panel

diff --git a/cubicweb/pyramid/debug_toolbar_templates/uicfg_content.dbtmako b/cubicweb/pyramid/debug_toolbar_templates/uicfg_content.dbtmako
@@ -0,0 +1,36 @@
1 +% for vreg_key, entities in sorted(vreg["uicfg"].items(), key=lambda x: x[0]):
2 +<h3>${vreg_key}</h3>
3 +
4 +% for entity in entities:
5 +
6 +<table class="table table-bordered table-striped declaration-table">
7 +<tr><th colspan="3">${entity} ${entity.__class__.__name__} ${source_code_url(entity) | n}</th></tr>
8 +% for key, value in sorted(entity._tagdefs.items(), key=lambda x: x[0]):
9 +<tr>
10 +    <td>${highlight(key, "python") | n}</td>
11 +    <td>${highlight(value, "python") | n}</td>
12 +    <%
13 +        declaration = key_to_declaration(entity, key)
14 +    %>
15 +    <td>
16 +    % if declaration:
17 +        <i>${declaration["inspect_frame"].filename}:</i>
18 +        <br>
19 +        ${highlight("\n".join(declaration["inspect_frame"].code_context).strip(), "python") | n} ${source_code_url_simple(declaration["inspect_frame"].filename, declaration["inspect_frame"].lineno) | n}
20 +    % endif
21 +    </td>
22 +</tr>
23 +% endfor
24 +</table>
25 +
26 +% endfor
27 +
28 +% endfor
29 +
30 +<style>
31 +.declaration-table .highlight {
32 +    display: inline-flex;
33 +}
34 +
35 +${generate_css() | n}
36 +</style>
diff --git a/cubicweb/pyramid/debugtoolbar_panels.py b/cubicweb/pyramid/debugtoolbar_panels.py
@@ -357,10 +357,56 @@
37              'source_code_url': source_code_url,
38              'source_code_url_simple': source_code_url_simple,
39          }
40 
41 
42 +class UicfgContentDebugPanel(DebugPanel):
43 +    """
44 +    CubicWeb uicfg content
45 +    """
46 +
47 +    name = 'uicfg_content'
48 +    has_content = True
49 +    template = 'cubicweb.pyramid:debug_toolbar_templates/uicfg_content.dbtmako'
50 +
51 +    def __init__(self, request):
52 +        self.data = {'vreg': []}
53 +        self.vreg = []  # we use a list in case of but that should only be one item
54 +        subscribe_to_debug_channel("vreg", self.collect_vreg)
55 +
56 +    def collect_vreg(self, vreg):
57 +        self.vreg.append(vreg)
58 +
59 +    @property
60 +    def title(self):
61 +        return 'uicfg content'
62 +
63 +    @property
64 +    def nav_title(self):
65 +        return 'uicfg content'
66 +
67 +    def key_to_declaration(self, entity, key):
68 +        if len(entity._tagdefs.declarations) == 0:
69 +            return ""
70 +
71 +        # TODO caching
72 +        return {x["key"]: x for x in entity._tagdefs.declarations}.get(key, "")
73 +
74 +    def process_response(self, response):
75 +        unsubscribe_to_debug_channel("vreg", self.collect_vreg)
76 +
77 +        # clear on every new response
78 +        self.data = {
79 +            'vreg': self.vreg[0]["vreg"] if self.vreg else None,
80 +            'key_to_declaration': self.key_to_declaration,
81 +            'highlight': highlight_html,
82 +            'generate_css': generate_css,
83 +            'source_code_url': source_code_url,
84 +            'source_code_url_simple': source_code_url_simple,
85 +        }
86 +
87 +
88  class RQLDebugPanel(DebugPanel):
89      """
90      CubicWeb RQL debug panel
91      """
92 
@@ -478,8 +524,9 @@
93      config.add_debugtoolbar_panel(CubicWebDebugPanel)
94      config.add_debugtoolbar_panel(RegistryDecisionsDebugPanel)
95      config.add_debugtoolbar_panel(RegistryDebugPanel)
96      config.add_debugtoolbar_panel(RenderingDebugPanel)
97      config.add_debugtoolbar_panel(UicfgDeclarationsDebugPanel)
98 +    config.add_debugtoolbar_panel(UicfgContentDebugPanel)
99      config.add_debugtoolbar_panel(RQLDebugPanel)
100      config.add_debugtoolbar_panel(SQLDebugPanel)
101      config.add_debugtoolbar_panel(HooksDebugPanel)