Răsfoiți Sursa

磁盘页面加入排序

James Iter 9 ani în urmă
părinte
comite
2327fce9e6
3 a modificat fișierele cu 53 adăugiri și 19 ștergeri
  1. 40 15
      templates/disk_show.html
  2. 3 3
      templates/guest_show.html
  3. 10 1
      views/disk.py

+ 40 - 15
templates/disk_show.html

@@ -288,9 +288,9 @@
         });
     }
 
-    function remove(uuids) {
+    function remove(disk_uuid) {
         $.ajax({
-            url : '/api/disks/' + uuids.join(','),
+            url : '/api/disks/' + disk_uuid,
             type : 'DELETE',
             contentType: "application/json; charset=utf-8",
             error : function() {
@@ -333,6 +333,12 @@
             });
         });
     }
+
+    function delete_at(me) {
+        var disk_uuid = $('#instance_uuid').val();
+        remove(disk_uuid);
+        $('#delete_modal').modal('hide');
+    }
 </script>
 <div class="panel">
     <div class="panel-body">
@@ -392,25 +398,29 @@
                                 更多
                             </a>
                             <ul class="dropdown-menu">
-                                <li class="{% if item.state not in [1] %} disabled {% endif %}">
+                                <li class="{% if item.state not in [1] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
                                     <a href="javascript:;" data-toggle="modal" data-target="#mount_modal"
                                        onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);">
                                         挂载
                                     </a>
                                 </li>
-                                <li class="{% if item.sequence == 0 or item.state not in [2] %} disabled {% endif %}">
+                                <li class="{% if item.sequence == 0 or item.state not in [2] %} disabled {% endif %}" style="{% if item.sequence == 0 %}display: none;{% endif %}">
                                     <a href="javascript:;" onclick="unmount_at(this);">卸载</a>
                                 </li>
-                                <li class="divider"></li>
+                                <li class="divider" style="{% if item.sequence == 0 %} display: none; {% endif %}"></li>
                                 <li class="{% if item.state not in [1, 2] %} disabled {% endif %}">
                                     <a href="javascript:;" data-toggle="modal" data-target="#resize_modal"
                                        onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);reset_resize_value(this);">
                                         磁盘扩容
                                     </a>
                                 </li>
-                                <li class="divider"></li>
-                                <li class="{% if item.state not in [1, 255] %} disabled {% endif %}">
-                                    <a href="javascript:;" onclick="delete_at(this);">删除</a>
+                                <li class="divider" style="{% if item.sequence == 0 %} display: none; {% endif %}"></li>
+                                <li class="{% if item.state not in [1, 255] %} disabled {% endif %}" style="{% if item.sequence == 0 %} display: none; {% endif %}">
+                                    <a href="javascript:;" data-toggle="modal" data-target="#delete_modal"
+                                       onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[1]).find('div a')[0].text);
+                                       $('#delete_instance_desc').text($('#instance_uuid').val().split('-')[0] + '/' + $($(this).parent().parent().parent().parent().parent().children()[1]).find('div p')[0].textContent)">
+                                        删除
+                                    </a>
                                 </li>
                             </ul>
                         </div>
@@ -427,10 +437,7 @@
                         <th>
                             <div class="row">
                                 <div class="col-sm-6">
-                                    <button class="btn btn-default btn-shortcut disabled" onclick="batch_boot();">挂载</button>
-                                    <button class="btn btn-default btn-shortcut disabled" onclick="batch_reboot();">卸载</button>
-                                    <button class="btn btn-default btn-shortcut disabled" onclick="batch_shutdown();">磁盘扩容</button>
-                                    <button class="btn btn-default btn-shortcut disabled" onclick="batch_suspend();">删除</button>
+                                    <button class="btn btn-default btn-shortcut disabled" onclick="batch_boot();">备注</button>
                                 </div>
                                 <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
                                     共有{{ disks_ret.paging.total }}条,每页显示:
@@ -444,15 +451,15 @@
                                     <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
                                         <ul id="pagination" class="pagination">
                                             <li class="{% if page == 1 %} disabled {% endif %}">
-                                                <a href="{{ resource_path }}?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">«</a>
+                                                <a href="{{ resource_path }}?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">«</a>
                                             </li>
                                             {% for item in pages %}
                                             <li class="{% if item == page %} active {% endif %}">
-                                                <a href="{{ resource_path }}?page={{ item }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">{{ item }}</a>
+                                                <a href="{{ resource_path }}?page={{ item }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">{{ item }}</a>
                                             </li>
                                             {% endfor %}
                                             <li class="{% if page == last_page %} disabled {% endif %}">
-                                                <a href="{{ resource_path }}?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">»</a>
+                                                <a href="{{ resource_path }}?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}{% if order_by %}&order_by={{ order_by }}{% endif %}{% if order %}&order={{ order }}{% endif %}">»</a>
                                             </li>
                                         </ul>
                                     </div>
@@ -523,4 +530,22 @@
         </div>
     </div>
 </div>
+
+<div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
+    <div class="modal-dialog">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h4 class="modal-title">删除磁盘:</h4>
+            </div>
+            <div class="modal-body">
+                <p>删除的磁盘将无法找回,上面数据将永久消失。你确定要删除该磁盘吗?</p>
+                <h3 style="color: orangered;" id="delete_instance_desc"></h3>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
+                <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
+            </div>
+        </div>
+    </div>
+</div>
 {% endblock content %}

+ 3 - 3
templates/guest_show.html

@@ -705,15 +705,15 @@
                                     <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
                                         <ul id="pagination" class="pagination">
                                             <li class="{% if page == 1 %} disabled {% endif %}">
-                                                <a href="{{ resource_path }}?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">«</a>
+                                                <a href="{{ resource_path }}?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}">«</a>
                                             </li>
                                             {% for item in pages %}
                                             <li class="{% if item == page %} active {% endif %}">
-                                                <a href="{{ resource_path }}?page={{ item }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">{{ item }}</a>
+                                                <a href="{{ resource_path }}?page={{ item }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}">{{ item }}</a>
                                             </li>
                                             {% endfor %}
                                             <li class="{% if page == last_page %} disabled {% endif %}">
-                                                <a href="{{ resource_path }}?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">»</a>
+                                                <a href="{{ resource_path }}?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}">»</a>
                                             </li>
                                         </ul>
                                     </div>

+ 10 - 1
views/disk.py

@@ -33,6 +33,8 @@ def show():
     page = int(request.args.get('page', 1))
     page_size = int(request.args.get('page_size', 10))
     keyword = request.args.get('keyword', None)
+    order_by = request.args.get('order_by', None)
+    order = request.args.get('order', None)
     resource_path = request.path
 
     if page is not None:
@@ -44,6 +46,12 @@ def show():
     if keyword is not None:
         args.append('keyword=' + keyword.__str__())
 
+    if order_by is not None:
+        args.append('order_by=' + order_by)
+
+    if order is not None:
+        args.append('order=' + order)
+
     host_url = request.host_url.rstrip('/')
 
     disks_url = host_url + url_for('api_disks.r_get_by_filter')
@@ -78,7 +86,8 @@ def show():
                 break
 
     return render_template('disk_show.html', disks_ret=disks_ret, resource_path=resource_path, page=page,
-                           page_size=page_size, keyword=keyword, pages=pages, last_page=last_page)
+                           page_size=page_size, keyword=keyword, pages=pages, order_by=order_by, order=order,
+                           last_page=last_page)
 
 
 def create():