From 211f1cb427db44e6a82a639b28644aecb121df3a Mon Sep 17 00:00:00 2001 From: zhaoke Date: Tue, 1 Aug 2023 11:10:00 +0800 Subject: [PATCH] * Fix error of host module. --- module/tree/control.php | 12 +++++ module/tree/lang/de.php | 9 ++++ module/tree/lang/en.php | 9 ++++ module/tree/lang/fr.php | 9 ++++ module/tree/lang/vi.php | 9 ++++ module/tree/lang/zh-cn.php | 9 ++++ module/tree/lang/zh-tw.php | 9 ++++ module/tree/model.php | 91 +++++++++++++++++++++++++++++++- module/tree/view/browse.html.php | 2 + 9 files changed, 158 insertions(+), 1 deletion(-) diff --git a/module/tree/control.php b/module/tree/control.php index 93c3343b04..bcfe84ac6b 100644 --- a/module/tree/control.php +++ b/module/tree/control.php @@ -302,6 +302,18 @@ class tree extends control $this->view->root = $root; } } + elseif(strpos($viewType, 'host') !== false) + { + $position = array(); + $title = $this->lang->tree->groupMaintenance; + + $root = new stdclass(); + $root->id = 0; + $root->name = $this->lang->tree->groupMaintenance; + + $this->view->productID = 0; + $this->view->root = $root; + } if($this->app->tab == 'project' and strpos($viewType, 'doc') === false) { diff --git a/module/tree/lang/de.php b/module/tree/lang/de.php index 6a01c30f88..fcafa99220 100755 --- a/module/tree/lang/de.php +++ b/module/tree/lang/de.php @@ -55,6 +55,15 @@ $lang->tree->repeatName = 'The name "%s" exists!'; $lang->tree->repeatDirName = 'The name "%s" exists!'; $lang->tree->shouldNotBlank = 'Module name should not be blank!'; $lang->tree->syncProductModule = 'Sync Module'; +$lang->tree->host = 'Host'; +$lang->tree->editHost = 'Edit host group'; +$lang->tree->deleteHost = 'Delete host group'; +$lang->tree->manageHostChild = 'Manage child host'; +$lang->tree->groupMaintenance = 'Manage host group'; +$lang->tree->groupName = 'Group Name'; +$lang->tree->parentGroup = 'Parent grpup'; +$lang->tree->childGroup = 'Child'; +$lang->tree->confirmDeleteHost = 'Do you want to delete this host and its child hosts?'; $lang->tree->module = 'Modul'; $lang->tree->name = 'Name'; diff --git a/module/tree/lang/en.php b/module/tree/lang/en.php index deeb25f38e..5fe0d33972 100755 --- a/module/tree/lang/en.php +++ b/module/tree/lang/en.php @@ -55,6 +55,15 @@ $lang->tree->repeatName = 'The name "%s" exists!'; $lang->tree->repeatDirName = 'The name "%s" exists!'; $lang->tree->shouldNotBlank = 'Module name should not be blank!'; $lang->tree->syncProductModule = 'Sync Module'; +$lang->tree->host = 'Host'; +$lang->tree->editHost = 'Edit host group'; +$lang->tree->deleteHost = 'Delete host group'; +$lang->tree->manageHostChild = 'Manage child host'; +$lang->tree->groupMaintenance = 'Manage host group'; +$lang->tree->groupName = 'Group Name'; +$lang->tree->parentGroup = 'Parent grpup'; +$lang->tree->childGroup = 'Child'; +$lang->tree->confirmDeleteHost = 'Do you want to delete this host and its child hosts?'; $lang->tree->module = 'Module'; $lang->tree->name = 'Module Name'; diff --git a/module/tree/lang/fr.php b/module/tree/lang/fr.php index 73a13be980..89b222e91a 100755 --- a/module/tree/lang/fr.php +++ b/module/tree/lang/fr.php @@ -55,6 +55,15 @@ $lang->tree->repeatName = 'Le nom "%s" existe déjà !'; $lang->tree->repeatDirName = 'The name "%s" exists!'; $lang->tree->shouldNotBlank = 'Module name should not be blank!'; $lang->tree->syncProductModule = 'Sync Module'; +$lang->tree->host = 'Host'; +$lang->tree->editHost = 'Edit host group'; +$lang->tree->deleteHost = 'Delete host group'; +$lang->tree->manageHostChild = 'Manage child host'; +$lang->tree->groupMaintenance = 'Manage host group'; +$lang->tree->groupName = 'Group Name'; +$lang->tree->parentGroup = 'Parent grpup'; +$lang->tree->childGroup = 'Child'; +$lang->tree->confirmDeleteHost = 'Do you want to delete this host and its child hosts?'; $lang->tree->module = 'Module'; $lang->tree->name = 'Nom'; diff --git a/module/tree/lang/vi.php b/module/tree/lang/vi.php index b73986b8a5..c2f3911d79 100755 --- a/module/tree/lang/vi.php +++ b/module/tree/lang/vi.php @@ -48,6 +48,15 @@ $lang->tree->successSave = 'Đã lưu.'; $lang->tree->successFixed = 'Đã sửa'; $lang->tree->repeatName = 'Tên "%s" đã tồn tại!'; $lang->tree->shouldNotBlank = 'Module name should not be blank!'; +$lang->tree->host = 'Host'; +$lang->tree->editHost = 'Edit host group'; +$lang->tree->deleteHost = 'Delete host group'; +$lang->tree->manageHostChild = 'Manage child host'; +$lang->tree->groupMaintenance = 'Manage host group'; +$lang->tree->groupName = 'Group Name'; +$lang->tree->parentGroup = 'Parent grpup'; +$lang->tree->childGroup = 'Child'; +$lang->tree->confirmDeleteHost = 'Do you want to delete this host and its child hosts?'; $lang->tree->module = 'Module'; $lang->tree->name = 'Tên'; diff --git a/module/tree/lang/zh-cn.php b/module/tree/lang/zh-cn.php index 17d570e238..a67b344713 100755 --- a/module/tree/lang/zh-cn.php +++ b/module/tree/lang/zh-cn.php @@ -55,6 +55,15 @@ $lang->tree->repeatName = '模块名“%s”已经存在!'; $lang->tree->repeatDirName = '目录名“%s”已经存在!'; $lang->tree->shouldNotBlank = '模块名不能为空格!'; $lang->tree->syncProductModule = "同步{$lang->productCommon}模块"; +$lang->tree->host = '主机'; +$lang->tree->editHost = '编辑主机分组'; +$lang->tree->deleteHost = '删除主机分组'; +$lang->tree->manageHostChild = '维护主机子分组'; +$lang->tree->groupMaintenance = '维护主机分组'; +$lang->tree->groupName = '分组名称'; +$lang->tree->parentGroup = '上级分组'; +$lang->tree->childGroup = '子分组'; +$lang->tree->confirmDeleteHost = '该分组及子分组都会被删除,您确定删除吗?'; $lang->tree->module = '模块'; $lang->tree->name = '模块名称'; diff --git a/module/tree/lang/zh-tw.php b/module/tree/lang/zh-tw.php index eca9f888a1..bdc8d73a12 100755 --- a/module/tree/lang/zh-tw.php +++ b/module/tree/lang/zh-tw.php @@ -47,6 +47,15 @@ $lang->tree->successSave = '成功保存'; $lang->tree->successFixed = '成功修正數據!'; $lang->tree->repeatName = '模組名“%s”已經存在!'; $lang->tree->shouldNotBlank = '模組名不能為空格!'; +$lang->tree->host = '主机'; +$lang->tree->editHost = '编辑主机分组'; +$lang->tree->deleteHost = '删除主机分组'; +$lang->tree->manageHostChild = '维护主机子分组'; +$lang->tree->groupMaintenance = '维护主机分组'; +$lang->tree->groupName = '分组名称'; +$lang->tree->parentGroup = '上级分组'; +$lang->tree->childGroup = '子分组'; +$lang->tree->confirmDeleteHost = '该分组及子分组都会被删除,您确定删除吗?'; $lang->tree->module = '模組'; $lang->tree->name = '模組名稱'; diff --git a/module/tree/model.php b/module/tree/model.php index 39d12ef757..f0b3f04329 100644 --- a/module/tree/model.php +++ b/module/tree/model.php @@ -909,7 +909,7 @@ class treeModel extends model while($module = $stmt->fetch()) { - $treeMenu = $this->buildTree($module, '', 0, array('treeModel', 'createHostLink')); + $treeMenu = $this->build20Tree($module, '', 0, array('treeModel', 'createHostLink')); if($module->parent == 0) $treeMenu->parent = $module->root; $menu[] = $treeMenu; @@ -997,6 +997,73 @@ class treeModel extends model $treeMenu[$module->parent] .= "\n"; } + /** + * Build tree of version 20. + * + * @param object $module + * @param string $type + * @param int|string $parent + * @param array $userFunc + * @param array $extra + * @param int $branch + * @access public + * @return object|false + */ + public function build20Tree(object $module, string $type, int|string $parent = 0, array $userFunc = array(), array|string $extra = array(), string $branch = 'all'): object|false + { + /* Add for task #1945. check the module has case or no. */ + if((isset($extra['rootID']) and isset($extra['branch']) and $branch === 'null') or ($type == 'case' and is_numeric($extra))) + { + static $objects = array(); + if(empty($objects)) + { + if(is_array($extra)) + { + $table = $this->config->objectTables[$type]; + $objects = $this->dao->select('module')->from($table)->where('product')->eq((int)$extra['rootID'])->andWhere('branch')->eq($extra['branch'])->fetchAll('module'); + } + else + { + $objects = $this->dao->select('t1.*,t2.module')->from(TABLE_TESTRUN)->alias('t1') + ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id') + ->where('t1.task')->eq((int)$extra) + ->fetchAll('module'); + } + } + static $modules = array(); + if(empty($modules)) + { + $typeCondition = "type='story'"; + if($type != 'story') $typeCondition .= " or type='{$type}'"; + $modules = $this->dao->select('id,path')->from(TABLE_MODULE)->where('root')->eq($module->root)->andWhere("({$typeCondition})")->fetchPairs('id', 'path'); + } + $childModules = array(); + foreach($modules as $moduleID => $modulePath) + { + if(strpos($modulePath, $module->path) === 0) $childModules[$moduleID] = $moduleID; + } + $hasObjects = false; + foreach($childModules as $moduleID) + { + if(isset($objects[$moduleID])) + { + $hasObjects = true; + break; + } + } + if(!$hasObjects) return false; + } + + if(is_array($extra)) $extra['branchID'] = $branch; + if(empty($extra)) + { + $extra = array(); + $extra['branchID'] = $branch; + } + + return call_user_func($userFunc, $type, $module, $parent, $extra); + } + /** * Get execution modules. * @@ -1454,6 +1521,28 @@ class treeModel extends model return html::a(helper::createLink('report', 'browsereport', "dimension={$dimension}&module={$module->id}"), $module->name, '', "id='module{$module->id}' title='{$module->name}'"); } + /** + * Create link of a host. + * + * @param string $type + * @param object $module + * @param int $parent + * @param array $extra + * @access public + * @return object + */ + public function createHostLink(string $type, object $module, int $parent = 0, array $extra = array()): object + { + $data = new stdclass(); + $data->id = $parent ? uniqid() : $module->id; + $data->parent = $parent ? $parent : $module->parent; + $data->name = $module->name; + + $data->url = helper::createLink('host', 'browse', "browseType=bymodule¶m={$module->id}"); + + return $data; + } + /** * Get sons of a module. * diff --git a/module/tree/view/browse.html.php b/module/tree/view/browse.html.php index 8a514324b1..9f8cc8e0e1 100644 --- a/module/tree/view/browse.html.php +++ b/module/tree/view/browse.html.php @@ -39,11 +39,13 @@ if($viewType == 'line') $name = $lang->tree->line; if($viewType == 'api') $name = $lang->tree->dir; if($viewType == 'doc') $name = $lang->doc->catalogName; if($viewType == 'report') $name = $lang->tree->reportGroup; +if($viewType == 'host') $name = $this->lang->tree->groupName;; if($viewType == 'trainskill' or $viewType == 'trainpost') $name = $lang->tree->cate; $childTitle = $lang->tree->child; if(strpos($viewType, 'doc') !== false or $viewType == 'api') $childTitle = $lang->doc->childType; if($viewType == 'line' or $viewType == 'trainskill' or $viewType == 'trainpost') $childTitle = ''; +if($viewType == 'host') $childTitle = $lang->tree->childGroup; $editTitle = $lang->tree->edit; $deleteTitle = $lang->tree->delete;