From 9066342e3b33bb5fa764bee4418ac18a0f807f46 Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Wed, 14 Sep 2022 08:49:42 +0800 Subject: [PATCH 1/4] * Code for task #68265. --- module/common/lang/menu.php | 2 +- module/zahost/control.php | 41 ++++++++ module/zahost/lang/de.php | 3 +- module/zahost/lang/en.php | 3 +- module/zahost/lang/fr.php | 3 +- module/zahost/lang/vi.php | 3 +- module/zahost/lang/zh-cn.php | 6 +- module/zahost/model.php | 116 ++++++++++++++++----- module/zahost/view/browse.html.php | 4 +- module/zahost/view/browsetemplate.html.php | 74 +++++++++++++ 10 files changed, 219 insertions(+), 36 deletions(-) create mode 100755 module/zahost/view/browsetemplate.html.php diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index f71684422f..4c3c4a864e 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -397,7 +397,7 @@ $lang->qa->menuOrder[40] = 'caselib'; $lang->qa->menuOrder[45] = 'zahost'; $lang->qa->menu->zahost['subMenu'] = new stdclass(); -$lang->qa->menu->zahost['subMenu']->browse = array('link' => "{$lang->zahost->common}|zahost|browse", 'alias' => 'browse,create,createtemplate'); +$lang->qa->menu->zahost['subMenu']->browse = array('link' => "{$lang->zahost->common}|zahost|browse", 'alias' => 'browse,create,createtemplate,browsetemplate'); // $lang->qa->menu->automation['subMenu'] = new stdclass(); // $lang->qa->menu->automation['subMenu']->browse = array('link' => "{$lang->automation->common}|zahost|browse", 'alias' => 'create'); diff --git a/module/zahost/control.php b/module/zahost/control.php index e159a67f1f..b2fd975525 100644 --- a/module/zahost/control.php +++ b/module/zahost/control.php @@ -94,4 +94,45 @@ class zahost extends control $this->view->title = $this->lang->zahost->createTemplate; $this->display(); } + + /* + * Browse VM template. + * + * @param int $hostID + * @param string $browseType + * @param string $param + * @param string $orderBy + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID + * @access public + * @return void + */ + public function browseTemplate($hostID, $browseType = 'all', $param = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + { + $browseType = strtolower($browseType); + $this->app->loadClass('pager', true); + + $queryID = ($browseType == 'bysearch') ? (int)$param : 0; + $pager = pager::init($recTotal, $recPerPage, $pageID); + $templateList = $this->zahost->getVMTemplateList($hostID, $browseType, $queryID, $orderBy, $pager); + + /* Build the search form. */ + //$actionURL = $this->createLink('zahost', 'browseVM', "browseType=bySearch&queryID=myQueryID"); + //$this->config->zaTemplate->search['actionURL'] = $actionURL; + //$this->config->zaTemplate->search['queryID'] = $queryID; + //$this->config->zaTemplate->search['onMenuBar'] = 'no'; + //$this->loadModel('search')->setSearchParams($this->config->zaTemplate->search); + + $this->view->title = $this->lang->zahost->vmTemplate->common; + $this->view->users = $this->loadModel('user')->getPairs('noletter|nodeleted'); + $this->view->templateList = $templateList; + $this->view->hostID = $hostID; + $this->view->pager = $pager; + $this->view->param = $param; + $this->view->orderBy = $orderBy; + $this->view->browseType = $browseType; + + $this->display(); + } } diff --git a/module/zahost/lang/de.php b/module/zahost/lang/de.php index 43e485c296..cfc5558906 100644 --- a/module/zahost/lang/de.php +++ b/module/zahost/lang/de.php @@ -26,7 +26,8 @@ $lang->zahost->editedBy = 'EditedBy'; $lang->zahost->editedDate = 'EditedDate'; $lang->zahost->registerDate = 'RegisterDate'; -$lang->zahost->empty = 'No Host'; +$lang->zahost->empty = 'No Host'; +$lang->zahost->templateEmpty = 'No Template'; $lang->zahost->statusList['online'] = 'Online'; diff --git a/module/zahost/lang/en.php b/module/zahost/lang/en.php index 43e485c296..cfc5558906 100644 --- a/module/zahost/lang/en.php +++ b/module/zahost/lang/en.php @@ -26,7 +26,8 @@ $lang->zahost->editedBy = 'EditedBy'; $lang->zahost->editedDate = 'EditedDate'; $lang->zahost->registerDate = 'RegisterDate'; -$lang->zahost->empty = 'No Host'; +$lang->zahost->empty = 'No Host'; +$lang->zahost->templateEmpty = 'No Template'; $lang->zahost->statusList['online'] = 'Online'; diff --git a/module/zahost/lang/fr.php b/module/zahost/lang/fr.php index 43e485c296..cfc5558906 100644 --- a/module/zahost/lang/fr.php +++ b/module/zahost/lang/fr.php @@ -26,7 +26,8 @@ $lang->zahost->editedBy = 'EditedBy'; $lang->zahost->editedDate = 'EditedDate'; $lang->zahost->registerDate = 'RegisterDate'; -$lang->zahost->empty = 'No Host'; +$lang->zahost->empty = 'No Host'; +$lang->zahost->templateEmpty = 'No Template'; $lang->zahost->statusList['online'] = 'Online'; diff --git a/module/zahost/lang/vi.php b/module/zahost/lang/vi.php index 43e485c296..cfc5558906 100644 --- a/module/zahost/lang/vi.php +++ b/module/zahost/lang/vi.php @@ -26,7 +26,8 @@ $lang->zahost->editedBy = 'EditedBy'; $lang->zahost->editedDate = 'EditedDate'; $lang->zahost->registerDate = 'RegisterDate'; -$lang->zahost->empty = 'No Host'; +$lang->zahost->empty = 'No Host'; +$lang->zahost->templateEmpty = 'No Template'; $lang->zahost->statusList['online'] = 'Online'; diff --git a/module/zahost/lang/zh-cn.php b/module/zahost/lang/zh-cn.php index 941d615211..e9aa7dc6b8 100644 --- a/module/zahost/lang/zh-cn.php +++ b/module/zahost/lang/zh-cn.php @@ -26,7 +26,7 @@ $lang->zahost->editedBy = '由谁修改'; $lang->zahost->editedDate = '最后修改时间'; $lang->zahost->registerDate = '最后注册时间'; -$lang->zahost->createTemplate = '创建虚拟机模板'; +$lang->zahost->createTemplate = '创建虚拟机模板'; $lang->zahost->memorySize = $lang->zahost->memory; $lang->zahost->cpuCoreNum = $lang->zahost->cpuCores; @@ -38,6 +38,7 @@ $lang->zahost->imageFile = '镜像文件'; $lang->zahost->vmTemplate = new stdclass; $lang->zahost->vmTemplate->name = '名称'; +$lang->zahost->vmTemplate->common = '虚拟机模板'; $lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores; $lang->zahost->vmTemplate->memorySize = $lang->zahost->memory; $lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize; @@ -52,7 +53,8 @@ $lang->zahost->langList['zh_cn'] = '简体中文'; $lang->zahost->langList['zh_tw'] = '繁体中文'; $lang->zahost->langList['en_us'] = '美式英语'; -$lang->zahost->empty = '暂时没有主机'; +$lang->zahost->empty = '暂时没有主机'; +$lang->zahost->templateEmpty = '暂时没有模板'; $lang->zahost->statusList['online'] = '已上架'; diff --git a/module/zahost/model.php b/module/zahost/model.php index c8f576dc25..0392e2154d 100644 --- a/module/zahost/model.php +++ b/module/zahost/model.php @@ -24,18 +24,6 @@ class zahostModel extends model $this->app->lang->vmtemplate = $this->lang->zahost; } - /** - * Get host by id. - * - * @param int $hostID - * @access public - * @return object - */ - public function getById($hostID) - { - return $this->dao->select('*')->from(TABLE_ZAHOST)->where('id')->eq($hostID)->fetch(); - } - /** * Create a host. * @@ -87,6 +75,58 @@ class zahostModel extends model return false; } + /** + * Create vm template. + * + * @access public + * @return void + */ + public function createTemplate() + { + $template = fixer::input('post') + ->setIF($this->post->diskSize > 0, 'diskSize', $this->post->diskSize * 1024) + ->get(); + + $this->dao->insert(TABLE_VMTEMPLATE)->data($template) + ->batchCheck($this->config->zahost->createTemplate->requiredFields, 'notempty') + ->batchCheck('cpuCoreNum,diskSize,memorySize', 'gt', 0) + ->autoCheck() + ->exec(); + if(dao::isError()) return false; + + $templateID = $this->dao->lastInsertID(); + $this->loadModel('action')->create('vmtemplate', $templateID, 'Created'); + } + + /** + * Get host by id. + * + * @param int $hostID + * @access public + * @return object + */ + public function getById($hostID) + { + return $this->dao->select('*')->from(TABLE_ZAHOST)->where('id')->eq($hostID)->fetch(); + } + + /** + * Get pairs. + * + * @param string $idFrom + * @access public + * @return array + */ + public function getPairs($idForm = 'asset') + { + $field = $idForm == 'asset' ? 't1.id' : 't2.id'; + return $this->dao->select("$field,t1.name")->from(TABLE_ASSET)->alias('t1') + ->leftJoin(TABLE_HOST)->alias('t2')->on('t1.id = t2.assetID') + ->where('t1.deleted')->eq('0') + ->orderBy('`group`') + ->fetchPairs('id', 'name'); + } + /** * Get host list. * @@ -137,25 +177,47 @@ class zahostModel extends model } /** - * Create vm template. + * Get VM template list. * + * @param int $hostID + * @param string $browseType + * @param int $param + * @param string $orderBy + * @param int $pager * @access public - * @return void + * @return array */ - public function createTemplate() + public function getVmTemplateList($hostID, $browseType = 'all', $param = 0, $orderBy = 'id_desc', $pager = null) { - $template = fixer::input('post') - ->setIF($this->post->diskSize > 0, 'diskSize', $this->post->diskSize * 1024) - ->get(); + $query = ''; + if($browseType == 'bysearch') + { + /* Concatenate the conditions for the query. */ + if($param) + { + $query = $this->loadModel('search')->getQuery($param); + if($query) + { + $this->session->set('zaTemplateQuery', $query->sql); + $this->session->set('zaTemplateForm', $query->form); + } + else + { + $this->session->set('zaTemplateQuery', ' 1 = 1'); + } + } + else + { + if($this->session->zaTemplateQuery == false) $this->session->set('zaTemplateQuery', ' 1 = 1'); + } + $query = $this->session->zaTemplateQuery; + } - $this->dao->insert(TABLE_VMTEMPLATE)->data($template) - ->batchCheck($this->config->zahost->createTemplate->requiredFields, 'notempty') - ->batchCheck('cpuCoreNum,diskSize,memorySize', 'gt', 0) - ->autoCheck() - ->exec(); - if(dao::isError()) return false; - - $templateID = $this->dao->lastInsertID(); - $this->loadModel('action')->create('vmtemplate', $templateID, 'Created'); + return $this->dao->select('*')->from(TABLE_VMTEMPLATE) + ->where('hostID')->eq($hostID) + ->beginIF($query)->andWhere($query)->fi() + ->orderBy($orderBy) + ->page($pager) + ->fetchAll(); } } diff --git a/module/zahost/view/browse.html.php b/module/zahost/view/browse.html.php index b6830e91da..1fb287e449 100644 --- a/module/zahost/view/browse.html.php +++ b/module/zahost/view/browse.html.php @@ -10,7 +10,7 @@ * @link http://www.zentao.net */ ?> -getModuleRoot() . 'common/view/header.html.php';?> + zahost->confirmDelete)?> -
' data-module='zahost'>
+
' data-module='vmTemplate'>
recTotal}&recPerPage={$pager->recPerPage}";?> @@ -41,12 +41,12 @@ idAB);?> zahost->name);?> - zahost->cpuCoreNum);?> - zahost->memory);?> - zahost->diskSize);?> - zahost->osCategory);?> - zahost->osType);?> - zahost->osVersion);?> + zahost->cpuCoreNum);?> + zahost->memory);?> + zahost->diskSize);?> + zahost->osCategory);?> + zahost->osType);?> + zahost->osVersion);?> zahost->osLang);?> From c347b99c04d9a5f32ff62b7cdcae8c3ab2b72d92 Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Wed, 14 Sep 2022 17:24:42 +0800 Subject: [PATCH 3/4] * Finish task #68256. --- module/zahost/css/browsetemplate.css | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 module/zahost/css/browsetemplate.css diff --git a/module/zahost/css/browsetemplate.css b/module/zahost/css/browsetemplate.css new file mode 100644 index 0000000000..273d944493 --- /dev/null +++ b/module/zahost/css/browsetemplate.css @@ -0,0 +1,3 @@ +.c-number {width: 100px;} +.c-os {width: 130px;} +.c-lang {width: 150px;} From 846b8604d4c146330c52f2f1e3f32ec61c5fe1bf Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Wed, 14 Sep 2022 17:32:13 +0800 Subject: [PATCH 4/4] * Add language. --- module/zahost/lang/de.php | 20 ++++++++++++++++++++ module/zahost/lang/en.php | 20 ++++++++++++++++++++ module/zahost/lang/fr.php | 20 ++++++++++++++++++++ module/zahost/lang/vi.php | 20 ++++++++++++++++++++ module/zahost/lang/zh-cn.php | 2 -- 5 files changed, 80 insertions(+), 2 deletions(-) diff --git a/module/zahost/lang/de.php b/module/zahost/lang/de.php index 1c7c7e242c..4285d60603 100644 --- a/module/zahost/lang/de.php +++ b/module/zahost/lang/de.php @@ -29,6 +29,26 @@ $lang->zahost->editedBy = 'EditedBy'; $lang->zahost->editedDate = 'EditedDate'; $lang->zahost->registerDate = 'RegisterDate'; +$lang->zahost->memorySize = $lang->zahost->memory; +$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->osType = 'Os Version'; +$lang->zahost->osCategory = 'System'; +$lang->zahost->osVersion = 'Os Version No'; +$lang->zahost->osLang = 'Language'; +$lang->zahost->imageFile = 'Image File'; + +$lang->zahost->vmTemplate = new stdclass; +$lang->zahost->vmTemplate->name = 'Name'; +$lang->zahost->vmTemplate->common = 'VM Template'; +$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory; +$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize; +$lang->zahost->vmTemplate->osType = $lang->zahost->osType; +$lang->zahost->vmTemplate->osCategory = $lang->zahost->osCategory; +$lang->zahost->vmTemplate->osVersion = $lang->zahost->osVersion; +$lang->zahost->vmTemplate->osLang = $lang->zahost->osLang; +$lang->zahost->vmTemplate->imageFile = $lang->zahost->imageFile; + $lang->zahost->empty = 'No Host'; $lang->zahost->templateEmpty = 'No Template'; diff --git a/module/zahost/lang/en.php b/module/zahost/lang/en.php index 1c7c7e242c..4285d60603 100644 --- a/module/zahost/lang/en.php +++ b/module/zahost/lang/en.php @@ -29,6 +29,26 @@ $lang->zahost->editedBy = 'EditedBy'; $lang->zahost->editedDate = 'EditedDate'; $lang->zahost->registerDate = 'RegisterDate'; +$lang->zahost->memorySize = $lang->zahost->memory; +$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->osType = 'Os Version'; +$lang->zahost->osCategory = 'System'; +$lang->zahost->osVersion = 'Os Version No'; +$lang->zahost->osLang = 'Language'; +$lang->zahost->imageFile = 'Image File'; + +$lang->zahost->vmTemplate = new stdclass; +$lang->zahost->vmTemplate->name = 'Name'; +$lang->zahost->vmTemplate->common = 'VM Template'; +$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory; +$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize; +$lang->zahost->vmTemplate->osType = $lang->zahost->osType; +$lang->zahost->vmTemplate->osCategory = $lang->zahost->osCategory; +$lang->zahost->vmTemplate->osVersion = $lang->zahost->osVersion; +$lang->zahost->vmTemplate->osLang = $lang->zahost->osLang; +$lang->zahost->vmTemplate->imageFile = $lang->zahost->imageFile; + $lang->zahost->empty = 'No Host'; $lang->zahost->templateEmpty = 'No Template'; diff --git a/module/zahost/lang/fr.php b/module/zahost/lang/fr.php index 1c7c7e242c..4285d60603 100644 --- a/module/zahost/lang/fr.php +++ b/module/zahost/lang/fr.php @@ -29,6 +29,26 @@ $lang->zahost->editedBy = 'EditedBy'; $lang->zahost->editedDate = 'EditedDate'; $lang->zahost->registerDate = 'RegisterDate'; +$lang->zahost->memorySize = $lang->zahost->memory; +$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->osType = 'Os Version'; +$lang->zahost->osCategory = 'System'; +$lang->zahost->osVersion = 'Os Version No'; +$lang->zahost->osLang = 'Language'; +$lang->zahost->imageFile = 'Image File'; + +$lang->zahost->vmTemplate = new stdclass; +$lang->zahost->vmTemplate->name = 'Name'; +$lang->zahost->vmTemplate->common = 'VM Template'; +$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory; +$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize; +$lang->zahost->vmTemplate->osType = $lang->zahost->osType; +$lang->zahost->vmTemplate->osCategory = $lang->zahost->osCategory; +$lang->zahost->vmTemplate->osVersion = $lang->zahost->osVersion; +$lang->zahost->vmTemplate->osLang = $lang->zahost->osLang; +$lang->zahost->vmTemplate->imageFile = $lang->zahost->imageFile; + $lang->zahost->empty = 'No Host'; $lang->zahost->templateEmpty = 'No Template'; diff --git a/module/zahost/lang/vi.php b/module/zahost/lang/vi.php index 1c7c7e242c..4285d60603 100644 --- a/module/zahost/lang/vi.php +++ b/module/zahost/lang/vi.php @@ -29,6 +29,26 @@ $lang->zahost->editedBy = 'EditedBy'; $lang->zahost->editedDate = 'EditedDate'; $lang->zahost->registerDate = 'RegisterDate'; +$lang->zahost->memorySize = $lang->zahost->memory; +$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->osType = 'Os Version'; +$lang->zahost->osCategory = 'System'; +$lang->zahost->osVersion = 'Os Version No'; +$lang->zahost->osLang = 'Language'; +$lang->zahost->imageFile = 'Image File'; + +$lang->zahost->vmTemplate = new stdclass; +$lang->zahost->vmTemplate->name = 'Name'; +$lang->zahost->vmTemplate->common = 'VM Template'; +$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory; +$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize; +$lang->zahost->vmTemplate->osType = $lang->zahost->osType; +$lang->zahost->vmTemplate->osCategory = $lang->zahost->osCategory; +$lang->zahost->vmTemplate->osVersion = $lang->zahost->osVersion; +$lang->zahost->vmTemplate->osLang = $lang->zahost->osLang; +$lang->zahost->vmTemplate->imageFile = $lang->zahost->imageFile; + $lang->zahost->empty = 'No Host'; $lang->zahost->templateEmpty = 'No Template'; diff --git a/module/zahost/lang/zh-cn.php b/module/zahost/lang/zh-cn.php index 2b9804ba97..8763ec22ce 100644 --- a/module/zahost/lang/zh-cn.php +++ b/module/zahost/lang/zh-cn.php @@ -29,8 +29,6 @@ $lang->zahost->editedBy = '由谁修改'; $lang->zahost->editedDate = '最后修改时间'; $lang->zahost->registerDate = '最后注册时间'; -$lang->zahost->createTemplate = '创建虚拟机模板'; - $lang->zahost->memorySize = $lang->zahost->memory; $lang->zahost->cpuCoreNum = $lang->zahost->cpuCores; $lang->zahost->osType = '操作系统版本';