From ce09153250e25abc13356b0fdafbb4e41798bb4b Mon Sep 17 00:00:00 2001 From: sunhao Date: Fri, 30 Jun 2023 15:30:05 +0800 Subject: [PATCH] + add dropmenu to product-browse. --- module/product/ui/ajaxgetdropmenu.html.php | 88 ++++++++++++++++++++++ module/product/ui/browse.html.php | 2 + 2 files changed, 90 insertions(+) create mode 100644 module/product/ui/ajaxgetdropmenu.html.php diff --git a/module/product/ui/ajaxgetdropmenu.html.php b/module/product/ui/ajaxgetdropmenu.html.php new file mode 100644 index 0000000000..5b228cc9e8 --- /dev/null +++ b/module/product/ui/ajaxgetdropmenu.html.php @@ -0,0 +1,88 @@ + + * @package product + * @version $Id + * @link https://www.zentao.net + */ +namespace zin; + +/** + * 获取产品所属分组。 + * Get product group. + * + * @param object $product + * @return string + */ +function getProductGroup(object $product): string +{ + global $app; + if($product->status == 'normal' and $product->PO == $app->user->account) return 'my'; + if($product->status == 'closed') return 'closed'; + return 'other'; +} + +/** + * 定义每个分组下的选项数据列表。 + * Define the grouped data list. + */ +$data = array('my' => array(), 'other' => array(), 'closed' => array()); + +/* 处理分组数据。Process grouped data. */ +foreach($products as $programID => $programProducts) +{ + $programItem = array(); + $programItem['id'] = $programID; + $programItem['type'] = 'program'; + $programItem['text'] = zget($programs, $programID); + $programItem['items'] = array(); + + foreach($programProducts as $index => $product) + { + $group = getProductGroup($product); + $name = ($config->systemMode == 'ALM' and $product->line) ? zget($lines, $product->line, '') . ' / ' . $product->name : $product->name; + + $item = array(); + $item['id'] = $product->id; + $item['text'] = $product->name; + $item['keys'] = zget(common::convert2Pinyin(array($product->name), $product->name), ''); + + if(!isset($data[$group][$programID])) $data[$group][$programID] = $programItem; + $data[$group][$programID]['items'][] = $item; + } +} + +/* 将分组数据转换为索引数组。Format grouped data to indexed array. */ +foreach ($data as $key => $value) $data[$key] = array_values($value); + +/** + * 定义每个分组名称信息,包括可展开的已关闭分组。 + * Define every group name, include expanded group. + */ +$tabs = array(); +$tabs[] = array('name' => 'my', 'text' => $lang->product->mine); +$tabs[] = array('name' => 'other', 'text' => $lang->product->other); +$tabs[] = array('name' => 'closed', 'text' => $lang->product->closedProduct); + +/** + * 定义最终的 JSON 数据。 + * Define the final json data. + */ +$json = array(); +$json['data'] = $data; +$json['tabs'] = $tabs; +$json['searchHint'] = $lang->searchAB; +$json['link'] = sprintf($link, '{id}'); +$json['labelMap'] = array('program' => $lang->program->common); +$json['expandName'] = 'closed'; +$json['itemType'] = 'product'; + +/** + * 渲染 JSON 字符串并发送到客户端。 + * Render json data to string and send to client. + */ +renderJson($json); diff --git a/module/product/ui/browse.html.php b/module/product/ui/browse.html.php index 1019635356..9506c121c7 100644 --- a/module/product/ui/browse.html.php +++ b/module/product/ui/browse.html.php @@ -18,6 +18,8 @@ $projectIDParam = $isProjectStory ? "projectID=$projectID&" : ''; $storyBrowseType = $this->session->storyBrowseType; $branchType = $showBranch ? $product->type : ''; +dropmenu(); + /* Generate sidebar to display module tree menu. */ $fnGenerateSideBar = function() use ($moduleTree, $moduleID, $productID, $branchID, $branchType) {