This commit is contained in:
hufangzhou
2022-04-28 10:56:13 +08:00
parent 950c04080c
commit bad39397ce
4 changed files with 60 additions and 17 deletions
+26 -12
View File
@@ -78,7 +78,7 @@ class api extends control
$this->view->libID = $libID;
$this->view->apiID = $apiID;
$this->view->libs = $libs;
$this->view->moduleTree = $libID ? $this->doc->getApiModuleTree($libID, $apiID, 0, $moduleID) : '';
$this->view->moduleTree = $libID ? $this->doc->getApiModuleTree($libID, $apiID, $release, $moduleID) : '';
$this->view->users = $this->user->getPairs('noclosed,noletter');
$this->display();
@@ -170,6 +170,8 @@ class api extends control
/**
* Api doc global struct page.
*
* @param int $libID
* @param int $releaseID
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
@@ -177,25 +179,34 @@ class api extends control
* @access public
* @return void
*/
public function struct($libID = 0, $orderBy = 'id', $recTotal = 0, $recPerPage = 15, $pageID = 1)
public function struct($libID = 0, $releaseID = 0, $orderBy = 'id', $recTotal = 0, $recPerPage = 15, $pageID = 1)
{
$libs = $this->doc->getApiLibs();
$this->app->loadClass('pager', $static = true);
$this->lang->modulePageNav = $this->generateLibsDropMenu($libs, $libID);
$this->lang->modulePageNav = $this->generateLibsDropMenu($libs, $libID, $releaseID);
$pager = new pager($recTotal, $recPerPage, $pageID);
/* Append id for secend sort. */
$sort = common::appendOrder($orderBy);
$structs = $this->api->getStructByQuery($libID, $pager, $sort);
if($releaseID)
{
$release = $this->api->getRelease($libID, 'byId', $releaseID);
$structs = $this->api->getStructListByRelease($release, '1 = 1 ', $sort);
}
else
{
$structs = $this->api->getStructByQuery($libID, $pager, $sort);
}
common::setMenuVars('doc', $libID);
$this->view->libID = $libID;
$this->view->structs = $structs;
$this->view->orderBy = $orderBy;
$this->view->title = $this->lang->api->struct;
$this->view->pager = $pager;
$this->view->libID = $libID;
$this->view->releaseID = $releaseID;
$this->view->structs = $structs;
$this->view->orderBy = $orderBy;
$this->view->title = $this->lang->api->struct;
$this->view->pager = $pager;
$this->display();
}
@@ -641,6 +652,8 @@ class api extends control
if(empty($libs)) return '';
if(!isset($libs[$libID])) return '';
$methodName = $this->app->rawMethod;
$libName = $libs[$libID]->name;
$output = <<<EOT
<div class='btn-group angle-btn'>
@@ -659,7 +672,7 @@ EOT;
foreach($libs as $key => $lib)
{
$selected = $key == $libID ? 'selected' : '';
$output .= html::a(inlink('index', "libID=$key"), $lib->name, '', "class='$selected' data-app='{$this->app->tab}'");
$output .= html::a(inlink($methodName, "libID=$key"), $lib->name, '', "class='$selected' data-app='{$this->app->tab}'");
}
$output .= "</div></div></div></div></div>";
@@ -682,12 +695,13 @@ EOT;
<div class='table-col'>
<div class='list-group'>
EOT;
$params = $methodName == 'index' ? "libID=$libID&moduleID=0&apiID=0&version=0" : "libID=$libID";
$selected = $version > 0 ? '' : 'selected';
$output .= html::a(inlink('index', "libID=$libID&moduleID=0&apiID=0&version=0&release=0"), $this->lang->api->defaultVersion, '', "class='$selected'");
$output .= html::a(inlink($methodName, $params . "&release=0"), $this->lang->api->defaultVersion, '', "class='$selected'");
foreach($versions as $key => $item)
{
$selected = $key == $version ? 'selected' : '';
$output .= html::a(inlink('index', "libID=$libID&moduleID=0&apiID=0&version=0&release=$key"), $item->version, '', "class='$selected' data-app='{$this->app->tab}'");
$output .= html::a(inlink($methodName, $params . "&release=$key"), $item->version, '', "class='$selected' data-app='{$this->app->tab}'");
}
$output .= "</div></div></div></div></div>";
}
+31 -2
View File
@@ -28,7 +28,9 @@ class apiModel extends model
const PARAMS_TYPE_CUSTOM = 'custom';
/**
* @param object $data
* Create release.
*
* @param object $data
* @access public
* @return int
*/
@@ -370,7 +372,7 @@ class apiModel extends model
* @access public
* @return array
*/
public function getApiListByRelease($release, $where = '')
public function getApiListByRelease($release, $where = '1 = 1 ')
{
$strJoin = array();
foreach($release->snap['apis'] as $api)
@@ -483,6 +485,33 @@ class apiModel extends model
->fetchAll();
}
/**
* Get struct list by release.
*
* @param object $release
* @param string $where
* @param string $orderBy
* @access public
* @return array
*/
public function getStructListByRelease($release, $where = '1 = 1 ', $orderBy = 'id')
{
$strJoin = array();
foreach($release->snap['structs'] as $struct)
{
$strJoin[] = "(object.id = {$struct['id']} and spec.version = {$struct['version']} )";
}
if($strJoin) $where .= 'and (' . implode(' or ', $strJoin) . ')';
$list = $this->dao->select('object.lib,spec.name,spec.type,spec.desc,spec.attribute,spec.version,spec.addedBy,spec.addedDate,object.id,user.realname as addedName')->from(TABLE_APISTRUCT)->alias('object')
->leftJoin(TABLE_APISTRUCT_SPEC)->alias('spec')->on('object.name = spec.name')
->leftJoin(TABLE_USER)->alias('user')->on('user.account = spec.addedBy')
->where($where)
->orderBy($orderBy)
->fetchAll();
return $list;
}
/**
* @param int $libID
* @param string $pager
+1 -1
View File
@@ -30,7 +30,7 @@
<table class='table has-sort-head' id='userList'>
<thead>
<tr>
<?php $vars = "libID={$libID}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}";?>
<?php $vars = "libID={$libID}&releaseID=$releaseID&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}";?>
<th class='c-id'><?php common::printOrderLink('id', $orderBy, $vars, $lang->idAB);?></th>
<th class='c-type'><?php common::printOrderLink('type', $orderBy, $vars, $lang->api->structType);?></th>
<th class='c-name'><?php echo $lang->api->structName;?></th>
+2 -2
View File
@@ -2267,7 +2267,7 @@ EOT;
if($release)
{
$rel = $this->api->getReleaseById($release);
$rel = $this->api->getRelease($rootID, 'byId', $release);
$docs = $this->api->getApiListByRelease($rel);
}
else
@@ -2288,7 +2288,7 @@ EOT;
$treeMenu = array();
if($release)
{
foreach($release->snap['modules'] as $module)
foreach($rel->snap['modules'] as $module)
{
$this->buildTree($treeMenu, 'api', 0, $rootID, $module, $moduleDocs, $docID, $moduleID);
}