diff --git a/config/zentaopms.php b/config/zentaopms.php index 5e57c970f7..8c8e6b8a00 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -246,6 +246,9 @@ define('TABLE_TESTTASK', '`' . $config->db->prefix . 'testtask`'); define('TABLE_TESTRUN', '`' . $config->db->prefix . 'testrun`'); define('TABLE_TESTRESULT', '`' . $config->db->prefix . 'testresult`'); define('TABLE_USERTPL', '`' . $config->db->prefix . 'usertpl`'); +define('TABLE_ZAHOST', '`' . $config->db->prefix . 'host`'); + +if(!defined('TABLE_ASSET')) define('TABLE_ASSET', '`' . $config->db->prefix . 'asset`'); define('TABLE_PRODUCT', '`' . $config->db->prefix . 'product`'); define('TABLE_BRANCH', '`' . $config->db->prefix . 'branch`'); @@ -402,4 +405,4 @@ $config->waterfallModules = array('workestimation', 'durationestimation', 'budge $config->showMainMenu = true; $config->maxPriValue = '256'; -$config->importWhiteList = array('user', 'task', 'story', 'bug', 'testcase', 'feedback'); \ No newline at end of file +$config->importWhiteList = array('user', 'task', 'story', 'bug', 'testcase', 'feedback'); diff --git a/db/update17.6.1.sql b/db/update17.6.1.sql index a35527452a..40926c93ff 100644 --- a/db/update17.6.1.sql +++ b/db/update17.6.1.sql @@ -1,3 +1,4 @@ ALTER TABLE `zt_host` ADD `type` varchar(30) NOT NULL DEFAULT 'normal' AFTER `admin`; ALTER TABLE `zt_host` ADD `secret` varchar(50) NOT NULL DEFAULT '' AFTER `type`; +ALTER TABLE `zt_host` ADD `virtualSoftware` varchar(30) NOT NULL DEFAULT '' AFTER `secret`; ALTER TABLE `zt_vmtemplate` ADD `type` varchar(30) NOT NULL DEFAULT 'normal' AFTER `hostID`; diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index 20b8040334..1111274f15 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -394,7 +394,13 @@ $lang->qa->menuOrder[25] = 'testsuite'; $lang->qa->menuOrder[30] = 'testtask'; $lang->qa->menuOrder[35] = 'report'; $lang->qa->menuOrder[40] = 'caselib'; -$lang->qa->menuOrder[45] = 'automation'; +$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|productID=%s", 'alias' => ''); + +//$lang->qa->menu->automation['subMenu'] = new stdclass(); +//$lang->qa->menu->automation['subMenu']->browse = array('link' => "{$lang->zahost->common}|zahost|browse|productID=%s", 'alias' => ''); $lang->qa->menu->automation['subMenu'] = new stdclass(); $lang->qa->menu->automation['subMenu']->browse = array('link' => "{$lang->zahost->common}|zahost|browse", 'alias' => 'create'); @@ -651,7 +657,8 @@ $lang->navGroup->qa = 'qa'; $lang->navGroup->bug = 'qa'; $lang->navGroup->testcase = 'qa'; $lang->navGroup->testtask = 'qa'; -$lang->navGroup->automation = 'qa'; +//$lang->navGroup->automation = 'qa'; +$lang->navGroup->zahost = 'qa'; $lang->navGroup->testreport = 'qa'; $lang->navGroup->testcase = 'qa'; $lang->navGroup->testtask = 'qa'; diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index a0ff9f225b..2f62a28e6a 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -39,7 +39,7 @@ $lang->moduleOrder[85] = 'testtask'; $lang->moduleOrder[90] = 'testsuite'; $lang->moduleOrder[95] = 'testreport'; $lang->moduleOrder[100] = 'caselib'; -$lang->moduleOrder[105] = 'automation'; +$lang->moduleOrder[105] = 'zahost'; $lang->moduleOrder[110] = 'doc'; $lang->moduleOrder[115] = 'report'; @@ -1191,6 +1191,13 @@ $lang->resource->automation->browse = 'browse'; $lang->automation->methodOrder[0] = 'browse'; +$lang->resource->zahost = new stdclass(); +$lang->resource->zahost->browse = 'browse'; +$lang->resource->zahost->create = 'create'; + +$lang->zahost->methodOrder[0] = 'browse'; +$lang->zahost->methodOrder[5] = 'create'; + $lang->resource->repo = new stdclass(); $lang->resource->repo->browse = 'browseAction'; $lang->resource->repo->view = 'view'; diff --git a/module/zahost/config.php b/module/zahost/config.php new file mode 100644 index 0000000000..5f95119755 --- /dev/null +++ b/module/zahost/config.php @@ -0,0 +1,4 @@ +zahost->create = new stdclass(); +$config->zahost->create->requiredFields = 'name,hostType,publicIP,cpuCores,memory,diskSize,virtualSoftware,instanceNum'; +$config->zahost->create->ipFields = 'publicIP'; diff --git a/module/zahost/control.php b/module/zahost/control.php new file mode 100644 index 0000000000..0f6b57641c --- /dev/null +++ b/module/zahost/control.php @@ -0,0 +1,38 @@ + + * @package zahost + * @version $Id$ + * @link http://www.zentao.net + */ +class zahost extends control +{ + /** + * Create host. + * + * @access public + * @return void + */ + public function create() + { + if($_POST) + { + $this->zahost->create(); + if(dao::isError()) + { + return $this->send(array('result' => 'fail', 'message' => dao::getError())); + } + + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + } + + $this->view->title = $this->lang->zahost->create; + + $this->display(); + } + +} diff --git a/module/zahost/css/create.css b/module/zahost/css/create.css new file mode 100644 index 0000000000..00c8e21f88 --- /dev/null +++ b/module/zahost/css/create.css @@ -0,0 +1,3 @@ +#unit {padding: 0px !important; width:0px; border-left: 0px;} +.input-group-addon {border: 0px;} +#unit_chosen a {border-left: 0px; border-radius: 0 2px;} diff --git a/module/zahost/js/create.js b/module/zahost/js/create.js new file mode 100644 index 0000000000..82c8283521 --- /dev/null +++ b/module/zahost/js/create.js @@ -0,0 +1,5 @@ +$(document).ready(function(){ + $('#publicIP').change(function(){ + //@todo check IP + }); +}); diff --git a/module/zahost/lang/zh-cn.php b/module/zahost/lang/zh-cn.php new file mode 100644 index 0000000000..566b9ea526 --- /dev/null +++ b/module/zahost/lang/zh-cn.php @@ -0,0 +1,41 @@ +zahost->common = '宿主机'; +$lang->zahost->browse = '主机列表'; +$lang->zahost->create = '添加宿主机'; +$lang->zahost->view = '主机详情'; +$lang->zahost->edit = '编辑'; +$lang->zahost->editAction = '编辑主机'; +$lang->zahost->delete = '删除'; +$lang->zahost->deleteAction = '删除主机'; +$lang->zahost->byQuery = '搜索'; + +$lang->zahost->name = '名称'; +$lang->zahost->IP = 'IP'; +$lang->zahost->publicIP = 'IP'; +$lang->zahost->memory = '内存大小'; +$lang->zahost->cpuCores = 'CPU核心数'; +$lang->zahost->diskSize = '硬盘容量'; +$lang->zahost->instanceNum = '最大实例数'; + +$lang->zahost->createdBy = '由谁创建'; +$lang->zahost->createdDate = '创建时间'; +$lang->zahost->editedBy = '由谁编辑'; +$lang->zahost->editedDate = '编辑时间'; +$lang->zahost->all = '所有主机'; + +$lang->zahost->empty = '暂时没有主机'; + +$lang->zahost->virtualSoftware = '虚拟化软件'; +$lang->zahost->softwareList['kvm'] = 'KVM'; + +$lang->zahost->unitList['GB'] = 'GB'; +$lang->zahost->unitList['TB'] = 'TB'; + +$lang->zahost->zaHostType = '主机类型'; +$lang->zahost->zaHostTypeList['physical'] = '实体主机'; +//$lang->zahost->zaHostTypeList['virtual'] = '虚拟主机'; + +$lang->zahost->confirmDelete = '是否删除该主机记录?'; + +$lang->zahost->notice = new stdclass(); +$lang->zahost->notice->ip = '『%s』格式不正确!'; diff --git a/module/zahost/model.php b/module/zahost/model.php new file mode 100644 index 0000000000..c8075ccfb2 --- /dev/null +++ b/module/zahost/model.php @@ -0,0 +1,90 @@ + + * @package zahost + * @version $Id$ + * @link http://www.zentao.net + */ +class zahostModel extends model +{ + /** + * Set lang; + * + * @access public + * @return void + */ + public function __construct() + { + parent::__construct(); + + $this->app->lang->host = $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. + * + * @access public + * @return int|bool + */ + public function create() + { + $hostInfo = fixer::input('post') + ->setDefault('cpuNumber,cpuCores,diskSize,memory', 0) + ->get(); + + $this->dao->table = 'zahost'; + $this->dao->update(TABLE_ZAHOST)->data($hostInfo) + ->batchCheck($this->config->zahost->create->requiredFields, 'notempty') + ->batchCheck('cpuCores,instanceNum', 'int') + ->batchCheck('cpuCores,diskSize,instanceNum', 'gt', 0) + ->batchCheck('diskSize,memory', 'float') + ->autoCheck(); + if(dao::isError()) return false; + + if(!preg_match('/((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/', $hostInfo->publicIP)) + { + dao::$errors['publicIP'][] = sprintf($this->lang->zahost->notice->ip, $this->lang->zahost->publicIP); + return false; + } + + $this->dao->update(TABLE_ASSET)->data($hostInfo)->check('name', 'unique'); + if(dao::isError()) return false; + + $assetInfo['name'] = $hostInfo->name; + $assetInfo['type'] = 'zahost'; + $assetInfo['status'] = 'normal'; + $assetInfo['createdBy'] = $this->app->user->account; + $assetInfo['createdDate'] = helper::now(); + + $this->dao->insert(TABLE_ASSET)->data($assetInfo)->autoCheck()->exec(); + if(dao::isError()) return false; + + $hostInfo->assetID = $this->dao->lastInsertID(); + + $this->dao->insert(TABLE_ZAHOST)->data($hostInfo, $skipFields='name')->autoCheck()->exec(); + $hostID = $this->dao->lastInsertID(); + if(!dao::isError()) + { + $this->loadModel('action')->create('zahost', $hostID, 'created'); + return true; + } + + return false; + } +} diff --git a/module/zahost/view/create.html.php b/module/zahost/view/create.html.php new file mode 100644 index 0000000000..c063c93dfe --- /dev/null +++ b/module/zahost/view/create.html.php @@ -0,0 +1,75 @@ + + * @package zahost + * @version $Id$ + * @link http://www.zentao.net + */ +?> +getModuleRoot() . 'common/view/header.html.php';?> +