browse.html.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <?php
  2. /**
  3. * The browse view file of product module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author chen.tao<chentao@easycorp.ltd>
  8. * @package product
  9. * @link https://www.zentao.net
  10. */
  11. namespace zin;
  12. include($this->app->getModuleRoot() . 'ai/ui/promptmenu.html.php');
  13. data('storyType', $storyType);
  14. data('activeMenuID', $storyType);
  15. jsVar('userAccount', $this->app->user->account);
  16. jsVar('URChanged', $this->lang->story->URChanged);
  17. jsVar('gradeGroup', $gradeGroup);
  18. jsVar('oldShowGrades', $showGrades);
  19. jsVar('storyType', $storyType);
  20. jsVar('tab', $app->tab);
  21. jsVar('vision', $config->vision);
  22. jsVar('window.globalSearchType', $storyType);
  23. jsVar('storyViewPriv', hasPriv('story', 'view'));
  24. jsVar('storyAssignedToPriv', hasPriv('story', 'assignTo'));
  25. jsVar('requirementViewPriv', hasPriv('requirement', 'view'));
  26. jsVar('requirementAssignedToPriv', hasPriv('requirement', 'assignTo'));
  27. jsVar('epicViewPriv', hasPriv('epic', 'view'));
  28. jsVar('epicAssignedToPriv', hasPriv('epic', 'assignTo'));
  29. $viewType = $this->cookie->storyViewType ? $this->cookie->storyViewType : 'tree';
  30. $storyCommon = $storyType == 'requirement' ? $lang->URCommon : $lang->SRCommon;
  31. $isProjectStory = $this->app->rawModule == 'projectstory';
  32. $projectHasProduct = $isProjectStory && !empty($project->hasProduct);
  33. $projectIDParam = $isProjectStory ? "projectID=$projectID&" : '';
  34. $storyBrowseType = $this->session->storyBrowseType;
  35. $storyProductIds = array();
  36. $isFromDoc = $from === 'doc';
  37. $isFromAI = $from === 'ai';
  38. $tabCondition = $app->tab == 'product' || $isFromDoc || $isFromAI;
  39. $storyCondition = $storyType == 'story' && count($gradeGroup['story']) <= 2;
  40. $hideGrade = ($tabCondition && $storyCondition) || $config->vision != 'rnd';
  41. jsVar('projectHasProduct', $projectHasProduct);
  42. foreach($stories as $story) $storyProductIds[$story->product] = $story->product;
  43. $storyProductID = count($storyProductIds) > 1 ? 0 : $productID;
  44. /* Generate sidebar to display module tree menu. */
  45. $fnGenerateSideBar = function() use ($moduleTree, $moduleID, $productID, $branchID, $projectHasProduct, $param, $isProjectStory, $projectProducts)
  46. {
  47. global $app;
  48. $params = $app->rawParams;
  49. if(isset($params['browseType'])) $params['browseType'] = 'byModule';
  50. if(isset($params['param'])) $params['param'] = '';
  51. if(isset($params['recTotal'])) $params['recTotal'] = 0;
  52. if(isset($params['pageID'])) $params['pageID'] = 1;
  53. if($isProjectStory && $params['productID']) $params['productID'] = 0;
  54. sidebar
  55. (
  56. moduleMenu
  57. (
  58. set::modules($moduleTree),
  59. set::activeKey($isProjectStory && empty($param) && !empty($productID) && count($projectProducts) > 1 ? "p_" . $productID : $moduleID),
  60. set::closeLink(helper::createLink($app->rawModule, $app->rawMethod, http_build_query($params))),
  61. $productID ? set::settingLink(helper::createLink('tree', 'browse', "rootID=$productID&view=story&currentModuleID=0&branch=$branchID")) : null,
  62. set::settingApp($isProjectStory && !$projectHasProduct ? 'project' : 'product')
  63. )
  64. );
  65. };
  66. /* Build create story button. */
  67. $fnBuildCreateStoryButton = function() use ($lang, $product, $isProjectStory, $storyType, $productID, $branch, $moduleID, $projectID, $project, $projectProducts, $hasFrozenStories)
  68. {
  69. if(!common::canModify('product', $product)) return null;
  70. if(!empty($project) && !common::canModify('project', $project)) return null;
  71. global $app, $config;
  72. $currentProductID = empty($productID) ? current(array_keys($projectProducts)) : $productID;
  73. $createLink = createLink($storyType, 'create', "product=" . $currentProductID . "&branch=$branch&moduleID=$moduleID&storyID=0&projectID=$projectID&bugID=0&planID=0&todoID=0&extra=&storyType=$storyType") . ($isProjectStory ? '#app=project' : '');
  74. $batchCreateLink = createLink($storyType, 'batchCreate', "productID=$productID&branch=$branch&moduleID=$moduleID&storyID=0&project=$projectID&plan=0&storyType=$storyType"). ($isProjectStory ? '#app=project' : '');
  75. $createBtnLink = '';
  76. $createBtnTitle = '';
  77. if(hasPriv($storyType, 'create'))
  78. {
  79. $createBtnLink = $createLink;
  80. $createBtnTitle = $lang->story->create;
  81. }
  82. elseif(hasPriv($storyType, 'batchCreate'))
  83. {
  84. $createBtnLink = empty($productID) ? '' : $batchCreateLink;
  85. $createBtnTitle = $lang->story->batchCreate;
  86. }
  87. /* With batch create privileges then render the dropdown menu. */
  88. $items = array();
  89. if(commonModel::isTutorialMode())
  90. {
  91. /* Tutorial create link. */
  92. $wizardParams = helper::safe64Encode("productID=$productID&branch=$branch&moduleID=$moduleID");
  93. if($isProjectStory) $wizardParams = helper::safe64Encode("productID=$productID&branch=$branch&moduleID=$moduleID&storyID=&projectID=$projectID");
  94. $link = $this->createLink('tutorial', 'wizard', "module=story&method=create&params=$wizardParams");
  95. $items[] = array('text' => $lang->story->create, 'url' => $link);
  96. }
  97. elseif(!$isProjectStory && hasPriv($storyType, 'create'))
  98. {
  99. $items[] = array('text' => $lang->story->create, 'url' => $createLink);
  100. }
  101. $batchItems = array();
  102. if($isProjectStory && $config->vision != 'lite')
  103. {
  104. if(!empty($productID) && common::hasPriv('story', 'batchCreate')) $batchItems[] = array('text' => $lang->SRCommon, 'url' => $batchCreateLink);
  105. if(strpos($project->storyType, 'requirement') !== false && $this->config->URAndSR)
  106. {
  107. if(common::hasPriv('requirement', 'create'))
  108. {
  109. if(empty($createBtnLink))
  110. {
  111. $createBtnLink = createLink('requirement', 'create', "product=$currentProductID&branch=$branch&moduleID=$moduleID&requirementID=0&projectID=$projectID") . '#app=project';
  112. $createBtnTitle = $lang->requirement->create;
  113. }
  114. $items[] = array('text' => $lang->requirement->create, 'url' => createLink('requirement', 'create', "product=$currentProductID&branch=$branch&moduleID=$moduleID&requirementID=0&projectID=$projectID") . '#app=project');
  115. }
  116. if(common::hasPriv('requirement', 'batchCreate') && !empty($productID))
  117. {
  118. if(empty($createBtnLink))
  119. {
  120. $createBtnLink = createLink('requirement', 'batchCreate', "productID=$productID&branch=$branch&moduleID=$moduleID&requirementID=0&project=$projectID") . '#app=project';
  121. $createBtnTitle = $lang->story->batchCreate . $lang->URCommon;
  122. }
  123. $batchItems[] = array('text' => $lang->URCommon, 'url' => createLink('requirement', 'batchCreate', "productID=$productID&branch=$branch&moduleID=$moduleID&requirementID=0&project=$projectID") . '#app=project');
  124. }
  125. }
  126. if(strpos($project->storyType, 'epic') !== false && $this->config->enableER)
  127. {
  128. if(common::hasPriv('epic', 'create'))
  129. {
  130. if(empty($createBtnLink))
  131. {
  132. $createBtnLink = createLink('epic', 'create', "product=$currentProductID&branch=$branch&moduleID=$moduleID&epicID=0&projectID=$projectID") . '#app=project';
  133. $createBtnTitle = $lang->epic->create;
  134. }
  135. $items[] = array('text' => $lang->epic->create, 'url' => createLink('epic', 'create', "product=$currentProductID&branch=$branch&moduleID=$moduleID&epicID=0&projectID=$projectID") . '#app=project');
  136. }
  137. if(common::hasPriv('epic', 'batchCreate') && !empty($productID))
  138. {
  139. if(empty($createBtnLink))
  140. {
  141. $createBtnLink = createLink('epic', 'batchCreate', "productID=$productID&branch=$branch&moduleID=$moduleID&epicID=0&project=$projectID") . '#app=project';
  142. $createBtnTitle = $lang->story->batchCreate . $lang->ERCommon;
  143. }
  144. $batchItems[] = array('text' => $lang->ERCommon, 'url' => createLink('epic', 'batchCreate', "productID=$productID&branch=$branch&moduleID=$moduleID&epicID=0&project=$projectID") . '#app=project');
  145. }
  146. }
  147. if(!empty($productID) && !empty($batchItems)) $items[] = array('text' => $lang->story->batchCreate, 'items' => $batchItems);
  148. }
  149. elseif(hasPriv($storyType, 'batchCreate'))
  150. {
  151. if(empty($createBtnLink))
  152. {
  153. $createBtnLink = $batchCreateLink;
  154. $createBtnTitle = $lang->story->batchCreate;
  155. }
  156. $items[] = array('text' => $lang->story->batchCreate, 'url' => $batchCreateLink);
  157. }
  158. if(empty($createBtnLink)) return null;
  159. if(!empty($items))
  160. {
  161. return btnGroup
  162. (
  163. $app->tab == 'project' ? setData('app', 'project') : null,
  164. btn
  165. (
  166. setClass(($app->tab != 'product' ? 'secondary' : 'primary') . ' create-story-btn'),
  167. $isProjectStory && $hasFrozenStories ? setClass('disabled') : null,
  168. $isProjectStory && $hasFrozenStories ? set::hint(sprintf($lang->story->frozenTip, $createBtnTitle)) : null,
  169. set::icon('plus'),
  170. set::text($createBtnTitle),
  171. set::url($createBtnLink)
  172. ),
  173. empty($items) || ($isProjectStory && $hasFrozenStories) ? null : dropdown
  174. (
  175. btn(setClass('dropdown-toggle'), setClass($app->tab != 'product' ? 'secondary' : 'primary'), setStyle(array('padding' => '6px', 'border-radius' => '0 2px 2px 0'))),
  176. set::placement('bottom-end'),
  177. set::items($items)
  178. )
  179. );
  180. }
  181. return item(set(array
  182. (
  183. 'text' => $createBtnTitle,
  184. 'icon' => 'plus',
  185. 'class' => $app->tab != 'product' ? 'secondary' : 'primary',
  186. 'url' => $createBtnLink
  187. )));
  188. };
  189. /* Build link story button. */
  190. $fnBuildLinkStoryButton = function() use($lang, $app, $product, $projectHasProduct, $project, $storyType, $isProjectStory, $hasFrozenStories)
  191. {
  192. if(!common::canModify('product', $product)) return null;
  193. if(!empty($project) && !common::canModify('project', $project)) return null;
  194. if(!$projectHasProduct) return null;
  195. /* Tutorial mode. */
  196. if(commonModel::isTutorialMode())
  197. {
  198. $wizardParams = helper::safe64Encode("project=$project->id");
  199. return item(set(array
  200. (
  201. 'text' => $lang->project->linkStory,
  202. 'url' => createLink('tutorial', 'wizard', "module=project&method=linkStory&params=$wizardParams")
  203. )));
  204. }
  205. $canLinkStory = common::hasPriv('projectstory', 'linkStory');
  206. $canlinkPlanStory = !empty($product) && common::hasPriv('projectstory', 'importPlanStories') && $storyType == 'story' && !$project->charter;
  207. $linkStoryUrl = $this->createLink('projectstory', 'linkStory', "project=$project->id&browseType=&param=0&orderBy=id_desc&recPerPage=50&pageID=1&extra=&storyType=$storyType");
  208. $linkItem = array('text' => $lang->execution->linkStory, 'url' => $linkStoryUrl, 'hint' => $isProjectStory && $hasFrozenStories ? sprintf($lang->story->frozenTip, $lang->execution->linkStory) : '');
  209. $linkPlanItem = array('text' => $lang->execution->linkStoryByPlan, 'url' => '#linkStoryByPlan', 'data-toggle' => 'modal', 'data-size' => 'sm', 'hint' => $isProjectStory && $hasFrozenStories ? sprintf($lang->story->frozenTip, $lang->execution->linkStoryByPlan) : '');
  210. if($canLinkStory && $canlinkPlanStory)
  211. {
  212. return btngroup
  213. (
  214. btn(
  215. setClass('btn primary'),
  216. $isProjectStory && $hasFrozenStories ? setClass('disabled') : null,
  217. $isProjectStory && $hasFrozenStories ? set::hint(sprintf($lang->story->frozenTip, $lang->execution->linkStory)) : null,
  218. set::icon('link'),
  219. set::url($linkStoryUrl),
  220. setData('app', $app->tab),
  221. $lang->execution->linkStory
  222. ),
  223. $isProjectStory && $hasFrozenStories ? null : dropdown
  224. (
  225. btn(setClass('btn primary dropdown-toggle'),
  226. setStyle(array('padding' => '6px', 'border-radius' => '0 2px 2px 0'))),
  227. set::items(array_filter(array($linkItem, $linkPlanItem))),
  228. set::placement('bottom-end')
  229. )
  230. );
  231. }
  232. if($canLinkStory && !$canlinkPlanStory) return item(set($linkItem + array('class' => 'btn primary link-story-btn' . ($isProjectStory && $hasFrozenStories ? ' disabled' : ''), 'icon' => 'link')));
  233. if($canlinkPlanStory && !$canLinkStory) return item(set($linkPlanItem + array('class' => 'btn primary' . ($isProjectStory && $hasFrozenStories ? ' disabled' : ''), 'icon' => 'link')));
  234. };
  235. /* DataTable columns. */
  236. $config->story->dtable->fieldList['title']['title'] = $lang->story->title;
  237. if($app->rawModule == 'projectstory') $config->story->dtable->fieldList['title']['link'] = array('module' => 'projectstory', 'method' => 'view', 'params' => 'storyID={id}&projectID={project}');
  238. $config->$storyType->dtable->fieldList['assignedTo']['assignLink']['module'] = $storyType;
  239. $setting = $this->loadModel('datatable')->getSetting('product', 'browse', false, $storyType);
  240. if($storyType != 'story') unset($setting['taskCount'], $setting['bugCount'], $setting['caseCount']);
  241. if($storyType == 'story' && $config->edition == 'ipd') unset($setting['roadmap']);
  242. if($viewType == 'tiled') $setting['title']['nestedToggle'] = false;
  243. if($isFromDoc || $isFromAI)
  244. {
  245. if(isset($setting['actions'])) unset($setting['actions']);
  246. foreach($setting as $key => $col)
  247. {
  248. $setting[$key]['sortType'] = false;
  249. if(isset($col['link'])) unset($setting[$key]['link']);
  250. if($key == 'assignedTo') $setting[$key]['type'] = 'user';
  251. if($key == 'title') $setting[$key]['link'] = array('url' => createLink('{type}', 'view', 'storyID={id}&version={version}'), 'data-toggle' => 'modal', 'data-size' => 'lg');
  252. }
  253. }
  254. $cols = array_values($setting);
  255. /* DataTable data. */
  256. $this->loadModel('story');
  257. $data = array();
  258. $options = array('storyTasks' => $storyTasks, 'storyBugs' => $storyBugs, 'storyCases' => $storyCases, 'modules' => $modules, 'plans' => (isset($plans) ? $plans : array()), 'users' => $users, 'execution' => $project, 'roadmaps' => $roadmaps, 'reports' => $reports);
  259. foreach($stories as $story)
  260. {
  261. $story->rawModule = $story->module;
  262. $story->from = $app->tab;
  263. $options['branches'] = zget($branchOptions, $story->product, array());
  264. $data[] = $this->story->formatStoryForList($story, $options, $storyType, $maxGradeGroup);
  265. }
  266. /* Generate toolbar of DataTable footer. */
  267. $fnGenerateFootToolbar = function() use ($lang, $app, $product, $productID, $project, $storyType, $browseType, $isProjectStory, $projectHasProduct, $storyProductID, $projectID, $branch, $users, $branchTagOption, $modules, $plans, $branchID, $gradePairs, $config,$noclosedRoadmaps, $gradeGroup, $hasFrozenStories)
  268. {
  269. /* Flag variables of permissions. */
  270. $storyModule = $storyType;
  271. $canBeChanged = common::canModify('product', $product);
  272. if(!empty($project)) $canBeChanged = $canBeChanged && common::canModify('project', $project);
  273. if($isProjectStory && $config->vision == 'rnd')
  274. {
  275. $storyModule = 'projectstory';
  276. $canBatchClose = $canBeChanged && hasPriv($storyModule, 'batchClose') && strtolower($browseType) != 'closedbyme';
  277. $canBatchEdit = $canBeChanged && hasPriv($storyModule, 'batchEdit');
  278. $canBatchReview = $canBeChanged && hasPriv($storyModule, 'batchReview');
  279. $canBatchAssignTo = $canBeChanged && hasPriv($storyModule, 'batchAssignTo');
  280. $canBatchChangePlan = $canBeChanged && hasPriv($storyModule, 'batchChangePlan') && $productID && $product;
  281. }
  282. else
  283. {
  284. $canBatchEdit = $canBeChanged && hasPriv($storyType, 'batchEdit');
  285. $canBatchClose = hasPriv($storyType, 'batchClose') && strtolower($browseType) != 'closedbyme' && strtolower($browseType) != 'closedstory';
  286. $canBatchReview = $canBeChanged && hasPriv($storyType, 'batchReview');
  287. $canBatchAssignTo = $canBeChanged && hasPriv($storyType, 'batchAssignTo');
  288. $canBatchChangePlan = $canBeChanged && hasPriv($storyType, 'batchChangePlan') && $config->vision == 'rnd' && $productID && $product && (($product->type != 'normal' && $branchID != 'all') || $product->type == 'normal');
  289. }
  290. $canBatchChangeGrade = $canBeChanged && hasPriv($storyType, 'batchChangeGrade') && count($gradePairs) > 1 && $config->{$storyType}->gradeRule == 'cross' && !$isProjectStory;
  291. $canBatchChangeStage = $canBeChanged && hasPriv('story', 'batchChangeStage') && $storyType == 'story' && $config->vision != 'lite';
  292. $canBatchChangeBranch = $canBeChanged && hasPriv($storyType, 'batchChangeBranch') && $product && $product->type != 'normal' && $productID;
  293. $canBatchChangeModule = $canBeChanged && hasPriv($storyType, 'batchChangeModule') && $productID && (($product->type != 'normal' && $branchID != 'all') || $product->type == 'normal') && !$isProjectStory;
  294. $canBatchChangeParent = $canBeChanged && hasPriv($storyType, 'batchChangeParent') && !($storyType == 'epic' && count($gradeGroup['epic']) < 2) && $app->tab == 'product';
  295. $canBatchUnlink = empty($hasFrozenStories) && $canBeChanged && $projectHasProduct && hasPriv('projectstory', 'batchUnlinkStory');
  296. $canBatchImportToLib = $canBeChanged && $isProjectStory && in_array($this->config->edition, array('max', 'ipd')) && hasPriv('story', 'batchImportToLib') && helper::hasFeature('storylib');
  297. $canBatchChangeRoadmap = $canBeChanged && hasPriv($storyType, 'batchChangeRoadmap') && $config->vision == 'or' && ($storyType == 'requirement' || $storyType == 'epic');
  298. $canBatchAction = $canBatchEdit || $canBatchClose || $canBatchReview || $canBatchChangeGrade || $canBatchChangeStage || $canBatchChangeModule || $canBatchChangePlan || $canBatchChangeParent || $canBatchAssignTo || $canBatchUnlink || $canBatchImportToLib || $canBatchChangeBranch || $canBatchChangeRoadmap;
  299. /* Remove empty data from data list. */
  300. unset($lang->story->reviewResultList[''], $lang->story->reviewResultList['revert']);
  301. unset($lang->story->reasonList[''], $lang->story->reasonList['subdivided'], $lang->story->reasonList['duplicate']);
  302. unset($lang->story->stageList[''], $users['']);
  303. if($storyType == 'story') $plans = \arrayUnion(array(0 => $lang->null), $plans);
  304. /* Generate dropdown menu items for the DataTable footer toolbar.*/
  305. $planItems = $planItems ?? array();
  306. $gradeItems = array();
  307. $roadmapItems = array();
  308. foreach($lang->story->reviewResultList as $key => $result) $reviewResultItems[$key] = array('text' => $result, 'class' => 'batch-btn', 'data-formaction' => $this->createLink($storyModule, 'batchReview', "result=$key"));
  309. foreach($gradePairs as $key => $result) $gradeItems[] = array('text' => $result, 'class' => 'batch-btn', 'data-formaction' => $this->createLink($storyModule, 'batchChangeGrade', "result=$key&type=$storyType"));
  310. foreach($lang->story->reasonList as $key => $reason) $reviewRejectItems[] = array('text' => $reason, 'class' => 'batch-btn', 'data-formaction' => $this->createLink($storyModule, 'batchReview', "result=reject&reason=$key"));
  311. foreach($branchTagOption as $branchID => $branchName) $branchItems[] = array('text' => $branchName, 'class' => 'batch-btn', 'data-formaction' => $this->createLink($storyModule, 'batchChangeBranch', "branchID=$branchID"), 'attrs' => array('title' => $branchName));
  312. foreach($modules as $moduleID => $moduleName) $moduleItems[] = array('text' => $moduleName, 'class' => 'batch-btn', 'data-formaction' => $this->createLink($storyModule, 'batchChangeModule', "moduleID=$moduleID"));
  313. foreach($plans as $planID => $planName) $planItems[] = array('text' => $planName, 'class' => 'batch-btn', 'data-formaction' => $this->createLink($storyModule, 'batchChangePlan', "planID=$planID"));
  314. foreach($noclosedRoadmaps as $roadmapID => $roadmapName) $roadmapItems[] = array('text' => empty($roadmapName) ? $lang->null : $roadmapName, 'class' => 'batch-btn', 'data-formaction' => $this->createLink($storyType, 'batchChangeRoadmap', "roadmapID=$roadmapID"));
  315. foreach($lang->story->stageList as $key => $stageName)
  316. {
  317. if(strpos('|tested|verified|rejected|released|closed|', "|$key|") === false) continue;
  318. $stageItems[] = array('text' => $stageName, 'class' => 'batch-btn', 'data-formaction' => $this->createLink('story', 'batchChangeStage', "stage=$key"));
  319. }
  320. $pinyinItems = common::convert2Pinyin($users);
  321. foreach($users as $account => $realname)
  322. {
  323. if($account == 'closed') continue;
  324. $assignItems[] = array('text' => $realname, 'keys' => zget($pinyinItems, $realname, ''), 'class' => 'batch-btn', 'data-formaction' => $this->createLink($storyModule, 'batchAssignTo', "productID={$productID}"), 'data-account' => $account);
  325. }
  326. if(isset($reviewResultItems['reject'])) $reviewResultItems['reject'] = array('class' => 'not-hide-menu', 'text' => $lang->story->reviewResultList['reject'], 'items' => $reviewRejectItems);
  327. $reviewResultItems = array_values($reviewResultItems);
  328. $navActionItems = array();
  329. if($canBatchClose) $navActionItems[] = array('class' => 'batch-btn batchClostBtn', 'text' => $lang->close, 'data-page' => 'batch', 'data-formaction' => helper::createLink($storyModule, 'batchClose', "productID={$productID}&executionID=0"));
  330. if($canBatchChangeGrade) $navActionItems[] = array('class' => 'not-hide-menu batchGradeBtn', 'text' => $lang->story->grade, 'items' => $gradeItems);
  331. if($canBatchReview) $navActionItems[] = array('class' => 'not-hide-menu batchReviewBtn', 'text' => $lang->story->review, 'items' => $reviewResultItems);
  332. if($canBatchChangeStage) $navActionItems[] = array('class' => 'not-hide-menu batchChangeStageBtn', 'text' => $lang->story->stageAB, 'items' => $stageItems);
  333. if(!$canBatchAction) return array();
  334. $items = array
  335. (
  336. /* Edit button group. */
  337. array('type' => 'btn-group', 'items' => array
  338. (
  339. /* Edit button. */
  340. array
  341. (
  342. 'text' => $lang->edit,
  343. 'className' => 'secondary batch-btn' . (empty($navActionItems) && !$canBatchEdit ? ' hidden' : ''),
  344. 'disabled' => ($canBatchEdit ? '': 'disabled'),
  345. 'data-page' => 'batch',
  346. 'data-formaction' => $this->createLink($storyModule, 'batchEdit', "productID=$storyProductID&projectID=$projectID&branch=$branch&type=$storyType")
  347. ),
  348. /* Popup menu trigger icon. */
  349. array('caret' => 'up', 'className' => 'size-sm secondary' . (empty($navActionItems) ? ' hidden' : ''), 'items' => $navActionItems, 'data-toggle' => 'dropdown', 'data-placement' => 'top-start')
  350. )),
  351. /* Unlink stories button. */
  352. !$canBatchUnlink ? null : array
  353. (
  354. 'text' => $lang->story->unlink,
  355. 'className' => 'secondary batchUnlinkStory'
  356. ),
  357. /* Module button. */
  358. array('caret' => 'up', 'text' => $lang->story->moduleAB, 'className' => $canBatchChangeModule ? 'secondary batchChangeModuleBtn' : 'hidden', 'items' => $moduleItems, 'type' => 'dropdown', 'data-placement' => 'top-start', 'data-menu' => array('searchBox' => true)),
  359. /* Plan button. */
  360. array('caret' => 'up', 'text' => $lang->story->planAB, 'className' => $canBatchChangePlan ? 'secondary batchCnangePlanBtn' : 'hidden', 'items' => $planItems, 'type' => 'dropdown', 'data-placement' => 'top-start', 'data-menu' => array('searchBox' => true)),
  361. $canBatchChangeRoadmap ? array('caret' => 'up', 'text' => $lang->roadmap->common, 'className' => 'secondary', 'items' => $roadmapItems, 'type' => 'dropdown', 'data-placement' => 'top-start', 'data-menu' => array('searchBox' => true)) : null,
  362. /* Change branch button. */
  363. ($canBatchChangeBranch && $product->type != 'normal') ? array('caret' => 'up', 'text' => $lang->product->branchName[$product->type], 'className' => 'batchChangeBranchBtn', 'items' => $branchItems, 'type' => 'dropdown', 'data-placement' => 'top-start', 'data-menu' => array('searchBox' => true)) : null,
  364. /* AssignedTo button. */
  365. array('caret' => 'up', 'text' => $lang->story->assignedTo, 'className' => ($canBatchAssignTo ? 'secondary batchAssignToBtn' : 'hidden'), 'items' => $assignItems, 'type' => 'dropdown', 'data-placement' => 'top-start', 'data-menu' => array('searchBox' => true)),
  366. /* Change parent button. */
  367. array('text' => $lang->story->changeParent, 'className' => $canBatchChangeParent ? 'secondary batchChangeParentBtn' : 'hidden', 'data-toggle' => 'modal', 'url' => createLink($storyType, 'batchChangeParent', "productID=$productID&storyType=$storyType")),
  368. /* Batch import to lib button .*/
  369. $canBatchImportToLib && $storyType != 'requirement' ? array('text' => $lang->story->importToLib, 'className' => 'btn secondary batchImportToLibBtn', 'id' => 'importToLib', 'data-toggle' => 'modal', 'url' => '#batchImportToLib', 'data-on' => 'click', 'data-call' => 'importToLib') : null
  370. );
  371. return array
  372. (
  373. 'btnProps' => array('size' => 'sm', 'btnType' => 'secondary'),
  374. 'items' => array_values(array_filter($items))
  375. );
  376. };
  377. /* Layout. */
  378. global $app;
  379. if($app->rawModule == 'projectstory' && !empty($project)) dropmenu(set::text($project->name));
  380. $checkedSummary = $lang->product->checkedSRSummary;
  381. if($storyType == 'requirement') $checkedSummary = $lang->product->checkedURSummary;
  382. if($storyType == 'epic') $checkedSummary = $lang->product->checkedERSummary;
  383. if($isProjectStory) $checkedSummary = $lang->product->checkedAllSummary;
  384. data('storyBrowseType', $storyBrowseType);
  385. jsVar('childrenAB', $lang->story->childrenAB);
  386. jsVar('projectID', $projectID);
  387. jsVar('modulePairs', $modulePairs);
  388. jsVar('storyType', $storyType);
  389. jsVar('checkedSummary', $checkedSummary);
  390. jsVar('from', $from);
  391. jsVar('productID', $productID);
  392. jsVar('branch', $branch);
  393. jsVar('browseType', $browseType);
  394. jsVar('param', $param);
  395. jsVar('orderBy', $orderBy);
  396. jsVar('recTotal', $pager->recTotal);
  397. jsVar('recPerPage', $pager->recPerPage);
  398. jsVar('pageID', $pager->pageID);
  399. if($isFromDoc || $isFromAI)
  400. {
  401. $this->app->loadLang('doc');
  402. $productChangeLink = createLink($app->rawModule, $app->rawMethod, $projectIDParam . "productID={productID}&branch=$branch&browseType=$browseType&param=$param&storyType=$storyType&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&projectID=$projectID&from=$from&blockID=$blockID");
  403. $insertListLink = createLink($app->rawModule, $app->rawMethod, $projectIDParam . "productID=$productID&branch=$branch&browseType=$browseType&param=$param&storyType=$storyType&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&projectID=$projectID&from=$from&blockID={blockID}");
  404. $blockType = 'productStory';
  405. if($storyType == 'epic') $blockType = 'ER';
  406. if($storyType == 'requirement') $blockType = 'UR';
  407. formPanel
  408. (
  409. setID('zentaolist'),
  410. setClass('mb-4-important'),
  411. set::title(sprintf($this->lang->doc->insertTitle, $this->lang->doc->zentaoList[$blockType])),
  412. set::actions(array()),
  413. set::showExtra(false),
  414. to::titleSuffix
  415. (
  416. span
  417. (
  418. setClass('text-muted text-sm text-gray-600 font-light'),
  419. span(setClass('text-warning mr-1'), icon('help')),
  420. $lang->doc->previewTip
  421. )
  422. ),
  423. formRow
  424. (
  425. formGroup
  426. (
  427. set::width('1/2'),
  428. set::name('product'),
  429. set::label($lang->doc->product),
  430. set::control(array('required' => false)),
  431. set::items($products),
  432. set::value($productID),
  433. set::required(),
  434. span
  435. (
  436. setClass('error-tip text-danger hidden'),
  437. $lang->doc->emptyError
  438. ),
  439. on::change('[name="product"]')->do("loadModal('$productChangeLink'.replace('{productID}', $(this).val()))")
  440. )
  441. )
  442. );
  443. }
  444. $queryMenuLink = createLink($app->rawModule, $app->rawMethod, $projectIDParam . "productID=$productID&branch=$branch&browseType=bySearch&param={queryID}&storyType=$storyType&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&projectID=$projectID&from=$from&blockID=$blockID");
  445. featureBar
  446. (
  447. $hideGrade ? null : to::leading
  448. (
  449. picker
  450. (
  451. set::boxClass('whitespace-nowrap'),
  452. set::tree(true),
  453. set::name('showGrades'),
  454. set::items($gradeMenu),
  455. set::search(false),
  456. set::multiple(true),
  457. set::width('150px'),
  458. setStyle('justify-content', 'center'),
  459. set::display($lang->story->viewAllGrades),
  460. set::menu(array('checkbox' => true, 'itemProps' => array('innerComponent' => 'a'))),
  461. set::value($showGrades),
  462. set::popMinWidth(150),
  463. set::toolbar(array('text' => $lang->confirm, 'onClick' => jsRaw('(e,info) => {setShowGrades();info.relativeTarget.close();}')), array('text' => $lang->cancel, 'onClick' => jsRaw('(e,info) => info.relativeTarget.close()')))
  464. )
  465. ),
  466. set::param($param),
  467. set::current($storyBrowseType),
  468. set::link(createLink($app->rawModule, $app->rawMethod, $projectIDParam . "productID=$productID&branch=$branch&browseType={key}&param=$param&storyType=$storyType&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&projectID=$projectID&from=$from&blockID=$blockID")),
  469. set::queryMenuLinkCallback(array(function ($key) use ($queryMenuLink) {
  470. return str_replace('{queryID}', (string)$key, $queryMenuLink);
  471. })),
  472. set::isModal($isFromDoc || $isFromAI),
  473. set::modalTarget('#stories_table'),
  474. li(searchToggle
  475. (
  476. set::simple($isFromDoc || $isFromAI),
  477. set::open(!$isFromDoc && !$isFromAI && ($browseType == 'bysearch' || $storyBrowseType == 'bysearch')),
  478. set::module($config->product->search['module']),
  479. ($isFromDoc || $isFromAI) ? set::target('#docSearchForm') : null,
  480. ($isFromDoc || $isFromAI) ? set::onSearch(jsRaw('function(){$(this.element).closest(".modal").find("#featureBar .nav-item>.active").removeClass("active").find(".label").hide()}')) : null
  481. ))
  482. );
  483. if($isFromDoc || $isFromAI)
  484. {
  485. div(setID('docSearchForm'));
  486. }
  487. $canExport = $isProjectStory ? hasPriv('projectstory', 'export') && $productID : hasPriv($storyType, 'export');
  488. $canReport = $isProjectStory ? hasPriv('projectstory', 'report') : hasPriv($storyType, 'report');
  489. $reportUrl = $isProjectStory ? helper::createLink('projectstory', 'report', "productID=$productID&branchID=$branch&storyType=$storyType&browseType=$browseType&moduleID=$moduleID&chartType=pie&projectID=$projectID") : helper::createLink($storyType, 'report', "productID=$productID&branchID=$branch&storyType=$storyType&browseType=$browseType&moduleID=$moduleID");
  490. $exportUrl = $isProjectStory ? helper::createLink('projectstory', 'export', "productID=$productID&orderBy=$orderBy&executionID=$projectID&browseType=$browseType") : helper::createLink($storyType, 'export', "productID=$productID&orderBy=$orderBy&executionID=$projectID&browseType=$browseType");
  491. toolbar
  492. (
  493. setClass(array('hidden' => $isFromDoc || $isFromAI)),
  494. item(set(array
  495. (
  496. 'type' => 'btnGroup',
  497. 'items' => array(array
  498. (
  499. 'icon' => 'list',
  500. 'class' => 'btn-icon switchButton' . ($viewType == 'tiled' ? ' text-primary' : ''),
  501. 'data-type' => 'tiled',
  502. 'hint' => $lang->story->viewTypeList['tiled']
  503. ), array
  504. (
  505. 'icon' => 'treeview',
  506. 'class' => 'switchButton btn-icon' . ($viewType == 'tree' ? ' text-primary' : ''),
  507. 'data-type' => 'tree',
  508. 'hint' => $lang->story->viewTypeList['tree']
  509. ))
  510. ))),
  511. (!$canReport || !$productID) ? null : item(set(array('id' => 'reportBtn', 'icon' => 'bar-chart', 'class' => 'ghost', 'url' => $reportUrl))),
  512. item(set(array('id' => 'exportBtn', 'icon' => 'export', 'class' => 'ghost' . ($canExport ? '' : ' hidden'), 'url' => $exportUrl, 'data-toggle' => 'modal'))),
  513. $fnBuildCreateStoryButton(),
  514. $fnBuildLinkStoryButton()
  515. );
  516. if(!$isFromDoc && !$isFromAI) $fnGenerateSideBar();
  517. if($isFromDoc) $footToolbar = array(array('text' => $lang->doc->insertText, 'data-on' => 'click', 'data-call' => "insertListToDoc('#stories', '$blockType', $blockID, '$insertListLink')"));
  518. if($isFromAI) $footToolbar = array(array('text' => $lang->doc->insertText, 'data-on' => 'click', 'data-call' => "insertListToAI('#stories', 'story')"));
  519. if(!$isFromDoc && !$isFromAI) $footToolbar = $fnGenerateFootToolbar();
  520. $sortLink = createLink('product', 'browse', "productID={$productID}&branch={$branch}&browseType={$browseType}&param={$param}&storyType={$storyType}&orderBy={name}_{sortType}&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&projectID=$projectID");
  521. if($this->app->rawModule == 'projectstory') $sortLink = createLink('projectstory', 'story', "projectID={$projectID}&productID={$productID}&branch=$branch&browseType=$browseType&param=$param&storyType=$storyType&orderBy={name}_{sortType}&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}");
  522. $emptyTip = $lang->story->noStory;
  523. if($storyType == 'requirement') $emptyTip = $lang->story->noRequirement;
  524. if($storyType == 'epic') $emptyTip = $lang->story->noEpic;
  525. $createStoryLink = createLink($storyType, 'create', 'product=' . (empty($productID) ? current(array_keys($projectProducts)) : $productID) . "&branch=$branch&moduleID=$moduleID&storyID=0&projectID=$projectID&bugID=0&planID=0&todoID=0&extra=&storyType=$storyType") . ($isProjectStory ? '#app=project' : '');
  526. $createStoryLink = hasPriv($storyType, 'create') ? $createStoryLink : '';
  527. dtable
  528. (
  529. set::id('stories'),
  530. set::userMap($users),
  531. set::checkable($isFromDoc || $isFromAI || !empty($footToolbar)), // The user can do batch action if this parameter is not false(true, null).
  532. set::cols($cols),
  533. set::moduleName($storyType),
  534. set::data($data),
  535. set::noNestedCheck(),
  536. set::orderBy($orderBy),
  537. set::modules($modulePairs),
  538. set::onRenderCell(jsRaw('window.renderCell')),
  539. set::footPager(usePager()),
  540. set::emptyTip($emptyTip),
  541. set::footToolbar($footToolbar),
  542. !$isFromDoc ? null : set::afterRender(jsCallback()->call('toggleCheckRows', $idList)),
  543. (!$isFromDoc && !$isFromAI) ? null : set::onCheckChange(jsRaw('window.checkedChange')),
  544. (!$isFromDoc && !$isFromAI) ? null : set::height(400),
  545. ($isFromDoc || $isFromAI) ? null : set::customCols(array('url' => createLink('datatable', 'ajaxcustom', "module={$app->moduleName}&method={$app->methodName}&extra={$storyType}"), 'globalUrl' => createLink('datatable', 'ajaxsaveglobal', "module={$app->moduleName}&method={$app->methodName}&extra={$storyType}"), 'resetUrl' => createLink('datatable', 'ajaxreset', "module={$app->moduleName}&method={$app->methodName}&system=0&confirm=no&extra={$storyType}"), 'resetGlobalUrl' => createLink('datatable', 'ajaxreset', "module={$app->moduleName}&method={$app->methodName}&system=1&confirm=no&extra={$storyType}"))),
  546. ($isFromDoc || $isFromAI) ? null : set::sortLink($sortLink),
  547. ($isFromDoc || $isFromAI) ? null : set::checkInfo(jsRaw("function(checkedIdList){return window.setStatistics(this, checkedIdList, '{$summary}');}")),
  548. ($isFromDoc || $isFromAI) ? null : set::createTip($lang->story->create),
  549. ($isFromDoc || $isFromAI || ($isProjectStory && $hasFrozenStories)) ? null : set::createLink($createStoryLink)
  550. );
  551. modal(set::id('#batchUnlinkStoryBox'));
  552. $linkStoryByPlanTips = $lang->execution->linkNormalStoryByPlanTips;
  553. if($product && $product->type != 'normal') $linkStoryByPlanTips = sprintf($lang->execution->linkBranchStoryByPlanTips, $lang->product->branchName[$product->type]);
  554. if($isProjectStory) $linkStoryByPlanTips = str_replace($lang->execution->common, $lang->projectCommon, $linkStoryByPlanTips);
  555. modal
  556. (
  557. setID('linkStoryByPlan'),
  558. set::modalProps(array('title' => $lang->execution->linkStoryByPlan)),
  559. div
  560. (
  561. setClass('flex-auto'),
  562. icon('info-sign', setClass('warning-pale rounded-full mr-1')),
  563. $linkStoryByPlanTips
  564. ),
  565. form
  566. (
  567. setClass('text-center', 'py-4'),
  568. set::actions(array('submit')),
  569. set::submitBtnText($lang->execution->linkStory),
  570. formGroup
  571. (
  572. set::label($lang->execution->selectStoryPlan),
  573. set::required(true),
  574. setClass('text-left'),
  575. picker
  576. (
  577. set::name('plan'),
  578. set::required(true),
  579. set::items($plans)
  580. )
  581. )
  582. )
  583. );
  584. if(isset($libs))
  585. {
  586. modal
  587. (
  588. setID('batchImportToLib'),
  589. set::title($lang->story->importToLib),
  590. form
  591. (
  592. set::action($this->createLink('story', 'batchImportToLib')),
  593. formGroup
  594. (
  595. set::label($lang->story->lib),
  596. picker
  597. (
  598. set::name('lib'),
  599. set::items($libs),
  600. set::required(true)
  601. ),
  602. input(set::className('hidden'), set::name('storyIdList'), set::id('storyIdList'))
  603. ),
  604. (!hasPriv('assetlib', 'approveStory') && !hasPriv('assetlib', 'batchApproveStory')) ? formGroup
  605. (
  606. set::label($lang->story->approver),
  607. picker
  608. (
  609. set::name('assignedTo'),
  610. set::items($approvers)
  611. )
  612. ) : null,
  613. set::submitBtnText($lang->import),
  614. set::actions(array('submit'))
  615. )
  616. );
  617. }
  618. render();