This commit is contained in:
holan20180123
2021-08-05 16:44:02 +08:00
8 changed files with 85 additions and 19 deletions
+54 -5
View File
@@ -64,7 +64,30 @@ class job extends control
if($_POST)
{
$jobID = $this->job->create();
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
if(dao::isError())
{
$errors = dao::getError();
if($this->post->engine == 'gitlab' and isset($errors['server']))
{
$errors['gitlabRepo'][] = sprintf($this->lang->error->notempty, $this->lang->job->repo);
unset($errors['server']);
unset($errors['pipeline']);
}
elseif($this->post->engine == 'jenkins')
{
if(isset($errors['server']))
{
$errors['jkServer'] = $errors['server'];
unset($errors['server']);
}
if(isset($errors['pipeline']))
{
$errors['jkTask'] = $errors['pipeline'];
unset($errors['pipeline']);
}
}
return $this->send(array('result' => 'fail', 'message' => $errors));
}
if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $jobID));
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
}
@@ -79,7 +102,7 @@ class job extends control
if(empty($repo->synced)) continue;
$repoPairs[$repo->id] = $repo->name;
$repoTypes[$repo->id] = $repo->SCM;
if($repo->SCM == 'Gitlab') $gitlabRepos[$repo->id] = $repo->name;
if(strtolower($repo->SCM) == 'gitlab') $gitlabRepos[$repo->id] = $repo->name;
}
$this->view->title = $this->lang->ci->job . $this->lang->colon . $this->lang->job->create;
@@ -108,21 +131,46 @@ class job extends control
if($_POST)
{
$this->job->update($id);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
if(dao::isError())
{
$errors = dao::getError();
if($this->post->engine == 'gitlab' and isset($errors['server']))
{
$errors['gitlabRepo'][] = sprintf($this->lang->error->notempty, $this->lang->job->repo);
unset($errors['server']);
unset($errors['pipeline']);
}
elseif($this->post->engine == 'jenkins')
{
if(isset($errors['server']))
{
$errors['jkServer'] = $errors['server'];
unset($errors['server']);
}
if(isset($errors['pipeline']))
{
$errors['jkTask'] = $errors['pipeline'];
unset($errors['pipeline']);
}
}
return $this->send(array('result' => 'fail', 'message' => $errors));
}
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
}
$repo = $this->loadModel('repo')->getRepoByID($job->repo);
$this->view->repo = $this->loadModel('repo')->getRepoByID($job->repo);
$repoList = $this->repo->getList($this->projectID);
$repoPairs = array(0 => '', $repo->id => $repo->name);
$repoList = $this->repo->getList($this->projectID);
$repoPairs = array(0 => '', $repo->id => $repo->name);
$gitlabRepos = array(0 => '');
$repoTypes[$repo->id] = $repo->SCM;
foreach($repoList as $repo)
{
if(empty($repo->synced)) continue;
$repoPairs[$repo->id] = $repo->name;
$repoTypes[$repo->id] = $repo->SCM;
if(strtolower($repo->SCM) == 'gitlab') $gitlabRepos[$repo->id] = $repo->name;
}
$products = $this->repo->getProductsByRepo($job->repo);
@@ -136,6 +184,7 @@ class job extends control
$this->view->position[] = html::a(inlink('browse'), $this->lang->ci->job);
$this->view->position[] = $this->lang->job->edit;
$this->view->repoPairs = $repoPairs;
$this->view->gitlabRepos = $gitlabRepos;
$this->view->repoTypes = $repoTypes;
$this->view->repoType = zget($repoTypes, $job->repo, 'Git');
$this->view->job = $job;
+1 -1
View File
@@ -8,7 +8,7 @@ $(document).ready(function()
$('#repo').change(function()
{
var repoID = $(this).val();
var link = createLink('repo', 'ajaxLoadPorducts', 'repoID=' + repoID);
var link = createLink('repo', 'ajaxLoadProducts', 'repoID=' + repoID);
$.get(link, function(data)
{
if(data)
+11 -2
View File
@@ -1,9 +1,14 @@
$(document).ready(function()
{
$('#gitlabRepo').change(function()
{
$('#repo').val($(this).val()).change();
})
$('#repo').change(function()
{
var repoID = $(this).val();
var link = createLink('repo', 'ajaxLoadPorducts', 'repoID=' + repoID);
var link = createLink('repo', 'ajaxLoadProducts', 'repoID=' + repoID);
$.get(link, function(data)
{
if(data)
@@ -107,7 +112,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];
@@ -130,10 +135,14 @@ $(document).ready(function()
if($(this).val() == 'gitlab')
{
$('#triggerType').find('[value=schedule]').remove();
$('tr.gitlabRepo').show();
$('tr.commonRepo').hide();
}
else if($('#triggerType').find('[value=schedule]').size() == 0 )
{
$('#triggerType').append(scheduleOption);
$('tr.gitlabRepo').hide();
$('tr.commonRepo').show();
}
});
+8 -4
View File
@@ -128,9 +128,11 @@ class jobModel extends model
if(strtolower($job->engine) == 'gitlab')
{
$job->repo = $job->gitlabRepo;
$repo = $this->loadModel('repo')->getRepoByID($job->repo);
$job->server = $repo->gitlab;
$job->pipeline = $repo->project;
$job->server = zget($repo, 'gitlab', '');
$job->pipeline = zget($repo, 'project', '');
unset($job->gitlabRepo);
}
unset($job->jkServer);
@@ -212,9 +214,11 @@ class jobModel extends model
if(strtolower($job->engine) == 'gitlab')
{
$job->repo = $job->gitlabRepo;
$repo = $this->loadModel('repo')->getRepoByID($job->repo);
$job->server = $repo->gitlab;
$job->pipeline = $repo->project;
$job->server = zget($repo, 'gitlab', '');
$job->pipeline = zget($repo, 'project', '');
unset($job->gitlabRepo);
}
unset($job->jkServer);
+1 -1
View File
@@ -126,7 +126,7 @@
<th></th>
<td class='text-center form-actions'>
<?php echo html::submitButton(); ?>
<?php echo html::backButton(); ?>
<?php if(!isonlybody()) echo html::a(inlink('browse', ""), $lang->goback, '', 'class="btn btn-wide"');?>
<?php echo html::hidden('repoType');?>
</td>
</tr>
+8 -5
View File
@@ -37,10 +37,13 @@
<td class='required'><?php echo zget($lang->job->engineList, $job->engine, '') . html::hidden('engine', $job->engine);?>
</td>
</tr>
<tr>
<th><?php echo $lang->job->repo;?></th>
<td><?php echo html::select('repo', $repoPairs, $job->repo, "class='form-control chosen'");?>
</td>
<tr class='commonRepo'>
<th><?php echo $lang->job->repo; ?></th>
<td><?php echo html::select('repo', $repoPairs, $job->repo, "class='form-control'"); ?></td>
</tr>
<tr class='gitlabRepo hide'>
<th><?php echo $lang->job->repo; ?></th>
<td><?php echo html::select('gitlabRepo', $gitlabRepos, $job->repo, "class='form-control'"); ?></td>
</tr>
<tr>
<th><?php echo $lang->job->product;?></th>
@@ -166,7 +169,7 @@
<th></th>
<td colspan="2" class='text-center form-actions'>
<?php echo html::submitButton();?>
<?php echo html::backButton();?>
<?php if(!isonlybody()) echo html::a(inlink('browse', ""), $lang->goback, '', 'class="btn btn-wide"');?>
<?php echo html::hidden('repoType', zget($repoTypes, $job->repo, 'Git'));?>
</td>
</tr>
+1 -1
View File
@@ -1164,7 +1164,7 @@ class repo extends control
* @access public
* @return void
*/
public function ajaxLoadPorducts($repoID)
public function ajaxLoadProducts($repoID)
{
$productPairs = $this->repo->getProductsByRepo($repoID);
echo html::select('product', array('') + $productPairs, key($productPairs), "class='form-control chosen'");
+1
View File
@@ -612,6 +612,7 @@ class repoModel extends model
public function getProductsByRepo($repoID)
{
$repo = $this->getRepoByID($repoID);
if(empty($repo)) return array();
return $this->dao->select('id,name')->from(TABLE_PRODUCT)
->where('id')->in($repo->product)
->andWhere('deleted')->eq(0)