* Add page for dev module api.

This commit is contained in:
caoyanyi
2023-04-03 16:01:36 +08:00
parent 42af40bcef
commit adae814406
4 changed files with 395 additions and 1 deletions
+28 -1
View File
@@ -15,11 +15,15 @@ class dev extends control
/**
* Get API of system.
*
* @param string $module
* @param int $apiID
* @access public
* @return void
*/
public function api($module = '')
public function api($module = '', $apiID = 1)
{
if($module == 'restapi') return print($this->fetch('dev', 'restAPI', "apiID=$apiID"));
$this->view->title = $this->lang->dev->api;
$this->view->position[] = html::a(inlink('api'), $this->lang->dev->common);
$this->view->position[] = $this->lang->dev->api;
@@ -32,6 +36,29 @@ class dev extends control
$this->display();
}
/**
* Get rest api list.
*
* @param int $apiID
* @access public
* @return void
*/
public function restAPI($apiID = 1)
{
list($api, $typeList, $menu) = $this->dev->getAPIData($apiID);
if($api)
{
$moduleID = $api->module;
$api->desc = htmlspecialchars_decode($api->desc);
}
$this->view->title = $this->lang->dev->api;
$this->view->moduleTree = $menu;
$this->view->typeList = $typeList;
$this->view->api = $api;
$this->view->apiID = $apiID;
$this->display();
}
/**
* Get schema of database.
*
File diff suppressed because one or more lines are too long
+52
View File
@@ -1120,4 +1120,56 @@ class devModel extends model
}
return $tree;
}
/**
* Create demo data.
*
* @param int $apiID
* @param string $version
* @access public
* @return int
*/
public function getAPIData($apiID = 0, $version = '16.0')
{
$modules = $this->loadModel('api')->getDemoData('module', $version);
$moduleNames = array();
foreach($modules as $index => $module)
{
$modules[$module->order] = $module;
unset($modules[$index]);
$moduleiNames[$module->id] = $module->name;
}
ksort($modules);
$apis = $this->api->getDemoData('api', $version);
$structs = $this->api->getDemoData('apistruct', $version);
$restApi = new stdClass();
$moduleAPIs = array();
foreach($apis as $api)
{
if(!isset($moduleAPIs[$api->module])) $moduleAPIs[$api->module] = array();
$moduleAPIs[$api->module][] = $api;
if($api->id == $apiID)
{
$api->moduleName = zget($moduleiNames, $api->module, '');
$api->params = json_decode($api->params, true);
$api->response = json_decode($api->response, true);
$restApi = $api;
}
}
$typeList = array();
foreach($this->lang->api->paramsTypeOptions as $key => $item) $typeList[$key] = $item;
foreach($structs as $struct) $typeList[$struct->id] = $struct->name;
$this->loadModel('doc');
$treeMenu = array();
foreach($modules as $module) $this->doc->buildTree($treeMenu, 'restapi', 0, 853, $module, $moduleAPIs, $apiID, 0);
$menu = "<ul id='modules' class='tree' data-ride='tree' data-name='tree-lib'>" . $treeMenu[0] . '</ul>';
return array($restApi, $typeList, $menu);
}
}
+154
View File
@@ -0,0 +1,154 @@
<?php
/**
* The index view file of doc module of ZenTaoPMS.
*
* @copyright Copyright 2009-2015 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Yidong Wang <yidong@cnezsoft.com>
* @package doc
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('confirmDelete', $lang->api->confirmDelete);?>
<div class="fade main-row split-row" id="mainRow">
<?php $sideWidth = common::checkNotCN() ? '270' : '238';?>
<div class="side-col" style="width:<?php echo $sideWidth;?>px" data-min-width="<?php echo $sideWidth;?>">
<div class="cell" style="min-height: 286px; overflow: visible;">
<div id='title'>
<li class='menu-title'>
<div class="title"><?php echo $this->lang->api->module;?></div>
</li>
</div>
<?php echo $moduleTree;?>
</div>
</div>
<div class="main-col" data-min-width="500">
<div id="mainContent" class="main-row in">
<div class="main-col col-8">
<div class="cell" id="content">
<div class="no-padding">
<div class="detail-title no-padding doc-title">
<div class="http-method label"><?php echo $api->method;?></div>
<div class="path" title="<?php echo $api->path;?>"><?php echo $api->path;?></div>
</div>
</div>
<div>
<h2 class="title" title="<?php echo $api->title;?>"><?php echo $api->title;?></h2>
<div class="desc"><?php echo $api->desc;?></div>
<?php if($api->params['header']):?>
<h3 class="title"><?php echo $lang->api->header;?></h3>
<table class="table table-data paramsTable">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th><?php echo $lang->api->req->type;?></th>
<th><?php echo $lang->api->req->required;?></th>
<th><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody>
<?php foreach($api->params['header'] as $param):?>
<tr>
<td><?php echo $param['field'];?></td>
<td>String</td>
<td><?php echo $lang->api->boolList[$param['required']];?></td>
<td><?php echo $param['desc'];?></td>
<tr>
<?php endforeach;
;?>
</tbody>
</table>
<?php endif;?>
<?php if($api->params['query']):?>
<h3 class="title"><?php echo $lang->api->query;?></h3>
<table class="table table-data paramsTable">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th><?php echo $lang->api->req->type;?></th>
<th><?php echo $lang->api->req->required;?></th>
<th><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody>
<?php foreach($api->params['query'] as $param):?>
<tr>
<td><?php echo $param['field'];?></td>
<td>String</td>
<td><?php echo $lang->api->boolList[$param['required']];?></td>
<td><?php echo $param['desc'];?></td>
<tr>
<?php endforeach;
;?>
</tbody>
</table>
<?php endif;?>
<?php
function parseTree($data, $typeList, $level = 0)
{
global $lang;
$str = '<tr>';
$field = '';
for($i = 0; $i < $level; $i++) $field .= '&nbsp;&nbsp;'. ($i == $level-1 ? '∟' : '&nbsp;') . '&nbsp;&nbsp;';
$field .= $data['field'];
$str .= '<td>' . $field . '</td>';
$str .= '<td>' . zget($typeList, $data['paramsType'], '') . '</td>';
$str .= '<td class="text-center">' . zget($lang->api->boolList, $data['required'], '') . '</td>';
$str .= '<td>' . $data['desc'] . '</td>';
$str .= '</tr>';
if(isset($data['children']) && count($data['children']) > 0)
{
$level++;
foreach($data['children'] as $item) $str .= parseTree($item, $typeList, $level);
}
return $str;
}
?>
<?php if($api->params['params']):?>
<h3 class="title"><?php echo $lang->api->params;?></h3>
<table class="table table-data paramsTable">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th class="w-50px"><?php echo $lang->api->req->type;?></th>
<th class="w-50px text-center"><?php echo $lang->api->req->required;?></th>
<th class="w-300px"><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody><?php foreach($api->params['params'] as $item) echo parseTree($item, $typeList);?></tbody>
</table>
<?php endif;?>
<?php if($api->paramsExample):?>
<h3 class="title"><?php echo $lang->api->paramsExample;?></h3>
<pre><code><?php echo $api->paramsExample;?></code></pre>
<?php endif;?>
<?php if($api->response):?>
<h3 class="title"><?php echo $lang->api->response;?></h3>
<table class="table table-data">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th class="w-50px"><?php echo $lang->api->req->type;?></th>
<th class="w-50px text-center"><?php echo $lang->api->req->required;?></th>
<th class="w-300px"><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody>
<?php foreach($api->response as $item) echo parseTree($item, $typeList);?>
</tbody>
</table>
<?php endif;?>
<?php if($api->responseExample):?>
<h3 class='title'><?php echo $lang->api->responseExample;?></h3>
<pre><code><?php echo $api->responseExample;?></code></pre>
<?php endif;?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include '../../common/view/footer.html.php';?>