1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Reorganize & clean up templatetag templates

This commit is contained in:
jeremystretch
2021-12-22 15:05:24 -05:00
parent 37065b7c50
commit f369b5f588
18 changed files with 49 additions and 64 deletions

View File

@@ -0,0 +1,7 @@
{% load form_helpers %}
{% for field in form %}
{% if field.name in form.custom_fields %}
{% render_field field %}
{% endif %}
{% endfor %}

View File

@@ -0,0 +1,31 @@
{% load form_helpers %}
{% load helpers %}
{% if form.errors or form.non_field_errors %}
<div class="alert alert-danger mt-3" role="alert">
<h4 class="alert-heading">Errors</h4>
{% if form.errors and '__all__' not in form.errors %}
<hr />
{% endif %}
<div class="ps-2">
{% if form.errors and '__all__' not in form.errors %}
{% for field_name, errors in form.errors.items %}
{% if not field_name|startswith:'__' %}
{% with field=form|getfield:field_name %}
<strong>{{ field.label }}</strong>
<ul>
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endwith %}
{% endif %}
{% endfor %}
{% endif %}
{% if form.non_field_errors %}
<hr />
{{ form.non_field_errors }}
{% endif %}
</div>
</div>
{% endif %}

View File

@@ -0,0 +1,127 @@
{% load form_helpers %}
{% load helpers %}
{% if field|widget_type == 'checkboxinput' %}
<div class="row mb-3">
<div class="col-sm-3"></div>
<div class="col">
<div class="form-check{% if field.errors %} has-error{% endif %}">
{{ field }}
<label for="{{ field.id_for_label }}" class="form-check-label">
{{ field.label }}
</label>
</div>
{% if field.help_text %}
<span class="form-text">{{ field.help_text|safe }}</span>
{% endif %}
{% if bulk_nullable %}
<div class="form-check my-1">
<input type="checkbox" class="form-check-input" name="_nullify" value="{{ field.name }}" />
<label class="form-check-label">Set Null</label>
</div>
{% endif %}
</div>
</div>
{% elif field|widget_type == 'textarea' and not field.label %}
<div class="row mb-3">
{% if label %}
<label class="col-sm-3 col-form-label text-lg-end{% if field.field.required %} required{% endif %}" for="{{ field.id_for_label }}">
{{ label }}
</label>
{% else %}
{% endif %}
<div class="col">
{{ field }}
{% if field.help_text %}
<span class="form-text">{{ field.help_text|safe }}</span>
{% endif %}
{% if bulk_nullable %}
<div class="form-check my-1">
<input type="checkbox" class="form-check-input" name="_nullify" value="{{ field.name }}" />
<label class="form-check-label">Set Null</label>
</div>
{% endif %}
</div>
</div>
{% elif field|widget_type == 'slugwidget' %}
<div class="row mb-3">
<label class="col-sm-3 col-form-label text-lg-end{% if field.field.required %} required{% endif %}" for="{{ field.id_for_label }}">
{{ field.label }}
</label>
<div class="col">
<div class="input-group">
{{ field }}
<button id="reslug" type="button" title="Regenerate Slug" class="btn btn-outline-dark border-input">
<i class="mdi mdi-reload"></i>
</button>
</div>
</div>
</div>
{% elif field|widget_type == 'fileinput' %}
<div class="input-group mb-3">
<input
class="form-control"
type="file"
name="{{ field.name }}"
placeholder="{{ field.placeholder }}"
id="id_{{ field.name }}"
accept="{{ field.field.widget.attrs.accept }}"
{% if field.is_required %}required{% endif %}
/>
<label for="{{ field.id_for_label }}" class="input-group-text">{{ field.label|bettertitle }}</label>
</div>
{% elif field|widget_type == 'clearablefileinput' %}
<div class="row mb-3">
<label for="{{ field.id_for_label }}" class="form-label col col-md-3 text-lg-end{% if field.field.required %} required{% endif %}">
{{ field.label }}
</label>
<div class="col col-md-9">
{{ field }}
</div>
</div>
{% elif field|widget_type == 'selectmultiple' %}
<div class="row mb-3">
<label for="{{ field.id_for_label }}" class="form-label col col-md-3 text-lg-end{% if field.field.required %} required{% endif %}">
{{ field.label }}
</label>
<div class="col col-md-9">
{{ field }}
{% if bulk_nullable %}
<div class="form-check my-1">
<input type="checkbox" class="form-check-input" name="_nullify" value="{{ field.name }}" />
<label class="form-check-label">Set Null</label>
</div>
{% endif %}
</div>
</div>
{% else %}
<div class="row mb-3">
<label for="{{ field.id_for_label }}" class="col-sm-3 col-form-label text-lg-end{% if field.field.required %} required{% endif %}">
{{ field.label }}
</label>
<div class="col">
{{ field }}
{% if field.help_text %}
<span class="form-text">{{ field.help_text|safe }}</span>
{% endif %}
<div class="invalid-feedback">
{% if field.field.required %}
<strong>{{ field.label }}</strong> field is required.
{% endif %}
</div>
{% if bulk_nullable %}
<div class="form-check my-1">
<input type="checkbox" class="form-check-input" name="_nullify" value="{{ field.name }}" />
<label class="form-check-label">Set Null</label>
</div>
{% endif %}
</div>
</div>
{% endif %}

