+ Add browseproject page for sonarqube.

This commit is contained in:
caoyanyi
2023-11-08 10:40:36 +08:00
parent b70af24af4
commit 7890a6bd01
7 changed files with 177 additions and 56 deletions
+36
View File
@@ -16,3 +16,39 @@ $config->sonarqube->createproject = new stdclass();
$config->sonarqube->createproject->requiredFields = 'projectName,projectKey';
$config->sonarqube->cacheTime = 10;
global $lang;
$config->sonarqube->actionList = array();
$config->sonarqube->actionList['list']['icon'] = 'list';
$config->sonarqube->actionList['list']['text'] = $lang->sonarqube->browseProject;
$config->sonarqube->actionList['list']['hint'] = $lang->sonarqube->browseProject;
$config->sonarqube->actionList['list']['url'] = helper::createLink('sonarqube', 'browseProject',"sonarqubeID={id}");
$config->sonarqube->actionList['edit']['icon'] = 'edit';
$config->sonarqube->actionList['edit']['text'] = $lang->sonarqube->edit;
$config->sonarqube->actionList['edit']['hint'] = $lang->sonarqube->edit;
$config->sonarqube->actionList['edit']['url'] = helper::createLink('sonarqube', 'edit',"sonarqubeID={id}");
$config->sonarqube->actionList['delete']['icon'] = 'trash';
$config->sonarqube->actionList['delete']['text'] = $lang->sonarqube->delete;
$config->sonarqube->actionList['delete']['hint'] = $lang->sonarqube->delete;
$config->sonarqube->actionList['delete']['ajaxSubmit'] = true;
$config->sonarqube->actionList['delete']['url'] = helper::createLink('sonarqube', 'delete',"sonarqubeID={id}");
$config->sonarqube->actionList['deleteProject']['icon'] = 'trash';
$config->sonarqube->actionList['deleteProject']['text'] = $lang->sonarqube->deleteProject;
$config->sonarqube->actionList['deleteProject']['hint'] = $lang->sonarqube->deleteProject;
$config->sonarqube->actionList['deleteProject']['ajaxSubmit'] = true;
$config->sonarqube->actionList['deleteProject']['data-confirm'] = $lang->sonarqube->confirmDeleteProject;
$config->sonarqube->actionList['deleteProject']['url'] = helper::createLink('sonarqube', 'deleteProject',"sonarqubeID={sonarqubeID}&projectID={projectKey}");
$config->sonarqube->actionList['execJob']['icon'] = 'sonarqube';
$config->sonarqube->actionList['execJob']['text'] = $lang->sonarqube->execJob;
$config->sonarqube->actionList['execJob']['hint'] = $lang->sonarqube->execJob;
$config->sonarqube->actionList['execJob']['url'] = helper::createLink('sonarqube', 'execJob',"jobID={jobID}");
$config->sonarqube->actionList['reportView']['icon'] = 'audit';
$config->sonarqube->actionList['reportView']['text'] = $lang->sonarqube->reportView;
$config->sonarqube->actionList['reportView']['hint'] = $lang->sonarqube->reportView;
$config->sonarqube->actionList['reportView']['data-toggle'] = 'modal';
$config->sonarqube->actionList['reportView']['url'] = helper::createLink('sonarqube', 'reportView',"jobID={jobID}");
+47 -40
View File
@@ -4,49 +4,56 @@ $app->loadLang('sonarqube');
$config->sonarqube->dtable = new stdclass();
$config->sonarqube->dtable->fieldList['id']['title'] = 'ID';
$config->sonarqube->dtable->fieldList['id']['name'] = 'id';
$config->sonarqube->dtable->fieldList['id']['type'] = 'number';
$config->sonarqube->dtable->fieldList['id']['sortType'] = 'desc';
$config->sonarqube->dtable->fieldList['id']['checkbox'] = false;
$config->sonarqube->dtable->fieldList['id']['width'] = '80';
$config->sonarqube->dtable->browse = new stdclass();
$config->sonarqube->dtable->browse->fieldList['id']['title'] = 'ID';
$config->sonarqube->dtable->browse->fieldList['id']['name'] = 'id';
$config->sonarqube->dtable->browse->fieldList['id']['type'] = 'number';
$config->sonarqube->dtable->browse->fieldList['id']['sortType'] = 'desc';
$config->sonarqube->dtable->browse->fieldList['id']['checkbox'] = false;
$config->sonarqube->dtable->browse->fieldList['id']['width'] = '80';
$config->sonarqube->dtable->fieldList['name']['title'] = $lang->sonarqube->name;
$config->sonarqube->dtable->fieldList['name']['name'] = 'name';
$config->sonarqube->dtable->fieldList['name']['type'] = 'desc';
$config->sonarqube->dtable->fieldList['name']['sortType'] = true;
$config->sonarqube->dtable->fieldList['name']['hint'] = true;
$config->sonarqube->dtable->fieldList['name']['minWidth'] = '356';
$config->sonarqube->dtable->browse->fieldList['name']['title'] = $lang->sonarqube->name;
$config->sonarqube->dtable->browse->fieldList['name']['name'] = 'name';
$config->sonarqube->dtable->browse->fieldList['name']['type'] = 'desc';
$config->sonarqube->dtable->browse->fieldList['name']['sortType'] = true;
$config->sonarqube->dtable->browse->fieldList['name']['hint'] = true;
$config->sonarqube->dtable->browse->fieldList['name']['minWidth'] = '356';
$config->sonarqube->dtable->fieldList['url']['title'] = $lang->sonarqube->url;
$config->sonarqube->dtable->fieldList['url']['name'] = 'url';
$config->sonarqube->dtable->fieldList['url']['type'] = 'desc';
$config->sonarqube->dtable->fieldList['url']['sortType'] = true;
$config->sonarqube->dtable->fieldList['url']['hint'] = true;
$config->sonarqube->dtable->fieldList['url']['minWidth'] = '356';
$config->sonarqube->dtable->browse->fieldList['url']['title'] = $lang->sonarqube->url;
$config->sonarqube->dtable->browse->fieldList['url']['name'] = 'url';
$config->sonarqube->dtable->browse->fieldList['url']['type'] = 'desc';
$config->sonarqube->dtable->browse->fieldList['url']['sortType'] = true;
$config->sonarqube->dtable->browse->fieldList['url']['hint'] = true;
$config->sonarqube->dtable->browse->fieldList['url']['minWidth'] = '356';
$config->sonarqube->actionList = array();
$config->sonarqube->actionList['list']['icon'] = 'list';
$config->sonarqube->actionList['list']['text'] = $lang->sonarqube->browseProject;
$config->sonarqube->actionList['list']['hint'] = $lang->sonarqube->browseProject;
$config->sonarqube->actionList['list']['url'] = helper::createLink('sonarqube', 'browseProject',"sonarqubeID={id}");
$config->sonarqube->dtable->browse->fieldList['actions']['name'] = 'actions';
$config->sonarqube->dtable->browse->fieldList['actions']['title'] = $lang->actions;
$config->sonarqube->dtable->browse->fieldList['actions']['type'] = 'actions';
$config->sonarqube->dtable->browse->fieldList['actions']['width'] = '160';
$config->sonarqube->dtable->browse->fieldList['actions']['sortType'] = false;
$config->sonarqube->dtable->browse->fieldList['actions']['fixed'] = 'right';
$config->sonarqube->dtable->browse->fieldList['actions']['menu'] = array('list', 'edit', 'delete');
$config->sonarqube->dtable->browse->fieldList['actions']['list'] = $config->sonarqube->actionList;
$config->sonarqube->actionList['edit']['icon'] = 'edit';
$config->sonarqube->actionList['edit']['text'] = $lang->sonarqube->edit;
$config->sonarqube->actionList['edit']['hint'] = $lang->sonarqube->edit;
$config->sonarqube->actionList['edit']['url'] = helper::createLink('sonarqube', 'edit',"sonarqubeID={id}");
$config->sonarqube->dtable->project = new stdclass();
$config->sonarqube->dtable->project->fieldList['key']['title'] = $lang->sonarqube->projectKey;
$config->sonarqube->dtable->project->fieldList['key']['type'] = 'text';
$config->sonarqube->dtable->project->fieldList['key']['sortType'] = true;
$config->sonarqube->dtable->project->fieldList['key']['width'] = '150';
$config->sonarqube->actionList['delete']['icon'] = 'trash';
$config->sonarqube->actionList['delete']['text'] = $lang->sonarqube->delete;
$config->sonarqube->actionList['delete']['hint'] = $lang->sonarqube->delete;
$config->sonarqube->actionList['delete']['ajaxSubmit'] = true;
$config->sonarqube->actionList['delete']['url'] = helper::createLink('sonarqube', 'delete',"sonarqubeID={id}");
$config->sonarqube->dtable->project->fieldList['name']['title'] = $lang->sonarqube->projectName;
$config->sonarqube->dtable->project->fieldList['name']['type'] = 'title';
$config->sonarqube->dtable->project->fieldList['name']['fixed'] = false;
$config->sonarqube->dtable->project->fieldList['name']['sortType'] = 'desc';
$config->sonarqube->dtable->fieldList['actions']['name'] = 'actions';
$config->sonarqube->dtable->fieldList['actions']['title'] = $lang->actions;
$config->sonarqube->dtable->fieldList['actions']['type'] = 'actions';
$config->sonarqube->dtable->fieldList['actions']['width'] = '160';
$config->sonarqube->dtable->fieldList['actions']['sortType'] = false;
$config->sonarqube->dtable->fieldList['actions']['fixed'] = 'right';
$config->sonarqube->dtable->fieldList['actions']['menu'] = array('list', 'edit', 'delete');
$config->sonarqube->dtable->fieldList['actions']['list'] = $config->sonarqube->actionList;
$config->sonarqube->dtable->project->fieldList['time']['title'] = $lang->sonarqube->projectlastAnalysis;
$config->sonarqube->dtable->project->fieldList['time']['name'] = 'lastAnalysisDate';
$config->sonarqube->dtable->project->fieldList['time']['type'] = 'datetime';
$config->sonarqube->dtable->project->fieldList['time']['sortType'] = true;
$config->sonarqube->dtable->project->fieldList['time']['width'] = '150';
$config->sonarqube->dtable->project->fieldList['actions']['name'] = 'actions';
$config->sonarqube->dtable->project->fieldList['actions']['title'] = $lang->actions;
$config->sonarqube->dtable->project->fieldList['actions']['type'] = 'actions';
$config->sonarqube->dtable->project->fieldList['actions']['menu'] = array('deleteProject', 'execJob', 'reportView');
$config->sonarqube->dtable->project->fieldList['actions']['list'] = $config->sonarqube->actionList;
+8 -12
View File
@@ -45,7 +45,7 @@ class sonarqube extends control
* @access public
* @return void
*/
public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
public function browse(string $orderBy = 'id_desc', int $recTotal = 0, int $recPerPage = 20, int $pageID = 1)
{
$this->app->loadClass('pager', true);
$pager = new pager($recTotal, $recPerPage, $pageID);
@@ -192,7 +192,7 @@ class sonarqube extends control
* @access public
* @return void
*/
public function edit($sonarqubeID)
public function edit(int $sonarqubeID)
{
$oldSonarQube = $this->loadModel('pipeline')->getByID($sonarqubeID);
@@ -227,7 +227,7 @@ class sonarqube extends control
* @access public
* @return void
*/
public function delete($sonarqubeID)
public function delete(int $sonarqubeID)
{
$oldSonarQube = $this->loadModel('pipeline')->getByID($sonarqubeID);
$this->loadModel('action');
@@ -257,7 +257,7 @@ class sonarqube extends control
* @access public
* @return void
*/
public function execJob($jobID)
public function execJob(int $jobID)
{
echo $this->fetch('job', 'exec', "jobID=$jobID");
}
@@ -273,7 +273,7 @@ class sonarqube extends control
* @access public
* @return void
*/
public function browseProject($sonarqubeID, $orderBy = 'name_desc', $recPerPage = 15, $pageID = 1)
public function browseProject(int $sonarqubeID, string $orderBy = 'name_desc', int $recPerPage = 15, int $pageID = 1)
{
$this->app->loadClass('pager', true);
$keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword');
@@ -318,7 +318,6 @@ class sonarqube extends control
$this->view->title = $this->lang->sonarqube->common . $this->lang->colon . $this->lang->sonarqube->browseProject;
$this->view->sonarqubeID = $sonarqubeID;
$this->view->sonarqubeProjectList = (empty($sonarqubeProjectList) or empty($sonarqubeProjectList[$pageID - 1])) ? array() : $sonarqubeProjectList[$pageID - 1];
$this->view->projectJobPairs = $projectJobPairs;
$this->view->orderBy = $orderBy;
$this->view->successJobs = $successJobs;
@@ -352,22 +351,19 @@ class sonarqube extends control
*
* @param int $sonarqubeID
* @param string $projectKey
* @param string $confirm
* @access public
* @return void
*/
public function deleteProject($sonarqubeID, $projectKey, $confirm = 'no')
public function deleteProject(int $sonarqubeID, string $projectKey)
{
if($confirm != 'yes') return print(js::confirm($this->lang->sonarqube->confirmDeleteProject, inlink('deleteProject', "sonarqubeID=$sonarqubeID&projectKey=$projectKey&confirm=yes")));
/* Fix error when request type is PATH_INFO and the tag name contains '-'.*/
$projectKey = str_replace('*', '-', $projectKey);
$reponse = $this->sonarqube->apiDeleteProject($sonarqubeID, $projectKey);
if(isset($reponse->errors)) return print(js::alert($reponse->errors[0]->msg));
if(isset($reponse->errors)) return $this->sendError($reponse->errors[0]->msg);
$this->loadModel('action')->create('sonarqubeproject', 0, 'deleted', '', $projectKey);
return print(js::reload('parent'));
return $this->sendSuccess(array('load' => true));
}
/**
+4
View File
@@ -0,0 +1,4 @@
function search()
{
loadPage({method:'post', data: {keyword: $('#keyword').val()}, target: '#table-sonarqube-browseproject>*'});
}
+2 -2
View File
@@ -341,8 +341,8 @@ class sonarqubeModel extends model
{
$action = strtolower($action);
if($action == 'execjob') return $sonarqube->exec == '';
if($action == 'reportview') return $sonarqube->report == '';
if($action == 'execjob') return $sonarqube->jobID;
if($action == 'reportview') return $sonarqube->reportView;
return true;
}
+2 -2
View File
@@ -19,7 +19,7 @@ $canCreate = hasPriv('sonarqube', 'create');
$createLink = $this->createLink('sonarqube', 'create');
$createItem = array('text' => $lang->sonarqube->create, 'url' => $createLink, 'class' => 'primary', 'icon' => 'plus');
$tableData = initTableData($sonarqubeList, $config->sonarqube->dtable->fieldList, $this->sonarqube);
$tableData = initTableData($sonarqubeList, $config->sonarqube->dtable->browse->fieldList, $this->sonarqube);
toolbar
(
@@ -33,7 +33,7 @@ jsVar('sortLink', helper::createLink('sonarqube', 'browse', "orderBy={or
dtable
(
set::cols(array_values($config->sonarqube->dtable->fieldList)),
set::cols(array_values($config->sonarqube->dtable->browse->fieldList)),
set::data($tableData),
set::sortLink(jsRaw('createSortLink')),
set::onRenderCell(jsRaw('window.renderCell')),
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
/**
* The browseproject view file of sonarqube module of ZenTaoPMS.
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Yanyi Cao <caoyanyi@easycorp.ltd>
* @package sonarqube
* @link http://www.zentao.net
*/
namespace zin;
$projectList = array();
foreach($sonarqubeProjectList as $project)
{
$project->jobID = 0;
$project->reportView = 0;
$project->sonarqubeID = $sonarqube->id ;
$project->projectKey = str_replace('-', '*', $project->key);
if(isset($projectJobPairs[$project->key]))
{
$project->jobID = $projectJobPairs[$project->key];
if(in_array($project->jobID, $successJobs)) $project->reportView = 1;
}
$projectList[] = $project;
}
$tableData = initTableData($sonarqubeProjectList, $config->sonarqube->dtable->project->fieldList, $this->sonarqube);
featureBar
(
backBtn(set::text($lang->goback)),
form
(
setID('searchForm'),
setClass('ml-4'),
set::actions(array()),
formRow
(
input
(
set::placeholder($lang->sonarqube->placeholderSearch),
set::name('keyword'),
set::value($keyword)
),
btn
(
setClass('primary'),
$lang->sonarqube->search,
on::click('search')
)
)
)
);
hasPriv('instance', 'manage') ? toolbar
(
item
(
set::text($lang->sonarqube->createProject),
set::url($this->createLink('sonarqube', 'createProject', "sonarqubeID={$sonarqube->id}")),
setClass('primary'),
set::icon('plus')
)
) : null;
dtable
(
set::cols($config->sonarqube->dtable->project->fieldList),
set::data($tableData),
set::sortLink(createLink('sonarqube', 'browseProject', "sonarqubeID={$sonarqube->id}&orderBy={name}_{sortType}")),
set::orderBy($orderBy),
set::footPager(usePager()),
);
render();