edit api doc

This commit is contained in:
thanatos
2021-09-24 08:48:47 +08:00
parent 02b0ab4dda
commit dbeacce70f
7 changed files with 282 additions and 108 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
ALTER TABLE `zt_doclib` ADD COLUMN `desc` text NULL AFTER `collector`;
ALTER TABLE `zt_doc` ADD COLUMN `baseUrl` varchar(255) NOT NULL DEFAULT '' AFTER `title`;
ALTER TABLE `zt_doclib` ADD COLUMN `baseUrl` varchar(255) NOT NULL DEFAULT '' AFTER `name`;
-- DROP TABLE IF EXISTS `zt_api_lib_release`;
CREATE TABLE `zt_api_lib_release`
+1
View File
@@ -952,6 +952,7 @@ class baseControl
* send success json
*
* @param array $data
* @return void
* @author thanatos thanatos915@163.com
*/
public function sendSuccess($data)
+2
View File
@@ -4,6 +4,8 @@ global $lang;
$config->api = new stdClass();
$config->api->createlib = new stdclass();
$config->api->createlib->requiredFields = 'name';
$config->api->editlib = new stdclass();
$config->api->editlib->requiredFields = 'name';
$config->api->create = new stdclass();
$config->api->create->requiredFields = 'lib,module,title,path,method,protocol';
+50 -9
View File
@@ -116,6 +116,46 @@ class api extends control
$this->display();
}
/**
* Edit an api doc library
*
* @param $id
* @access public
* @return void
*/
public function editLib($id)
{
$doc = $this->doc->getLibById($id);
if(!empty($_POST))
{
$lib = fixer::input('post')
->join('groups', ',')
->join('users', ',')
->get();
if($lib->acl == 'private') $lib->users = $this->app->user->account;
$this->doc->updateApiLib($id, $doc, $lib);
if(dao::isError())
{
$this->sendError(dao::getError());
exit;
}
$res = array(
'message' => $this->lang->saveSuccess,
'closeModal' => true,
'callback' => "redirectParentWindow($id)",
);
return $this->sendSuccess($res);
}
$this->view->doc = $doc;
$this->view->groups = $this->group->getPairs();
$this->view->users = $this->user->getPairs('nocode');
$this->display();
}
/**
* Edit library.
*
@@ -234,8 +274,8 @@ class api extends control
}
/**
* @param $apiID
* @param string $confirm
* @param $apiID
* @param string $confirm
* @author thanatos thanatos915@163.com
*/
public function delete($apiID, $confirm = 'no')
@@ -266,7 +306,7 @@ class api extends control
/**
* Get params type options by scope
*
* @param string $scope the params position
* @param string $scope the params position
* @author thanatos thanatos915@163.com
*/
public function ajaxGetParamsTypeOptions($scope)
@@ -366,6 +406,7 @@ EOT;
/**
* Show doc of api doc library
*
* @author thanatos thanatos915@163.com
*/
public function showLibs($libID = 0)
@@ -395,9 +436,9 @@ EOT;
/**
* Execute a module's model's method, return the result.
*
* @param string $moduleName
* @param string $methodName
* @param string $params param1=value1,param2=value2, don't use & to join them.
* @param string $moduleName
* @param string $methodName
* @param string $params param1=value1,param2=value2, don't use & to join them.
* @access public
* @return string
*/
@@ -428,8 +469,8 @@ EOT;
/**
* The interface of api.
*
* @param int $filePath
* @param int $action
* @param int $filePath
* @param int $action
* @access public
* @return void
*/
@@ -469,7 +510,7 @@ EOT;
/**
* Query sql.
*
* @param string $keyField
* @param string $keyField
* @access public
* @return void
*/
+16 -1
View File
@@ -160,4 +160,19 @@ $(document).ready(function()
$('.split-row').splitRow();
});
});
});
/**
* Redirect the parent window.
*
* @param int hasLibPriv
* @param int libID
* @access public
* @return void
*/
function redirectParentWindow(libID)
{
var link = createLink('api', 'index', 'libID=' + libID);
parent.location.href = link;
}
+85
View File
@@ -0,0 +1,85 @@
<?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->createLib;?></h2>
</div>
<form class='load-indicator main-form form-ajax' id="apiForm" method='post' enctype='multipart/form-data'>
<table class='table table-form'>
<tr>
<th><?php echo $lang->api->name?></th>
<td style="width: 80%"><?php echo html::input('name', $doc->name, "class='form-control'")?></td>
</tr>
<tr>
<th><?php echo $lang->api->baseUrl?></th>
<td style="width: 80%"><?php echo html::input('baseUrl', $doc->baseUrl, "class='form-control'")?></td>
</tr>
<tr>
<th><?php echo $lang->api->control;?></th>
<td>
<span><?php echo html::radio('acl', $lang->acl->aclList, 'open', "onchange='toggleAcl(this.value, \"lib\")'")?></span>
<span class='text-info' id='noticeAcl'><?php echo $lang->noticeAcl['open'];?></span>
</td>
</tr>
<tr id='whiteListBox' class='hidden'>
<th><?php echo $lang->acl->whiteList;?></th>
<td>
<div class='input-group'>
<span class='input-group-addon groups-addon'><?php echo $lang->acl->group?></span>
<?php echo html::select('groups[]', $groups, $doc->groups, "class='form-control chosen' multiple")?>
</div>
<div class='input-group'>
<span class='input-group-addon'><?php echo $lang->acl->user?></span>
<?php echo html::select('users[]', $users, $doc->users, "class='form-control chosen' multiple")?>
</div>
</td>
</tr>
<tr>
<th><?php echo $lang->api->desc;?></th>
<td colspan='2'>
<?php echo html::textarea('desc', $doc->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>
<div class='hidden'>
<table>
<tr id='aclBoxA'>
<th><?php echo $lang->api->control;?></th>
<td>
<?php echo html::radio('acl', $lang->api->aclListA, 'default', "onchange='toggleAcl(this.value, \"lib\")'")?>
</td>
</tr>
<tr id='aclBoxB'>
<th><?php echo $lang->api->control;?></th>
<td>
<?php echo html::radio('acl', $lang->api->aclListB, 'open', "onchange='toggleAcl(this.value, \"lib\")'")?>
</td>
</tr>
</table>
</div>
<?php js::set('noticeAcl', $lang->noticeAcl);?>
<?php include '../../common/view/footer.lite.html.php';?>
+127 -97
View File
@@ -15,13 +15,18 @@
class docModel extends model
{
/**
* @var actionModel
*/
public $action;
// api doc type
const DOC_TYPE_API = 'api';
/**
* Get library by id.
*
* @param int $libID
* @param int $libID
* @access public
* @return object
*/
@@ -52,10 +57,10 @@ class docModel extends model
/**
* Get libraries.
*
* @param string $type
* @param string $extra
* @param string $appendLibs
* @param int $projectID
* @param string $type
* @param string $extra
* @param string $appendLibs
* @param int $projectID
* @access public
* @return array
*/
@@ -181,7 +186,8 @@ class docModel extends model
/**
* creat a api doc library.
* @param stdClass $data form data.
*
* @param stdClass $data form data.
* @return int
* @author thanatos thanatos915@163.com
*/
@@ -198,10 +204,34 @@ class docModel extends model
return $this->dao->lastInsertID();
}
/**
* @param int $id
* @param stdClass $oldDoc
* @param array $data
* @return array|int
*/
public function updateApiLib($id, $oldDoc, $data)
{
$data->type = static::DOC_TYPE_API;
$this->dao->update(TABLE_DOCLIB)->data($data)->autoCheck()
->batchCheck($this->config->api->editlib->requiredFields, 'notempty')
->where('id')->eq($id)
->exec();
$changes = array();
if(!dao::isError()) {
$this->loadModel('action');
$changes = common::createChanges($oldDoc, $data);
$actionID = $this->action->create('docLib', $id, 'Edited');
$this->action->logHistory($actionID, $changes);
}
return $changes;
}
/**
* Update a library.
*
* @param int $libID
* @param int $libID
* @access public
* @return void
*/
@@ -230,11 +260,11 @@ class docModel extends model
/**
* Get docs by browse type.
*
* @param string $browseType
* @param int $queryID
* @param int $moduleID
* @param string $sort
* @param object $pager
* @param string $browseType
* @param int $queryID
* @param int $moduleID
* @param string $sort
* @param object $pager
* @access public
* @return array
*/
@@ -361,7 +391,7 @@ class docModel extends model
/**
* Get projects, executions and products by docIdList.
*
* @param array $docIdList
* @param array $docIdList
* @access public
* @return array
*/
@@ -391,10 +421,10 @@ class docModel extends model
/**
* Get docs.
*
* @param int|string $libID
* @param int $module
* @param string $orderBy
* @param object $pager
* @param int|string $libID
* @param int $module
* @param string $orderBy
* @param object $pager
* @access public
* @return void
*/
@@ -412,9 +442,9 @@ class docModel extends model
/**
* Get priv docs.
*
* @param int $libID
* @param int $module
* @param string $mode normal|all
* @param int $libID
* @param int $module
* @param string $mode normal|all
* @access public
* @return void
*/
@@ -440,9 +470,9 @@ class docModel extends model
/**
* Get doc info by id.
*
* @param int $docID
* @param int $version
* @param bool $setImgSize
* @param int $docID
* @param int $version
* @param bool $setImgSize
* @access public
* @return void
*/
@@ -504,7 +534,7 @@ class docModel extends model
/**
* Get docs info by id list.
*
* @param array $docIdList
* @param array $docIdList
* @access public
* @return array
*/
@@ -609,7 +639,7 @@ class docModel extends model
/**
* Update a doc.
*
* @param int $docID
* @param int $docID
* @access public
* @return void
*/
@@ -713,7 +743,7 @@ class docModel extends model
/**
* Save draft.
*
* @param int $docID
* @param int $docID
* @access public
* @return void
*/
@@ -734,10 +764,10 @@ class docModel extends model
/**
* Build search form.
*
* @param string $libID
* @param array $libs
* @param int $queryID
* @param string $actionURL
* @param string $libID
* @param array $libs
* @param int $queryID
* @param string $actionURL
* @access public
* @return void
*/
@@ -780,8 +810,8 @@ class docModel extends model
/**
* Get doc menu.
*
* @param int $libID
* @param int $parent
* @param int $libID
* @param int $parent
* @access public
* @return array
*/
@@ -815,7 +845,7 @@ class docModel extends model
*
* Like this: <table class="ke-table1" style="width:100%;" cellpadding="2" cellspacing="0" border="1" bordercolor="#000000">
*
* @param string $content
* @param string $content
* @access public
* @return void
*/
@@ -850,8 +880,8 @@ class docModel extends model
/**
* Check priv for lib.
*
* @param object $object
* @param string $extra
* @param object $object
* @param string $extra
* @access public
* @return bool
*/
@@ -895,7 +925,7 @@ class docModel extends model
/**
* Check priv for doc.
*
* @param object $object
* @param object $object
* @access public
* @return bool
*/
@@ -931,9 +961,9 @@ class docModel extends model
/**
* Get all libs by type.
*
* @param string $type
* @param int $pager
* @param string $extra
* @param string $type
* @param int $pager
* @param string $extra
* @access public
* @return array
*/
@@ -989,7 +1019,7 @@ class docModel extends model
/**
* Get all lib groups.
*
* @param string $appendLibs
* @param string $appendLibs
* @access public
* @return array
*/
@@ -1076,8 +1106,8 @@ class docModel extends model
/**
* Get limit libs.
*
* @param string $type
* @param int $limit
* @param string $type
* @param int $limit
* @access public
* @return array
*/
@@ -1146,8 +1176,8 @@ class docModel extends model
/**
* Get execution or product libs groups.
*
* @param string $type
* @param array $idList
* @param string $type
* @param array $idList
* @access public
* @return array
*/
@@ -1173,10 +1203,10 @@ class docModel extends model
/**
* Get libs by object.
*
* @param string $type
* @param int $objectID
* @param string $mode
* @param int $appendLib
* @param string $type
* @param int $objectID
* @param string $mode
* @param int $appendLib
* @access public
* @return array
*/
@@ -1233,7 +1263,7 @@ class docModel extends model
/**
* Get ordered objects for dic.
*
* @param string $objectType
* @param string $objectType
* @access public
* @return array
*/
@@ -1334,7 +1364,7 @@ class docModel extends model
/**
* Stat module and document counts of lib.
*
* @param array $idList
* @param array $idList
* @access public
* @return array
*/
@@ -1375,10 +1405,10 @@ class docModel extends model
/**
* Get lib files.
*
* @param string $type
* @param int $objectID
* @param string $orderBy
* @param object $pager
* @param string $type
* @param int $objectID
* @param string $orderBy
* @param object $pager
* @access public
* @return array
*/
@@ -1490,7 +1520,7 @@ class docModel extends model
/**
* Get file source pairs.
*
* @param array $files
* @param array $files
* @access public
* @return array
*/
@@ -1519,7 +1549,7 @@ class docModel extends model
/**
* Get file icon.
*
* @param array $files
* @param array $files
* @access public
* @return array
*/
@@ -1550,7 +1580,7 @@ class docModel extends model
/**
* Get doc tree.
*
* @param int $libID
* @param int $libID
* @access public
* @return array
*/
@@ -1570,8 +1600,8 @@ class docModel extends model
/**
* Fill docs in tree.
*
* @param object $node
* @param int $libID
* @param object $node
* @param int $libID
* @access public
* @return array
*/
@@ -1631,8 +1661,8 @@ class docModel extends model
/**
* Get product crumb.
*
* @param int $productID
* @param int $executionID
* @param int $productID
* @param int $executionID
* @access public
* @return string
*/
@@ -1662,8 +1692,8 @@ class docModel extends model
/**
* Set lib users.
*
* @param string $type
* @param int $objectID
* @param string $type
* @param int $objectID
* @access public
* @return bool
*/
@@ -1744,8 +1774,8 @@ class docModel extends model
/**
* Get the previous and next doc.
*
* @param int $docID
* @param int $libID
* @param int $docID
* @param int $libID
* @access public
* @return object
*/
@@ -1848,9 +1878,9 @@ class docModel extends model
/**
* Build document module index page create document button.
*
* @param string $objectType
* @param int $objectID
* @param int $libID
* @param string $objectType
* @param int $objectID
* @param int $libID
* @access public
* @return string
*/
@@ -1944,9 +1974,9 @@ class docModel extends model
/**
* Build browse switch button.
*
* @param int $type
* @param int $objectID
* @param int $viewType
* @param int $type
* @param int $objectID
* @param int $viewType
* @access public
* @return void
*/
@@ -1963,7 +1993,7 @@ class docModel extends model
/**
* Set past menu.
*
* @param string $fastLib
* @param string $fastLib
* @access public
* @return string
*/
@@ -1986,7 +2016,7 @@ class docModel extends model
/**
* Get toList and ccList.
*
* @param object $doc
* @param object $doc
* @access public
* @return bool|array
*/
@@ -2017,11 +2047,11 @@ class docModel extends model
/**
* Create the select code of doc.
*
* @param string $type
* @param array $objects
* @param int $objectID
* @param array $libs
* @param int $libID
* @param string $type
* @param array $objects
* @param int $objectID
* @param array $libs
* @param int $libID
* @access public
* @return string
*/
@@ -2146,7 +2176,7 @@ EOT;
$currentMethod = $this->app->getMethodName();
$users = $this->loadModel('user')->getPairs('noletter');
$docs = $this->dao->select('*')->from(TABLE_API)
$docs = $this->dao->select('*')->from(TABLE_API)
->where('lib')->eq($rootID)
->andWhere('deleted')->eq(0)
->fetchAll();
@@ -2196,11 +2226,11 @@ EOT;
/**
* Get doc tree menu.
*
* @param string $type
* @param int $objectID
* @param int $rootID
* @param int $startModule
* @param pointer $docID
* @param string $type
* @param int $objectID
* @param int $rootID
* @param int $startModule
* @param pointer $docID
* @access public
* @return string
*/
@@ -2271,13 +2301,13 @@ EOT;
/**
* Build doc tree menu.
*
* @param pointer $treeMenu
* @param string $type
* @param int $objectID
* @param int $libID
* @param object $module
* @param array $moduleDocs
* @param pointer $docID
* @param pointer $treeMenu
* @param string $type
* @param int $objectID
* @param int $libID
* @param object $module
* @param array $moduleDocs
* @param pointer $docID
* @access private
* @return string
*/
@@ -2339,7 +2369,7 @@ EOT;
if($type == static::DOC_TYPE_API)
{
$params = $_GET;
$params = $_GET;
$moduleID = isset($params['moduleID']) ? $params['moduleID'] : 0;
if($moduleID && $moduleID == $module->id)
{
@@ -2357,7 +2387,7 @@ EOT;
/**
* Count the number and size of files on the current page.
*
* @param arary $files
* @param arary $files
* @access public
* @return string
*/
@@ -2409,10 +2439,10 @@ EOT;
/**
* Set doc menu by type.
*
* @param string $type
* @param int $objectID
* @param int $libID
* @param int $appendLib
* @param string $type
* @param int $objectID
* @param int $libID
* @param int $appendLib
* @access public
* @return array
*/