browse.html.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. /**
  3. * The browse view file of bug module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Tingting Dai <daitingting@easycorp.ltd>
  7. * @package bug
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. jsVar('productID', $product->id);
  12. jsVar('branch', $branch);
  13. jsVar('today', date('Y-m-d'));
  14. jsVar('caseCommonLang', $this->lang->testcase->common);
  15. jsVar('from', $from);
  16. $queryMenuLink = createLink('bug', 'browse', "productID={$product->id}&branch={$branch}&browseType=bySearch&param={queryID}");
  17. $currentType = $browseType == 'bysearch' ? $param : ($browseType == 'bymodule' ? $this->session->bugBrowseType : $browseType);
  18. $isFromDoc = $from === 'doc';
  19. $isFromAI = $from === 'ai';
  20. if($isFromDoc || $isFromAI)
  21. {
  22. $this->app->loadLang('doc');
  23. $products = $this->loadModel('product')->getPairs('', 0, '', 'all');
  24. $productChangeLink = createLink($app->rawModule, $app->rawMethod, "productID={productID}&branch=$branch&browseType=$browseType&param=$param&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&from=$from&blockID=$blockID");
  25. $insertListLink = createLink($app->rawModule, $app->rawMethod, "productID=$product->id&branch=$branch&browseType=$browseType&param=$param&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&from=$from&blockID={blockID}");
  26. formPanel
  27. (
  28. setID('zentaolist'),
  29. setClass('mb-4-important'),
  30. set::title(sprintf($this->lang->doc->insertTitle, $this->lang->doc->zentaoList['productBug'])),
  31. set::actions(array()),
  32. set::showExtra(false),
  33. to::titleSuffix
  34. (
  35. span
  36. (
  37. setClass('text-muted text-sm text-gray-600 font-light'),
  38. span(setClass('text-warning mr-1'), icon('help')),
  39. $lang->doc->previewTip
  40. )
  41. ),
  42. formRow
  43. (
  44. formGroup
  45. (
  46. set::width('1/2'),
  47. set::name('product'),
  48. set::label($lang->doc->product),
  49. set::control(array('required' => false)),
  50. set::items($products),
  51. set::value($product->id),
  52. set::required(),
  53. span
  54. (
  55. setClass('error-tip text-danger hidden'),
  56. $lang->doc->emptyError
  57. ),
  58. on::change('[name="product"]')->do("loadModal('$productChangeLink'.replace('{productID}', $(this).val()))")
  59. )
  60. )
  61. );
  62. }
  63. featureBar
  64. (
  65. set::current($currentType),
  66. set::linkParams("product={$product->id}&branch={$branch}&browseType={key}&param={$param}&orderBy={$orderBy}&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&from=$from&blockID=$blockID"),
  67. set::isModal($isFromDoc || $isFromAI),
  68. set::queryMenuLinkCallback(array(function ($key) use ($queryMenuLink) {
  69. return str_replace('{queryID}', (string)$key, $queryMenuLink);
  70. })),
  71. li(searchToggle
  72. (
  73. set::simple($isFromDoc || $isFromAI),
  74. set::open($browseType == 'bysearch'),
  75. ($isFromDoc || $isFromAI) ? set::target('#docSearchForm') : null,
  76. ($isFromDoc || $isFromAI) ? set::onSearch(jsRaw('function(){$(this.element).closest(".modal").find("#featureBar .nav-item>.active").removeClass("active").find(".label").hide()}')) : null
  77. ))
  78. );
  79. if($isFromDoc || $isFromAI)
  80. {
  81. div(setID('docSearchForm'));
  82. }
  83. $canBeChanged = common::canModify('product', $product);
  84. $canBatchEdit = $canBeChanged && hasPriv('bug', 'batchEdit');
  85. $canBatchConfirm = $canBeChanged && hasPriv('bug', 'batchConfirm');
  86. $canBatchActivate = $canBeChanged && hasPriv('bug', 'batchActivate');
  87. $canBatchChangeBranch = $canBeChanged && hasPriv('bug', 'batchChangeBranch');
  88. $canBatchChangeModule = $canBeChanged && hasPriv('bug', 'batchChangeModule');
  89. $canBatchResolve = $canBeChanged && hasPriv('bug', 'batchResolve');
  90. $canBatchAssignTo = $canBeChanged && hasPriv('bug', 'batchAssignTo');
  91. $canBatchClose = hasPriv('bug', 'batchClose');
  92. $canManageModule = hasPriv('tree', 'browse');
  93. /* 如果是多分支多平台产品,且选定的是所有分支,则不允许批量更改所属模块。 If it is a multi-branch multi-platform product, and all branches are selected, it is not allowed to batch change the module. */
  94. if($product->type != 'normal' && $branch == 'all') $canBatchChangeModule = false;
  95. $canBatchAction = $canBatchEdit || $canBatchConfirm || $canBatchClose || $canBatchActivate || $canBatchChangeBranch || $canBatchChangeModule || $canBatchResolve || $canBatchAssignTo;
  96. if(!isonlybody())
  97. {
  98. $canCreate = false;
  99. $canBatchCreate = false;
  100. if($canBeChanged)
  101. {
  102. $canCreate = hasPriv('bug', 'create');
  103. $canBatchCreate = hasPriv('bug', 'batchCreate');
  104. $selectedBranch = $branch != 'all' ? $branch : 0;
  105. $createLink = $this->createLink('bug', 'create', "productID={$product->id}&branch=$selectedBranch&extra=moduleID=$currentModuleID");
  106. $batchCreateLink = $this->createLink('bug', 'batchCreate', "productID={$product->id}&branch=$branch&executionID=0&moduleID=$currentModuleID");
  107. if(commonModel::isTutorialMode())
  108. {
  109. $wizardParams = helper::safe64Encode("productID={$product->id}&branch=$branch&extra=moduleID=$currentModuleID");
  110. $createLink = $this->createLink('tutorial', 'wizard', "module=bug&method=create&params=$wizardParams");
  111. }
  112. $createItem = array('text' => $lang->bug->create, 'url' => $createLink);
  113. $batchCreateItem = array('text' => $lang->bug->batchCreate, 'url' => $batchCreateLink);
  114. }
  115. toolbar
  116. (
  117. setClass(array('hidden' => $isFromDoc || $isFromAI)),
  118. hasPriv('bug', 'report') ? item(set(array
  119. (
  120. 'icon' => 'bar-chart',
  121. 'text' => $lang->bug->report->common,
  122. 'class' => 'ghost',
  123. 'url' => createLink('bug', 'report', "productID=$product->id&browseType=$browseType&branch=$branch&module=$currentModuleID")
  124. ))) : null,
  125. hasPriv('bug', 'export') ? item(set(array
  126. (
  127. 'text' => $lang->export,
  128. 'icon' => 'export',
  129. 'class' => 'ghost',
  130. 'url' => createLink('bug', 'export', "productID={$product->id}&browseType={$browseType}"),
  131. 'data-toggle' => 'modal'
  132. ))) : null,
  133. $canCreate && $canBatchCreate ? btngroup
  134. (
  135. btn(setClass('btn primary create-bug-btn'), set::icon('plus'), set::url($createLink), $lang->bug->create),
  136. dropdown
  137. (
  138. btn(setClass('btn primary dropdown-toggle'), setStyle(array('padding' => '6px', 'border-radius' => '0 2px 2px 0'))),
  139. set::items(array($createItem, $batchCreateItem)),
  140. set::placement('bottom-end')
  141. )
  142. ) : null,
  143. $canCreate && !$canBatchCreate ? item(set($createItem + array('class' => 'btn primary', 'icon' => 'plus'))) : null,
  144. $canBatchCreate && !$canCreate ? item(set($batchCreateItem + array('class' => 'btn primary', 'icon' => 'plus'))) : null
  145. );
  146. }
  147. $closeLink = createLink('bug', 'browse', "productID={$product->id}&branch={$branch}&browseType=byModule&param=0&orderBy={$orderBy}&recTotal=0&recPerPage={$pager->recPerPage}");
  148. $settingLink = $canManageModule ? createLink('tree', 'browse', "productID={$product->id}&view=bug&currentModuleID=0&branch=0&from={$this->lang->navGroup->bug}") : '';
  149. if(!$isFromDoc && !$isFromAI)
  150. {
  151. sidebar
  152. (
  153. moduleMenu(set(array
  154. (
  155. 'modules' => $moduleTree,
  156. 'activeKey' => $currentModuleID,
  157. 'closeLink' => $closeLink,
  158. 'settingLink' => $settingLink
  159. )))
  160. );
  161. }
  162. $resolveItems = array();
  163. foreach($lang->bug->resolutionList as $key => $resolution)
  164. {
  165. if(empty($key) || $key == 'duplicate' || $key == 'tostory') continue;
  166. if($key == 'fixed')
  167. {
  168. $buildItems = array();
  169. foreach($builds as $key => $build) $buildItems[] = array('text' => $build, 'innerClass' => 'batch-btn ajax-btn not-open-url', 'data-url' => createLink('bug', 'batchResolve', "resolution=fixed&resolvedBuild=$key"));
  170. $resolveItems[] = array('text' => $resolution, 'class' => 'not-hide-menu', 'items' => $buildItems);
  171. }
  172. else
  173. {
  174. $resolveItems[] = array('text' => $resolution, 'innerClass' => 'batch-btn ajax-btn not-open-url', 'data-url' => createLink('bug', 'batchResolve', "resolution=$key"));
  175. }
  176. }
  177. $batchItems = array
  178. (
  179. array('text' => $lang->bug->confirm, 'innerClass' => 'batch-btn ajax-btn not-open-url ' . ($canBatchConfirm ? '' : 'hidden'), 'data-url' => helper::createLink('bug', 'batchConfirm')),
  180. array('text' => $lang->bug->close, 'innerClass' => 'batch-btn ajax-btn not-open-url ' . ($canBatchClose ? '' : 'hidden'), 'data-url' => helper::createLink('bug', 'batchClose')),
  181. array('text' => $lang->bug->activate, 'innerClass' => 'batch-btn not-open-url ' . ($canBatchActivate ? '' : 'hidden'), 'data-url' => helper::createLink('bug', 'batchActivate', "productID=$product->id&branch=$branch")),
  182. array('text' => $lang->bug->resolve, 'innerClass' => 'not-hide-menu ' . ($canBatchResolve ? '' : 'hidden'), 'items' => $resolveItems)
  183. );
  184. $branchItems = array();
  185. foreach($branchTagOption as $branchID => $branchName)
  186. {
  187. $branchItems[] = array('text' => $branchName, 'innerClass' => 'batch-btn ajax-btn not-open-url', 'data-url' => helper::createLink('bug', 'batchChangeBranch', "branchID=$branchID"));
  188. }
  189. $moduleItems = array();
  190. foreach($modules as $moduleID => $module)
  191. {
  192. $moduleItems[] = array('text' => $module, 'innerClass' => 'batch-btn ajax-btn not-open-url', 'data-url' => helper::createLink('bug', 'batchChangeModule', "moduleID=$moduleID"));
  193. }
  194. $footToolbar = array();
  195. if($canBatchAction)
  196. {
  197. $footToolbar['items'] = array();
  198. $footToolbar['items'][] = array('type' => 'btn-group', 'items' => array
  199. (
  200. array('text' => $lang->edit, 'className' => 'primary batch-btn not-open-url', 'disabled' => ($canBatchEdit ? '': 'disabled'), 'data-url' => createLink('bug', 'batchEdit', "productID={$product->id}&branch=$branch")),
  201. array('caret' => 'up', 'data-placement' => 'top-start', 'class' => 'btn btn-caret size-sm primary not-open-url', 'items' => $batchItems)
  202. ));
  203. if($canBatchChangeBranch && $product->type != 'normal')
  204. {
  205. $footToolbar['items'][] = array('caret' => 'up', 'text' => $lang->product->branchName[$product->type], 'type' => 'dropdown', 'data-placement' => 'top-start', 'items' => $branchItems);
  206. }
  207. if($canBatchChangeModule)
  208. {
  209. $footToolbar['items'][] = array('caret' => 'up', 'text' => $lang->bug->abbr->module, 'type' => 'dropdown', 'data-placement' => 'top-start', 'items' => $moduleItems, 'data-menu' => array('searchBox' => true));
  210. }
  211. if($canBatchAssignTo)
  212. {
  213. $pinyinItems = common::convert2Pinyin($memberPairs);
  214. $assignedToItems = array();
  215. foreach($memberPairs as $key => $value)
  216. {
  217. $key = base64_encode((string)$key); // 编码用户名中的特殊字符
  218. $assignedToItems[] = array('text' => $value, 'keys' => zget($pinyinItems, $value, ''), 'innerClass' => 'batch-btn ajax-btn not-open-url', 'data-url' => helper::createLink('bug', 'batchAssignTo', "assignedTo=$key&productID={$product->id}&type=product"));
  219. }
  220. $footToolbar['items'][] = array('caret' => 'up', 'text' => $lang->bug->assignedTo, 'type' => 'dropdown', 'data-placement' => 'top-start', 'items' => $assignedToItems, 'data-menu' => array('searchBox' => true));
  221. }
  222. $footToolbar['btnProps'] = array('size' => 'sm', 'btnType' => 'secondary');
  223. }
  224. if($isFromDoc) $footToolbar = array(array('text' => $lang->doc->insertText, 'data-on' => 'click', 'data-call' => "insertListToDoc('#bugs', 'bug', $blockID, '$insertListLink')"));
  225. if($isFromAI) $footToolbar = array(array('text' => $lang->doc->insertText, 'data-on' => 'click', 'data-call' => "insertListToAI('#bugs', 'bug')"));
  226. $cols = $this->loadModel('datatable')->getSetting('bug');
  227. if(isset($cols['branch'])) $cols['branch']['map'] = array(BRANCH_MAIN => $lang->trunk) + $branchTagOption;
  228. if(isset($cols['project'])) $cols['project']['map'] = array('') + $projectPairs;
  229. if(isset($cols['execution'])) $cols['execution']['map'] = array('') + $executions;
  230. if(isset($cols['plan'])) $cols['plan']['map'] = array('') + $plans;
  231. if(isset($cols['task'])) $cols['task']['map'] = array('') + $tasks;
  232. if(isset($cols['toTask'])) $cols['toTask']['map'] = array('') + $tasks;
  233. if(isset($cols['story'])) $cols['story']['map'] = array('') + $stories;
  234. if(isset($cols['activatedCount'])) $cols['activatedCount']['map'] = array('');
  235. if($product->type == 'normal') unset($cols['branch']);
  236. foreach($cols as $colName => $col)
  237. {
  238. if(!isset($col['sortType'])) $cols[$colName]['sortType'] = true;
  239. }
  240. if($isFromDoc || $isFromAI)
  241. {
  242. if(isset($cols['actions'])) unset($cols['actions']);
  243. foreach($cols as $key => $col)
  244. {
  245. $cols[$key]['sortType'] = false;
  246. if(isset($col['link'])) unset($cols[$key]['link']);
  247. if($key == 'assignedTo') $cols[$key]['type'] = 'user';
  248. if($key == 'pri') $cols[$key]['priList'] = $lang->bug->priList;
  249. if($key == 'severity') $cols[$key]['severityList'] = $lang->bug->severityList;
  250. if($key == 'title') $cols[$key]['link'] = array('url' => createLink('bug', 'view', "bugID={id}"), 'data-toggle' => 'modal', 'data-size' => 'lg');
  251. }
  252. }
  253. $bugs = initTableData($bugs, $cols, $this->bug);
  254. $createBugLink = $canBeChanged && hasPriv('bug', 'create') ? createLink('bug', 'create', "productID={$product->id}&branch={$branch}&extra=moduleID=$currentModuleID") : '';
  255. dtable
  256. (
  257. set::id('bugs'),
  258. set::cols($cols),
  259. set::data(array_values($bugs)),
  260. set::userMap($users),
  261. set::checkable($canBatchAction || $isFromDoc || $isFromAI),
  262. set::orderBy($orderBy),
  263. set::footToolbar($footToolbar),
  264. set::footPager(usePager()),
  265. !$isFromDoc ? null : set::afterRender(jsCallback()->call('toggleCheckRows', $idList)),
  266. (!$isFromDoc && !$isFromAI) ? null : set::height(400),
  267. (!$isFromDoc && !$isFromAI) ? null : set::onCheckChange(jsRaw('window.checkedChange')),
  268. ($isFromDoc || $isFromAI) ? null : set::customCols(true),
  269. ($isFromDoc || $isFromAI) ? null : set::sortLink(inlink('browse', "product={$product->id}&branch={$branch}&browseType={$browseType}&param={$param}&orderBy={name}_{sortType}&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}")),
  270. set::onRenderCell(jsRaw('window.onRenderCell')),
  271. set::modules($modulePairs),
  272. set::emptyTip($lang->bug->notice->noBug),
  273. ($isFromDoc || $isFromAI) ? null : set::createTip($lang->bug->create),
  274. ($isFromDoc || $isFromAI) ? null : set::createLink($createBugLink)
  275. );
  276. render();