Support configuring card icon on dashboard

This commit is contained in:
Jonathan Senecal 2023-05-18 11:30:20 -04:00
parent 121e5c2c91
commit 7d566837b6
3 changed files with 12 additions and 3 deletions

View File

@ -24,6 +24,10 @@ class DashboardWidgetForm(BootstrapMixin, forms.Form):
choices=add_blank_choice(ButtonColorChoices),
required=False,
)
icon_name = forms.CharField(
required=False,
help_text=_('Icon name from Material design icons (e.g. "globe")')
)
class DashboardWidgetAddForm(DashboardWidgetForm):
@ -37,4 +41,4 @@ class DashboardWidgetAddForm(DashboardWidgetForm):
),
label=_('Widget type')
)
field_order = ('widget_class', 'title', 'color')
field_order = ('widget_class', 'title', 'color', 'icon_name')

View File

@ -80,11 +80,12 @@ class DashboardWidget:
"""
pass
def __init__(self, id=None, title=None, color=None, config=None, width=None, height=None, x=None, y=None):
def __init__(self, id=None, title=None, color=None, icon_name=None, config=None, width=None, height=None, x=None, y=None):
self.id = id or str(uuid.uuid4())
self.config = config or self.default_config
self.title = title or self.default_title
self.color = color
self.icon_name = icon_name
if width:
self.width = width
if height:
@ -118,6 +119,7 @@ class DashboardWidget:
return {
'title': self.title,
'color': self.color,
'icon_name': self.icon_name,
'config': self.config,
}

View File

@ -27,7 +27,10 @@
><i class="mdi mdi-close text-gray"></i></a>
</div>
{% if widget.title %}
<h6 class="card-header">{{ widget.title }}</h6>
<h6 class="card-header text-center">
{% if widget.icon_name %}<i class="mdi mdi-{{ widget.icon_name }}"></i>{% endif %}
<span class="ms-1">{{ widget.title }}</span>
</h6>
{% endif %}
</div>
<div class="card-body overflow-auto mb-4">