Просмотр исходного кода

Refactor image attachments panel template

jeremystretch 4 лет назад
Родитель
Сommit
357a5d1e65

+ 1 - 16
netbox/templates/dcim/device.html

@@ -290,22 +290,7 @@
                 </div>
                 </div>
                 {% endif %}
                 {% endif %}
             </div>
             </div>
-            <div class="card">
-                <h5 class="card-header">
-                    Images
-                </h5>
-                <div class="card-body">
-                    {% include 'inc/image_attachments.html' with images=object.images.all %}
-                </div>
-                {% if perms.extras.add_imageattachment %}
-                <div class="card-footer text-end noprint">
-                    <a href="{% url 'extras:imageattachment_add' %}?content_type=dcim.device&object_id={{ object.pk }}" class="btn btn-primary btn-sm">
-                        <span class="mdi mdi-plus-thick" aria-hidden="true"></span>
-                        Attach an Image
-                    </a>
-                </div>
-                {% endif %}
-            </div>
+            {% include 'inc/image_attachments_panel.html' %}
             <div class="card noprint">
             <div class="card noprint">
                 <h5 class="card-header">
                 <h5 class="card-header">
                     Related Devices
                     Related Devices

+ 1 - 16
netbox/templates/dcim/location.html

@@ -59,22 +59,7 @@
   </div>
   </div>
 	<div class="col col-md-6">
 	<div class="col col-md-6">
     {% include 'inc/custom_fields_panel.html' %}
     {% include 'inc/custom_fields_panel.html' %}
-    <div class="card">
-        <h5 class="card-header">
-            Images
-        </h5>
-        <div class="card-body">
-          {% include 'inc/image_attachments.html' with images=object.images.all %}
-        </div>
-        {% if perms.extras.add_imageattachment %}
-          <div class="card-footer text-end noprint">
-              <a href="{% url 'extras:imageattachment_add' %}?content_type=dcim.location&object_id={{ object.pk }}" class="btn btn-primary btn-sm">
-                  <span class="mdi mdi-plus-thick" aria-hidden="true"></span>
-                  Attach an Image
-              </a>
-          </div>
-        {% endif %}
-    </div>
+    {% include 'inc/image_attachments_panel.html' %}
     {% plugin_right_page object %}
     {% plugin_right_page object %}
 	</div>
 	</div>
 </div>
 </div>

+ 1 - 16
netbox/templates/dcim/rack.html

@@ -210,22 +210,7 @@
                 </div>
                 </div>
             </div>
             </div>
         {% endif %}
         {% endif %}
-        <div class="card">
-            <h5 class="card-header">
-                Images
-            </h5>
-            <div class="card-body">
-            {% include 'inc/image_attachments.html' with images=object.images.all %}
-            </div>
-            {% if perms.extras.add_imageattachment %}
-            <div class="card-footer text-end noprint">
-                <a href="{% url 'extras:imageattachment_add' %}?content_type=dcim.rack&object_id={{ object.pk }}" class="btn btn-primary btn-sm">
-                    <i class="mdi mdi-plus-thick" aria-hidden="true"></i>
-                    Attach an Image
-                </a>
-            </div>
-            {% endif %}
-        </div>
+        {% include 'inc/image_attachments_panel.html' %}
         <div class="card">
         <div class="card">
             <h5 class="card-header">
             <h5 class="card-header">
                 Reservations
                 Reservations

+ 1 - 16
netbox/templates/dcim/site.html

@@ -242,22 +242,7 @@
               {% endif %}
               {% endif %}
             </div>
             </div>
         </div>
         </div>
-        <div class="card">
-            <h5 class="card-header">
-                Images
-            </h5>
-            <div class="card-body">
-            {% include 'inc/image_attachments.html' with images=object.images.all %}
-            </div>
-            {% if perms.extras.add_imageattachment %}
-                <div class="card-footer text-end noprint">
-                    <a href="{% url 'extras:imageattachment_add' %}?content_type=dcim.site&object_id={{ object.pk }}" class="btn btn-primary btn-sm">
-                        <i class="mdi mdi-plus-thick" aria-hidden="true"></i>
-                        Attach an image
-                    </a>
-                </div>
-            {% endif %}
-        </div>
+        {% include 'inc/image_attachments_panel.html' %}
         {% plugin_right_page object %}
         {% plugin_right_page object %}
 	</div>
 	</div>
 </div>
 </div>

