guest_show.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. {% extends "layout.html" %}
  2. {% block title %} Guest {% endblock %}
  3. {% block head %}
  4. {{ super() }}
  5. <style type="text/css">
  6. .table {
  7. font-size: 12px;
  8. border-width: 1px;
  9. line-height: 20px;
  10. }
  11. .table > thead > tr > th,
  12. .table > tfoot > tr > th {
  13. color: #999999;
  14. font-weight: normal;
  15. border-bottom: 0 solid #e1e6eb;
  16. background-color: #F5F6FA;
  17. }
  18. .table > tbody > tr > td {
  19. color: #6d6e6f;
  20. }
  21. .table-bordered > tbody > tr {
  22. padding-top: 10px;
  23. padding-bottom: 10px;
  24. height: 106px;
  25. }
  26. .table-bordered > thead > tr > th,
  27. .table-bordered > tbody > tr > th,
  28. .table-bordered > tfoot > tr > th,
  29. .table-bordered > thead > tr > td,
  30. .table-bordered > tbody > tr > td,
  31. .table-bordered > tfoot > tr > td {
  32. border-style: solid;
  33. border-width: 1px 0 0 0;
  34. }
  35. .btn,
  36. .form-control,
  37. .modal-content {
  38. border-radius: 0 !important;
  39. }
  40. </style>
  41. {% endblock head %}
  42. {% block content %}
  43. <script type="text/javascript">
  44. var page = 1;
  45. var page_size = 10;
  46. var keyword = '';
  47. var cur_url = '/guests';
  48. $(document).ready(function() {
  49. page_size = $('#page_size').val();
  50. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  51. var last_ready = null;
  52. $('#content_search').keydown(function() {
  53. if (last_ready !== null) {
  54. clearTimeout(last_ready);
  55. }
  56. last_ready = setTimeout(function () {
  57. keyword = $('#content_search').val();
  58. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  59. if (keyword.length > 0) {
  60. cur_url = '/guests?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  61. }
  62. window.location.href=cur_url;
  63. }, 1000);
  64. });
  65. $('#page_size').change(function () {
  66. keyword = $('#content_search').val();
  67. page_size = $('#page_size').val();
  68. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  69. if (keyword.length > 0) {
  70. cur_url = '/guests?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  71. }
  72. window.location.href=cur_url;
  73. });
  74. $("thead").on('click', ".all_selector", function() {
  75. if ($("thead .all_selector").is(':checked')) {
  76. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  77. $(".all_selector").prop('checked', true);
  78. } else {
  79. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  80. $(".all_selector").prop('checked', false);
  81. }
  82. });
  83. $("tfoot").on('click', ".all_selector", function() {
  84. if ($("tfoot .all_selector").is(':checked')) {
  85. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  86. $(".all_selector").prop('checked', true);
  87. } else {
  88. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  89. $(".all_selector").prop('checked', false);
  90. }
  91. });
  92. $('body').addClass('add-transition');
  93. $('.add-page-transition').on('click', function(){
  94. var transAttr = $(this).attr('data-transition');
  95. $('.add-transition').attr('class', 'add-transition');
  96. $('.add-transition').addClass(transAttr);
  97. });
  98. $('#edit_remark_modal').on('show.bs.modal', function (me) {
  99. $('#instance_uuid').val($(me.relatedTarget).parent().parent().prev().prev().text());
  100. $('#edit_remark').val($(me.relatedTarget).prev().text());
  101. })
  102. });
  103. function refresh() {
  104. keyword = $('#content_search').val();
  105. page = $('#pagination li.active a').text();
  106. page_size = $('#page_size').val();
  107. cur_url = '/guests?page=' + page + '&page_size=' + page_size;
  108. if (keyword.length > 0) {
  109. cur_url = '/guests?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  110. }
  111. window.location.href=cur_url;
  112. }
  113. function row_onmouseover(me) {
  114. $(me).find(".edit_remark_trigger").css('display','inline-flex');
  115. }
  116. function row_onmouseout(me) {
  117. $(me).find(".edit_remark_trigger").css('display','none');
  118. }
  119. function remark_update(me) {
  120. var uuid = $('#instance_uuid').val();
  121. var remark = $('#edit_remark').val();
  122. $('#edit_remark_modal').modal('hide');
  123. $.ajax({
  124. url : '/api/guest/' + uuid,
  125. type : 'PATCH',
  126. contentType: "application/json; charset=utf-8",
  127. data : JSON.stringify({
  128. remark: remark
  129. }),
  130. error : function() {
  131. alter_danger('实例备注更新失败!');
  132. },
  133. success : function() {
  134. $('#guest_list tbody').find('td:contains(' + uuid + ')').next().next().find('p').text(remark);
  135. alter_success('实例备注更新成功!');
  136. }
  137. });
  138. }
  139. </script>
  140. <div class="panel">
  141. <div class="panel-body">
  142. <h3 class="title-hero" style="font-size: 24px;">
  143. 虚拟机实例
  144. </h3>
  145. <div>
  146. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  147. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  148. <div class="col-sm-12" style="padding-right: 0;">
  149. <div id="datatable-row-highlight_filter" class="dataTables_filter" style="display: inline-block;">
  150. <input id="content_search" type="search" class="form-control" placeholder="模糊搜索..." value="{%- if keyword -%} {{ keyword }} {%- endif -%}" style="margin-left: 0; border-radius: 0;">
  151. </div>
  152. <div class="pull-right">
  153. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  154. <a class="btn btn-info add-page-transition" href="/guests/create" data-transition="pt-page-moveFromRight-init" style="border-radius: 0; padding-left: 40px; padding-right: 40px;">创建实例</a>
  155. </div>
  156. </div>
  157. </div>
  158. <table id="guest_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  159. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  160. <thead>
  161. <tr role="row">
  162. <th style="display: none;">UUID</th>
  163. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  164. <th width="180px;">名称</th>
  165. <th></th>
  166. <th>状态</th>
  167. <th>计算节点</th>
  168. <th>配置</th>
  169. <th>IP</th>
  170. <th>密码</th>
  171. <th>创建时间</th>
  172. <th>操作</th>
  173. </tr>
  174. </thead>
  175. <tbody>
  176. {% for item in guests_ret.data %}
  177. <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
  178. <td style="display: none;">{{ item.uuid }}</td>
  179. <td><input title="选中" type="checkbox"></td>
  180. <td>
  181. <div>
  182. <a href="javascript:;">{{ item.name }}</a>
  183. </div>
  184. <div>
  185. <p style="display: inline-block;">{{ item.remark }}</p>
  186. <a href="javascript:;" class="edit_remark_trigger" data-toggle="modal" data-target="#edit_remark_modal" style="display: none; float: right;">
  187. <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>
  188. </a>
  189. </div>
  190. </td>
  191. <td><span class="{{ os_template_mapping_by_id[item.os_template_id].icon }}"></span></td>
  192. <td>{{ format_guest_status(item.status)|safe }}</td>
  193. <td>{{ item.on_host }}</td>
  194. <td>CPU :&nbsp;&nbsp;{{ item.cpu }}&nbsp;核<br />内存 :&nbsp;&nbsp;{{ item.memory }}&nbsp;GB</td>
  195. <td>{{ item.ip }}</td>
  196. <td>{{ item.password }}</td>
  197. <td>{{ format_datetime_by_tus(item.create_time) }}</td>
  198. <td>
  199. <div class="dropdown inline-block">
  200. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  201. 更多
  202. </a>
  203. <ul class="dropdown-menu">
  204. <li class="{% if item.status not in [4, 5, 6] %} disabled {% endif %}">
  205. <a href="javascript:;">启动</a>
  206. </li>
  207. <li class="{% if item.status not in [1] %} disabled {% endif %}">
  208. <a href="javascript:;">重启</a>
  209. </li>
  210. <li class="{% if item.status not in [1] %} disabled {% endif %}">
  211. <a href="javascript:;">停止</a>
  212. </li>
  213. <li class="divider"></li>
  214. <li class="{% if item.status not in [1] %} disabled {% endif %}">
  215. <a href="javascript:;">暂停</a>
  216. </li>
  217. <li class="{% if item.status not in [3] %} disabled {% endif %}">
  218. <a href="javascript:;">恢复</a>
  219. </li>
  220. <li class="divider"></li>
  221. <li class="">
  222. <a href="javascript:;">密码重置</a>
  223. </li>
  224. <li class="{% if item.status not in [1, 3, 4, 5, 6] %} disabled {% endif %}">
  225. <a href="javascript:;">迁移到</a>
  226. </li>
  227. <li class="divider"></li>
  228. <li class="{% if item.status not in [4, 5, 6, 255] %} disabled {% endif %}">
  229. <a href="javascript:;">删除</a>
  230. </li>
  231. </ul>
  232. </div>
  233. </td>
  234. </tr>
  235. {% endfor %}
  236. </tbody>
  237. </table>
  238. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  239. <tfoot>
  240. <tr>
  241. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  242. <th>
  243. <div class="row">
  244. <div class="col-sm-8" style="font-size: 12px; padding-top: 5px; text-align: right;">
  245. 共有{{ guests_ret.paging.total }}条,每页显示:
  246. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  247. <option value="1" {% if page_size == 1 %} selected {% endif %}>1</option>
  248. <option value="2" {% if page_size == 2 %} selected {% endif %}>2</option>
  249. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  250. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  251. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  252. </select>&nbsp;&nbsp;条
  253. </div>
  254. <div class="col-sm-4" style="text-align: left;">
  255. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  256. <ul id="pagination" class="pagination">
  257. <li class="{% if page == 1 %} disabled {% endif %}">
  258. <a href="/guests?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">«</a>
  259. </li>
  260. {% for item in pages %}
  261. <li class="{% if item == page %} active {% endif %}">
  262. <a href="/guests?page={{ item }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">{{ item }}</a>
  263. </li>
  264. {% endfor %}
  265. <li class="{% if page == last_page %} disabled {% endif %}">
  266. <a href="/guests?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %} &keyword={{ keyword }} {% endif %}">»</a>
  267. </li>
  268. </ul>
  269. </div>
  270. </div>
  271. </div>
  272. </th>
  273. </tr>
  274. </tfoot>
  275. </table>
  276. </div>
  277. </div>
  278. </div>
  279. </div>
  280. <div class="modal" id="edit_remark_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  281. <div class="modal-dialog modal-sm">
  282. <div class="modal-content">
  283. <div class="modal-header">
  284. <h4 class="modal-title">编辑实例名称:</h4>
  285. </div>
  286. <div class="modal-body">
  287. <input id="instance_uuid" title="实例 UUID" class="form-control" name="uuid" hidden>
  288. <input id="edit_remark" title="实例名称" class="form-control" name="remark">
  289. </div>
  290. <div class="modal-footer">
  291. <button type="button" class="btn btn-sm btn-primary" onclick="remark_update();">确定</button>
  292. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  293. </div>
  294. </div>
  295. </div>
  296. </div>
  297. {% endblock content %}