list ci tasks

This commit is contained in:
aaronchen2k
2020-01-09 15:16:45 +08:00
parent a786e50b33
commit 2d91158097
8 changed files with 513 additions and 13 deletions
+2
View File
@@ -171,6 +171,8 @@ define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`');
define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`');
define('TABLE_CREDENTIAL', '`' . $config->db->prefix . 'credential`');
define('TABLE_JENKINS', '`' . $config->db->prefix . 'jenkins`');
define('TABLE_CI_TASK', '`' . $config->db->prefix . 'citask`');
define('TABLE_CI_BUILD', '`' . $config->db->prefix . 'cibuild`');
define('TABLE_REPO', '`' . $config->db->prefix . 'repo`');
define('TABLE_REPOHISTORY', '`' . $config->db->prefix . 'repohistory`');
+101 -3
View File
@@ -47,7 +47,7 @@ class ci extends control
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$this->view->title = $this->lang->credential->common . $this->lang->colon . $this->lang->credential->list;
$this->view->title = $this->lang->credential->common . $this->lang->colon . $this->lang->ci->list;
$this->view->credentialList = $this->ci->listCredential($orderBy, $pager);
$this->view->position[] = $this->lang->ci->common;
@@ -144,7 +144,7 @@ class ci extends control
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$this->view->title = $this->lang->jenkins->common . $this->lang->colon . $this->lang->jenkins->list;
$this->view->title = $this->lang->jenkins->common . $this->lang->colon . $this->lang->ci->list;
$this->view->jenkinsList = $this->ci->listJenkins($orderBy, $pager);
$this->view->position[] = $this->lang->ci->common;
@@ -229,6 +229,104 @@ class ci extends control
$this->send(array('result' => 'success'));
}
/**
* Browse ci task.
*
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function browseCitask($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$this->view->title = $this->lang->citask->common . $this->lang->colon . $this->lang->ci->list;
$this->view->citaskList = $this->ci->listCitask($orderBy, $pager);
$this->view->position[] = $this->lang->ci->common;
$this->view->position[] = $this->lang->citask->common;
$this->view->orderBy = $orderBy;
$this->view->pager = $pager;
$this->view->module = 'citask';
$this->display();
}
/**
* Create a ci task.
*
* @access public
* @return void
*/
public function createCitask()
{
if($_POST)
{
$this->ci->createCitask();
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseCitask')));
}
$this->app->loadLang('action');
$this->view->title = $this->lang->citask->create . $this->lang->colon . $this->lang->citask->common;
$this->view->position[] = $this->lang->ci->common;
$this->view->position[] = html::a(inlink('browseCitask'), $this->lang->citask->common);
$this->view->position[] = $this->lang->citask->create;
$this->view->repoList = $this->ci->listRepoForSelection("true");
$this->view->module = 'citask';
$this->display();
}
/**
* Edit a ci task.
*
* @param int $id
* @access public
* @return void
*/
public function editCitask($id)
{
$citask = $this->ci->getJenkinsByID($id);
if($_POST)
{
$this->ci->updateCitask($id);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseCitask')));
}
$this->app->loadLang('action');
$this->view->title = $this->lang->citask->edit . $this->lang->colon . $citask->name;
$this->view->position[] = $this->lang->ci->common;
$this->view->position[] = html::a(inlink('browseCitask'), $this->lang->citask->common);
$this->view->position[] = $this->lang->citask->edit;
$this->view->citask = $citask;
$this->view->module = 'jenkins';
$this->display();
}
/**
* Delete a ci task.
*
* @param int $id
* @access public
* @return void
*/
public function deleteCitask($id)
{
$this->ci->delete(TABLE_CI_TASK, $id);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success'));
}
/**
* Browse repo.
@@ -245,7 +343,7 @@ class ci extends control
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->list;
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->ci->list;
$this->view->position[] = $this->lang->ci->common;
$this->view->position[] = $this->lang->repo->common;
+47
View File
@@ -0,0 +1,47 @@
$(function()
{
triggerTypeChanged('tag');
});
function triggerTypeChanged(type) {
if(type == 'tag') {
$('.tag-fields').removeClass('hidden');
$('.comment-fields').addClass('hidden');
scheduleTypeChanged();
} else if(type == 'commit') {
$('.tag-fields').addClass('hidden');
$('.comment-fields').removeClass('hidden');
$('.corn-fields').addClass('hidden');
$('.custom-fields').addClass('hidden');
scheduleTypeChanged();
} else if(type == 'schedule') {
$('.tag-fields').addClass('hidden');
$('.comment-fields').addClass('hidden');
var val = $("input[name='scheduleType']:checked").val();
console.log(val);
scheduleTypeChanged(val? val: 'corn');
}
}
function scheduleTypeChanged(type) {
if(type == 'corn') {
$('.schedule-fields').removeClass('hidden');
$('.corn-fields').removeClass('hidden');
$('.custom-fields').addClass('hidden');
} else if(type == 'custom') {
$('.schedule-fields').removeClass('hidden');
$('.corn-fields').addClass('hidden');
$('.custom-fields').removeClass('hidden');
} else {
$('.schedule-fields').addClass('hidden');
$('.corn-fields').addClass('hidden');
$('.custom-fields').addClass('hidden');
}
}
+34
View File
@@ -8,6 +8,7 @@ $lang->ci->name = '名称';
$lang->ci->subModules['credential'] = '凭证';
$lang->ci->subModules['jenkins'] = 'Jenkins';
$lang->ci->subModules['repo'] = '代码库';
$lang->ci->subModules['citask'] = '构建任务';
// credential
$lang->credential->common = '凭证';
@@ -52,6 +53,39 @@ $lang->jenkins->desc = '描述';
$lang->jenkins->typeList['token'] = 'Token';
$lang->jenkins->typeList['credential'] = '凭证';
// ci task
$lang->citask->common = '构建任务';
$lang->citask->browse = '浏览构建任务';
$lang->citask->create = '添加构建任务';
$lang->citask->edit = '编辑构建任务';
$lang->citask->delete = '删除构建任务';
$lang->citask->confirmDelete = '确认删除该构建任务吗?';
$lang->citask->id = 'ID';
$lang->citask->name = '名称';
$lang->citask->repo = '代码库';
$lang->citask->jenkins = 'Jenkins服务';
$lang->citask->jenkinsTask = 'Jenkins任务名';
$lang->citask->buildType = '构建类型';
$lang->citask->triggerType = '触发方式';
$lang->citask->scheduleType = '时间计划';
$lang->citask->cornExpression = 'Corn表达式';
$lang->citask->custom = '自定义';
$lang->citask->scheduleInterval = '间隔';
$lang->citask->tagKeywords = '标签关键字';
$lang->citask->commentKeywords = '注释关键字';
$lang->citask->everyDay = '每天';
$lang->citask->workDay = '工作日';
$lang->citask->at = '在';
$lang->citask->de = '的';
$lang->citask->lastExe = '最后执行';
$lang->citask->buildTypeList = array(build=>'仅构建', buildAndDeploy=>'构建部署', buildAndTest=>'构建测试');
$lang->citask->triggerTypeList = array(tag=>'打标签', commit=>'代码提交注释', schedule=>'定时计划');
$lang->citask->scheduleTypeList = array(corn=>'Corn表达式', custom=>'自定义');
// repo
$lang->repo->common = '代码库';
$lang->repo->browse = '浏览代码库';
+105 -10
View File
@@ -167,20 +167,81 @@ class ciModel extends model
}
/**
* list credential for repo and jenkins edit page
* Get a ci task by id.
*
* @param $whr
* @return mixed
* @param int $id
* @access public
* @return object
*/
public function listCredentialForSelection($whr)
public function getCitaskByID($id)
{
$credentials = $this->dao->select('id, name')->from(TABLE_CREDENTIAL)
$jenkins = $this->dao->select('*')->from(TABLE_CI_TASK)->where('id')->eq($id)->fetch();
return $jenkins;
}
/**
* Get ci task list.
*
* @param string $orderBy
* @param object $pager
* @param bool $decode
* @access public
* @return array
*/
public function listCitask($orderBy = 'id_desc', $pager = null, $decode = true)
{
$jenkinsList = $this->dao->select('*')->from(TABLE_CI_TASK)
->where('deleted')->eq('0')
->beginIF(!empty(whr))->andWhere($whr)->fi()
->orderBy(id)
->fetchPairs();
$credentials[''] = '';
return $credentials;
->orderBy($orderBy)
->page($pager)
->fetchAll('id');
return $jenkinsList;
}
/**
* Create a ci task.
*
* @access public
* @return bool
*/
public function createCitask()
{
$jenkins = fixer::input('post')
->add('createdBy', $this->app->user->account)
->add('createdDate', helper::now())
->get();
$this->dao->insert(TABLE_CI_TASK)->data($jenkins)
->batchCheck($this->config->jenkins->create->requiredFields, 'notempty')
->batchCheck("serviceUrl", 'URL')
->batchCheckIF($jenkins->type === 'credential', "credential", 'notempty')
->autoCheck()
->exec();
return !dao::isError();
}
/**
* Update a ci task.
*
* @param int $id
* @access public
* @return bool
*/
public function updateCitask($id)
{
$jenkins = fixer::input('post')
->add('editedBy', $this->app->user->account)
->add('editedDate', helper::now())
->get();
$this->dao->update(TABLE_CI_TASK)->data($jenkins)
->batchCheck($this->config->jenkins->edit->requiredFields, 'notempty')
->batchCheck("serviceUrl", 'URL')
->batchCheckIF($jenkins->type === 'credential', "credential", 'notempty')
->autoCheck()
->where('id')->eq($id)
->exec();
return !dao::isError();
}
/**
@@ -592,4 +653,38 @@ class ciModel extends model
$link .= $pathParams;
return $link;
}
/**
* list credential for repo and jenkins edit page
*
* @param $whr
* @return mixed
*/
public function listCredentialForSelection($whr)
{
$credentials = $this->dao->select('id, name')->from(TABLE_CREDENTIAL)
->where('deleted')->eq('0')
->beginIF(!empty(whr))->andWhere($whr)->fi()
->orderBy(id)
->fetchPairs();
$credentials[''] = '';
return $credentials;
}
/**
* list repos for jenkins task edit
*
* @return mixed
*/
public function listRepoForSelection($whr)
{
$repos = $this->dao->select('id, name')->from(TABLE_REPO)
->where('deleted')->eq('0')
->beginIF(!empty(whr))->andWhere($whr)->fi()
->orderBy(id)
->fetchPairs();
$repos[''] = '';
return $repos;
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
/**
* The browse view file of jenkins module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package jenkins
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include 'header.html.php'; ?>
<?php js::set('confirmDelete', $lang->jenkins->confirmDelete); ?>
<div id='mainContent' class='main-row'>
<div class='side-col' id='sidebar'>
<?php include 'menu.html.php'; ?>
</div>
<div class='main-col main-content'>
<form class='main-table' id='ajaxForm' method='post'>
<table id='jenkinsList' class='table has-sort-head table-fixed'>
<thead>
<tr>
<?php $vars = "orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?>
<th class='w-60px'><?php common::printOrderLink('id', $orderBy, $vars, $lang->citask->id); ?></th>
<th class='w-200px text-left'>
<?php common::printOrderLink('name', $orderBy, $vars, $lang->citask->name); ?></th>
<th class='w-150px text-left'>
<?php common::printOrderLink('repo', $orderBy, $vars, $lang->citask->jenkins); ?></th>
<th class='w-120px text-left'><?php echo $lang->citask->jenkinsTask; ?></th>
<th class='w-100px text-left'><?php echo $lang->citask->buildType; ?></th>
<th class='w-100px text-left'><?php echo $lang->citask->triggerType; ?></th>
<th class='w-200px text-left'><?php echo $lang->citask->lastExe; ?></th>
<th class='c-actions-4'><?php echo $lang->actions; ?></th>
</tr>
</thead>
<tbody>
<?php foreach (citaskList as $id => $task): ?>
<tr>
<td class='text-center'><?php echo $id; ?></td>
<td class='text' title='<?php echo $task->name; ?>'><?php echo $task->name; ?></td>
<td class='text' title='<?php echo $task->jenkinsServer; ?>'><?php echo $task->jenkinsServer; ?></td>
<td class='text' title='<?php echo $task->jenkinsTask; ?>'><?php echo $task->jenkinsTask; ?></td>
<td class='text' title='<?php echo $lang->citask->buildTypeList[$task->buildType]; ?>'>
<?php echo $lang->citask->buildTypeList[$task->buildType]; ?></td>
<td class='text' title='<?php echo $lang->citask->triggerTypeList[$task->triggerType]; ?>'>
<?php echo $lang->citask->triggerTypeList[$task->triggerType]; ?></td>
<td class='text' title='<?php echo $lang->citask->lastBuild; ?>'><?php echo $task->lastBuild; ?></td>
<td class='c-actions text-right'>
<?php
common::printIcon('ci', 'editJenkins', "jenkinsID=$id", '', 'list', 'edit');
if (common::hasPriv('ci', 'deleteJenkins')) {
$deleteURL = $this->createLink('ci', 'deleteJenkins', "jenkinsID=$id&confirm=yes");
echo html::a("javascript:ajaxDelete(\"$deleteURL\", \"jenkinsList\", confirmDelete)", '<i class="icon-trash"></i>', '', "title='{$lang->jenkins->delete}' class='btn'");
}
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php if ($jenkinss): ?>
<div class='table-footer'><?php $pager->show('rignt', 'pagerjs'); ?></div>
<?php endif; ?>
</form>
</div>
</div>
<?php include '../../common/view/footer.html.php'; ?>
+92
View File
@@ -0,0 +1,92 @@
<?php
/**
* The create view file of jenkins module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package jenkins
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include 'header.html.php'; ?>
<?php include '../../common/view/form.html.php'; ?>
<div id='mainContent' class='main-row'>
<div class='side-col' id='sidebar'>
<?php include 'menu.html.php'; ?>
</div>
<div class='main-col main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $lang->citask->create; ?></h2>
</div>
<form id='citaskForm' method='post' class='form-ajax'>
<table class='table table-form'>
<tr>
<th><?php echo $lang->citask->name; ?></th>
<td colspan="3" class='required'><?php echo html::input('name', '', "class='form-control'"); ?></td>
</tr>
<tr>
<th><?php echo $lang->citask->repo; ?></th>
<td><?php echo html::select('repo', $repoList, '', "class='form-control chosen'"); ?></td>
<th><?php echo $lang->citask->buildType; ?></th>
<td><?php echo html::select('buildType', $lang->citask->buildTypeList, 'buildAndDeploy', "class='form-control chosen'"); ?></td>
</tr>
<tr>
<th><?php echo $lang->citask->jenkins; ?></th>
<td><?php echo html::select('jenkins', $jenkinsList, '', "class='form-control chosen'"); ?></td>
<th><?php echo $lang->citask->jenkinsTask; ?></th>
<td><?php echo html::input('jenkinsTask', '', "class='form-control'"); ?></td>
</tr>
<tr>
<th><?php echo $lang->citask->triggerType; ?></th>
<td><?php echo html::select('triggerType', $lang->citask->triggerTypeList, '',
"onchange='triggerTypeChanged(this.value)' class='form-control chosen'"); ?></td>
<th class="schedule-fields"><?php echo $lang->citask->scheduleType; ?></th>
<td class="schedule-fields"><?php echo html::radio('scheduleType', $lang->citask->scheduleTypeList, 'corn',
"onclick='scheduleTypeChanged(this.value)'");?></td>
</tr>
<tr class="tag-fields">
<th><?php echo $lang->citask->tagKeywords; ?></th>
<td><?php echo html::input('tagKeywords', '', "class='form-control'"); ?></td>
<td colspan="2"><span style="font-style: italic">*build_*</span></td>
</tr>
<tr class="comment-fields">
<th><?php echo $lang->citask->commentKeywords; ?></th>
<td><?php echo html::input('commentKeywords', '', "class='form-control'"); ?></td>
<td colspan="2"><span style="font-style: italic">build_now</span></td>
</tr>
<tr class="corn-fields">
<th><?php echo $lang->citask->cornExpression; ?></th>
<td><?php echo html::input('cornExpression', '', "class='form-control'"); ?></td>
<td colspan="2"><span style="font-style: italic">0 0 2 * * ?</span></td>
</tr>
<tr class="custom-fields">
<th><?php echo $lang->citask->custom; ?></th>
<td colspan="3"></td>
</tr>
<tr>
<th><?php echo $lang->jenkins->desc; ?></th>
<td colspan="3"><?php echo html::textarea('desc', '', "rows='3' class='form-control'"); ?></td>
</tr>
<tr>
<th></th>
<td class='text-center form-actions'>
<?php echo html::submitButton(); ?>
<?php echo html::backButton(); ?>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php include '../../common/view/footer.html.php'; ?>
+61
View File
@@ -0,0 +1,61 @@
<?php
/**
* The edit view file of jenkins module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package jenkins
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include 'header.html.php'; ?>
<?php include '../../common/view/form.html.php'; ?>
<div id='mainContent' class='main-row'>
<div class='side-col' id='sidebar'>
<?php include 'menu.html.php'; ?>
</div>
<div class='main-col main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $lang->jenkins->edit; ?></h2>
</div>
<form id='jenkinsForm' method='post' class='form-ajax'>
<table class='table table-form'>
<tr>
<th><?php echo $lang->jenkins->name; ?></th>
<td class='required'><?php echo html::input('name', $jenkins->name, "class='form-control'"); ?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->jenkins->serviceUrl; ?></th>
<td class='required'><?php echo html::input('serviceUrl', $jenkins->serviceUrl, "class='form-control'"); ?></td>
<td></td>
</tr>
<tr id="credential-field">
<th class='thWidth'><?php echo $lang->credential->common; ?></th>
<td style="width:550px"><?php echo html::select('credential', $credentialList, $jenkins->credential, "class='form-control'"); ?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->jenkins->desc; ?></th>
<td><?php echo html::textarea('desc', $jenkins->desc, "rows='3' class='form-control'"); ?></td>
<td></td>
</tr>
<tr>
<th></th>
<td class='text-center form-actions'>
<?php echo html::submitButton(); ?>
<?php echo html::backButton() ?>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php include '../../common/view/footer.html.php'; ?>