Skip to content

Commit

Permalink
Merge pull request #604 from mind84/bootstrap_5_tooltip
Browse files Browse the repository at this point in the history
update html tooltip to handle bootstrap 5 tabs
  • Loading branch information
Gustry authored Sep 23, 2024
2 parents 24966ac + 6326d93 commit d8de1f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
5 changes: 4 additions & 1 deletion lizmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3013,7 +3013,10 @@ def maptip_from_form(self):

root = config.invisibleRootContainer()
relation_manager = self.project.relationManager()
html_content = Tooltip.create_popup_node_item_from_form(layer, root, 0, [], '', relation_manager)
html_content = Tooltip.create_popup_node_item_from_form(
layer, root, 0, [], '', relation_manager,
bootstrap_5=self.current_lwc_version() >= LwcVersions.Lizmap_3_9,
)
html_content = Tooltip.create_popup(html_content)
html_content += Tooltip.css()
self._set_maptip(layer, html_content)
Expand Down
8 changes: 7 additions & 1 deletion lizmap/test/test_tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def test_tooltip_layer(self):
root = config.invisibleRootContainer()
# noinspection PyArgumentList
html_content = Tooltip.create_popup_node_item_from_form(
layer, root, 0, [], '', QgsProject.instance().relationManager())
layer, root, 0, [], '', QgsProject.instance().relationManager(), bootstrap_5=False)

self.maxDiff = None
expected = '''<ul class="nav nav-tabs">
Expand Down Expand Up @@ -554,3 +554,9 @@ def test_tooltip_layer(self):
</div>'''

self.assertEqual(expected, html_content, html_content)
self.assertFalse('data-bs-toggle="tab"' in html_content)

# Same but with Bootstrap 5
html_content = Tooltip.create_popup_node_item_from_form(
layer, root, 0, [], '', QgsProject.instance().relationManager(), bootstrap_5=True)
self.assertTrue('data-bs-toggle="tab"' in html_content)
23 changes: 19 additions & 4 deletions lizmap/tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def create_popup_node_item_from_form(
headers: list,
html: str,
relation_manager: QgsRelationManager,
bootstrap_5: bool = False,
) -> str:
regex = re.compile(r"[^a-zA-Z0-9_]", re.IGNORECASE)
a = ''
Expand Down Expand Up @@ -173,9 +174,22 @@ def create_popup_node_item_from_form(
if visibility and not active:
active = visibility
h += '\n' + SPACES
h += (
'<li class="{}"><a href="#popup_dd_[% $id %]_{}" data-toggle="tab">{}</a></li>'
).format(active, regex.sub('_', node.name()), node.name())
id_tab = regex.sub('_', node.name())
if bootstrap_5:
h += (
f'<li class="nav-item">'
f'<button class="nav-link {active}" data-bs-toggle="tab" '
f'data-bs-target="#popup_dd_[% $id %]_{id_tab}">'
f'{node.name()}'
f'</button>'
f'</li>'
)
else:
h += (
f'<li class="{active}">'
f'<a href="#popup_dd_[% $id %]_{id_tab}" data-toggle="tab">{node.name()}</a>'
f'</li>'
)
headers.append(h)

if lvl > 1:
Expand All @@ -190,7 +204,8 @@ def create_popup_node_item_from_form(

level += 1
for n in node.children():
h = Tooltip.create_popup_node_item_from_form(layer, n, level, headers, html, relation_manager)
h = Tooltip.create_popup_node_item_from_form(
layer, n, level, headers, html, relation_manager, bootstrap_5)
# If it is not root children, add html
if lvl > 0:
a += h
Expand Down

0 comments on commit d8de1f7

Please sign in to comment.