testtask.ui.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. $(document).off('click','.batch-btn').on('click', '.batch-btn', function()
  2. {
  3. const dtable = zui.DTable.query($(this).target);
  4. const checkedList = dtable.$.getChecks();
  5. if(!checkedList.length) return;
  6. const url = $(this).data('url');
  7. const form = new FormData();
  8. checkedList.forEach((id) => form.append('taskIdList[]', id));
  9. if($(this).hasClass('ajax-btn'))
  10. {
  11. $.ajaxSubmit({url, data: form});
  12. }
  13. else
  14. {
  15. postAndLoadPage(url, form);
  16. }
  17. })
  18. /**
  19. * 计算测试单表格信息的统计。
  20. * Set task summary for table footer.
  21. *
  22. * @param element element
  23. * @param array checkedIDList
  24. * @access public
  25. * @return object
  26. */
  27. window.setStatistics = function(element, checkedIDList)
  28. {
  29. let waitCount = 0;
  30. let doingCount = 0;
  31. let doneCount = 0;
  32. let blockedCount = 0;
  33. let totalCount = 0;
  34. const rows = element.layout.allRows;
  35. rows.forEach((row) => {
  36. if(checkedIDList.length == 0 || checkedIDList.includes(row.id))
  37. {
  38. if(row.id.includes('_')) return;
  39. const task = row.data;
  40. if(task.rawStatus == 'wait')
  41. {
  42. waitCount ++;
  43. }
  44. else if(task.rawStatus == 'doing')
  45. {
  46. doingCount ++;
  47. }
  48. else if(task.rawStatus == 'done')
  49. {
  50. doneCount ++;
  51. }
  52. else if(task.rawStatus == 'blocked')
  53. {
  54. blockedCount ++;
  55. }
  56. totalCount ++;
  57. }
  58. })
  59. resetFooterPadding();
  60. const summary = checkedIDList.length > 0 ? checkedAllSummary : pageSummary;
  61. return {
  62. html: summary.replace('%total%', totalCount)
  63. .replace('%wait%', waitCount)
  64. .replace('%testing%', doingCount)
  65. .replace('%blocked%', blockedCount)
  66. .replace('%done%', doneCount)
  67. };
  68. }
  69. let initialOptions;
  70. $(function()
  71. {
  72. const options = zui.evalValue($('[zui-create-dtable]').attr('zui-create-dtable'));
  73. initialOptions = $.extend(true, {}, options);
  74. });
  75. window.resetFooterPadding = function()
  76. {
  77. const width = $('#taskTable .dtable-body .dtable-cells-container .dtable-cell.is-last-row').width();
  78. $('#taskTable .dtable-footer').css('padding-left', width + 12);
  79. }
  80. /**
  81. * 产品列显示展开收起的图标。
  82. * Display show icon in the product column.
  83. *
  84. * @param object result
  85. * @param object info
  86. * @access public
  87. * @return object
  88. */
  89. window.onRenderCell = function(result, {row, col})
  90. {
  91. if(result && col.name == 'productName')
  92. {
  93. if(row.data.hidden)
  94. {
  95. result.unshift({html: '<a class="dtable-nested-toggle state" data-on="click" data-product=' + row.data.product + ' data-call="deformation" data-params="event")><span class="toggle-icon is-collapsed"></span></a>'});
  96. }
  97. else
  98. {
  99. result.unshift({html: '<a class="dtable-nested-toggle state" data-on="click" data-product=' + row.data.product + ' data-call="deformation" data-params="event")><span class="toggle-icon is-expanded"></span></a>'});
  100. result.push({outer: false, style: {alignItems: 'start', 'padding-top': '8px'}})
  101. }
  102. }
  103. if(result && col.name == 'taskID' && row.data.hidden)
  104. {
  105. result.push({outer: false, style: {alignItems: 'center', justifyContent: 'start'}})
  106. }
  107. if(col.name == 'status' && result)
  108. {
  109. result[0] = {html: `<span class='status-${row.data.rawStatus}'>` + row.data.status + "</span>"};
  110. }
  111. return result;
  112. }
  113. /**
  114. * 产品列合并单元格。
  115. * Merge cell in the product column.
  116. *
  117. * @param object cell
  118. * @access public
  119. * @return object
  120. */
  121. window.getCellSpan = function(cell)
  122. {
  123. if(cell.col.name == 'productName' && cell.row.data.rowspan)
  124. {
  125. return {rowSpan: cell.row.data.rowspan};
  126. }
  127. if(cell.col.name == 'taskID' && cell.row.data.colspan)
  128. {
  129. return {colSpan: cell.row.data.colspan};
  130. }
  131. }
  132. window.deformation = function(event)
  133. {
  134. let newData = [];
  135. const options = zui.DTable.query().options;
  136. const product = $(event.target).closest('a').data('product');
  137. const oldOptions = $.extend(true, {}, initialOptions);
  138. if($(event.target).closest('a').find('span').hasClass('is-collapsed'))
  139. {
  140. $.each(options.data, function(index)
  141. {
  142. if(!options.data[index]) return;
  143. if(options.data[index].product == product)
  144. {
  145. $.each(oldOptions.data, function(key)
  146. {
  147. if(!oldOptions.data[key]) return;
  148. if(oldOptions.data[key].product == product) newData.push(oldOptions.data[key]);
  149. });
  150. }
  151. else
  152. {
  153. newData.push(options.data[index]);
  154. }
  155. });
  156. options.data = newData;
  157. options.cols.forEach((col) => {if(col.name == 'taskID') col.checkbox = true});
  158. $(event.target).closest('a').find('span').removeClass('is-collapsed').addClass('is-expanded');
  159. $('#taskTable').zui('dtable').render(options);
  160. }
  161. else
  162. {
  163. options.data = options.data.filter(function(option)
  164. {
  165. return option.product != product || option.rowspan != 0;
  166. });
  167. $.each(options.data, function(index)
  168. {
  169. if(options.data[index] && options.data[index].product == product)
  170. {
  171. options.data[index].taskID = {html: '<span class="text-gray">' + allTasks + ' ' + '<strong>' + options.data[index].rowspan + '</strong></span>'};
  172. options.data[index].rowspan = 1;
  173. options.data[index].colspan = 10;
  174. options.data[index].hidden = true;
  175. }
  176. });
  177. options.cols.forEach((col) => {if(col.name == 'taskID') col.checkbox = false});
  178. $(event.target).closest('a').find('span').removeClass('is-expanded').addClass('is-collapsed');
  179. $('#taskTable').zui('dtable').render();
  180. }
  181. }