diff --git a/module/api/control.php b/module/api/control.php index 30c2127800..91920c7e3e 100755 --- a/module/api/control.php +++ b/module/api/control.php @@ -106,7 +106,7 @@ class api extends control /* Get an api doc. */ if($apiID > 0) { - echo $this->fetch('api', 'view', "libID=$libID&apiID=$apiID&moduleID=$moduleID&release=$release&version=$version"); + echo $this->fetch('api', 'view', "libID=$libID&apiID=$apiID&moduleID=$moduleID&version=$version&release=$release"); return; } else @@ -147,6 +147,7 @@ class api extends control $this->view->libTree = $this->doc->getLibTree($libID, $libs, 'api', $moduleID, $objectID, $browseType, $param); $this->view->users = $this->user->getPairs('noclosed,noletter'); $this->view->objectDropdown = isset($libs[$libID]) ? $this->generateLibsDropMenu($libs[$libID], $release) : ''; + $this->view->spaceType = 'api'; $this->display(); } @@ -226,6 +227,8 @@ class api extends control $this->view->users = $this->user->getPairs('noclosed,noletter'); $this->view->libTree = $libTree; $this->view->objectDropdown = $objectDropdown; + $this->view->spaceType = 'api'; + $this->display(); } diff --git a/module/api/css/view.ui.css b/module/api/css/view.ui.css new file mode 100644 index 0000000000..ca4c4c10e9 --- /dev/null +++ b/module/api/css/view.ui.css @@ -0,0 +1,6 @@ +.panel-heading { justify-content: space-between; } +.panel-actions { margin-left: auto; } +.panel .path {font-size: 18px; font-weight: 600; margin: 0;} +.panel h2 {font-size: 17px; font-weight: 600; margin: 0;} +.panel h3 {font-size: 17px; margin-top: 20px; margin-bottom: 10px;} +pre { display: block; padding: 9.5px; margin: 0px 0px 10px; font-size: 12px; line-height: 1.38462; color: rgb(49, 60, 82); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; } diff --git a/module/api/ui/index.html.php b/module/api/ui/index.html.php index ea033a71b5..35bf62e589 100644 --- a/module/api/ui/index.html.php +++ b/module/api/ui/index.html.php @@ -72,33 +72,34 @@ $list = array(); foreach($apiList as $api) { $list[] = h::li + ( + setClass('list-group-item'), + div ( - setClass('list-group-item'), - div + setClass("heading {$api->method}"), + a ( - setClass("heading {$api->method}"), - a + set::href(createLink('api', 'index', "libID={$api->lib}&moduleID=0&apiID={$api->id}&version=0")), + span ( - set::href(createLink('api', 'index', "libID={$api->lib}&moduleID=0&apiID={$api->id}&version=0")), - span - ( - setClass('method'), - $api->method - ), - span - ( - setClass('path'), - $api->path - ), - span - ( - setClass('desc'), - $api->title - ), - ) + setClass('method'), + $api->method + ), + span + ( + setClass('path'), + $api->path + ), + span + ( + setClass('desc'), + $api->title + ), ) - ); + ) + ); } + $delimiter = strpos($app->clientLang, 'zh') === 0 ? ':' : ': '; panel ( diff --git a/module/api/ui/view.html.php b/module/api/ui/view.html.php new file mode 100644 index 0000000000..ef032134e8 --- /dev/null +++ b/module/api/ui/view.html.php @@ -0,0 +1,265 @@ + + * @package api + * @link https://www.zentao.net + */ +namespace zin; + +featureBar +( + li(backBtn(setClass('ghost'), set::icon('back'), $lang->goback)), +); + +toolbar +( + $libID && common::hasPriv('api', 'struct') ? item(set(array + ( + 'icon' => 'treemap', + 'class' => 'ghost', + 'text' => $lang->api->struct, + 'url' => createLink('api', 'struct', "libID={$libID}"), + ))) : null, + $libID && common::hasPriv('api', 'releases') ? item(set(array + ( + 'icon' => 'version', + 'class' => 'ghost', + 'text' => $lang->api->releases, + 'url' => createLink('api', 'releases', "libID={$libID}"), + 'data-toggle' => 'modal' + ))) : null, + $libID && common::hasPriv('api', 'createRelease') ? item(set(array + ( + 'icon' => 'publish', + 'class' => 'ghost', + 'text' => $lang->api->createRelease, + 'url' => createLink('api', 'createRelease', "libID={$libID}"), + 'data-toggle' => 'modal' + ))) : null, + $libID && common::hasPriv('api', 'export') && $config->edition != 'open' ? item(set(array + ( + 'icon' => 'export', + 'class' => 'ghost export', + 'text' => $lang->export, + 'url' => createLink('api', 'export', "libID={$libID}&version={$version}&release={$release}&moduleID={$moduleID}"), + 'data-toggle' => 'modal' + ))) : null, + common::hasPriv('api', 'createLib') ? item(set(array + ( + 'icon' => 'plus', + 'class' => 'btn secondary', + 'text' => $lang->api->createLib, + 'url' => createLink('api', 'createLib', "type=" . ($objectType ? $objectType : 'nolink') . "&objectID=$objectID"), + 'data-toggle' => 'modal' + ))) : null, + $libID && common::hasPriv('api', 'create') ? item(set(array + ( + 'icon' => 'plus', + 'class' => 'btn primary', + 'text' => $lang->api->createApi, + 'url' => createLink('api', 'create', "libID={$libID}&moduleID={$moduleID}"), + ))) : null, +); + +include '../../doc/ui/left.html.php'; + +$versionList = array(); +for($itemVersion = $api->version; $itemVersion > 0; $itemVersion--) +{ + $versionList[] = array('text' => "V$itemVersion", 'url' => createLink('api', 'index', "libID={$libID}&moduleID=$moduleID&apiID={$apiID}&version={$itemVersion}")); +} + +$apiHeader = $apiQuery = $apiParams = $apiResponse = array(); +if($api->params['header']) +{ + $tbody = array(); + foreach($api->params['header'] as $param) + { + $tbody[] = h::tr + ( + h::td($param['field']), + h::td('String'), + h::td(zget($lang->api->boolList, (string)$param['required'])), + h::td($param['desc']), + ); + } + + $apiHeader[] = h3($lang->api->header); + $apiHeader[] = h::table + ( + setClass('table condensed bordered'), + h::tr + ( + h::th($lang->api->req->name), + h::th($lang->api->req->type), + h::th($lang->api->req->required), + h::th($lang->api->req->desc), + ), + $tbody + ); +} + +if($api->params['query']) +{ + $tbody = array(); + foreach($api->params['query'] as $param) + { + $tbody[] = h::tr + ( + h::td($param['field']), + h::td('String'), + h::td(zget($lang->api->boolList, (string)$param['required'])), + h::td($param['desc']), + ); + } + + $apiQuery[] = h3($lang->api->query); + $apiQuery[] = h::table + ( + setClass('table condensed bordered'), + h::tr + ( + h::th($lang->api->req->name), + h::th($lang->api->req->type), + h::th($lang->api->req->required), + h::th($lang->api->req->desc), + ), + $tbody + ); +} + +if($api->params['params']) +{ + $tbody = array(); + foreach($api->params['params'] as $param) + { + $tbody[] = h::tr + ( + h::td($param['field']), + h::td(zget($typeList, (string)$param['paramsType'], '')), + h::td(zget($lang->api->boolList, (string)$param['required'])), + h::td($param['desc']), + ); + } + + $apiParams[] = h3($lang->api->params); + $apiParams[] = h::table + ( + setClass('table condensed bordered'), + h::tr + ( + h::th($lang->api->req->name), + h::th($lang->api->req->type), + h::th($lang->api->req->required), + h::th($lang->api->req->desc), + ), + $tbody + ); +} + +if($api->response) +{ + $tbody = array(); + foreach($api->response as $response) + { + $tbody[] = h::tr + ( + h::td($response['field']), + h::td(zget($typeList, (string)$response['paramsType'], '')), + h::td(zget($lang->api->boolList, (string)$response['required'])), + h::td($response['desc']), + ); + } + + $apiResponse[] = h3($lang->api->response); + $apiResponse[] = h::table + ( + setClass('table condensed bordered'), + h::tr + ( + h::th($lang->api->req->name), + h::th($lang->api->req->type), + h::th($lang->api->req->required), + h::th($lang->api->req->desc), + ), + $tbody + ); +} + +panel +( + div + ( + setClass('panel-heading'), + div + ( + setClass('http-method label'), + $api->method + ), + div + ( + setClass('path'), + $api->path + ), + dropdown + ( + btn + ( + setClass('ghost btn square btn-default'), + 'V' . ($version ? $version : $api->version) + ), + set::items($versionList) + ), + div + ( + setClass('panel-actions'), + div + ( + setClass('toolbar'), + btn + ( + set::url('javascript:fullScreen()'), + setClass('btn ghost'), + icon('fullscreen'), + ), + (!$isRelease && common::hasPriv('api', 'edit')) ? btn + ( + set::url(createLink('api', 'edit', "apiID=$api->id")), + setClass('btn ghost'), + icon('edit'), + ) : null, + (!$isRelease && common::hasPriv('api', 'delete')) ? btn + ( + set::url(createLink('api', 'delete', "apiID=$api->id")), + setClass('btn ghost'), + icon('trash'), + ) : null, + btn + ( + set::id('hisTrigger'), + set::url('###)'), + setClass('btn ghost'), + icon('clock'), + ), + ) + ) + ), + div + ( + set::Class('panel-body'), + h2($api->title), + div(setClass('desc'), $api->desc), + $apiHeader, + $apiQuery, + $apiParams, + $api->paramsExample ? h3($lang->api->paramsExample) : null, + $api->paramsExample ? html("
" . $api->paramsExample . "
") : null, + $apiResponse, + $api->responseExample ? h3($lang->api->responseExample) : null, + $api->responseExample ? html("
" . $api->responseExample . "
") : null, + ) +);