* Adjust codes after code review for job module.

This commit is contained in:
dingguodong
2021-08-03 15:22:26 +08:00
parent 7a2bbe1bad
commit 415eee6922
6 changed files with 35 additions and 49 deletions

View File

@@ -299,6 +299,7 @@ class job extends control
$product = $repo->product;
if(strpos($product, ','))
{
/* Do not use `array_intersect()` here. */
$productList = explode(',', $product);
$matchedProducts = array();
$productPair = $this->loadModel('product')->getPairs();

View File

@@ -3,12 +3,6 @@ $(document).ready(function()
$('#repo').change(function()
{
var repoID = $(this).val();
$.getJSON(createLink('job', 'ajaxGetProductByRepo', 'repoID=' + repoID), function(product)
{
console.log(product);
}
);
var type = 'Git';
if(typeof(repoTypes[repoID]) != 'undefined') type = repoTypes[repoID];
@@ -97,7 +91,7 @@ $(document).ready(function()
$('#jenkinsServerTR .input-group').append("<div class='load-indicator loading'></div>");
$.getJSON(createLink('jenkins', 'ajaxGetJenkinsTasks', 'jenkinsID=' + jenkinsID), function(tasks)
{
html = "<select id='jkTask' name='jkTask' class='form-control'>";
html = "<select id='jkTask' name='jkTask' class='form-control'>";
for(taskKey in tasks)
{
var task = tasks[taskKey];

View File

@@ -3,12 +3,6 @@ $(document).ready(function()
$('#repo').change(function()
{
var repoID = $(this).val();
$.getJSON(createLink('job', 'ajaxGetProductByRepo', 'repoID=' + repoID), function(product)
{
console.log(product);
}
);
var type = 'Git';
if(typeof(repoTypes[repoID]) != 'undefined') type = repoTypes[repoID];

View File

@@ -109,7 +109,7 @@ class jobModel extends model
* Create a job.
*
* @access public
* @return bool
* @return int|bool
*/
public function create()
{
@@ -177,12 +177,9 @@ class jobModel extends model
->batchCheckIF(($this->post->repoType == 'Subversion' and $job->triggerType == 'tag'), "svnDir", 'notempty')
->autoCheck()
->exec();
if(dao::isError()) return dao::getError();
$id = $this->dao->lastInsertId();
if($id == 0) return false;
if(strtolower($job->engine) == 'jenkins') $this->initJob($id, $job, $this->post->repoType);
return $id;
}

View File

@@ -38,17 +38,17 @@
<th class='w-120px c-actions-3'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody class='text-left'>
<tbody>
<?php foreach($jobList as $id => $job):?>
<tr class='text-left'>
<td class='text-center'><?php echo $id; ?></td>
<td class='text-left' title='<?php echo $job->name; ?>'><?php echo common::hasPriv('job', 'view') ? html::a($this->createLink('job', 'view', "jobID={$job->id}", 'html', true), $job->name, '', "class='iframe' data-width='90%'") : $job->name;?></td>
<td title='<?php echo $job->repoName; ?>'><?php echo $job->repoName; ?></td>
<td class='text-center'><?php echo $id;?></td>
<td class='text-left' title='<?php echo $job->name;?>'><?php echo common::hasPriv('job', 'view') ? html::a($this->createLink('job', 'view', "jobID={$job->id}", 'html', true), $job->name, '', "class='iframe' data-width='90%'") : $job->name;?></td>
<td title='<?php echo $job->repoName;?>'><?php echo $job->repoName;?></td>
<td><?php echo zget($lang->job->engineList, $job->engine);?></td>
<td><?php echo zget($lang->job->frameList, $job->frame);?></td>
<?php if(strtolower($job->engine) == 'gitlab') $job->pipeline = $this->loadModel('gitlab')->getObjectNameForJob($job->server, $job->pipeline);?>
<?php $jenkins = urldecode($job->pipeline) . '@' . $job->jenkinsName;?>
<td title='<?php echo $jenkins; ?>'><?php echo $jenkins; ?></td>
<td title='<?php echo $jenkins;?>'><?php echo $jenkins;?></td>
<?php $triggerConfig = $this->job->getTriggerConfig($job);?>
<td title='<?php echo $triggerConfig;?>'><?php echo $triggerConfig;?></td>
<td class='text-center'><?php if($job->lastStatus) echo zget($lang->compile->statusList, $job->lastStatus);?></td>
@@ -71,4 +71,4 @@
<?php endif;?>
</form>
</div>
<?php include '../../common/view/footer.html.php'; ?>
<?php include '../../common/view/footer.html.php';?>

View File

@@ -10,7 +10,7 @@
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php'; ?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('repoTypes', $repoTypes)?>
<?php js::set('triggerType', $job->triggerType);?>
@@ -23,35 +23,35 @@
<div class='main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $lang->job->edit; ?></h2>
<h2><?php echo $lang->job->edit;?></h2>
</div>
<form id='jobForm' method='post' class='form-ajax'>
<table class='table table-form'>
<tr>
<th class='w-120px'><?php echo $lang->job->name; ?></th>
<td class='required'><?php echo html::input('name', $job->name, "class='form-control'"); ?></td>
<th class='w-120px'><?php echo $lang->job->name;?></th>
<td class='required'><?php echo html::input('name', $job->name, "class='form-control'");?></td>
<td colspan="2" ></td>
</tr>
<tr>
<th><?php echo $lang->job->engine; ?></th>
<th><?php echo $lang->job->engine;?></th>
<td class='required'><?php echo html::select('engine', $lang->job->engineList, $job->engine, "class='form-control chosen'");?>
</td>
</tr>
<tr>
<th><?php echo $lang->job->repo; ?></th>
<th><?php echo $lang->job->repo;?></th>
<td><?php echo html::select('repo', $repoPairs, $job->repo, "class='form-control chosen'");?>
</td>
</tr>
<tr>
<th><?php echo $lang->job->product; ?></th>
<td><?php echo html::select('product', $products, $job->product, "class='form-control chosen'"); ?></td>
<th><?php echo $lang->job->product;?></th>
<td><?php echo html::select('product', $products, $job->product, "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->job->frame; ?></th>
<td><?php echo html::select('frame', $lang->job->frameList, $job->frame, "class='form-control chosen'"); ?></td>
<th><?php echo $lang->job->frame;?></th>
<td><?php echo html::select('frame', $lang->job->frameList, $job->frame, "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->job->triggerType; ?></th>
<th><?php echo $lang->job->triggerType;?></th>
<?php if($repoType == 'Subversion') $lang->job->triggerTypeList['tag'] = $lang->job->dirChange;?>
<td><?php echo html::select('triggerType', $lang->job->triggerTypeList, $job->triggerType, "class='form-control chosen'");?></td>
<td colspan="2"></td>
@@ -103,13 +103,13 @@
</tr>
<?php if($job->engine == 'jenkins'):?>
<tr id="jenkinsServerTR">
<th><?php echo $lang->job->server; ?></th>
<th><?php echo $lang->job->server;?></th>
<td colspan='2'>
<div class='table-row'>
<div class='table-col'><?php echo html::select('jkServer', $jenkinsServerList, $job->server, "class='form-control chosen'");?></div>
<div class='table-col'>
<div class='input-group'>
<span class='input-group-addon'><?php echo $lang->job->Pipeline; ?></span>
<span class='input-group-addon'><?php echo $lang->job->Pipeline;?></span>
<?php echo html::select('jkTask', array('' => ''), $job->pipeline, "class='form-control chosen'");?>
</div>
</div>
@@ -123,15 +123,15 @@
<?php if($job->customParam):?>
<?php foreach(json_decode($job->customParam) as $paramName => $paramValue):?>
<div class='table-row input-group'>
<span class='input-group-addon w-50px'><?php echo $lang->job->paramName; ?></span>
<?php echo html::input('paramName[]', $paramName, "class='form-control'"); ?>
<span class='input-group-addon w-40px'><?php echo $lang->job->paramValue; ?></span>
<?php $isCustom = zget($lang->job->paramValueList, $paramValue, '') ? false : true; ?>
<span class='input-group-addon w-50px'><?php echo $lang->job->paramName;?></span>
<?php echo html::input('paramName[]', $paramName, "class='form-control'");?>
<span class='input-group-addon w-40px'><?php echo $lang->job->paramValue;?></span>
<?php $isCustom = zget($lang->job->paramValueList, $paramValue, '') ? false : true;?>
<?php if($isCustom):?>
<?php echo html::input('paramValue[]', $paramValue, "class='form-control'"); ?>
<?php echo html::input('paramValue[]', $paramValue, "class='form-control'");?>
<?php echo html::select('paramValue[]', $lang->job->paramValueList, '', "class='form-control hidden' onchange='setParamName(this)' disabled");?>
<?php else:?>
<?php echo html::input('paramValue[]', '', "class='form-control hidden' id='paramValue' disabled"); ?>
<?php echo html::input('paramValue[]', '', "class='form-control hidden' id='paramValue' disabled");?>
<?php echo html::select('paramValue[]', $lang->job->paramValueList, $paramValue, "class='form-control' onchange='setParamName(this)'");?>
<?php endif;?>
<span class='input-group-addon w-90px'>
@@ -146,14 +146,14 @@
<?php endforeach;?>
<?php endif;?>
<div class='table-row input-group'>
<span class='input-group-addon w-50px'><?php echo $lang->job->paramName; ?></span>
<?php echo html::input('paramName[]', '', "class='form-control' id='paramName'"); ?>
<span class='input-group-addon w-40px'><?php echo $lang->job->paramValue; ?></span>
<span class='input-group-addon w-50px'><?php echo $lang->job->paramName;?></span>
<?php echo html::input('paramName[]', '', "class='form-control' id='paramName'");?>
<span class='input-group-addon w-40px'><?php echo $lang->job->paramValue;?></span>
<?php echo html::select('paramValue[]', $lang->job->paramValueList, '', "class='form-control' onchange='setParamName(this)'");?>
<?php echo html::input('paramValue[]', '', "class='form-control hidden' id='paramValue' disabled"); ?>
<?php echo html::input('paramValue[]', '', "class='form-control hidden' id='paramValue' disabled");?>
<span class='input-group-addon w-90px'>
<div class='checkbox-primary'>
<input type='checkbox' name='custom' id='custom' value='1' onclick='setValueInput(this);' />
<input type='checkbox' name='custom' id='custom' value='1' onclick='setValueInput(this);'/>
<label for='custom'><?php echo $lang->job->custom;?></label>
</div>
</span>
@@ -165,8 +165,8 @@
<tr>
<th></th>
<td colspan="2" class='text-center form-actions'>
<?php echo html::submitButton(); ?>
<?php echo html::backButton(); ?>
<?php echo html::submitButton();?>
<?php echo html::backButton();?>
<?php echo html::hidden('repoType', zget($repoTypes, $job->repo, 'Git'));?>
</td>
</tr>