testtask.ui.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. * Merge cell in the product column.
  21. *
  22. * @param object cell
  23. * @access public
  24. * @return object
  25. */
  26. window.getCellSpan = function(cell)
  27. {
  28. if(cell.col.name == 'productName' && cell.row.data.rowspan)
  29. {
  30. return {rowSpan: cell.row.data.rowspan};
  31. }
  32. if(cell.col.name == 'idName' && cell.row.data.colspan)
  33. {
  34. return {colSpan: cell.row.data.colspan};
  35. }
  36. }
  37. /**
  38. * 产品列显示展开收起的图标。
  39. * Display show icon in the product column.
  40. *
  41. * @param object result
  42. * @param object info
  43. * @access public
  44. * @return object
  45. */
  46. window.onRenderCell = function(result, {row, col})
  47. {
  48. if(result && col.name == 'productName')
  49. {
  50. if(row.data.hidden)
  51. {
  52. 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>'});
  53. }
  54. else
  55. {
  56. 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>'});
  57. result.push({outer: false, style: {alignItems: 'start', 'padding-top': '8px'}})
  58. }
  59. }
  60. if(result && col.name == 'idName' && row.data.hidden)
  61. {
  62. result.push({outer: false, style: {alignItems: 'center', justifyContent: 'start'}})
  63. }
  64. if(col.name == 'status' && result)
  65. {
  66. result[0] = {html: `<span class='status-${row.data.rawStatus}'>` + row.data.status + "</span>"};
  67. }
  68. return result;
  69. }
  70. window.deformation = function(event)
  71. {
  72. let newData = [];
  73. const options = zui.DTable.query().options;
  74. const product = $(event.target).closest('a').data('product');
  75. const oldData = JSON.parse(JSON.stringify(options.taskData));
  76. if($(event.target).closest('a').find('span').hasClass('is-collapsed'))
  77. {
  78. $.each(options.data, function(index)
  79. {
  80. if(!options.data[index]) return;
  81. if(options.data[index].product == product)
  82. {
  83. $.each(oldData, function(key)
  84. {
  85. if(!oldData[key]) return;
  86. if(oldData[key].product == product) newData.push(oldData[key]);
  87. });
  88. }
  89. else
  90. {
  91. newData.push(options.data[index]);
  92. }
  93. });
  94. options.data = newData;
  95. $(event.target).closest('a').find('span').removeClass('is-collapsed').addClass('is-expanded');
  96. $('#taskTable').zui('dtable').render(options);
  97. }
  98. else
  99. {
  100. options.data = options.data.filter(function(option)
  101. {
  102. return option.product != product || option.rowspan != 0;
  103. });
  104. $.each(options.data, function(index, data)
  105. {
  106. if(data && data.product == product)
  107. {
  108. options.data[index].idName = {html: '<span class="text-gray">' + allTasks + ' ' + '<strong>' + data.rowspan + '</strong></span>'};
  109. options.data[index].rowspan = 1;
  110. options.data[index].colspan = 10;
  111. options.data[index].hidden = 1;
  112. }
  113. });
  114. $(event.target).closest('a').find('span').removeClass('is-expanded').addClass('is-collapsed');
  115. $('#taskTable').zui('dtable').render();
  116. }
  117. }
  118. /**
  119. * 计算测试单表格信息的统计。
  120. * Set task summary for table footer.
  121. *
  122. * @param element element
  123. * @param array checkedIDList
  124. * @access public
  125. * @return object
  126. */
  127. window.setStatistics = function(element, checkedIDList)
  128. {
  129. let waitCount = 0;
  130. let doingCount = 0;
  131. let doneCount = 0;
  132. let blockedCount = 0;
  133. let totalCount = 0;
  134. const rows = element.layout.allRows;
  135. rows.forEach((row) => {
  136. if(checkedIDList.length == 0 || checkedIDList.includes(row.id))
  137. {
  138. if(row.id.includes('_')) return;
  139. const task = row.data;
  140. if(task.rawStatus == 'wait')
  141. {
  142. waitCount ++;
  143. }
  144. else if(task.rawStatus == 'doing')
  145. {
  146. doingCount ++;
  147. }
  148. else if(task.rawStatus == 'done')
  149. {
  150. doneCount ++;
  151. }
  152. else if(task.rawStatus == 'blocked')
  153. {
  154. blockedCount ++;
  155. }
  156. totalCount ++;
  157. }
  158. })
  159. const summary = checkedIDList.length > 0 ? checkedAllSummary : pageSummary;
  160. return {
  161. html: summary.replace('%total%', totalCount)
  162. .replace('%wait%', waitCount)
  163. .replace('%testing%', doingCount)
  164. .replace('%blocked%', blockedCount)
  165. .replace('%done%', doneCount)
  166. };
  167. }
  168. /**
  169. * 判断当前行是否可以选中。
  170. * Judge whether the row can be selected.
  171. *
  172. * @param string rowID
  173. * @access public
  174. * @return bool
  175. */
  176. window.canRowCheckable = function(rowID)
  177. {
  178. let checkable = true;
  179. $.each(this.options.data, function(index, data)
  180. {
  181. if(data.id == rowID)
  182. {
  183. if(data.hidden == 1) checkable = false;
  184. return false;
  185. }
  186. });
  187. return checkable;
  188. }