* Add edit node.

This commit is contained in:
zhaoke
2022-11-24 08:13:33 +00:00
parent b48be4763b
commit 0eb5f89999
18 changed files with 192 additions and 42 deletions
+1 -1
View File
@@ -286,7 +286,7 @@ class zahost extends control
*/
public function initHost($hostID)
{
$this->view->title = $this->lang->zahost->vmTemplate->common;
$this->view->title = $this->lang->zahost->init;
$this->view->users = $this->loadModel('user')->getPairs('noletter|nodeleted');
$this->view->hostID = $hostID;
+7 -3
View File
@@ -4,6 +4,7 @@ $lang->zahost->common = 'ZAhost';
$lang->zahost->browse = 'Host List';
$lang->zahost->create = 'Add Host';
$lang->zahost->view = 'Host View';
$lang->zahost->init = 'Init Host';
$lang->zahost->edit = 'Edit';
$lang->zahost->editAction = 'Edit Host';
$lang->zahost->delete = 'Delete';
@@ -11,10 +12,11 @@ $lang->zahost->deleteAction = 'Delete Host';
$lang->zahost->byQuery = 'Search';
$lang->zahost->all = 'All';
$lang->zahost->browseNode = 'ZAnode Browse';
$lang->zahost->deleted = "Deleted";
$lang->zahost->name = 'Name';
$lang->zahost->IP = 'IP/Domain';
$lang->zahost->extranet = 'IP';
$lang->zahost->IP = 'Extranet Address';
$lang->zahost->extranet = 'Extranet Address';
$lang->zahost->cpuCores = 'CPU Cores';
$lang->zahost->memory = 'Memory Size';
$lang->zahost->diskSize = 'diskSize Size';
@@ -30,7 +32,9 @@ $lang->zahost->registerDate = 'RegisterDate';
$lang->zahost->memorySize = $lang->zahost->memory;
$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores;
$lang->zahost->osType = 'Os Version';
$lang->zahost->os = 'System';
$lang->zahost->osVersion = 'Os Version No';
$lang->zahost->osLang = 'Language';
$lang->zahost->imageName = 'Image File';
@@ -69,7 +73,7 @@ $lang->zahost->image->name = 'Name';
$lang->zahost->image->desc = 'Description';
$lang->zahost->image->memory = $lang->zahost->memory;
$lang->zahost->image->disk = $lang->zahost->diskSize;
$lang->zahost->image->os = $lang->zahost->osCategory;
$lang->zahost->image->os = $lang->zahost->os;
$lang->zahost->image->imageName = $lang->zahost->imageName;
$lang->zahost->image->statusList['created'] = 'Created';
+2
View File
@@ -4,6 +4,7 @@ $lang->zahost->common = 'ZAhost';
$lang->zahost->browse = 'Host List';
$lang->zahost->create = 'Add Host';
$lang->zahost->view = 'Host View';
$lang->zahost->init = 'Init Host';
$lang->zahost->edit = 'Edit';
$lang->zahost->editAction = 'Edit Host';
$lang->zahost->delete = 'Delete';
@@ -11,6 +12,7 @@ $lang->zahost->deleteAction = 'Delete Host';
$lang->zahost->byQuery = 'Search';
$lang->zahost->all = 'All';
$lang->zahost->browseNode = 'ZAnode Browse';
$lang->zahost->deleted = "Deleted";
$lang->zahost->name = 'Name';
$lang->zahost->IP = 'Extranet Address';
+1
View File
@@ -4,6 +4,7 @@ $lang->zahost->common = 'ZAhost';
$lang->zahost->browse = 'Hôte Liste';
$lang->zahost->create = 'Ajouter Hôte';
$lang->zahost->view = 'Hôte Détail';
$lang->zahost->init = 'Init Host';
$lang->zahost->edit = 'Éditer';
$lang->zahost->editAction = 'Éditer Hôte';
$lang->zahost->delete = 'Supprimer';
+4 -5
View File
@@ -4,6 +4,7 @@ $lang->zahost->common = 'ZAhost';
$lang->zahost->browse = 'Host List';
$lang->zahost->create = 'Add Host';
$lang->zahost->view = 'Host View';
$lang->zahost->init = 'Init Host';
$lang->zahost->edit = 'Edit';
$lang->zahost->editAction = 'Edit Host';
$lang->zahost->delete = 'Delete';
@@ -11,10 +12,11 @@ $lang->zahost->deleteAction = 'Delete Host';
$lang->zahost->byQuery = 'Search';
$lang->zahost->all = 'All';
$lang->zahost->browseNode = 'ZAnode Browse';
$lang->zahost->deleted = "Deleted";
$lang->zahost->name = 'Name';
$lang->zahost->IP = 'IP/Domain';
$lang->zahost->extranet = 'IP';
$lang->zahost->IP = 'Extranet Address';
$lang->zahost->extranet = 'Extranet Address';
$lang->zahost->cpuCores = 'CPU Cores';
$lang->zahost->memory = 'Memory Size';
$lang->zahost->diskSize = 'diskSize Size';
@@ -71,10 +73,7 @@ $lang->zahost->image->name = 'Name';
$lang->zahost->image->desc = 'Description';
$lang->zahost->image->memory = $lang->zahost->memory;
$lang->zahost->image->disk = $lang->zahost->diskSize;
$lang->zahost->image->osType = $lang->zahost->osType;
$lang->zahost->image->os = $lang->zahost->os;
$lang->zahost->image->osVersion = $lang->zahost->osVersion;
$lang->zahost->image->osLang = $lang->zahost->osLang;
$lang->zahost->image->imageName = $lang->zahost->imageName;
$lang->zahost->image->statusList['created'] = 'Created';
+2
View File
@@ -5,6 +5,7 @@ $lang->zahost->common = '宿主机';
$lang->zahost->browse = '宿主机列表';
$lang->zahost->create = '添加宿主机';
$lang->zahost->view = '宿主机详情';
$lang->zahost->init = '初始化宿主机';
$lang->zahost->edit = '编辑';
$lang->zahost->editAction = '编辑宿主机';
$lang->zahost->delete = '删除';
@@ -12,6 +13,7 @@ $lang->zahost->deleteAction = '删除宿主机';
$lang->zahost->byQuery = '搜索';
$lang->zahost->all = '全部主机';
$lang->zahost->browseNode = '执行节点列表';
$lang->zahost->deleted = "已删除";
$lang->zahost->name = '名称';
$lang->zahost->IP = 'IP/域名';
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
$config->zanode->create = new stdClass();
$config->zanode->edit = new stdClass();
$config->zanode->create->requiredFields = 'name,host,image,cpu,memory,disk,os';
$config->zanode->create->requiredFields = 'name,host,image,cpu,memory,disk,osName';
$config->zanode->edit->requiredFields = '';
$config->zanode->defaultPort = '8086';
+46 -9
View File
@@ -77,6 +77,37 @@ class zanode extends control
return $this->display();
}
/**
* Edit node.
*
* @param int $hostID
* @access public
* @return void
*/
public function edit($id)
{
if($_POST)
{
$changes = $this->zanode->update($id);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
if($changes)
{
$actionID = $this->loadModel('action')->create('zanode', $id, 'Edited');
if(!empty($changes)) $this->action->logHistory($actionID, $changes);
}
if(isonlybody()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent'));
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
}
$this->view->title = $this->lang->zanode->editAction;
$this->view->zanode = $this->zanode->getNodeByID($id);
$this->view->host = $this->zanode->getHostByID($this->view->zanode->parent);
$this->view->image = $this->zanode->getImageByID($this->view->zanode->image);
$this->display();
}
/**
* View Node.
*
@@ -90,7 +121,6 @@ class zanode extends control
$this->view->zanode = $this->zanode->getNodeByID($id);
$this->view->actions = $this->loadModel('action')->getList('zanode', $id);
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->display();
}
@@ -157,19 +187,26 @@ class zanode extends control
* @param int $nodeID
* @return void
*/
public function destroy($nodeID)
public function delete($nodeID, $confirm = 'no')
{
$error = $this->zanode->destroy($nodeID);
if($error)
if($confirm == 'no')
{
return print(js::alert($error));
return print(js::confirm($this->lang->zanode->confirmDelete, inlink('delete', "nodeID=$nodeID&confirm=yes")));
}
else
{
if(isonlybody()) return print(js::alert($this->lang->zanode->actionSuccess) . js::reload('parent.parent'));
return print(js::alert($this->lang->zanode->actionSuccess) . js::reload('parent'));
}
$error = $this->zanode->destroy($nodeID);
if($error)
{
return print(js::alert($error));
}
else
{
if(isonlybody()) return print(js::alert($this->lang->zanode->actionSuccess) . js::reload('parent.parent'));
return print(js::alert($this->lang->zanode->actionSuccess) . js::reload('parent'));
}
}
}
/**
+10 -8
View File
@@ -4,14 +4,16 @@ $(function()
$('#parent').change(function()
{
var hostID = $('#parent').val();
var link = createLink('zanode', 'ajaxGetImages', 'hostID=' + hostID);
$.get(link, function(data)
{
$('#template').html('').append(data);
$('#image').chosen().trigger("chosen:updated");
$('#image').change();
});
if(config.currentMethod == 'create'){
var hostID = $('#parent').val();
var link = createLink('zanode', 'ajaxGetImages', 'hostID=' + hostID);
$.get(link, function(data)
{
$('#template').html('').append(data);
$('#image').chosen().trigger("chosen:updated");
$('#image').change();
});
}
});
$(document).on("change", '#image', function()
+3 -1
View File
@@ -2,6 +2,7 @@
$lang->zanode->common = 'Execution Node';
$lang->zanode->browse = 'Execution Node List';
$lang->zanode->create = 'Create Execution Node';
$lang->zanode->editAction = 'Edit Execution Node';
$lang->zanode->view = 'View Execution Node';
$lang->zanode->suspend = 'Suspend Execution Node';
$lang->zanode->destroy = 'Destroy Execution Node';
@@ -21,7 +22,7 @@ $lang->zanode->hostName = 'Host Name';
$lang->zanode->host = $lang->zanode->hostName;
$lang->zanode->extranet = 'IP/Domain';
$lang->zanode->osArch = 'Arch';
$lang->zanode->cpuCores = 'CPU Cores';
$lang->zanode->cpuCores = 'CPU Cores';
$lang->zanode->memory = 'Memory Size';
$lang->zanode->desc = 'Description';
$lang->zanode->diskSize = 'Disk Size';
@@ -38,6 +39,7 @@ $lang->zanode->confirmShutdown = "Are you sure to shutdown the execution node
$lang->zanode->confirmSuspend = "Are you sure to suspend the execution node";
$lang->zanode->confirmResume = "Are you sure to resume the execution node";
$lang->zanode->actionSuccess = 'Success';
$lang->zanode->deleted = "Deleted";
$lang->zanode->notFoundAgent = 'No Agent service is found';
$lang->zanode->createVmFail = 'Failed to create a execution node';
+2
View File
@@ -2,6 +2,7 @@
$lang->zanode->common = 'Execution Node';
$lang->zanode->browse = 'Execution Node List';
$lang->zanode->create = 'Create Execution Node';
$lang->zanode->editAction = 'Edit Execution Node';
$lang->zanode->view = 'View Execution Node';
$lang->zanode->suspend = 'Suspend Execution Node';
$lang->zanode->destroy = 'Destroy Execution Node';
@@ -38,6 +39,7 @@ $lang->zanode->confirmShutdown = "Are you sure to shutdown the execution node
$lang->zanode->confirmSuspend = "Are you sure to suspend the execution node";
$lang->zanode->confirmResume = "Are you sure to resume the execution node";
$lang->zanode->actionSuccess = 'Success';
$lang->zanode->deleted = "Deleted";
$lang->zanode->notFoundAgent = 'No Agent service is found';
$lang->zanode->createVmFail = 'Failed to create a execution node';
+3 -1
View File
@@ -2,6 +2,7 @@
$lang->zanode->common = 'Execution Node';
$lang->zanode->browse = 'Execution Node List';
$lang->zanode->create = 'Create Execution Node';
$lang->zanode->editAction = 'Edit Execution Node';
$lang->zanode->view = 'View Execution Node';
$lang->zanode->suspend = 'Suspend Execution Node';
$lang->zanode->destroy = 'Destroy Execution Node';
@@ -21,7 +22,7 @@ $lang->zanode->hostName = 'Host Name';
$lang->zanode->host = $lang->zanode->hostName;
$lang->zanode->extranet = 'IP/Domain';
$lang->zanode->osArch = 'Arch';
$lang->zanode->cpuCores = 'CPU Cores';
$lang->zanode->cpuCores = 'CPU Cores';
$lang->zanode->memory = 'Memory Size';
$lang->zanode->desc = 'Description';
$lang->zanode->diskSize = 'Disk Size';
@@ -38,6 +39,7 @@ $lang->zanode->confirmShutdown = "Are you sure to shutdown the execution node
$lang->zanode->confirmSuspend = "Are you sure to suspend the execution node";
$lang->zanode->confirmResume = "Are you sure to resume the execution node";
$lang->zanode->actionSuccess = 'Success';
$lang->zanode->deleted = "Deleted";
$lang->zanode->notFoundAgent = 'No Agent service is found';
$lang->zanode->createVmFail = 'Failed to create a execution node';
+2
View File
@@ -2,6 +2,7 @@
$lang->zanode->common = '执行节点';
$lang->zanode->browse = '执行节点列表';
$lang->zanode->create = '创建执行节点';
$lang->zanode->editAction = '编辑执行节点';
$lang->zanode->view = '执行节点详情';
$lang->zanode->suspend = '暂停执行节点';
$lang->zanode->destroy = '销毁执行节点';
@@ -38,6 +39,7 @@ $lang->zanode->confirmShutdown = "您确定关闭执行节点吗?";
$lang->zanode->confirmSuspend = "您确定暂停执行节点吗?";
$lang->zanode->confirmResume = "您确定恢复执行节点吗?";
$lang->zanode->actionSuccess = '操作成功';
$lang->zanode->deleted = "已删除";
$lang->zanode->notFoundAgent = '没有发现Agent服务';
$lang->zanode->createVmFail = '创建执行节点失败';
+15 -7
View File
@@ -214,17 +214,25 @@ class zanodemodel extends model
}
/**
* Update Node attribute.
* Update Node.
*
* @param int $id
* @param array $data
* @return void
*/
public function update($id, $data)
public function update($id)
{
$this->dao->update(TABLE_ZAHOST)->data($data)
->where('id')->eq($id)
->exec();
$oldHost = $this->getNodeById($id);
$hostInfo = fixer::input('post')->get();
$hostInfo->editedBy = $this->app->user->account;
$hostInfo->editedDate = helper::now();
$this->dao->update(TABLE_ZAHOST)->data($hostInfo)
->batchCheck($this->config->zanode->edit->requiredFields, 'notempty');
if(dao::isError()) return false;
$this->dao->update(TABLE_ZAHOST)->data($hostInfo)->autoCheck()
->where('id')->eq($id)->exec();
return common::createChanges($oldHost, $hostInfo);
}
/**
@@ -433,7 +441,7 @@ class zanodemodel extends model
$returnData = new stdClass();
$returnData->hostIP = $host->extranet;
$returnData->agentPort = $host->agentPort;
$returnData->vnc = $vm->vnc;
$returnData->vnc = $vm->vnc;
$returnData->token = $result->data->token;
return $returnData;
}
+3 -2
View File
@@ -57,7 +57,7 @@
<th class='c-os'><?php common::printOrderLink('t1.osName', $orderBy, $vars, $lang->zanode->osName); ?></th>
<th class='c-status'><?php common::printOrderLink('t1.status', $orderBy, $vars, $lang->zanode->status); ?></th>
<th class='c-host'><?php common::printOrderLink('t2.id', $orderBy, $vars, $lang->zanode->hostName); ?>
<th class='c-actions-4'><?php echo $lang->actions ?></th>
<th class='c-actions-5'><?php echo $lang->actions ?></th>
</tr>
</thead>
<tbody>
@@ -84,7 +84,8 @@
common::printLink('zanode', 'suspend', "zanodeID={$node->id}", "<i class='icon icon-pause'></i> ", '', $suspendAttr);
common::printLink('zanode', 'resume', "zanodeID={$node->id}", "<i class='icon icon-back'></i> ", '', $resumeAttr);
common::printLink('zanode', 'reboot', "zanodeID={$node->id}", "<i class='icon icon-restart'></i> ", '', $rebootAttr);
common::printLink('zanode', 'destroy', "zanodeID={$node->id}", "<i class='icon icon-trash'></i> ", '', "title='{$lang->zanode->destroy}' class='btn btn-primary' target='hiddenwin' onclick='if(confirm(\"{$lang->zanode->confirmDelete}\")==false) return false;'");
common::printIcon('zanode', 'edit', "id={$node->id}", $node, 'list');
common::printLink('zanode', 'delete', "zanodeID={$node->id}", "<i class='icon icon-trash'></i> ", '', "title='{$lang->zanode->destroy}' class='btn btn-primary' target='hiddenwin' onclick='if(confirm(\"{$lang->zanode->confirmDelete}\")==false) return false;'");
?>
</td>
</tr>
+81
View File
@@ -0,0 +1,81 @@
<?php
/**
* The create view file of vm module of ZenTaoPMS.
*
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author xiawenlong <xiawenlong@cnezsoft.com>
* @package host
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include $app->getModuleRoot() . 'common/view/kindeditor.html.php';?>
<div id='mainContent' class='main-row'>
<div class='main-col main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $lang->zanode->editAction;?></h2>
</div>
<form method='post' target='hiddenwin' id='ajaxForm' class="load-indicator main-form form-ajax">
<table class='table table-form'>
<tr>
<th><?php echo $lang->zanode->hostName;?></th>
<td class='p-25f'><?php echo html::input('', $host->name, "class='form-control' readonly='readonly'");?></td>
</tr>
<tr>
<th class='w-120px'><?php echo $lang->zanode->name;?></th>
<td class='p-25f'><?php echo html::input('name', $zanode->name, "class='form-control' placeholder=\"{$lang->zanode->nameValid}\"");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->zanode->image;?></th>
<td class='p-25f'><?php echo html::input('', $image->name, "class='form-control' readonly='readonly'");?></td>
</tr>
<tr>
<th><?php echo $lang->zanode->cpuCores;?></th>
<td class='p-25f'><?php echo html::input('', zget($config->zanode->os->cpuCores, $zanode->cpuCores), "class='form-control' readonly='readonly'");?></td>
</tr>
<tr>
<th><?php echo $lang->zanode->memory;?></th>
<td>
<div class='input-group'>
<?php echo html::input('memory', $zanode->memory, "class='form-control' readonly='readonly'");?>
<span class="input-group-addon" id="memory-addon"><?php echo $lang->zahost->unitList['GB'];?></span>
</div>
</td>
</tr>
<tr>
<th><?php echo $lang->zanode->diskSize;?></th>
<td>
<div class='input-group'>
<?php echo html::input('diskSize', $zanode->diskSize, "class='form-control' readonly='readonly'");?>
<span class='input-group-addon fix-border fix-padding' id='unit'>
<?php echo $lang->zahost->unitList['GB'];?>
</span>
</div>
</td>
</tr>
<tr>
<th><?php echo $lang->zanode->osName;?></th>
<td><?php echo html::input('osName', $zanode->osName, "class='form-control' readonly='readonly'")?></td>
</tr>
<tr>
<th><?php echo $lang->zanode->desc ?></th>
<td colspan='2'><?php echo html::textarea('desc', $zanode->desc, "class='form-control'")?></td>
<td></td>
</tr>
<tr>
<td colspan="2" class='text-center form-actions'>
<?php echo html::submitButton();?>
<?php echo html::a(inlink('browse'), $lang->goback, '', "class='btn btn-wide btn-back'");?>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>
+9 -4
View File
@@ -96,10 +96,15 @@
<?php echo html::backButton('<i class="icon icon-back icon-sm"></i> ' . $lang->goback, '', 'btn btn-secondary'); ?>
<div class='divider'></div>
<?php
if (empty($zanode->deleted)) {
if(in_array($zanode->status, array("suspend", "")))
common::printLink('zanode', 'suspend', "id={$zanode->id}", "<i class='icon icon-restart'></i> " . $lang->zanode->suspend, '', "title='{$lang->zanode->suspend}' class='btn' target='hiddenwin' onclick='if(confirm(\"{$lang->zanode->confirmSuspend}\")==false) return false;'");
common::printLink('zanode', 'resume', "id={$zanode->id}", "<i class='icon icon-restart'></i> " . $lang->zanode->resume, '', "title='{$lang->zanode->resume}' class='btn' target='hiddenwin' onclick='if(confirm(\"{$lang->zanode->confirmResume}\")==false) return false;'");
if (empty($zanode->deleted))
{
if($zanode->status == "running"){
common::printLink('zanode', 'suspend', "id={$zanode->id}", "<i class='icon icon-restart'></i> " . $lang->zanode->suspend, '', "title='{$lang->zanode->suspend}' class='btn' target='hiddenwin' onclick='if(confirm(\"{$lang->zanode->confirmSuspend}\")==false) return false;'");
}
elseif($zanode->status == "suspend")
{
common::printLink('zanode', 'resume', "id={$zanode->id}", "<i class='icon icon-restart'></i> " . $lang->zanode->resume, '', "title='{$lang->zanode->resume}' class='btn' target='hiddenwin' onclick='if(confirm(\"{$lang->zanode->confirmResume}\")==false) return false;'");
}
common::printLink('zanode', 'getVNC', "id={$zanode->id}", "<i class='icon icon-desktop'></i> " . $lang->zanode->getVNC, '', "title='{$lang->zanode->getVNC}' class='btn' target='hiddenwin'");
}
?>