Split object list and filters into tabs

This commit is contained in:
jeremystretch 2021-08-06 13:56:53 -04:00
parent 6ce8dd5ac3
commit 5360967abc
4 changed files with 272 additions and 182 deletions

View File

@ -1,24 +1,56 @@
{% extends 'base/layout.html' %} {% extends 'base/layout.html' %}
{% load buttons %} {% load buttons %}
{% load helpers %}
{% load render_table from django_tables2 %} {% load render_table from django_tables2 %}
{% block title %}{{ title }}{% endblock %} {% block title %}{{ title }}{% endblock %}
{% block extra_controls %}{% export_button content_type %}{% endblock %} {% block extra_controls %}{% export_button content_type %}{% endblock %}
{% block content %} {% block tabs %}
<div class="row mb-3"> <ul class="nav nav-tabs px-3">
<div class="col col-md-7 col-lg-8 col-xl-9 col-xxl-10"> {% block tab_items %}
{% include 'inc/table_controls.html' %} <li class="nav-item" role="presentation">
<button class="nav-link active" id="connections-list-tab" data-bs-toggle="tab" data-bs-target="#connections-list" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
{{ title }}
{% badge table.page.paginator.count %}
</button>
</li>
{% if filter_form %}
<li class="nav-item" role="presentation">
<button class="nav-link" id="filters-form-tab" data-bs-toggle="tab" data-bs-target="#filters-form" type="button" role="tab" aria-controls="object-list" aria-selected="false">
Filters
</button>
</li>
{% endif %}
{% endblock tab_items %}
</ul>
{% endblock tabs %}
<div class="table-responsive"> {% block content-wrapper %}
{% render_table table 'inc/table.html' %} <div class="tab-content">
</div>
{% include 'inc/paginator.html' with paginator=table.paginator page=table.page %} {# Conncetions list #}
<div class="tab-pane show active" id="connections-list" role="tabpanel" aria-labelledby="connections-list-tab">
{% include 'inc/table_controls.html' %}
<div class="card">
<div class="card-body">
<div class="table-responsive">
{% render_table table 'inc/table.html' %}
</div>
</div> </div>
{% if filter_form %} </div>
{% include 'inc/filter_list.html' %}
{% endif %} {% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
</div> </div>
{% endblock %}
{# Filter form #}
{% if filter_form %}
<div class="tab-pane show" id="filters-form" role="tabpanel" aria-labelledby="filters-form-tab">
{% include 'inc/filter_list.html' %}
</div>
{% endif %}
</div>
{% endblock content-wrapper %}

View File

@ -22,41 +22,70 @@
</div> </div>
{% endblock %} {% endblock %}
{% block content %} {% block tabs %}
<div class="row"> <ul class="nav nav-tabs px-3">
<div class="col col-md-7 col-lg-8 col-xl-9 col-xxl-10"> {% block tab_items %}
{% if page %} <li class="nav-item" role="presentation">
<div style="white-space: nowrap; overflow-x: scroll;"> <button class="nav-link active" id="rack-elevations-tab" data-bs-toggle="tab" data-bs-target="#rack-elevations" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
{% for rack in page %} Rack Elevations
<div style="display: inline-block; margin-right: 12px; width: 254px"> {% badge page.paginator.count %}
<div style="margin-left: 30px"> </button>
<div class="text-center"> </li>
<strong><a href="{% url 'dcim:rack' pk=rack.pk %}">{{ rack.name }}</a></strong> {% if filter_form %}
{% if rack.role %} <li class="nav-item" role="presentation">
<br /><span class="badge my-3" style="color: {{ rack.role.color|fgcolor }}; background-color: #{{ rack.role.color }}">{{ rack.role }}</span> <button class="nav-link" id="filters-form-tab" data-bs-toggle="tab" data-bs-target="#filters-form" type="button" role="tab" aria-controls="object-list" aria-selected="false">
{% endif %} Filters
{% if rack.facility_id %} </button>
<br /><small class="text-muted">{{ rack.facility_id }}</small> </li>
{% endif %} {% endif %}
</div> {% endblock tab_items %}
{% include 'dcim/inc/rack_elevation.html' with object=rack face=rack_face %} </ul>
<div class="clearfix"></div> {% endblock tabs %}
<div class="text-center">
<strong><a href="{% url 'dcim:rack' pk=rack.pk %}">{{ rack.name }}</a></strong> {% block content-wrapper %}
{% if rack.facility_id %} <div class="tab-content">
<small class="text-muted">({{ rack.facility_id }})</small>
{% endif %} {# Rack elevations #}
</div> <div class="tab-pane show active" id="rack-elevations" role="tabpanel" aria-labelledby="rack-elevations-tab">
</div> {% if page %}
</div> <div style="white-space: nowrap; overflow-x: scroll;">
{% endfor %} {% for rack in page %}
</div> <div style="display: inline-block; margin-right: 12px; width: 254px">
<br /> <div style="margin-left: 30px">
{% include 'inc/paginator.html' %} <div class="text-center">
{% else %} <strong><a href="{% url 'dcim:rack' pk=rack.pk %}">{{ rack.name }}</a></strong>
<p>No Racks Found</p> {% if rack.role %}
{% endif %} <br /><span class="badge my-3" style="color: {{ rack.role.color|fgcolor }}; background-color: #{{ rack.role.color }}">{{ rack.role }}</span>
</div> {% endif %}
{% include 'inc/filter_list.html' %} {% if rack.facility_id %}
<br /><small class="text-muted">{{ rack.facility_id }}</small>
{% endif %}
</div>
{% include 'dcim/inc/rack_elevation.html' with object=rack face=rack_face %}
<div class="clearfix"></div>
<div class="text-center">
<strong><a href="{% url 'dcim:rack' pk=rack.pk %}">{{ rack.name }}</a></strong>
{% if rack.facility_id %}
<small class="text-muted">({{ rack.facility_id }})</small>
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
<br />
{% include 'inc/paginator.html' %}
{% else %}
<p>No Racks Found</p>
{% endif %}
</div> </div>
{% endblock %}
{# Filter form #}
{% if filter_form %}
<div class="tab-pane show" id="filters-form" role="tabpanel" aria-labelledby="filters-form-tab">
{% include 'inc/filter_list.html' %}
</div>
{% endif %}
</div>
{% endblock content-wrapper %}

View File

@ -23,78 +23,112 @@
</div> </div>
{% endblock controls %} {% endblock controls %}
{% block content %} {% block tabs %}
{% if table.paginator.num_pages > 1 %} <ul class="nav nav-tabs px-3">
{% with bulk_edit_url=content_type.model_class|validated_viewname:"bulk_edit" bulk_delete_url=content_type.model_class|validated_viewname:"bulk_delete" %} {% block tab_items %}
<div id="select-all-box" class="d-none card noprint"> <li class="nav-item" role="presentation">
<form method="post" class="form col-md-12"> <button class="nav-link active" id="object-list-tab" data-bs-toggle="tab" data-bs-target="#object-list" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
{% csrf_token %} {{ content_type.model_class|meta:"verbose_name_plural"|bettertitle }}
<div class="card-body"> {% badge table.page.paginator.count %}
<div class="float-end"> </button>
{% if bulk_edit_url and permissions.change %} </li>
<button type="submit" name="_edit" formaction="{% url bulk_edit_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-warning btn-sm" disabled> {% if filter_form %}
<span class="mdi mdi-pencil" aria-hidden="true"></span> Edit All <li class="nav-item" role="presentation">
</button> <button class="nav-link" id="filters-form-tab" data-bs-toggle="tab" data-bs-target="#filters-form" type="button" role="tab" aria-controls="object-list" aria-selected="false">
{% endif %} Filters
{% if bulk_delete_url and permissions.delete %} </button>
<button type="submit" name="_delete" formaction="{% url bulk_delete_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-danger btn-sm" disabled> </li>
<span class="mdi mdi-trash-can-outline" aria-hidden="true"></span> Delete All {% endif %}
</button> {% endblock tab_items %}
{% endif %} </ul>
</div> {% endblock tabs %}
<div class="form-check">
<input type="checkbox" id="select-all" name="_all" class="form-check-input" /> {% block content-wrapper %}
<label for="select-all" class="form-check-label"> <div class="tab-content">
Select <strong>all {{ table.rows|length }} {{ table.data.verbose_name_plural }}</strong> matching query
</label> {# Object list #}
<div class="tab-pane show active" id="object-list" role="tabpanel" aria-labelledby="object-list-tab">
{% if table.paginator.num_pages > 1 %}
{# "Select all" form #}
{% with bulk_edit_url=content_type.model_class|validated_viewname:"bulk_edit" bulk_delete_url=content_type.model_class|validated_viewname:"bulk_delete" %}
<div id="select-all-box" class="d-none card noprint">
<form method="post" class="form col-md-12">
{% csrf_token %}
<div class="card-body">
<div class="float-end">
{% if bulk_edit_url and permissions.change %}
<button type="submit" name="_edit" formaction="{% url bulk_edit_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-warning btn-sm" disabled>
<span class="mdi mdi-pencil" aria-hidden="true"></span> Edit All
</button>
{% endif %}
{% if bulk_delete_url and permissions.delete %}
<button type="submit" name="_delete" formaction="{% url bulk_delete_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-danger btn-sm" disabled>
<span class="mdi mdi-trash-can-outline" aria-hidden="true"></span> Delete All
</button>
{% endif %}
</div>
<div class="form-check">
<input type="checkbox" id="select-all" name="_all" class="form-check-input" />
<label for="select-all" class="form-check-label">
Select <strong>all {{ table.rows|length }} {{ table.data.verbose_name_plural }}</strong> matching query
</label>
</div>
</div>
</form>
</div>
{% endwith %}
{% endif %}
{# Object table controls #}
{% include 'inc/table_controls.html' with table_modal="ObjectTable_config" %}
{# Object table #}
<div class="card">
<div class="card-body">
{% with bulk_edit_url=content_type.model_class|validated_viewname:"bulk_edit" bulk_delete_url=content_type.model_class|validated_viewname:"bulk_delete" %}
{% if permissions.change or permissions.delete %}
<form method="post" class="form form-horizontal">
{% csrf_token %}
<input type="hidden" name="return_url" value="{% if return_url %}{{ return_url }}{% else %}{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}{% endif %}" />
<div class="table-responsive">
{% render_table table 'inc/table.html' %}
</div>
<div class="noprint bulk-buttons">
<div class="bulk-button-group">
{% block bulk_buttons %}{% endblock %}
{% if bulk_edit_url and permissions.change %}
<button type="submit" name="_edit" formaction="{% url bulk_edit_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-warning btn-sm">
<i class="mdi mdi-pencil" aria-hidden="true"></i> Edit Selected
</button>
{% endif %}
{% if bulk_delete_url and permissions.delete %}
<button type="submit" name="_delete" formaction="{% url bulk_delete_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-danger btn-sm">
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> Delete Selected
</button>
{% endif %}
</div>
</div>
</form>
{% else %}
<div class="table-responsive">
{% render_table table 'inc/table.html' %}
</div>
{% endif %}
{% endwith %}
</div> </div>
</div> </div>
</form> {% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
</div> </div>
{% endwith %}
{% endif %}
{# Object table #} {# Filter form #}
<div class="row"> {% if filter_form %}
<div class="col {% if filter_form %}col-md-7 col-lg-8 col-xl-9 col-xxl-10{% else %}col-12{% endif %}"> <div class="tab-pane show" id="filters-form" role="tabpanel" aria-labelledby="filters-form-tab">
{# Object list filter, table config #} {% include 'inc/filter_list.html' %}
{% include 'inc/table_controls.html' with table_modal="ObjectTable_config" %} </div>
{% endif %}
{% with bulk_edit_url=content_type.model_class|validated_viewname:"bulk_edit" bulk_delete_url=content_type.model_class|validated_viewname:"bulk_delete" %}
{% if permissions.change or permissions.delete %}
<form method="post" class="form form-horizontal">
{% csrf_token %}
<input type="hidden" name="return_url" value="{% if return_url %}{{ return_url }}{% else %}{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}{% endif %}" />
<div class="table-responsive">
{% render_table table 'inc/table.html' %}
</div>
<div class="noprint bulk-buttons">
<div class="bulk-button-group">
{% block bulk_buttons %}{% endblock %}
{% if bulk_edit_url and permissions.change %}
<button type="submit" name="_edit" formaction="{% url bulk_edit_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-warning btn-sm">
<i class="mdi mdi-pencil" aria-hidden="true"></i> Edit Selected
</button>
{% endif %}
{% if bulk_delete_url and permissions.delete %}
<button type="submit" name="_delete" formaction="{% url bulk_delete_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-danger btn-sm">
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> Delete Selected
</button>
{% endif %}
</div>
</div>
</form>
{% else %}
<div class="table-responsive">
{% render_table table 'inc/table.html' %}
</div>
{% endif %}
{% endwith %}
{% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
</div> </div>
{% if filter_form %}
{% include 'inc/filter_list.html' %} {# Table config form #}
{% endif %} {% table_config_form table table_name="ObjectTable" %}
</div> {% endblock content-wrapper %}
{% table_config_form table table_name="ObjectTable" %}
{% endblock content %}

View File

@ -1,65 +1,60 @@
{% load form_helpers %} {% load form_helpers %}
{% load helpers %} {% load helpers %}
<div class="col col-md-5 col-lg-4 col-xl-3 col-xxl-2 noprint"> <form action="." method="get">
<form action="." method="get"> <div class="card">
<div class="card small"> <div class="card-body overflow-visible d-flex flex-wrap justify-content-between py-3">
<h5 class="card-header"> {% for field in filter_form.hidden_fields %}
Field Filters {{ field }}
</h5> {% endfor %}
<div class="card-body overflow-visible d-flex flex-wrap justify-content-between py-3"> {% if filter_form.field_groups %}
{% for field in filter_form.hidden_fields %} {% for group in filter_form.field_groups %}
{{ field }} <div class="col col-12">
{% endfor %} {% for name in group %}
{% if filter_form.field_groups %} {% with field=filter_form|get_item:name %}
{% for group in filter_form.field_groups %} {% if field|widget_type == 'checkboxinput' %}
<div class="col col-12"> <div class="form-check mb-3">
{% for name in group %} <label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
{% with field=filter_form|get_item:name %} {{ field }}
{% if field|widget_type == 'checkboxinput' %} </div>
<div class="form-check mb-3"> {% else %}
<label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label> <div class="mb-3 px-2">
{{ field }} <label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
</div> {{ field }}
{% else %} </div>
<div class="mb-3 px-2"> {% endif %}
<label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label> {% endwith %}
{{ field }} {% endfor %}
</div> </div>
{% endif %} {% if forloop.counter != filter_form.field_groups|length %}
{% endwith %} <hr class="card-divider mt-0" />
{% endfor %} {% endif %}
</div> {% endfor %}
{% if forloop.counter != filter_form.field_groups|length %} {% else %}
<hr class="card-divider mt-0" /> {% for field in filter_form.visible_fields %}
{% endif %} <div class="col col-12">
{% endfor %} {% if field|widget_type == 'checkboxinput' %}
{% else %} <div class="form-check mb-3">
{% for field in filter_form.visible_fields %} <label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="col col-12"> {{ field }}
{% if field|widget_type == 'checkboxinput' %} </div>
<div class="form-check mb-3"> {% else %}
<label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label> <div class="mb-3 px-2">
{{ field }} <label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
</div> {{ field }}
{% else %} </div>
<div class="mb-3 px-2"> {% endif %}
<label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label> </div>
{{ field }} {% endfor %}
</div> {% endif %}
{% endif %} </div>
</div> <div class="card-footer text-end noprint border-0">
{% endfor %} <button type="button" class="btn btn-sm btn-outline-danger m-1" data-reset-select>
{% endif %} <i class="mdi mdi-backspace"></i> Reset
</div> </button>
<div class="card-footer text-end noprint border-0"> <button type="submit" class="btn btn-sm btn-primary m-1">
<button type="button" class="btn btn-sm btn-outline-danger m-1" data-reset-select> <i class="mdi mdi-filter-variant"></i> Filter
<i class="mdi mdi-backspace"></i> Reset </button>
</button> </div>
<button type="submit" class="btn btn-sm btn-primary m-1"> </div>
<i class="mdi mdi-filter-variant"></i> Filter </form>
</button>
</div>
</div>
</form>
</div>