View File

@@ -0,0 +1,8 @@
{% load form_helpers %}
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
{% for field in form.visible_fields %}
{% render_field field %}
{% endfor %}

View File

@@ -0,0 +1,14 @@
{% if applied_filters %}
<div class="mb-3">
{% for filter in applied_filters %}
<a href="{{ filter.link_url }}" class="badge rounded-pill bg-primary text-decoration-none me-1">
<i class="mdi mdi-close"></i> {{ filter.link_text }}
</a>
{% endfor %}
{% if applied_filters|length > 1 %}
<a href="?" class="badge rounded-pill bg-danger text-decoration-none me-1">
<i class="mdi mdi-tag-off"></i> Clear all
</a>
{% endif %}
</div>
{% endif %}

View File

@@ -0,0 +1 @@
{% if value or show_empty %}<span class="badge bg-{{ bg_class }}">{{ value }}</span>{% endif %}

View File

@@ -0,0 +1,44 @@
{% load form_helpers %}
<div class="modal fade" tabindex="-1" id="{{ table_name }}_config">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Table Configuration</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form class="form-horizontal userconfigform" data-url="{% url 'users-api:userconfig-list' %}" data-config-root="tables.{{ form.table_name }}">
<div class="modal-body row">
<div class="col-5 text-center">
{{ form.available_columns.label }}
{{ form.available_columns }}
</div>
<div class="col-2 d-flex align-items-center">
<div>
<a class="btn btn-success btn-sm w-100 my-2" id="add_columns">
<i class="mdi mdi-arrow-right-bold"></i> Add
</a>
<a class="btn btn-danger btn-sm w-100 my-2" id="remove_columns">
<i class="mdi mdi-arrow-left-bold"></i> Remove
</a>
</div>
</div>
<div class="col-5 text-center">
{{ form.columns.label }}
{{ form.columns }}
<a class="btn btn-primary btn-sm mt-2" id="move-option-up" data-target="id_columns">
<i class="mdi mdi-arrow-up-bold"></i> Move Up
</a>
<a class="btn btn-primary btn-sm mt-2" id="move-option-down" data-target="id_columns">
<i class="mdi mdi-arrow-down-bold"></i> Move Down
</a>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-outline-danger" id="reset_tableconfig" value="Reset">Reset</button>
<button type="submit" class="btn btn-primary" id="save_tableconfig" value="Save">Save</button>
</div>
</form>
</div>
</div>
</div>

View File

@@ -0,0 +1,3 @@
{% load helpers %}
{% if url_name %}<a href="{% url url_name %}?tag={{ tag.slug }}">{% endif %}<span class="badge" style="color: {{ tag.color|fgcolor }}; background-color: #{{ tag.color }}">{{ tag }}</span>{% if url_name %}</a>{% endif %}

View File

@@ -0,0 +1,21 @@
{% if utilization == 0 %}
<div class="progress align-items-center justify-content-center">
<span class="w-100 text-center">{{ utilization }}%</span>
</div>
{% else %}
<div class="progress">
<div
role="progressbar"
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="{{ utilization }}"
class="progress-bar {{ bar_class }}"
style="width: {{ utilization }}%;"
>
{% if utilization >= 25 %}{{ utilization }}%{% endif %}
</div>
{% if utilization < 25 %}
<span class="ps-1">{{ utilization }}%</span>
{% endif %}
</div>
{% endif %}