From 7d566837b6700acc904711952f50606a4ae2fec1 Mon Sep 17 00:00:00 2001 From: Jonathan Senecal Date: Thu, 18 May 2023 11:30:20 -0400 Subject: [PATCH] Support configuring card icon on dashboard --- netbox/extras/dashboard/forms.py | 6 +++++- netbox/extras/dashboard/widgets.py | 4 +++- netbox/templates/extras/dashboard/widget.html | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/netbox/extras/dashboard/forms.py b/netbox/extras/dashboard/forms.py index 1e9f15408..9c6548d57 100644 --- a/netbox/extras/dashboard/forms.py +++ b/netbox/extras/dashboard/forms.py @@ -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') diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py index 5c5d2fe31..13c61b91f 100644 --- a/netbox/extras/dashboard/widgets.py +++ b/netbox/extras/dashboard/widgets.py @@ -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, } diff --git a/netbox/templates/extras/dashboard/widget.html b/netbox/templates/extras/dashboard/widget.html index 6f9565aad..e30d8ab99 100644 --- a/netbox/templates/extras/dashboard/widget.html +++ b/netbox/templates/extras/dashboard/widget.html @@ -27,7 +27,10 @@ > {% if widget.title %} -
{{ widget.title }}
+
+ {% if widget.icon_name %}{% endif %} + {{ widget.title }} +
{% endif %}