Show help link when generating or viewing report, if applicable

This commit is contained in:
Lance Edgar 2023-01-04 16:39:37 -06:00
parent 31b213610f
commit db62bd20b3
3 changed files with 74 additions and 7 deletions

View file

@ -7,8 +7,19 @@
<%def name="render_buefy_form()">
<div class="form">
<p style="padding: 1em;">${report.__doc__}</p>
<br />
<p class="block">
${report.__doc__}
</p>
% if report.help_url:
<p class="block">
<b-button icon-pack="fas"
icon-left="question-circle"
tag="a" target="_blank"
href="${report.help_url}">
Help for this report
</b-button>
</p>
% endif
<tailbone-form></tailbone-form>
</div>
</%def>

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar
# Copyright © 2010-2023 Lance Edgar
#
# This file is part of Rattail.
#
@ -2643,6 +2643,47 @@ class MasterView(View):
normal.append(button)
return normal
def make_buefy_button(self, label, is_primary=False,
url=None, is_external=False,
**kwargs):
"""
Make and return a HTML ``<b-button>`` literal.
"""
btn_kw = dict(c=label, icon_pack='fas')
if 'type' in kwargs:
btn_kw['type'] = kwargs['type']
elif is_primary:
btn_kw['type'] = 'is-primary'
if url:
btn_kw['href'] = url
if 'icon_left' in kwargs:
btn_kw['icon_left'] = kwargs['icon_left']
elif is_external:
btn_kw['icon_left'] = 'external-link-alt'
else:
btn_kw['icon_left'] = 'eye'
if 'target' in kwargs:
btn_kw['target'] = kwargs['target']
elif is_external:
btn_kw['target'] = '_blank'
button = HTML.tag('b-button', **btn_kw)
if url:
# nb. unfortunately HTML.tag() calls its first arg 'tag' and
# so we can't pass a kwarg with that name...so instead we
# patch that into place manually
button = six.text_type(button)
button = button.replace('<b-button ',
'<b-button tag="a"')
button = HTML.literal(button)
return button
def make_xref_button(self, **kwargs):
"""
Make and return a HTML ``<b-button>`` literal, for display in
@ -2655,6 +2696,8 @@ class MasterView(View):
assumed to be external, which affects the icon and causes
button click to open link in a new tab.
"""
# TODO: this should call make_buefy_button()
# nb. unfortunately HTML.tag() calls its first arg 'tag' and
# so we can't pass a kwarg with that name...so instead we
# patch that into place manually

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar
# Copyright © 2010-2023 Lance Edgar
#
# This file is part of Rattail.
#
@ -267,6 +267,9 @@ class ReportOutputView(ExportMasterView):
def render_report_type(self, output, field):
type_key = getattr(output, field)
# just show type key by default
rendered = type_key
# (try to) show link to poser report if applicable
if type_key and type_key.startswith('poser_'):
app = self.get_rattail_app()
@ -276,10 +279,20 @@ class ReportOutputView(ExportMasterView):
if not report.get('error'):
url = self.request.route_url('poser_reports.view',
report_key=poser_key)
return tags.link_to(type_key, url)
rendered = tags.link_to(type_key, url)
# fallback to showing value as-is
return type_key
# add help button if report has a link
report = self.report_handler.get_report(type_key)
if report and report.help_url:
button = self.make_buefy_button("Help for this report",
url=report.help_url,
is_external=True,
icon_left='question-circle')
button = HTML.tag('div', class_='level-item', c=[button])
rendered = HTML.tag('div', class_='level-item', c=[rendered])
rendered = HTML.tag('div', class_='level-left', c=[rendered, button])
return rendered
def render_params(self, report, field):
params = report.params