guests_boot_jobs.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. {% extends "layout.html" %}
  2. {% block head %}
  3. {{ super() }}
  4. <style type="text/css">
  5. .table {
  6. font-size: 12px;
  7. border-width: 1px;
  8. line-height: 20px;
  9. }
  10. .table > thead > tr > th,
  11. .table > tfoot > tr > th {
  12. color: #999999;
  13. font-weight: normal;
  14. border-bottom: 0 solid #e1e6eb;
  15. background-color: #F5F6FA;
  16. }
  17. .table > tbody > tr > td {
  18. color: #424547;
  19. }
  20. .table-bordered > tbody > tr {
  21. padding-top: 10px;
  22. padding-bottom: 10px;
  23. }
  24. .table-bordered > thead > tr > th,
  25. .table-bordered > tbody > tr > th,
  26. .table-bordered > tfoot > tr > th,
  27. .table-bordered > thead > tr > td,
  28. .table-bordered > tbody > tr > td,
  29. .table-bordered > tfoot > tr > td {
  30. border-style: solid;
  31. border-width: 1px 0 0 0;
  32. }
  33. .btn,
  34. .form-control,
  35. .modal-content {
  36. border-radius: 0 !important;
  37. }
  38. .tr-selected td,
  39. .tr-selected {
  40. color: #000 !important;
  41. background: #fafaff !important;
  42. }
  43. </style>
  44. {% endblock head %}
  45. {% block content %}
  46. <script type="text/javascript">
  47. var page = 1;
  48. var page_size = 10;
  49. var keyword = '';
  50. var resource_path = window.location.pathname;
  51. var cur_url = resource_path;
  52. $(document).ready(function() {
  53. page_size = $('#page_size').val();
  54. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  55. var last_ready = null;
  56. $('#content_search').keydown(function() {
  57. if (last_ready !== null) {
  58. clearTimeout(last_ready);
  59. }
  60. last_ready = setTimeout(function () {
  61. keyword = $('#content_search').val();
  62. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  63. if (keyword.length > 0) {
  64. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  65. }
  66. window.location.href=cur_url;
  67. }, 1000);
  68. });
  69. $('#page_size').change(function () {
  70. keyword = $('#content_search').val();
  71. page_size = $('#page_size').val();
  72. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  73. if (keyword.length > 0) {
  74. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size + '&keyword=' + keyword;
  75. }
  76. window.location.href=cur_url;
  77. });
  78. $("thead").on('click', ".all_selector", function() {
  79. if ($("thead .all_selector").is(':checked')) {
  80. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  81. $(".all_selector").prop('checked', true);
  82. } else {
  83. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  84. $(".all_selector").prop('checked', false);
  85. }
  86. select_item_action();
  87. });
  88. $("tfoot").on('click', ".all_selector", function() {
  89. if ($("tfoot .all_selector").is(':checked')) {
  90. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', true);
  91. $(".all_selector").prop('checked', true);
  92. } else {
  93. $("tbody tr").find('td input[type="checkbox"]:eq(0)').prop('checked', false);
  94. $(".all_selector").prop('checked', false);
  95. }
  96. select_item_action();
  97. });
  98. $("tbody tr").on('click', "input[type='checkbox']", function() {
  99. select_item_action();
  100. });
  101. $('body').addClass('add-transition');
  102. $('.add-page-transition').on('click', function(){
  103. var transAttr = $(this).attr('data-transition');
  104. $('.add-transition').attr('class', 'add-transition');
  105. $('.add-transition').addClass(transAttr);
  106. });
  107. });
  108. function get_selected_element(checked) {
  109. if (checked === null) {
  110. checked = true;
  111. }
  112. if (checked) {
  113. return $('tbody :checked');
  114. } else {
  115. return $('tbody input:not(:checked)');
  116. }
  117. }
  118. function highlight_selected_element() {
  119. var selected_element = get_selected_element(true);
  120. var no_selected_element = get_selected_element(false);
  121. selected_element.each(function(i, e) {
  122. $(e).parent().parent().toggleClass('tr-selected', true);
  123. });
  124. no_selected_element.each(function(i, e) {
  125. $(e).parent().parent().toggleClass('tr-selected', false);
  126. });
  127. }
  128. function shortcut_bar_enable() {
  129. var selected_element = get_selected_element(true);
  130. if (selected_element.length > 0) {
  131. $('.btn-shortcut').toggleClass('disabled', false);
  132. } else {
  133. $('.btn-shortcut').toggleClass('disabled', true);
  134. }
  135. }
  136. function select_item_action() {
  137. highlight_selected_element();
  138. shortcut_bar_enable();
  139. }
  140. function refresh() {
  141. page = $('#pagination li.active a').text();
  142. page_size = $('#page_size').val();
  143. cur_url = resource_path + '?page=' + page + '&page_size=' + page_size;
  144. window.location.href=cur_url;
  145. }
  146. function remove(uuid, boot_job_id, do_refresh) {
  147. $.ajax({
  148. url : '/api/guests/_boot_jobs/' + uuid + '/' + boot_job_id,
  149. type : 'DELETE',
  150. contentType: "application/json; charset=utf-8",
  151. error : function() {
  152. alter_danger('启动作业删除指令发送失败!');
  153. },
  154. success : function() {
  155. // 未指定值的参数为 undefined
  156. if (do_refresh) {
  157. alter_success('启动作业删除指令发送成功!');
  158. refresh();
  159. }
  160. }
  161. });
  162. }
  163. function delete_at(me) {
  164. var uuid = $('#instance_uuid').val();
  165. var boot_job_id = $('#instance_boot_job_id').val();
  166. remove(uuid, boot_job_id, true);
  167. $('#delete_modal').modal('hide');
  168. }
  169. function get_selected_uuids_and_boot_jobs_id() {
  170. var selected_element = get_selected_element(true);
  171. var uuids = [];
  172. var boot_jobs_id = [];
  173. selected_element.each(function(i, e) {
  174. var uuid = $(e).parent().prev().prev().text();
  175. var boot_job_id = $(e).parent().prev().text();
  176. uuids.push(uuid);
  177. boot_jobs_id.push(boot_job_id);
  178. });
  179. return {'uuids': uuids, 'boot_jobs_id': boot_jobs_id};
  180. }
  181. function get_checked_uuids_and_boot_jobs_id() {
  182. var uuids_and_boot_jobs_id = get_selected_uuids_and_boot_jobs_id();
  183. if (uuids_and_boot_jobs_id['uuids'].length < 1) {
  184. alter_warning('未选择任何可操作的实例!');
  185. return false;
  186. }
  187. return uuids_and_boot_jobs_id;
  188. }
  189. function batch_delete() {
  190. var uuids_and_boot_jobs_id = get_checked_uuids_and_boot_jobs_id();
  191. if (uuids_and_boot_jobs_id['uuids'] && uuids_and_boot_jobs_id['boot_jobs_id']) {
  192. for (var i=0; i<uuids_and_boot_jobs_id['uuids'].length; i++) {
  193. if (i === uuids_and_boot_jobs_id['uuids'].length - 1) {
  194. remove(uuids_and_boot_jobs_id['uuids'][i], uuids_and_boot_jobs_id['boot_jobs_id'][i], true);
  195. } else {
  196. remove(uuids_and_boot_jobs_id['uuids'][i], uuids_and_boot_jobs_id['boot_jobs_id'][i], false);
  197. }
  198. }
  199. }
  200. $('#batch_delete_modal').modal('hide');
  201. }
  202. </script>
  203. <div class="panel">
  204. <div class="panel-body">
  205. <h3 class="title-hero" style="font-size: 24px;">
  206. 虚拟机启动作业
  207. </h3>
  208. <div>
  209. <div id="datatable-row-highlight_wrapper" class="dataTables_wrapper form-inline">
  210. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  211. <div class="col-sm-12" style="padding-right: 0;">
  212. <div class="pull-right">
  213. <button class="btn btn-default" onclick="refresh()" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  214. </div>
  215. </div>
  216. </div>
  217. <table id="guests_boot_jobs_list" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  218. style="width: 100%; margin-bottom: 0; border-bottom-width: 0;">
  219. <thead>
  220. <tr role="row">
  221. <th style="display: none;">UUID</th>
  222. <th style="display: none;">启动作业 ID</th>
  223. <th><input class="all_selector" title="选取所有" type="checkbox"></th>
  224. <th width="180px;">有效时间</th>
  225. <th width="180px;">启动作业</th>
  226. <th width="180px;">名称</th>
  227. <th></th>
  228. <th>状态</th>
  229. <th>IP</th>
  230. <th>操作</th>
  231. </tr>
  232. </thead>
  233. <tbody>
  234. {% for uuid, boot_jobs in guests_boot_jobs_ret.data.iteritems() %}
  235. {% for boot_job_id in boot_jobs.boot_jobs %}
  236. <tr role="row" class="odd">
  237. <td style="display: none;">{{ uuid }}</td>
  238. <td style="display: none;">{{ boot_job_id }}</td>
  239. <td><input title="选中" type="checkbox"></td>
  240. <td>
  241. <span style="color: #b94a48; {% if boot_jobs.ttl // 60 == 0 %}display: none;{% endif %}">{{ boot_jobs.ttl // 60 }}分</span>
  242. <span style="color: #b94a48; {% if boot_jobs.ttl % 60 == 0 %}display: none;{% endif %}">{{ boot_jobs.ttl % 60 }}秒</span>
  243. </td>
  244. <td>
  245. <div>
  246. <a href="/operate_rules?boot_job_id={{ boot_job_id }}">
  247. <p style="display: inline-block;">{{ boot_jobs_mapping_by_id[boot_job_id | int].name }}</p>
  248. </a>
  249. </div>
  250. </td>
  251. <td>
  252. <div>
  253. <a href="/guest/detail/{{ uuid }}">
  254. <p style="display: inline-block;">
  255. {{ guests_mapping_by_uuid[uuid].label }}
  256. </p>
  257. </a>
  258. <div>
  259. <p style="display: inline-block;">{{ guests_mapping_by_uuid[uuid].remark }}</p>
  260. </div>
  261. </div>
  262. </td>
  263. <td><span class="{{ os_templates_mapping_by_id[guests_mapping_by_uuid[uuid].os_template_id].icon }}"></span></td>
  264. <td>{{ format_guest_status(guests_mapping_by_uuid[uuid].status, guests_mapping_by_uuid[uuid].progress)|safe }}</td>
  265. <td>{{ guests_mapping_by_uuid[uuid].ip }}</td>
  266. <td>
  267. <div class="dropdown inline-block">
  268. <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
  269. 更多
  270. </a>
  271. <ul class="dropdown-menu">
  272. <li>
  273. <a href="javascript:;" data-toggle="modal" data-target="#delete_modal"
  274. onclick="$('#instance_uuid').val($(this).parent().parent().parent().parent().parent().children()[0].textContent);
  275. $('#instance_boot_job_id').val($(this).parent().parent().parent().parent().parent().children()[1].textContent);
  276. $('#delete_instance_desc').text($($(this).parent().parent().parent().parent().parent().children()[5]).find('div a')[0].text);
  277. $('#delete_instance_desc').append('/' + $($(this).parent().parent().parent().parent().parent().children()[4]).find('div a')[0].text)">
  278. 删除
  279. </a>
  280. </li>
  281. </ul>
  282. </div>
  283. </td>
  284. </tr>
  285. {% endfor %}
  286. {% endfor %}
  287. </tbody>
  288. </table>
  289. <table class="table table-bordered" style="border-top-width: 0; z-index: 99; position: sticky; bottom: 0;">
  290. <tfoot>
  291. <tr style="height: 70px;">
  292. <th><input type="checkbox" title="选取所有" class="all_selector"></th>
  293. <th>
  294. <div class="row">
  295. <div class="col-sm-6">
  296. <button class="btn btn-default btn-shortcut disabled" data-toggle="modal" data-target="#batch_delete_modal">删除</button>
  297. </div>
  298. <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
  299. 共有{{ paging_total }}个,每页显示:
  300. <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
  301. <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
  302. <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
  303. <option value="50" {% if page_size == 50 %} selected {% endif %}>50</option>
  304. </select>&nbsp;&nbsp;个
  305. </div>
  306. <div class="col-sm-3" style="text-align: left;">
  307. <div class="dataTables_paginate paging_bootstrap" id="datatable-row-highlight_paginate">
  308. <ul id="pagination" class="pagination">
  309. <li class="{% if page == 1 %} disabled {% endif %}">
  310. <a href="{{ resource_path }}?page={{ page - 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}">«</a>
  311. </li>
  312. {% for item in pages %}
  313. <li class="{% if item == page %} active {% endif %}">
  314. <a href="{{ resource_path }}?page={{ item }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}">{{ item }}</a>
  315. </li>
  316. {% endfor %}
  317. <li class="{% if page == last_page %} disabled {% endif %}">
  318. <a href="{{ resource_path }}?page={{ page + 1 }}&page_size={{ page_size }}{% if keyword %}&keyword={{ keyword }}{% endif %}">»</a>
  319. </li>
  320. </ul>
  321. </div>
  322. </div>
  323. </div>
  324. </th>
  325. </tr>
  326. </tfoot>
  327. </table>
  328. </div>
  329. </div>
  330. </div>
  331. </div>
  332. <input id="instance_uuid" title="实例 UUID" class="form-control" name="uuid" hidden>
  333. <input id="instance_boot_job_id" title="实例启动作业 ID" class="form-control" name="boot_job_id" hidden>
  334. <div class="modal" id="delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  335. <div class="modal-dialog">
  336. <div class="modal-content">
  337. <div class="modal-header">
  338. <h4 class="modal-title">删除启动作业:</h4>
  339. </div>
  340. <div class="modal-body">
  341. <p>你确定要删除该启动作业吗?</p>
  342. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  343. </div>
  344. <div class="modal-footer">
  345. <button type="button" class="btn btn-sm btn-primary" onclick="delete_at();">确定</button>
  346. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  347. </div>
  348. </div>
  349. </div>
  350. </div>
  351. <div class="modal" id="batch_delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  352. <div class="modal-dialog">
  353. <div class="modal-content">
  354. <div class="modal-header">
  355. <h4 class="modal-title">批量删除启动作业:</h4>
  356. </div>
  357. <div class="modal-body">
  358. <p>您确定要执行批量删除选择的启动作业吗?</p>
  359. </div>
  360. <div class="modal-footer">
  361. <button type="button" class="btn btn-sm btn-primary" onclick="batch_delete();">确定</button>
  362. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  363. </div>
  364. </div>
  365. </div>
  366. </div>
  367. {% endblock content %}