+ 0 - 38
netbox/templates/inc/image_attachments.html

@@ -1,38 +0,0 @@
-{% load helpers %}
-
-{% if images %}
-    <table class="table table-hover">
-        <tr>
-            <th>Name</th>
-            <th>Size</th>
-            <th>Created</th>
-            <th></th>
-        </tr>
-        {% for attachment in images %}
-            <tr{% if not attachment.size %} class="table-danger"{% endif %}>
-                <td>
-                    <i class="mdi mdi-file-image-outline"></i>
-                    <a class="image-preview" href="{{ attachment.image.url }}" target="_blank">{{ attachment }}</a>
-                </td>
-                <td>{{ attachment.size|filesizeformat }}</td>
-                <td>{{ attachment.created|annotated_date }}</td>
-                <td class="text-end noprint">
-                    {% if perms.extras.change_imageattachment %}
-                        <a href="{% url 'extras:imageattachment_edit' pk=attachment.pk %}" class="btn btn-warning btn-sm lh-1" title="Edit Image">
-                            <i class="mdi mdi-pencil" aria-hidden="true"></i>
-                        </a>
-                    {% endif %}
-                    {% if perms.extras.delete_imageattachment %}
-                        <a href="{% url 'extras:imageattachment_delete' pk=attachment.pk %}" class="btn btn-danger btn-sm lh-1" title="Delete Image">
-                            <i class="mdi mdi-trash-can-outline" aria-hidden="true"></i>
-                        </a>
-                    {% endif %}
-                </td>
-            </tr>
-        {% endfor %}
-    </table>
-{% else %}
-    <div class="text-muted">
-        None
-    </div>
-{% endif %}

+ 52 - 0
netbox/templates/inc/image_attachments_panel.html

@@ -0,0 +1,52 @@
+{% load helpers %}
+
+<div class="card">
+  <h5 class="card-header">
+    Images
+  </h5>
+  <div class="card-body">
+    {% with images=object.images.all %}
+      {% if images.exists %}
+        <table class="table table-hover">
+          <tr>
+            <th>Name</th>
+            <th>Size</th>
+            <th>Created</th>
+            <th></th>
+          </tr>
+          {% for attachment in images %}
+            <tr{% if not attachment.size %} class="table-danger"{% endif %}>
+              <td>
+                <i class="mdi mdi-file-image-outline"></i>
+                <a class="image-preview" href="{{ attachment.image.url }}" target="_blank">{{ attachment }}</a>
+              </td>
+              <td>{{ attachment.size|filesizeformat }}</td>
+              <td>{{ attachment.created|annotated_date }}</td>
+              <td class="text-end noprint">
+                {% if perms.extras.change_imageattachment %}
+                  <a href="{% url 'extras:imageattachment_edit' pk=attachment.pk %}" class="btn btn-warning btn-sm lh-1" title="Edit Image">
+                    <i class="mdi mdi-pencil" aria-hidden="true"></i>
+                  </a>
+                {% endif %}
+                {% if perms.extras.delete_imageattachment %}
+                  <a href="{% url 'extras:imageattachment_delete' pk=attachment.pk %}" class="btn btn-danger btn-sm lh-1" title="Delete Image">
+                    <i class="mdi mdi-trash-can-outline" aria-hidden="true"></i>
+                  </a>
+                {% endif %}
+              </td>
+            </tr>
+          {% endfor %}
+        </table>
+      {% else %}
+        <div class="text-muted">None</div>
+      {% endif %}
+    {% endwith %}
+  </div>
+  {% if perms.extras.add_imageattachment %}
+    <div class="card-footer text-end noprint">
+      <a href="{% url 'extras:imageattachment_add' %}?content_type={{ object|meta:"app_label" }}.{{ object|meta:"model_name" }}&object_id={{ object.pk }}" class="btn btn-primary btn-sm">
+        <i class="mdi mdi-plus-thick" aria-hidden="true"></i> Attach an image
+      </a>
+    </div>
+  {% endif %}
+</div>