mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Clean up widgets
This commit is contained in:
parent
0bfd986f08
commit
f876e9ed04
@ -7,8 +7,8 @@ DEFAULT_DASHBOARD = [
|
|||||||
'widget': 'extras.ObjectCountsWidget',
|
'widget': 'extras.ObjectCountsWidget',
|
||||||
'width': 4,
|
'width': 4,
|
||||||
'height': 3,
|
'height': 3,
|
||||||
|
'title': 'IPAM',
|
||||||
'config': {
|
'config': {
|
||||||
'title': 'IPAM',
|
|
||||||
'models': [
|
'models': [
|
||||||
'ipam.Aggregate',
|
'ipam.Aggregate',
|
||||||
'ipam.Prefix',
|
'ipam.Prefix',
|
||||||
@ -21,8 +21,8 @@ DEFAULT_DASHBOARD = [
|
|||||||
'widget': 'extras.ObjectCountsWidget',
|
'widget': 'extras.ObjectCountsWidget',
|
||||||
'width': 4,
|
'width': 4,
|
||||||
'height': 3,
|
'height': 3,
|
||||||
|
'title': 'DCIM',
|
||||||
'config': {
|
'config': {
|
||||||
'title': 'DCIM',
|
|
||||||
'models': [
|
'models': [
|
||||||
'dcim.Site',
|
'dcim.Site',
|
||||||
'dcim.Rack',
|
'dcim.Rack',
|
||||||
@ -36,7 +36,7 @@ DEFAULT_DASHBOARD = [
|
|||||||
'width': 4,
|
'width': 4,
|
||||||
'height': 3,
|
'height': 3,
|
||||||
'config': {
|
'config': {
|
||||||
'content': 'Welcome to NetBox!'
|
'content': 'Welcome to **NetBox**!'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,6 @@ def get_dashboard(user):
|
|||||||
config = user.config.get('dashboard')
|
config = user.config.get('dashboard')
|
||||||
else:
|
else:
|
||||||
config = get_default_dashboard_config()
|
config = get_default_dashboard_config()
|
||||||
print(config)
|
|
||||||
if not user.is_anonymous:
|
if not user.is_anonymous:
|
||||||
user.config.set('dashboard', config, commit=True)
|
user.config.set('dashboard', config, commit=True)
|
||||||
|
|
||||||
@ -60,6 +59,7 @@ def get_default_dashboard_config():
|
|||||||
})
|
})
|
||||||
config['widgets'][id] = {
|
config['widgets'][id] = {
|
||||||
'class': widget['widget'],
|
'class': widget['widget'],
|
||||||
|
'title': widget.get('title'),
|
||||||
'config': widget.get('config', {}),
|
'config': widget.get('config', {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,10 @@ import uuid
|
|||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
from utilities.templatetags.builtins.filters import render_markdown
|
||||||
from .utils import register_widget
|
from .utils import register_widget
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -15,6 +17,8 @@ __all__ = (
|
|||||||
|
|
||||||
|
|
||||||
class DashboardWidget:
|
class DashboardWidget:
|
||||||
|
title = None
|
||||||
|
description = None
|
||||||
width = 4
|
width = 4
|
||||||
height = 3
|
height = 3
|
||||||
|
|
||||||
@ -45,14 +49,23 @@ class DashboardWidget:
|
|||||||
|
|
||||||
@register_widget
|
@register_widget
|
||||||
class StaticContentWidget(DashboardWidget):
|
class StaticContentWidget(DashboardWidget):
|
||||||
|
description = _('Display some arbitrary custom content. Markdown is supported.')
|
||||||
|
default_content = """
|
||||||
|
<div class="d-flex justify-content-center align-items-center" style="height: 100%">
|
||||||
|
<div class="text-center text-muted">Empty</div>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
return self.config.get('content', 'Empty!')
|
if content := self.config.get('content'):
|
||||||
|
return render_markdown(content)
|
||||||
|
return mark_safe(self.default_content)
|
||||||
|
|
||||||
|
|
||||||
@register_widget
|
@register_widget
|
||||||
class ObjectCountsWidget(DashboardWidget):
|
class ObjectCountsWidget(DashboardWidget):
|
||||||
title = _('Objects')
|
title = _('Objects')
|
||||||
|
description = _('Display a set of NetBox models and the number of objects created for each type.')
|
||||||
template_name = 'extras/dashboard/widgets/objectcounts.html'
|
template_name = 'extras/dashboard/widgets/objectcounts.html'
|
||||||
|
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
@ -70,9 +83,9 @@ class ObjectCountsWidget(DashboardWidget):
|
|||||||
|
|
||||||
@register_widget
|
@register_widget
|
||||||
class ChangeLogWidget(DashboardWidget):
|
class ChangeLogWidget(DashboardWidget):
|
||||||
|
title = _('Change Log')
|
||||||
width = 12
|
width = 12
|
||||||
height = 4
|
height = 4
|
||||||
title = _('Change log')
|
|
||||||
template_name = 'extras/dashboard/widgets/changelog.html'
|
template_name = 'extras/dashboard/widgets/changelog.html'
|
||||||
|
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
{% load helpers %}
|
||||||
|
|
||||||
{% if counts %}
|
{% if counts %}
|
||||||
<div class="list-group list-group-flush">
|
<div class="list-group list-group-flush">
|
||||||
{% for model, count in counts %}
|
{% for model, count in counts %}
|
||||||
<a href="#" class="list-group-item list-group-item-action">
|
<a href="{% url model|viewname:"list" %}" class="list-group-item list-group-item-action">
|
||||||
<div class="d-flex w-100 justify-content-between align-items-center">
|
<div class="d-flex w-100 justify-content-between align-items-center">
|
||||||
{{ model|meta:"verbose_name_plural"|bettertitle }}
|
{{ model|meta:"verbose_name_plural"|bettertitle }}
|
||||||
<h6 class="mb-1">{{ count }}</h6>
|
<h6 class="mb-1">{{ count }}</h6>
|
||||||
|
Loading…
Reference in New Issue
Block a user