Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update html tooltip to handle bootstrap 5 tabs #604

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lizmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3014,7 +3014,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