finish api release.

This commit is contained in:
xiawenlong
2021-10-14 15:57:38 +08:00
parent 1cb991b70f
commit 4f9086045a
12 changed files with 463 additions and 272 deletions
+7 -5
View File
@@ -191,11 +191,13 @@ define('TABLE_BURN', '`' . $config->db->prefix . 'burn`');
define('TABLE_BUILD', '`' . $config->db->prefix . 'build`');
define('TABLE_ACL', '`' . $config->db->prefix . 'acl`');
define('TABLE_DOCLIB', '`' . $config->db->prefix . 'doclib`');
define('TABLE_DOC', '`' . $config->db->prefix . 'doc`');
define('TABLE_API', '`' . $config->db->prefix . 'api`');
define('TABLE_API_SPEC', '`' . $config->db->prefix . 'apispec`');
define('TABLE_APISTRUCT', '`' . $config->db->prefix . 'apistruct`');
define('TABLE_DOCLIB', '`' . $config->db->prefix . 'doclib`');
define('TABLE_DOC', '`' . $config->db->prefix . 'doc`');
define('TABLE_API', '`' . $config->db->prefix . 'api`');
define('TABLE_API_SPEC', '`' . $config->db->prefix . 'apispec`');
define('TABLE_APISTRUCT', '`' . $config->db->prefix . 'apistruct`');
define('TABLE_APISTRUCT_SPEC', '`' . $config->db->prefix . 'apistruct_spec`');
define('TABLE_API_LIB_RELEASE', '`' . $config->db->prefix . 'api_lib_release`');
define('TABLE_MODULE', '`' . $config->db->prefix . 'module`');
define('TABLE_ACTION', '`' . $config->db->prefix . 'action`');
+63 -84
View File
@@ -8,6 +8,7 @@ CREATE TABLE `zt_api_lib_release`
(
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`doclib` int UNSIGNED NOT NULL DEFAULT 0,
`desc` varchar(255) NOT NULL DEFAULT '',
`version` varchar(255) NOT NULL DEFAULT '',
`snap` mediumtext NOT NULL,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
@@ -18,106 +19,84 @@ CREATE TABLE `zt_api_lib_release`
-- DROP TABLE IF EXISTS `zt_api`;
CREATE TABLE `zt_api`
(
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`product` varchar(255) NOT NULL DEFAULT '',
`lib` int UNSIGNED NOT NULL DEFAULT 0,
`module` int UNSIGNED NOT NULL DEFAULT 0,
`title` varchar(100) NOT NULL DEFAULT '',
`path` varchar(255) NOT NULL DEFAULT '',
`protocol` varchar(10) NOT NULL DEFAULT '',
`method` varchar(10) NOT NULL DEFAULT '',
`requestType` varchar(100) NOT NULL DEFAULT '',
`responseType` varchar(100) NOT NULL DEFAULT '',
`status` varchar(20) NOT NULL DEFAULT '',
`owner` varchar(30) NOT NULl DEFAULT 0,
`desc` text NULL,
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`product` varchar(255) NOT NULL DEFAULT '',
`lib` int UNSIGNED NOT NULL DEFAULT 0,
`module` int UNSIGNED NOT NULL DEFAULT 0,
`title` varchar(100) NOT NULL DEFAULT '',
`path` varchar(255) NOT NULL DEFAULT '',
`protocol` varchar(10) NOT NULL DEFAULT '',
`method` varchar(10) NOT NULL DEFAULT '',
`requestType` varchar(100) NOT NULL DEFAULT '',
`responseType` varchar(100) NOT NULL DEFAULT '',
`status` varchar(20) NOT NULL DEFAULT '',
`owner` varchar(30) NOT NULl DEFAULT 0,
`desc` text NULL,
`version` smallint UNSIGNED NOT NULL DEFAULT 0,
`params` text NULL,
`paramsExample` text NUll,
`responseExample` text NUll,
`response` text NULL,
`commonParams` text NULL,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
`addedDate` datetime NOT NULL,
`editedBy` varchar(30) NOT NULL DEFAULT 0,
`editedDate` datetime NOT NULL,
`deleted` enum ('0', '1') NOT NULL DEFAULT '0',
`params` text NULL,
`paramsExample` text NUll,
`responseExample` text NUll,
`response` text NULL,
`commonParams` text NULL,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
`addedDate` datetime NOT NULL,
`editedBy` varchar(30) NOT NULL DEFAULT 0,
`editedDate` datetime NOT NULL,
`deleted` enum ('0', '1') NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
);
-- DROP TABLE IF EXISTS `zt_apispec`;
CREATE TABLE `zt_apispec`
(
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`doc` int UNSIGNED NOT NULL DEFAULT 0,
`module` int UNSIGNED NOT NULL DEFAULT 0,
`title` varchar(100) NOT NULL DEFAULT '',
`path` varchar(255) NOT NULL DEFAULT '',
`protocol` varchar(10) NOT NULL DEFAULT '',
`method` varchar(10) NOT NULL DEFAULT '',
`requestType` varchar(100) NOT NULL DEFAULT '',
`responseType` varchar(100) NOT NULL DEFAULT '',
`status` tinyint UNSIGNED NOT NULL DEFAULT 0,
`owner` varchar(255) NOT NULl DEFAULT 0,
`desc` text NULL,
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`doc` int UNSIGNED NOT NULL DEFAULT 0,
`module` int UNSIGNED NOT NULL DEFAULT 0,
`title` varchar(100) NOT NULL DEFAULT '',
`path` varchar(255) NOT NULL DEFAULT '',
`protocol` varchar(10) NOT NULL DEFAULT '',
`method` varchar(10) NOT NULL DEFAULT '',
`requestType` varchar(100) NOT NULL DEFAULT '',
`responseType` varchar(100) NOT NULL DEFAULT '',
`status` tinyint UNSIGNED NOT NULL DEFAULT 0,
`owner` varchar(255) NOT NULl DEFAULT 0,
`desc` text NULL,
`version` smallint UNSIGNED NOT NULL DEFAULT 0,
`params` text NULL,
`response` text NULL,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
`addedDate` datetime NULL,
`params` text NULL,
`response` text NULL,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
`addedDate` datetime NULL,
PRIMARY KEY (`id`)
);
-- DROP TABLE IF EXISTS `zt_apistruct`;
create table `zt_apistruct`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
`lib` int UNSIGNED NOT NULL DEFAULT 0,
`name` varchar(30) NOT NULL DEFAULT '',
`type` varchar(50) NOT NULL DEFAULT '',
`desc` varchar(255) NOT NULL DEFAULT '',
`attribute` text NULL,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
`addedDate` datetime NOT NULL,
`editEdBy` varchar(30) NOT NULL DEFAULT 0,
`editedDate` datetime NOT NULL,
`id` int unsigned NOT NULL AUTO_INCREMENT,
`lib` int UNSIGNED NOT NULL DEFAULT 0,
`name` varchar(30) NOT NULL DEFAULT '',
`type` varchar(50) NOT NULL DEFAULT '',
`desc` varchar(255) NOT NULL DEFAULT '',
`version` smallint unsigned NOT NULL DEFAULT 0,
`attribute` text NULL,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
`addedDate` datetime NOT NULL,
`editEdBy` varchar(30) NOT NULL DEFAULT 0,
`editedDate` datetime NOT NULL,
`deleted` enum ('0', '1') NOT NULL DEFAULT '0',
primary key (`id`)
);
-- DROP TABLE IF EXISTS `zt_api_const`;
create table `zt_api_const`
-- DROP TABLE IF EXISTS `zt_apistruct_spec`;
create table `zt_apistruct_spec`
(
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`doclib` int UNSIGNED NOT NULL DEFAULT 0,
`field` varchar(50) NOT NULL DEFAULT '',
`scope` varchar(50) NOT NULL DEFAULT '',
`type` varchar(20) NOT NULL DEFAULT '',
`default` varchar(1000) NOT NULL DEFAULT '',
`required` tinyint UNSIGNED NOT NULL DEFAULT 0,
`desc` varchar(255) NOT NULL DEFAULT 0,
`version` smallint UNSIGNED NOT NULL DEFAULT 0,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
`addedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`editEdBy` varchar(30) NOT NULL DEFAULT 0,
`editedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`deletedDate` datetime NULL,
PRIMARY KEY (`id`)
);
-- DROP TABLE IF EXISTS `zt_api_const_spec`;
create table `zt_api_const_spec`
(
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`doclib` int UNSIGNED NOT NULL DEFAULT 0,
`field` varchar(50) NOT NULL DEFAULT '',
`scope` varchar(50) NOT NULL DEFAULT '',
`type` varchar(20) NOT NULL DEFAULT '',
`default` varchar(1000) NOT NULL DEFAULT '',
`required` tinyint UNSIGNED NOT NULL DEFAULT 0,
`desc` varchar(255) NOT NULL DEFAULT 0,
`version` smallint UNSIGNED NOT NULL DEFAULT 0,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
`addedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
);
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`type` varchar(50) NOT NULL DEFAULT '',
`desc` varchar(255) NOT NULL DEFAULT '',
`attribute` text NULL,
`version` smallint unsigned NOT NULL DEFAULT 0,
`addedBy` varchar(30) NOT NULL DEFAULT 0,
`addedDate` datetime NOT NULL,
primary key (`id`)
)
+46 -44
View File
@@ -181,9 +181,9 @@ class baseControl
* 2. set the pathes of current module, and load it's model class.
* 3. auto assign the $lang and $config to the view.
*
* @param string $moduleName
* @param string $methodName
* @param string $appName
* @param string $moduleName
* @param string $methodName
* @param string $appName
* @access public
* @return void
*/
@@ -253,7 +253,7 @@ class baseControl
* 设置方法名。
* Set the method name.
*
* @param string $methodName 方法名,如果为空,则从$app中获取。The method name, if empty, get it from $app.
* @param string $methodName 方法名,如果为空,则从$app中获取。The method name, if empty, get it from $app.
* @access public
* @return void
*/
@@ -266,8 +266,8 @@ class baseControl
* 加载指定模块的model文件。
* Load the model file of one module.
*
* @param string $moduleName 模块名,如果为空,使用当前模块。The module name, if empty, use current module's name.
* @param string $appName The app name, if empty, use current app's name.
* @param string $moduleName 模块名,如果为空,使用当前模块。The module name, if empty, use current module's name.
* @param string $appName The app name, if empty, use current app's name.
* @access public
* @return object|bool 如果没有model文件,返回false,否则返回model对象。If no model file, return false, else return the model object.
*/
@@ -365,8 +365,8 @@ class baseControl
* 设置视图文件:主视图文件,扩展视图文件, 站点扩展视图文件,以及钩子脚本。
* Set view files: the main file, extension view file, site extension view file and hook files.
*
* @param string $moduleName module name
* @param string $methodName method name
* @param string $moduleName module name
* @param string $methodName method name
* @access public
* @return string the view file
*/
@@ -404,7 +404,7 @@ class baseControl
* 获取某一个视图文件的扩展。
* Get the extension file of an view.
*
* @param string $viewFile
* @param string $viewFile
* @access public
* @return string|bool If extension view file exists, return the path. Else return fasle.
*/
@@ -440,8 +440,8 @@ class baseControl
* 获取适用于当前方法的css:该模块公用的css + 当前方法的css + 扩展的css。
* Get css codes applied to current method: module common css + method css + extension css.
*
* @param string $moduleName
* @param string $methodName
* @param string $moduleName
* @param string $methodName
* @access public
* @return string
*/
@@ -507,7 +507,7 @@ class baseControl
/**
* Get extension css and extension css with lang.
*
* @param array $files
* @param array $files
* @access public
* @return string
*/
@@ -559,8 +559,8 @@ class baseControl
* 获取适用于当前方法的js:该模块公用的js + 当前方法的js + 扩展的js。
* Get js codes applied to current method: module common js + method js + extension js.
*
* @param string $moduleName
* @param string $methodName
* @param string $moduleName
* @param string $methodName
* @access public
* @return string
*/
@@ -609,8 +609,8 @@ class baseControl
* 向$view传递一个变量。
* Assign one var to the view vars.
*
* @param string $name the name.
* @param mixed $value the value.
* @param string $name the name.
* @param mixed $value the value.
* @access public
* @return void
*/
@@ -635,8 +635,8 @@ class baseControl
* 渲染视图文件。
* Parse view file.
*
* @param string $moduleName module name, if empty, use current module.
* @param string $methodName method name, if empty, use current method.
* @param string $moduleName module name, if empty, use current module.
* @param string $methodName method name, if empty, use current method.
* @access public
* @return string the parsed result.
*/
@@ -655,8 +655,8 @@ class baseControl
* 渲染json格式。
* Parse json format.
*
* @param string $moduleName module name
* @param string $methodName method name
* @param string $moduleName module name
* @param string $methodName method name
* @access public
* @return void
*/
@@ -683,8 +683,8 @@ class baseControl
* 默认渲染方法,适用于viewType = html的时候。
* Default parse method when viewType != json, like html.
*
* @param string $moduleName module name
* @param string $methodName method name
* @param string $moduleName module name
* @param string $methodName method name
* @access public
* @return void
*/
@@ -694,7 +694,7 @@ class baseControl
* 设置视图文件。(PHP7有一个bug,不能直接$viewFile = $this->setViewFile())。
* Set viewFile. (Can't assign $viewFile = $this->setViewFile() directly because one php7's bug.)
*/
$results = $this->setViewFile($moduleName, $methodName);
$results = $this->setViewFile($moduleName, $methodName);
$viewFile = $results;
if(is_array($results)) extract($results);
@@ -740,9 +740,9 @@ class baseControl
* Get the output of one module's one method as a string, thus in one module's method, can fetch other module's content.
* If the module name is empty, then use the current module and method. If set, use the user defined module and method.
*
* @param string $moduleName module name.
* @param string $methodName method name.
* @param array $params params.
* @param string $moduleName module name.
* @param string $methodName method name.
* @param array $params params.
* @access public
* @return string the parsed html.
*/
@@ -868,8 +868,8 @@ class baseControl
* 向浏览器输出内容。
* Print the content of the view.
*
* @param string $moduleName module name
* @param string $methodName method name
* @param string $moduleName module name
* @param string $methodName method name
* @access public
* @return void
*/
@@ -883,8 +883,8 @@ class baseControl
* 直接输出data数据,通常用于ajax请求中。
* Send data directly, for ajax requests.
*
* @param mixed $data
* @param string $type
* @param mixed $data
* @param string $type
* @access public
* @return void
*/
@@ -938,21 +938,23 @@ class baseControl
/**
* return error json
* @param mixed $error
*
* @param mixed $error
* @return void
* @author thanatos thanatos915@163.com
*/
public function sendError($error)
{
$this->send([
'result' => 'fail',
'message' => $error,
]);
'result' => 'fail',
'message' => $error,
]);
}
/**
* send success json
*
* @param array $data
* @param array $data
* @return void
* @author thanatos thanatos915@163.com
*/
@@ -967,11 +969,11 @@ class baseControl
* 创建一个模块方法的链接。
* Create a link to one method of one module.
*
* @param string $moduleName module name
* @param string $methodName method name
* @param string|array $vars the params passed, can be array(key=>value) or key1=value1&key2=value2
* @param string $viewType the view type
* @param string $onlybody remove header and footer or not in iframe
* @param string $moduleName module name
* @param string $methodName method name
* @param string|array $vars the params passed, can be array(key=>value) or key1=value1&key2=value2
* @param string $viewType the view type
* @param string $onlybody remove header and footer or not in iframe
* @access public
* @return string the link string.
*/
@@ -985,9 +987,9 @@ class baseControl
* 创建当前模块的一个方法链接。
* Create a link to the inner method of current module.
*
* @param string $methodName method name
* @param string|array $vars the params passed, can be array(key=>value) or key1=value1&key2=value2
* @param string $viewType the view type
* @param string $methodName method name
* @param string|array $vars the params passed, can be array(key=>value) or key1=value1&key2=value2
* @param string $viewType the view type
* @access public
* @return string the link string.
*/
@@ -1000,7 +1002,7 @@ class baseControl
* 重定向到另一个页面。
* Location to another page.
*
* @param string $url the target url.
* @param string $url the target url.
* @access public
* @return void
*/
+5
View File
@@ -15,7 +15,12 @@ $config->api->create->requiredFields = 'lib,title,path';
$config->api->edit = new stdclass();
$config->api->edit->requiredFields = 'lib,title,path';
$config->api->publish = new stdclass();
$config->api->publish->requiredFields = 'version';
$config->api->editor = new stdclass();
$config->api->editor->createlib = array('id' => 'desc', 'tools' => 'simpleTools');
$config->api->editor->create = array('id' => 'desc', 'tools' => 'simpleTools');
$config->api->editor->edit = array('id' => 'desc', 'tools' => 'simpleTools');
$config->api->editor->publish = array('id' => 'desc', 'tools' => 'simpleTools');
Regular → Executable
+37 -4
View File
@@ -76,6 +76,38 @@ class api extends control
$this->display();
}
/**
* Publish a api doc lib.
*
* @param $libID
* @access public
* @return void
*/
public function publish($libID)
{
$lib = $this->doc->getLibById($libID);
if(!empty($_POST)) {
$data = fixer::input('post')
->add('lib', $libID)
->add('addedBy', $this->app->user->account)
->add('addedDate', helper::now())
->get();
// check version is exist.
if($this->api->getReleaseByVersion($data->version))
{
return $this->sendError($this->lang->api->noUniqueVersion);
}
$this->api->publishLib($data);
if(dao::isError()) return $this->sendError(dao::getError());
return $this->sendSuccess(array('locate' => $this->createLink('api', 'index', "libID=$libID")));
}
$this->view->title = $this->lang->api->publish . $lib->name;
$this->display();
}
/**
* Api doc global struct page.
*
@@ -159,6 +191,7 @@ class api extends control
*/
public function editStruct($libID, $structID)
{
common::setMenuVars('doc', $libID);
$struct = $this->api->getStructByID($structID);
if(!empty($_POST))
@@ -321,7 +354,6 @@ class api extends control
return $this->sendError(dao::getError());
}
$this->action->create('api', $apiID, 'Edited');
return $this->sendSuccess(array('locate' => helper::createLink('api', 'index', "libID=0&moduleID=0&apiID=$apiID")));
}
@@ -345,9 +377,9 @@ class api extends control
'value' => $key,
];
}
$this->view->typeOptions = $options;
$this->view->user = $this->app->user->account;
$this->view->allUsers = $this->loadModel('user')->getPairs('devfirst|noclosed');;
$this->view->typeOptions = $options;
$this->view->user = $this->app->user->account;
$this->view->allUsers = $this->loadModel('user')->getPairs('devfirst|noclosed');;
$this->view->moduleOptionMenu = $this->loadModel('tree')->getOptionMenu($api->lib, 'api', $startModuleID = 0);
$this->view->moduleID = $api->module ? (int)$api->module : (int)$this->cookie->lastDocModule;
$this->view->example = $example;
@@ -517,6 +549,7 @@ class api extends control
// global struct link
$menu = '';
$menu .= html::a(helper::createLink('api', 'publish', "libID=$libID"), $this->lang->api->publish, '', 'class="btn btn-link iframe"');
// page of index menu
if(intval($libID) > 0)
{
+4 -4
View File
@@ -3,9 +3,9 @@ var app = new Vue({
data: {
header: [],
queryP: [],
body: [],
params: "",
body: "",
response: "",
params: "",
defaultHeader: [
{ field: '', required: '', desc: '' }
],
@@ -33,7 +33,7 @@ var app = new Vue({
},
deep: true
},
params: {
body: {
handler() {
this.setParams()
},
@@ -42,7 +42,7 @@ var app = new Vue({
},
methods: {
changeAttr(val) {
this.params = JSON.stringify(val)
this.body = val
},
changeRes(val) {
this.response = JSON.stringify(val)
+1
View File
@@ -1,3 +1,4 @@
console.log(struct)
new Vue({
el: '#app',
data: function () {
+13
View File
@@ -0,0 +1,13 @@
$(document).ready(function()
{
$('#apiForm').ajaxForm({
success: (data) => {
if (data.result == 'success') {
if (data.locate) {
window.parent.location.href = data.locate
}
$.zui.closeModal()
}
}
})
});
Regular → Executable
+3
View File
@@ -14,6 +14,7 @@ $lang->api->common = 'API接口';
$lang->api->getModel = '超级model调用接口';
$lang->api->sql = 'SQL查询接口';
$lang->api->publish = '发布';
$lang->api->edit = '编辑';
$lang->api->delete = '删除';
$lang->api->position = '位置';
@@ -29,6 +30,8 @@ $lang->api->noParam = 'GET方式调试不需要输入参数,';
$lang->api->noModule = '接口库下没有目录,请先维护目录';
$lang->api->post = 'POST方式调试请参照页面表单';
$lang->api->noUniqueName = '接口库名已存在。';
$lang->api->noUniqueVersion = '版本已存在。';
$lang->api->version = '版本';
$lang->api->createLib = '创建接口库';
$lang->api->createStruct = '创建数据结构';
$lang->api->editStruct = '修改数据结构';
+100 -3
View File
@@ -28,6 +28,59 @@ class apiModel extends model
/* Params. */
const PARAMS_TYPE_CUSTOM = 'custom';
/**
* @param object $data
* @access public
* @return int
*/
public function publishLib($data)
{
/* Get lib modules list. */
$modules = $this->dao->select('*')->from(TABLE_MODULE)
->where('root')->eq((int)$data->lib)
->andWhere('type')->eq('api')
->andWhere('deleted')->eq(0)
->orderBy('grade desc, `order`')
->fetchAll();
/* Get all api list. */
$apis = $this->dao->select('id,version')->from(TABLE_API)
->where('lib')->eq($data->lib)
->andWhere('deleted')->eq(0)
->fetchAll();
/* Get all struct list. */
$structs = $this->dao->select('id,version')->from(TABLE_APISTRUCT)
->where('lib')->eq($data->lib)
->andWhere('deleted')->eq(0)
->fetchAll();
$snap = array('modules' => $modules, 'apis' => $apis, 'structs' => $structs);
$data->snap = json_encode($snap);
$this->dao->insert(TABLE_API_LIB_RELEASE)->data($data)
->autoCheck()
->batchCheck($this->config->api->publish->requiredFields, 'notempty')
->exec();
return dao::isError() ? false : $this->dao->lastInsertID();
}
/**
* Delete a lib publish.
*
* @param int $id
* @access public
* @return void
*/
public function deletePublish($id)
{
$this->dao->update(TABLE_API_LIB_RELEASE)
->set('deleted')->eq(1)
->where('id')->eq($id)
->exec();
}
/**
* Create an api doc.
*
@@ -54,11 +107,24 @@ class apiModel extends model
*/
public function createStruct($data)
{
$data->version = 1;
$this->dao->insert(TABLE_APISTRUCT)->data($data)
->autoCheck()
->batchCheck($this->config->api->struct->requiredFields, 'notempty')
->exec();
/* Create a struct version. */
$version = array(
'name' => $data->name,
'type' => $data->type,
'desc' => $data->desc,
'version' => $data->version,
'attribute' => $data->attribute,
'addedBy' => $data->addedBy,
'addedDate' => $data->addedDate
);
$this->dao->insert(TABLE_APISTRUCT_SPEC)->data($version)->exec();
return dao::isError() ? 0 : $this->dao->lastInsertID();
}
@@ -77,6 +143,8 @@ class apiModel extends model
unset($data->addedBy);
unset($data->addedDate);
$data->version = $old->version + 1;
$this->dao->update(TABLE_APISTRUCT)
->data($data)->autoCheck()
->batchCheck($this->config->api->struct->requiredFields, 'notempty')
@@ -85,6 +153,18 @@ class apiModel extends model
if(dao::isError()) return false;
/* Create a struct version */
$version = array(
'name' => $data->name,
'type' => $data->type,
'desc' => $data->desc,
'version' => $data->version,
'attribute' => $data->attribute,
'addedBy' => $data->editedBy,
'addedDate' => $data->editedDate
);
$this->dao->insert(TABLE_APISTRUCT_SPEC)->data($version)->exec();
return common::createChanges($old, $data);
}
@@ -170,6 +250,23 @@ class apiModel extends model
return $model;
}
/**
* Get release by version.
*
* @param $version
* @access public
* @return object
*/
public function getReleaseByVersion($version)
{
$model = $this->dao->select('*')
->from(TABLE_API_LIB_RELEASE)
->where('version')->eq($version)
->fetch();
if($model) $model->snap = json_decode(htmlspecialchars_decode($model->snap), true);
return $model;
}
/**
* Get api doc by id.
@@ -249,7 +346,7 @@ class apiModel extends model
public static function getApiStatusText($status)
{
global $lang;
switch($status)
switch ($status)
{
case static::STATUS_DOING:
{
@@ -432,12 +529,12 @@ class apiModel extends model
}
else
{
while($row = $stmt->fetch()) $rows[$row->$keyField] = $row;
while ($row = $stmt->fetch()) $rows[$row->$keyField] = $row;
}
$result['status'] = 'success';
$result['data'] = $rows;
} catch(PDOException $e)
} catch (PDOException $e)
{
$result['status'] = 'fail';
$result['message'] = $e->getMessage();
+140 -128
View File
@@ -17,10 +17,10 @@
<ul class='dropdown-menu api-version-menu'
style='max-height:240px; max-width: 300px; overflow-y:auto'>
<?php for($version = $api->version; $version > 0; $version--):?>
<li>
<a href='javascript:void(0)'
data-url='<?php echo $this->createLink('api', 'index', "libID=0&moduleID=0&apiID=$apiID&version=$version");?>'>#<?php echo $version;?></a>
</li>
<li>
<a href='javascript:void(0)'
data-url='<?php echo $this->createLink('api', 'index', "libID=0&moduleID=0&apiID=$apiID&version=$version");?>'>#<?php echo $version;?></a>
</li>
<?php endfor;?>
</ul>
</div>
@@ -35,7 +35,7 @@
$deleteURL = $this->createLink('api', 'delete', "apiID=$api->id&confirm=yes");
echo html::a("javascript:ajaxDeleteApi(\"$deleteURL\", confirmDelete)", '<i class="icon-trash"></i>', '', "title='{$lang->api->delete}' class='btn btn-link'");
}
;?>
;?>
</div>
</div>
</div>
@@ -43,121 +43,133 @@
<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 $param['required'] ? '是' : '否';?></td>
<td><?php echo $param['desc'];?></td>
<tr>
<?php endforeach;
;?>
</tbody>
</table>
<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 $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 $param['required'] ? '是' : '否';?></td>
<td><?php echo $param['desc'];?></td>
<tr>
<?php endforeach;
;?>
</tbody>
</table>
<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 $param['required'] ? '是' : '否';?></td>
<td><?php echo $param['desc'];?></td>
<tr>
<?php endforeach;
;?>
</tbody>
</table>
<?php endif;?>
<?php
function parseTree($data) {
$str = '<tr>';
$str .= '<td>'. $data['field'] .'</td>';
$str .= '<td>'. $data['paramsType'] .'</td>';
function parseTree($data, $level = 0)
{
$str = '<tr>';
$field = '';
for($i=0; $i < $level; $i++)
{
$field .= '&nbsp;&nbsp;&nbsp;';
}
$field .= $data['field'];
$str .= '<td>' . $field . '</td>';
$str .= '<td>' . $data['paramsType'] . '</td>';
$require = $data['required'] ? '是' : '否';
$str .= '<td>'. $require .'</td>';
$str .= '<td>'. $data['desc'] .'</td>';
$str .= '</tr>';
if(isset($data['children']) && count($data['children']) > 0) {
foreach($data['children'] as $item) {
$str .= parseTree($item);
$str .= '<td>' . $require . '</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, $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><?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['params'] as $item) {
echo parseTree($item);
}
?>
</tbody>
</table>
<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><?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['params'] as $item)
{
echo parseTree($item);
}
?>
</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>
<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">
<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->response as $item) {
echo parseTree($item);
}
?>
</tbody>
</table>
<h3 class="title"><?php echo $lang->api->response;?></h3>
<table class="table">
<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->response as $item)
{
echo parseTree($item);
}
?>
</tbody>
</table>
<?php endif;?>
<?php if($api->responseExample):?>
<h3><?php echo $lang->api->responseExample;?></h3>
<pre><code><?php echo $api->responseExample;?></code></pre>
<h3><?php echo $lang->api->responseExample;?></h3>
<pre><code><?php echo $api->responseExample;?></code></pre>
<?php endif;?>
</div>
</div>
@@ -166,7 +178,7 @@
<?php
$canBeChanged = common::canBeChanged('api', $api);
if($canBeChanged) $actionFormLink = $this->createLink('action', 'comment', "objectType=doc&objectID=$api->id");
;?>
;?>
<?php include '../../common/view/action.html.php';?>
</div>
</div>
@@ -180,30 +192,30 @@
<div class="detail-content">
<table class="table table-data">
<tbody>
<tr>
<th class='c-lib'><?php echo $lang->api->lib;?></th>
<td><?php echo $api->libName;?></td>
</tr>
<tr>
<th><?php echo $lang->doc->module;?></th>
<td><?php echo $api->moduleName ? $api->moduleName : '/';?></td>
</tr>
<tr>
<th><?php echo $lang->doc->addedDate;?></th>
<td><?php echo $api->addedDate;?></td>
</tr>
<tr>
<th><?php echo $lang->api->owner;?></th>
<td><?php echo zget($users, $api->owner, '');?></td>
</tr>
<tr>
<th><?php echo $lang->doc->editedBy;?></th>
<td><?php echo zget($users, $api->editedBy, '');?></td>
</tr>
<tr>
<th><?php echo $lang->doc->editedDate;?></th>
<td><?php echo $api->editedDate;?></td>
</tr>
<tr>
<th class='c-lib'><?php echo $lang->api->lib;?></th>
<td><?php echo $api->libName;?></td>
</tr>
<tr>
<th><?php echo $lang->doc->module;?></th>
<td><?php echo $api->moduleName ? $api->moduleName : '/';?></td>
</tr>
<tr>
<th><?php echo $lang->doc->addedDate;?></th>
<td><?php echo $api->addedDate;?></td>
</tr>
<tr>
<th><?php echo $lang->api->owner;?></th>
<td><?php echo zget($users, $api->owner, '');?></td>
</tr>
<tr>
<th><?php echo $lang->doc->editedBy;?></th>
<td><?php echo zget($users, $api->editedBy, '');?></td>
</tr>
<tr>
<th><?php echo $lang->doc->editedDate;?></th>
<td><?php echo $api->editedDate;?></td>
</tr>
</tbody>
</table>
</div>
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* The createlib view of doc module of ZenTaoPMS.
*
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Jia Fu <fujia@cnezsoft.com>
* @package doc
* @version $Id: createlib.html.php 975 2010-07-29 03:30:25Z jajacn@126.com $
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.lite.html.php';?>
<?php include '../../common/view/chosen.html.php';?>
<?php include '../../common/view/kindeditor.html.php';?>
<div id="main">
<div class="container">
<div id='mainContent' class='main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $lang->api->publish;?></h2>
</div>
<form class='load-indicator main-form' id="apiForm" method='post' enctype='multipart/form-data'>
<table class='table table-form'>
<tr>
<th><?php echo $lang->api->version?></th>
<td style="width: 80%"><?php echo html::input('version', '', "class='form-control'")?></td>
</tr>
<tr>
<th><?php echo $lang->api->desc;?></th>
<td colspan='2'>
<?php echo html::textarea('desc', '', "rows='8' class='form-control kindeditor' hidefocus='true' tabindex=''");?>
</td>
</tr>
<tr>
<td class='text-center form-actions' colspan='2'><?php echo html::submitButton();?></td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
<?php include '../../common/view/footer.lite.html.php';?>