mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
#9416: Add view to reset user's dashboard
This commit is contained in:
parent
6e6e8fa2d9
commit
90527b799d
@ -88,6 +88,7 @@ urlpatterns = [
|
|||||||
path('changelog/<int:pk>/', include(get_model_urls('extras', 'objectchange'))),
|
path('changelog/<int:pk>/', include(get_model_urls('extras', 'objectchange'))),
|
||||||
|
|
||||||
# User dashboard
|
# User dashboard
|
||||||
|
path('dashboard/reset/', views.DashboardResetView.as_view(), name='dashboard_reset'),
|
||||||
path('dashboard/widgets/add/', views.DashboardWidgetAddView.as_view(), name='dashboardwidget_add'),
|
path('dashboard/widgets/add/', views.DashboardWidgetAddView.as_view(), name='dashboardwidget_add'),
|
||||||
path('dashboard/widgets/<uuid:id>/configure/', views.DashboardWidgetConfigView.as_view(), name='dashboardwidget_config'),
|
path('dashboard/widgets/<uuid:id>/configure/', views.DashboardWidgetConfigView.as_view(), name='dashboardwidget_config'),
|
||||||
path('dashboard/widgets/<uuid:id>/delete/', views.DashboardWidgetDeleteView.as_view(), name='dashboardwidget_delete'),
|
path('dashboard/widgets/<uuid:id>/delete/', views.DashboardWidgetDeleteView.as_view(), name='dashboardwidget_delete'),
|
||||||
|
@ -5,6 +5,7 @@ from django.db.models import Count, Q
|
|||||||
from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponse
|
from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponse
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
|
|
||||||
from core.choices import JobStatusChoices, ManagedFileRootPathChoices
|
from core.choices import JobStatusChoices, ManagedFileRootPathChoices
|
||||||
@ -665,9 +666,36 @@ class JournalEntryBulkDeleteView(generic.BulkDeleteView):
|
|||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Dashboard widgets
|
# Dashboard & widgets
|
||||||
#
|
#
|
||||||
|
|
||||||
|
class DashboardResetView(LoginRequiredMixin, View):
|
||||||
|
template_name = 'extras/dashboard/reset.html'
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
get_object_or_404(Dashboard.objects.all(), user=request.user)
|
||||||
|
form = ConfirmationForm()
|
||||||
|
|
||||||
|
return render(request, self.template_name, {
|
||||||
|
'form': form,
|
||||||
|
'return_url': reverse('home'),
|
||||||
|
})
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
dashboard = get_object_or_404(Dashboard.objects.all(), user=request.user)
|
||||||
|
form = ConfirmationForm(request.POST)
|
||||||
|
|
||||||
|
if form.is_valid():
|
||||||
|
dashboard.delete()
|
||||||
|
messages.success(request, _("Your dashboard has been reset."))
|
||||||
|
return redirect(reverse('home'))
|
||||||
|
|
||||||
|
return render(request, self.template_name, {
|
||||||
|
'form': form,
|
||||||
|
'return_url': reverse('home'),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class DashboardWidgetAddView(LoginRequiredMixin, View):
|
class DashboardWidgetAddView(LoginRequiredMixin, View):
|
||||||
template_name = 'extras/dashboard/widget_add.html'
|
template_name = 'extras/dashboard/widget_add.html'
|
||||||
|
|
||||||
|
8
netbox/templates/extras/dashboard/reset.html
Normal file
8
netbox/templates/extras/dashboard/reset.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{% extends 'generic/confirmation_form.html' %}
|
||||||
|
|
||||||
|
{% block title %}Reset Dashboard?{% endblock %}
|
||||||
|
|
||||||
|
{% block message %}
|
||||||
|
<p>This will remove <strong>all</strong> configured widgets and restore the default dashboard configuration.</p>
|
||||||
|
<p>This change affects on <i>your</i> dashboard, and will not impact other users.</p>
|
||||||
|
{% endblock %}
|
@ -29,19 +29,26 @@
|
|||||||
{% include 'extras/dashboard/widget.html' %}
|
{% include 'extras/dashboard/widget.html' %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-end px-2">
|
<div class="d-flex px-3">
|
||||||
<a href="#"
|
<div class="flex-grow-1">
|
||||||
hx-get="{% url 'extras:dashboardwidget_add' %}"
|
<a href="#"
|
||||||
hx-target="#htmx-modal-content"
|
hx-get="{% url 'extras:dashboardwidget_add' %}"
|
||||||
data-bs-toggle="modal"
|
hx-target="#htmx-modal-content"
|
||||||
data-bs-target="#htmx-modal"
|
data-bs-toggle="modal"
|
||||||
class="btn btn-success btn-sm"
|
data-bs-target="#htmx-modal"
|
||||||
>
|
class="btn btn-success btn-sm"
|
||||||
<i class="mdi mdi-plus"></i> Add Widget
|
>
|
||||||
</a>
|
<i class="mdi mdi-plus"></i> Add Widget
|
||||||
<button id="save_dashboard" class="btn btn-primary btn-sm" data-url="{% url 'extras-api:dashboard' %}">
|
</a>
|
||||||
<i class="mdi mdi-content-save-outline"></i> Save Layout
|
</div>
|
||||||
</button>
|
<div>
|
||||||
|
<button id="save_dashboard" class="btn btn-primary btn-sm" data-url="{% url 'extras-api:dashboard' %}">
|
||||||
|
<i class="mdi mdi-content-save-outline"></i> Save Layout
|
||||||
|
</button>
|
||||||
|
<a href="{% url 'extras:dashboard_reset' %}" class="btn btn-danger btn-sm">
|
||||||
|
<i class="mdi mdi-backspace"></i> Reset Dashboard
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock content-wrapper %}
|
{% endblock content-wrapper %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user