snapshots_show.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. {% extends "layout.html" %}
  2. {% block head %}
  3. {{ super() }}
  4. <style type="text/css">
  5. @media (min-width: 768px) {
  6. .form-horizontal .control-label {
  7. text-align: left;
  8. }
  9. }
  10. label>span {
  11. color: deepskyblue;
  12. }
  13. .table {
  14. font-size: 12px;
  15. border-width: 1px;
  16. line-height: 20px;
  17. }
  18. .table > thead > tr > th,
  19. .table > tfoot > tr > th {
  20. color: #999999;
  21. font-weight: normal;
  22. border-bottom: 0 solid #e1e6eb;
  23. background-color: #F5F6FA;
  24. }
  25. .table > tbody > tr > td {
  26. color: #424547;
  27. }
  28. .table-bordered > tbody > tr {
  29. padding-top: 10px;
  30. padding-bottom: 10px;
  31. }
  32. .table-bordered > thead > tr > th,
  33. .table-bordered > tbody > tr > th,
  34. .table-bordered > tfoot > tr > th,
  35. .table-bordered > thead > tr > td,
  36. .table-bordered > tbody > tr > td,
  37. .table-bordered > tfoot > tr > td {
  38. border-style: solid;
  39. border-width: 1px 0 0 0;
  40. }
  41. .btn,
  42. .form-control,
  43. .modal-content {
  44. border-radius: 0 !important;
  45. }
  46. .btn-shortcut {
  47. font-size: 12px !important;
  48. padding: 0 26px;
  49. }
  50. .show {
  51. display: inline-block !important;
  52. }
  53. .tr-selected td,
  54. .tr-selected {
  55. color: #000 !important;
  56. background: #fafaff !important;
  57. }
  58. </style>
  59. {% endblock head %}
  60. {% block content %}
  61. <script type="text/javascript">
  62. var page = 1;
  63. var page_size = 10;
  64. var keyword = '';
  65. var resource_path = window.location.pathname;
  66. var cur_url = resource_path;
  67. $(document).ready(function() {
  68. page_size = $('#page_size').val();
  69. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  70. var last_ready = null;
  71. $('#content_search').keydown(function() {
  72. if (last_ready !== null) {
  73. clearTimeout(last_ready);
  74. }
  75. last_ready = setTimeout(function () {
  76. keyword = $('#content_search').val();
  77. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  78. if (keyword.length > 0) {
  79. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  80. }
  81. window.location.href=cur_url;
  82. }, 1000);
  83. });
  84. $('#page_size').change(function () {
  85. keyword = $('#content_search').val();
  86. page_size = $('#page_size').val();
  87. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  88. if (keyword.length > 0) {
  89. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  90. }
  91. window.location.href=cur_url;
  92. });
  93. $("thead").on('click', ".all_selector", function() {
  94. if ($("thead .all_selector").is(':checked')) {
  95. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  96. $(".all_selector").prop('checked', true);
  97. } else {
  98. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  99. $(".all_selector").prop('checked', false);
  100. }
  101. select_item_action();
  102. });
  103. $("tfoot").on('click', ".all_selector", function() {
  104. if ($("tfoot .all_selector").is(':checked')) {
  105. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  106. $(".all_selector").prop('checked', true);
  107. } else {
  108. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  109. $(".all_selector").prop('checked', false);
  110. }
  111. select_item_action();
  112. });
  113. $("tbody tr").on('click', "input[type='checkbox']", function() {
  114. select_item_action();
  115. });
  116. $('#edit_label_modal').on('show.bs.modal', function (me) {
  117. $('#snapshot_id').val($(me.relatedTarget).parent().parent().prev().prev().text());
  118. $('#edit_label').val($(me.relatedTarget).prev().text());
  119. });
  120. });
  121. function refresh() {
  122. keyword = $('#content_search').val();
  123. page = $('#pagination li.active a').text();
  124. page_size = $('#page_size').val();
  125. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  126. if (keyword.length > 0) {
  127. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  128. }
  129. window.location.href=cur_url;
  130. }
  131. function row_onmouseover(me) {
  132. $(me).find(".edit_label_trigger").css('display','inline-flex');
  133. }
  134. function row_onmouseout(me) {
  135. $(me).find(".edit_label_trigger").css('display','none');
  136. }
  137. function label_update(me) {
  138. var snapshot_id = $('#snapshot_id').val();
  139. var label = $('#edit_label').val();
  140. $('#edit_label_modal').modal('hide');
  141. $.ajax({
  142. url : '/api/snapshot/' + snapshot_id,
  143. type : 'PATCH',
  144. contentType: "application/json; charset=utf-8",
  145. data : JSON.stringify({
  146. label: label
  147. }),
  148. error : function() {
  149. alter_danger('快照名称更新失败!');
  150. },
  151. success : function() {
  152. alter_success('快照名称更新成功!');
  153. setTimeout(function() {
  154. refresh();
  155. }, 1000);
  156. }
  157. });
  158. }
  159. function revert_snapshot(me) {
  160. var snapshot_id = $('#snapshot_id').val();
  161. $('#snapshot_revert_modal').modal('hide');
  162. $.ajax({
  163. url : '/api/snapshot/_revert/' + snapshot_id,
  164. type : 'PUT',
  165. error : function() {
  166. alter_danger('快照恢复失败!');
  167. },
  168. success : function() {
  169. alter_success('快照恢复成功!');
  170. setTimeout(function() {
  171. refresh();
  172. }, 1000);
  173. }
  174. });
  175. }
  176. function delete_snapshot(me) {
  177. var snapshot_id = $('#snapshot_id').val();
  178. $('#snapshot_delete_modal').modal('hide');
  179. $.ajax({
  180. url : '/api/snapshots/' + snapshot_id,
  181. type : 'DELETE',
  182. error : function() {
  183. alter_danger('快照删除失败!');
  184. },
  185. success : function() {
  186. alter_success('快照删除成功!');
  187. setTimeout(function() {
  188. refresh();
  189. }, 1000);
  190. }
  191. });
  192. }
  193. function get_selected_element(checked) {
  194. if (checked === null) {
  195. checked = true;
  196. }
  197. if (checked) {
  198. return $('tbody :checked');
  199. } else {
  200. return $('tbody input:not(:checked)');
  201. }
  202. }
  203. function highlight_selected_element() {
  204. var selected_element = get_selected_element(true);
  205. var no_selected_element = get_selected_element(false);
  206. selected_element.each(function(i, e) {
  207. $(e).parent().parent().toggleClass('tr-selected', true);
  208. });
  209. no_selected_element.each(function(i, e) {
  210. $(e).parent().parent().toggleClass('tr-selected', false);
  211. });
  212. }
  213. function shortcut_bar_enable() {
  214. var selected_element = get_selected_element(true);
  215. if (selected_element.length > 0) {
  216. $('.btn-shortcut').toggleClass('disabled', false);
  217. } else {
  218. $('.btn-shortcut').toggleClass('disabled', true);
  219. }
  220. }
  221. function select_item_action() {
  222. highlight_selected_element();
  223. shortcut_bar_enable();
  224. }
  225. </script>
  226. <div class="panel">
  227. <div class="panel-body">
  228. <h3 class="title-hero" style="font-size: 24px;">
  229. 虚拟机实例快照
  230. </h3>
  231. <div>
  232. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  233. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  234. <div class="col-sm-12" style="padding-right: 0;">
  235. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  236. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  237. </div>
  238. <div class="pull-right">
  239. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  240. </div>
  241. </div>
  242. </div>
  243. <table id="snapshots_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  244. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  245. <thead>
  246. <tr role="row">
  247. <th style="display: none;">ID</th>
  248. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  249. <th width="180px;">名称</th>
  250. <th>进度</th>
  251. <th>状态</th>
  252. <th>所属虚拟机</th>
  253. <th>创建时间</th>
  254. <th>操作</th>
  255. </tr>
  256. </thead>
  257. <tbody>
  258. {% for item in snapshots_ret.data %}
  259. <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
  260. <td style="display: none;">{{ item.snapshot_id }}</td>
  261. <td><input title="选中" type="checkbox"></td>
  262. <td>
  263. <div>
  264. <a href="/snapshot/detail/{{ item.snapshot_id }}">{{ item.snapshot_id }}</a>
  265. </div>
  266. <div>
  267. <p style="display: inline-block;">{{ item.label }}</p>
  268. <a href="javascript:;" class="edit_label_trigger" data-toggle="modal" data-target="#edit_label_modal" style="display: none; float: right;">
  269. <span class="glyph-icon icon-elusive-pencil" style="width: 20px; height: 20px; margin-left: 10px; border-radius: 0; border: 1px solid rgb(220, 233, 255); background-color: #ffffff;"></span>
  270. </a>
  271. </div>
  272. </td>
  273. <td>
  274. {% if item.progress == 255 %}
  275. <span style="color: #990000;">创建失败</span>
  276. {% elif item.progress == 254 %}
  277. <span style="color: #ff0000dd;">删除中...</span>
  278. {% elif item.progress == 253 %}
  279. <span style="color: #009cc5;">恢复中...</span>
  280. {% elif item.progress == 100 %}
  281. <span style="color: #00BB00;">{{ item.progress }}%</span>
  282. {% else %}
  283. <span style="color: #e5b715;">{{ item.progress }}%</span>
  284. {% endif %}
  285. </td>
  286. <td>{{ format_guest_status(item.status, 100)|safe }}</td>
  287. <td><a href="/guest/detail/{{ item.guest_uuid }}" {% if 'guest' not in item %}style="display: none"{% endif %}>
  288. {% if 'guest' in item %}
  289. {{ item.guest.label }}/{{ item.guest.remark }}
  290. {% endif %}</a>
  291. </td>
  292. <td>{{ format_datetime_by_tus(item.create_time) }}</td>
  293. <td>
  294. <div class="dropdown inline-block">
  295. <a href="javascript:;" class="{% if item.progress not in [100] %} a-disabled {% endif %}" style="color: #0066cc" data-toggle="modal" data-target="#snapshot_revert_modal" onclick="$('#snapshot_id').val($(this).parent().parent().parent().children()[0].textContent);
  296. $('#revert_snapshot_instance_desc').text($($(this).parent().parent().parent().children()[2]).find('div a')[0].textContent + '/' + $($(this).parent().parent().parent().children()[2]).find('div p')[0].textContent)">恢复</a>
  297. <span> | </span>
  298. <a href="javascript:;" class="{% if item.progress not in [100, 255] %} a-disabled {% endif %}" style="color: #0066cc" data-toggle="modal" data-target="#snapshot_delete_modal" onclick="$('#snapshot_id').val($(this).parent().parent().parent().children()[0].textContent);
  299. $('#delete_snapshot_instance_desc').text($($(this).parent().parent().parent().children()[2]).find('div a')[0].textContent + '/' + $($(this).parent().parent().parent().children()[2]).find('div p')[0].textContent)">删除</a>
  300. </div>
  301. </td>
  302. </tr>
  303. {% endfor %}
  304. </tbody>
  305. </table>
  306. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  307. <tfoot>
  308. <tr style="height: 70px;">
  309. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  310. <th>
  311. <div class="row">
  312. <div class="col-sm-6">
  313. </div>
  314. <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
  315. 共有{{ snapshots_ret.paging.total }}条,每页显示:
  316. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  317. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  318. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  319. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  320. </select>&nbsp;&nbsp;条
  321. </div>
  322. <div class="col-sm-3" style="text-align: left;">
  323. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  324. <ul id="pagination" class="pagination">
  325. <li class="{% if page == 1 %} disabled {% endif %}">
  326. <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>
  327. </li>
  328. {% for item in pages %}
  329. <li class="{% if item == page %} active {% endif %}">
  330. <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>
  331. </li>
  332. {% endfor %}
  333. <li class="{% if page == last_page %} disabled {% endif %}">
  334. <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>
  335. </li>
  336. </ul>
  337. </div>
  338. </div>
  339. </div>
  340. </th>
  341. </tr>
  342. </tfoot>
  343. </table>
  344. </div>
  345. </div>
  346. </div>
  347. </div>
  348. <input id="snapshot_id" title="快照 ID" class="form-control" name="snapshot_id" hidden>
  349. <div class="modal" id="edit_label_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  350. <div class="modal-dialog modal-sm">
  351. <div class="modal-content">
  352. <div class="modal-header">
  353. <h4 class="modal-title">编辑实例快照名称:</h4>
  354. </div>
  355. <div class="modal-body">
  356. <input id="edit_label" title="实例快照名称" class="form-control" name="snapshot_label">
  357. </div>
  358. <div class="modal-footer">
  359. <button type="button" class="btn btn-sm btn-primary" onclick="label_update();">确定</button>
  360. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  361. </div>
  362. </div>
  363. </div>
  364. </div>
  365. <div class="modal" id="snapshot_revert_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  366. <div class="modal-dialog">
  367. <div class="modal-content">
  368. <div class="modal-header">
  369. <h4 class="modal-title">恢复实例快照:</h4>
  370. </div>
  371. <div class="modal-body">
  372. <p>你确定要使该虚拟机恢复至此快照吗?</p>
  373. <h3 style="color: orangered;" id="revert_snapshot_instance_desc"></h3>
  374. </div>
  375. <div class="modal-footer">
  376. <button type="button" class="btn btn-sm btn-primary" onclick="revert_snapshot();">确定</button>
  377. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  378. </div>
  379. </div>
  380. </div>
  381. </div>
  382. <div class="modal" id="snapshot_delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  383. <div class="modal-dialog">
  384. <div class="modal-content">
  385. <div class="modal-header">
  386. <h4 class="modal-title">删除实例快照:</h4>
  387. </div>
  388. <div class="modal-body">
  389. <p>你确定要删除此快照吗?</p>
  390. <h3 style="color: orangered;" id="delete_snapshot_instance_desc"></h3>
  391. </div>
  392. <div class="modal-footer">
  393. <button type="button" class="btn btn-sm btn-primary" onclick="delete_snapshot();">确定</button>
  394. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  395. </div>
  396. </div>
  397. </div>
  398. </div>
  399. {% endblock content %}