diff --git a/module/gitea/control.php b/module/gitea/control.php index 246abb0096..286475f283 100644 --- a/module/gitea/control.php +++ b/module/gitea/control.php @@ -68,8 +68,17 @@ class gitea extends control { if($_POST) { - $this->checkToken(); - $giteaID = $this->gitea->create(); + $gitea = form::data($this->config->gitea->form->create) + ->add('type', 'gitea') + ->add('private',md5(rand(10,113450))) + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->trim('url,token') + ->skipSpecial('url,token') + ->remove('account,password,appType') + ->get(); + $this->checkToken($gitea); + $giteaID = $this->loadModel('pipeline')->create($gitea); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $actionID = $this->loadModel('action')->create('gitea', $giteaID, 'created'); @@ -165,9 +174,8 @@ class gitea extends control * @access protected * @return void */ - protected function checkToken() + protected function checkToken(object $gitea) { - $gitea = fixer::input('post')->trim('url,token')->get(); $this->dao->update('gitea')->data($gitea)->batchCheck($this->config->gitea->create->requiredFields, 'notempty'); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); diff --git a/module/gitea/lang/en.php b/module/gitea/lang/en.php index 9cff6aac7f..8cc2a85b8b 100644 --- a/module/gitea/lang/en.php +++ b/module/gitea/lang/en.php @@ -21,7 +21,7 @@ $lang->gitea->browseAction = 'Gitea List'; $lang->gitea->deleteAction = 'Delete Gitea'; $lang->gitea->id = 'ID'; -$lang->gitea->name = "Server Name"; +$lang->gitea->name = "Application Name"; $lang->gitea->url = 'Server URL'; $lang->gitea->token = 'Token'; diff --git a/module/gitea/lang/zh-cn.php b/module/gitea/lang/zh-cn.php index 30a8bfec17..49a6b06778 100644 --- a/module/gitea/lang/zh-cn.php +++ b/module/gitea/lang/zh-cn.php @@ -21,7 +21,7 @@ $lang->gitea->browseAction = 'Gitea列表'; $lang->gitea->deleteAction = '删除Gitea'; $lang->gitea->id = 'ID'; -$lang->gitea->name = "服务器名称"; +$lang->gitea->name = "应用名称"; $lang->gitea->url = '服务器地址'; $lang->gitea->token = 'Token'; diff --git a/module/gitea/model.php b/module/gitea/model.php index 06782ea84f..6777723925 100644 --- a/module/gitea/model.php +++ b/module/gitea/model.php @@ -81,17 +81,6 @@ class giteaModel extends model return rtrim($gitea->url, '/') . '/api/v1%s' . "?token={$gitea->token}" . $sudoParam; } - /** - * Create a gitea. - * - * @access public - * @return bool - */ - public function create() - { - return $this->loadModel('pipeline')->create('gitea'); - } - /** * Update a gitea. * diff --git a/module/gitlab/config/form.php b/module/gitlab/config/form.php index 366b444cc4..5129b21400 100644 --- a/module/gitlab/config/form.php +++ b/module/gitlab/config/form.php @@ -4,7 +4,6 @@ $config->gitlab->form = new stdclass(); $config->gitlab->form->create = common::formConfig('gitlab', 'create'); -$config->gitlab->form->create['type'] = array('type' => 'string', 'required' => true, 'default' => 'gitlab'); $config->gitlab->form->create['name'] = array('type' => 'string', 'required' => true, 'default' => ''); $config->gitlab->form->create['url'] = array('type' => 'string', 'required' => true, 'default' => ''); $config->gitlab->form->create['token'] = array('type' => 'string', 'required' => true, 'default' => ''); diff --git a/module/gitlab/control.php b/module/gitlab/control.php index bb490c51d6..92a6f4aed5 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -62,13 +62,22 @@ class gitlab extends control { if($_POST) { - $this->checkToken(); - $gitlabID = $this->gitlab->create(); + $gitlab = form::data($this->config->gitlab->form->create) + ->add('type', 'gitlab') + ->add('private',md5(rand(10,113450))) + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->trim('url,token') + ->skipSpecial('url,token,account,password') + ->remove('account,password,appType') + ->get(); + $this->checkToken($gitlab); + $gitlabID = $this->loadModel('pipeline')->create($gitlab); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->loadModel('action'); $actionID = $this->action->create('gitlab', $gitlabID, 'created'); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('space', 'browse'))); } $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->lblCreate; @@ -116,7 +125,7 @@ class gitlab extends control $actionID = $this->action->create('gitlab', $id, 'edited'); $changes = common::createChanges($oldGitLab, $gitLab); $this->action->logHistory($actionID, $changes); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('space', 'browse'))); } $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->edit; @@ -283,9 +292,8 @@ class gitlab extends control * @access protected * @return void */ - protected function checkToken() + protected function checkToken(object $gitlab) { - $gitlab = fixer::input('post')->trim('url,token')->get(); $this->dao->update('gitlab')->data($gitlab)->batchCheck($this->config->gitlab->create->requiredFields, 'notempty'); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index e958e8896d..97de26f410 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -60,7 +60,7 @@ $lang->gitlab->deleteTag = '删除标签'; $lang->gitlab->svaeFailed = '『%s』保存失败'; $lang->gitlab->id = 'ID'; -$lang->gitlab->name = "服务器名称"; +$lang->gitlab->name = "应用名称"; $lang->gitlab->url = '服务器地址'; $lang->gitlab->token = 'Token'; $lang->gitlab->defaultProject = '默认项目'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 82f8751dd1..f36b030713 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -428,17 +428,6 @@ class gitlabModel extends model return $comments; } - /** - * Create a gitlab. - * - * @access public - * @return bool - */ - public function create() - { - return $this->loadModel('pipeline')->create('gitlab'); - } - /** * Update a gitlab. * diff --git a/module/gogs/control.php b/module/gogs/control.php index e9f16a4955..0a1b674d0c 100644 --- a/module/gogs/control.php +++ b/module/gogs/control.php @@ -68,8 +68,17 @@ class gogs extends control { if($_POST) { - $this->checkToken(); - $gogsID = $this->gogs->create(); + $gogs = form::data($this->config->gogs->form->create) + ->add('type', 'gogs') + ->add('private',md5(rand(10,113450))) + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->trim('url,token') + ->skipSpecial('url,token') + ->remove('account,password,appType') + ->get(); + $this->checkToken($gogs); + $gogsID = $this->loadModel('pipeline')->create($gogs); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $actionID = $this->loadModel('action')->create('gogs', $gogsID, 'created'); @@ -165,9 +174,8 @@ class gogs extends control * @access protected * @return void */ - protected function checkToken() + protected function checkToken(object $gogs) { - $gogs = fixer::input('post')->trim('url,token')->get(); $this->dao->update('gogs')->data($gogs)->batchCheck($this->config->gogs->create->requiredFields, 'notempty'); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); diff --git a/module/gogs/lang/en.php b/module/gogs/lang/en.php index ae278521c0..6299ce0044 100644 --- a/module/gogs/lang/en.php +++ b/module/gogs/lang/en.php @@ -21,7 +21,7 @@ $lang->gogs->browseAction = 'Gogs List'; $lang->gogs->deleteAction = 'Delete Gogs'; $lang->gogs->id = 'ID'; -$lang->gogs->name = "Server Name"; +$lang->gogs->name = "Application Name"; $lang->gogs->url = 'Server URL'; $lang->gogs->token = 'Token'; diff --git a/module/gogs/lang/zh-cn.php b/module/gogs/lang/zh-cn.php index 2b0c798486..926e376b28 100644 --- a/module/gogs/lang/zh-cn.php +++ b/module/gogs/lang/zh-cn.php @@ -21,7 +21,7 @@ $lang->gogs->browseAction = 'Gogs列表'; $lang->gogs->deleteAction = '删除Gogs'; $lang->gogs->id = 'ID'; -$lang->gogs->name = "服务器名称"; +$lang->gogs->name = "应用名称"; $lang->gogs->url = '服务器地址'; $lang->gogs->token = 'Token'; diff --git a/module/gogs/model.php b/module/gogs/model.php index 62989fd9c4..8bd7298b1d 100644 --- a/module/gogs/model.php +++ b/module/gogs/model.php @@ -65,17 +65,6 @@ class gogsModel extends model return rtrim($gogs->url, '/') . '/api/v1%s' . "?token={$gogs->token}"; } - /** - * Create a gogs. - * - * @access public - * @return bool - */ - public function create() - { - return $this->loadModel('pipeline')->create('gogs'); - } - /** * Update a gogs. * diff --git a/module/jenkins/control.php b/module/jenkins/control.php index 31045d8693..acb2a538c2 100644 --- a/module/jenkins/control.php +++ b/module/jenkins/control.php @@ -57,7 +57,17 @@ class jenkins extends control { if($_POST) { - $jenkinsID = $this->jenkins->create(); + $jenkins = form::data($this->config->jenkins->form->create) + ->add('type', 'jenkins') + ->add('private',md5(rand(10,113450))) + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->trim('url,token,account,password') + ->skipSpecial('url,token,account,password') + ->remove('appType') + ->get(); + $jenkinsID = $this->loadModel('pipeline')->create($jenkins); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $jenkinsID)); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); diff --git a/module/jenkins/lang/en.php b/module/jenkins/lang/en.php index c00c117dcc..51a4bf26a3 100644 --- a/module/jenkins/lang/en.php +++ b/module/jenkins/lang/en.php @@ -10,7 +10,7 @@ $lang->jenkins->browseAction = 'Jenkins List'; $lang->jenkins->deleteAction = 'Delete Jenkins'; $lang->jenkins->id = 'ID'; -$lang->jenkins->name = 'Server Name'; +$lang->jenkins->name = 'Application Name'; $lang->jenkins->url = 'Server URL'; $lang->jenkins->token = 'Token'; $lang->jenkins->account = 'Username'; diff --git a/module/jenkins/lang/zh-cn.php b/module/jenkins/lang/zh-cn.php index 61ca75e9d5..68098365b6 100644 --- a/module/jenkins/lang/zh-cn.php +++ b/module/jenkins/lang/zh-cn.php @@ -10,7 +10,7 @@ $lang->jenkins->browseAction = 'Jenkins列表'; $lang->jenkins->deleteAction = '删除Jenkins'; $lang->jenkins->id = 'ID'; -$lang->jenkins->name = '服务器名称'; +$lang->jenkins->name = '应用名称'; $lang->jenkins->url = '服务器地址'; $lang->jenkins->token = 'Token'; $lang->jenkins->account = '用户名'; diff --git a/module/jenkins/model.php b/module/jenkins/model.php index a76caf0d7c..6bb21a75d2 100644 --- a/module/jenkins/model.php +++ b/module/jenkins/model.php @@ -128,17 +128,6 @@ class jenkinsModel extends model return $tasks; } - /** - * Create a jenkins. - * - * @access public - * @return bool - */ - public function create() - { - return $this->loadModel('pipeline')->create('jenkins'); - } - /** * Update a jenkins. * diff --git a/module/pipeline/lang/en.php b/module/pipeline/lang/en.php index 34072e6ece..13b1693dcf 100644 --- a/module/pipeline/lang/en.php +++ b/module/pipeline/lang/en.php @@ -1,6 +1,6 @@ pipeline->id = 'ID'; -$lang->pipeline->name = 'Server Name'; +$lang->pipeline->name = 'Application Name'; $lang->pipeline->url = 'Server URL'; $lang->pipeline->token = 'Token'; $lang->pipeline->account = 'Username'; diff --git a/module/pipeline/lang/zh-cn.php b/module/pipeline/lang/zh-cn.php index 75d1d9a52f..d77321aa96 100644 --- a/module/pipeline/lang/zh-cn.php +++ b/module/pipeline/lang/zh-cn.php @@ -1,6 +1,6 @@ pipeline->id = 'ID'; -$lang->pipeline->name = '服务器名称'; +$lang->pipeline->name = '应用名称'; $lang->pipeline->url = '服务器地址'; $lang->pipeline->token = 'Token'; $lang->pipeline->account = '用户名'; diff --git a/module/pipeline/model.php b/module/pipeline/model.php index 431987a4d7..2fb37432d4 100644 --- a/module/pipeline/model.php +++ b/module/pipeline/model.php @@ -69,16 +69,9 @@ class pipelineModel extends model * @access public * @return bool */ - public function create($type) + public function create(object $pipeline): int|false { - $pipeline = fixer::input('post') - ->add('type', $type) - ->add('private',md5(rand(10,113450))) - ->add('createdBy', $this->app->user->account) - ->add('createdDate', helper::now()) - ->trim('url,token,account,password') - ->skipSpecial('url,token,account,password') - ->get(); + $type = $pipeline->type; if($type == 'gitlab') $pipeline->url = rtrim($pipeline->url, '/'); if(isset($pipeline->password)) $pipeline->password = base64_encode($pipeline->password); diff --git a/module/sonarqube/control.php b/module/sonarqube/control.php index 986e371bd0..e3494a03d6 100644 --- a/module/sonarqube/control.php +++ b/module/sonarqube/control.php @@ -131,8 +131,17 @@ class sonarqube extends control { if($_POST) { - $this->checkToken(); - $sonarqubeID = $this->loadModel('pipeline')->create('sonarqube'); + $sonarqube = form::data($this->config->sonarqube->form->create) + ->add('type', 'sonarqube') + ->add('private',md5(rand(10,113450))) + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->trim('url,account,password') + ->skipSpecial('url,token,account,password') + ->remove('token,appType') + ->get(); + $this->checkToken($sonarqube); + $sonarqubeID = $this->loadModel('pipeline')->create($sonarqube); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->loadModel('action')->create('sonarqube', $sonarqubeID, 'created'); @@ -147,11 +156,11 @@ class sonarqube extends control /** * Check post info. * - * @param int $sonarqubeID + * @param object $sonarqube * @access protected * @return void */ - protected function checkToken($sonarqubeID = 0) + protected function checkToken(object $sonarqube) { $sonarqube = fixer::input('post')->trim('url,token,account,password')->get(); $this->dao->update('sonarqube')->data($sonarqube) @@ -173,7 +182,7 @@ class sonarqube extends control $result = $this->sonarqube->apiValidate($sonarqube->url, $token); if(!empty($result)) return $this->send(array('result' => 'fail', 'message' => $result)); - $this->post->set('token', $token); + $sonarqube->token = $token; } /** diff --git a/module/sonarqube/lang/en.php b/module/sonarqube/lang/en.php index 90c759611b..a0185a5277 100644 --- a/module/sonarqube/lang/en.php +++ b/module/sonarqube/lang/en.php @@ -19,7 +19,7 @@ $lang->sonarqube->createBug = "Create Bug"; $lang->sonarqube->delError = "There are bound jobs under this server, please delete the association and then operate"; $lang->sonarqube->id = 'ID'; -$lang->sonarqube->name = "Server Name"; +$lang->sonarqube->name = "Application Name"; $lang->sonarqube->url = 'Server Address'; $lang->sonarqube->account = 'Username'; $lang->sonarqube->password = 'Password'; diff --git a/module/sonarqube/lang/zh-cn.php b/module/sonarqube/lang/zh-cn.php index e2d8854b2a..5a804f9a4d 100644 --- a/module/sonarqube/lang/zh-cn.php +++ b/module/sonarqube/lang/zh-cn.php @@ -19,7 +19,7 @@ $lang->sonarqube->createBug = "转bug"; $lang->sonarqube->delError = "该服务器下有绑定的构建,请删除关联之后操作"; $lang->sonarqube->id = 'ID'; -$lang->sonarqube->name = "服务器名称"; +$lang->sonarqube->name = "应用名称"; $lang->sonarqube->url = '服务器地址'; $lang->sonarqube->account = '用户名'; $lang->sonarqube->password = '密码'; diff --git a/module/space/control.php b/module/space/control.php index b8f5949561..fd97edac60 100644 --- a/module/space/control.php +++ b/module/space/control.php @@ -85,7 +85,8 @@ class space extends control public function createApplication() { - $this->app->loadLang('gitlab'); + $this->app->loadLang('sonarqube'); + $this->app->loadLang('jenkins'); $this->display(); } diff --git a/module/space/js/createapplication.ui.js b/module/space/js/createapplication.ui.js new file mode 100644 index 0000000000..f2c54136f7 --- /dev/null +++ b/module/space/js/createapplication.ui.js @@ -0,0 +1,58 @@ +function onChangeType(event) +{ + const type = $(event.target).val(); +} + +function onChangeAppType(event) +{ + const appType = $(event.target).val(); + + if(appType == 'Jenkins' || appType == 'Sonarqube') + { + $('div.jenkins').removeClass('hidden'); + if(appType == 'Jenkins') + { + $('div.token').removeClass('hidden'); + $('div.password .form-label').removeClass('required'); + } + else + { + $('div.token').addClass('hidden'); + $('div.password .form-label').addClass('required'); + } + } + else + { + $('div.jenkins').addClass('hidden'); + $('div.token').removeClass('hidden'); + } + + $('#url').attr('placeholder', ''); + $('#token').attr('placeholder', ''); + $('#account').attr('placeholder', ''); + $('#password').attr('placeholder', ''); + switch(appType) + { + case 'Gitlab': + $('#createAppForm').attr('action', $.createLink('gitlab', 'create')); + $('#url').attr('placeholder', gitlabUrlTips); + $('#token').attr('placeholder', gitlabTokenTips); + break; + case 'Gitea': + $('#createAppForm').attr('action', $.createLink('gitea', 'create')); + break; + case 'Gogs': + $('#createAppForm').attr('action', $.createLink('gogs', 'create')); + break; + case 'Jenkins': + $('#createAppForm').attr('action', $.createLink('jenkins', 'create')); + $('#token').attr('placeholder', jenkinsTokenTips); + $('#password').attr('placeholder', jenkinsPasswordTips); + break; + case 'Sonarqube': + $('#createAppForm').attr('action', $.createLink('sonarqube', 'create')); + $('#url').attr('placeholder', sonarqubeUrlTips); + $('#account').attr('placeholder', sonarqubeAccountTips); + break; + } +} diff --git a/module/space/ui/createapplication.html.php b/module/space/ui/createapplication.html.php new file mode 100644 index 0000000000..0018de1176 --- /dev/null +++ b/module/space/ui/createapplication.html.php @@ -0,0 +1,90 @@ + + * @package space + * @link https://www.zentao.net + */ +namespace zin; + +jsVar('gitlabUrlTips', $lang->gitlab->placeholder->url); +jsVar('gitlabTokenTips', $lang->gitlab->placeholder->token); +jsVar('sonarqubeUrlTips', $lang->sonarqube->placeholder->url); +jsVar('sonarqubeAccountTips', $lang->sonarqube->placeholder->account); +jsVar('jenkinsTokenTips', $lang->jenkins->tokenFirst); +jsVar('jenkinsPasswordTips', $lang->jenkins->tips); + +formPanel +( + set::id('createAppForm'), + set::title($lang->space->install), + set::url($this->createLink('gitlab', 'create')), + formGroup + ( + set::width('1/2'), + set::label($lang->app->common), + set::name('appType'), + set::items($lang->space->appType), + set::required(true), + on::change('onChangeAppType'), + ), + formGroup + ( + set::label($lang->space->addType), + set::name('type'), + set::value('external'), + set::control('radioListInline'), + set::items(array(array('text' => $lang->store->common, 'value' => 'store'), array('text' => $lang->space->handConfig, 'value' => 'external'))), + set::required(true), + on::change('onChangeType'), + ), + formGroup + ( + set::label($lang->gitlab->name), + set::name('name'), + set::required(true), + ), + formGroup + ( + set::label($lang->gitlab->url), + set::name('url'), + set::required(true), + set::placeholder($lang->gitlab->placeholder->url) + ), + formRow + ( + setClass('jenkins sonarqube hidden'), + formGroup + ( + set::label($lang->user->account), + set::name('account'), + set::required(true), + ), + ), + formRow + ( + setClass('token'), + formGroup + ( + set::label($lang->gitlab->token), + set::name('token'), + set::placeholder($lang->gitlab->placeholder->token), + set::required(true), + ), + ), + formRow + ( + setClass('jenkins sonarqube password hidden'), + formGroup + ( + set::label($lang->user->password), + set::name('password'), + ), + ), +); + +render(); +