* [story #131255] refactor doc-view for docApp.
This commit is contained in:
+8
-34
@@ -198,43 +198,17 @@ class api extends control
|
||||
*/
|
||||
public function view(int $libID, int $apiID, int $moduleID = 0, int $version = 0, int $release = 0)
|
||||
{
|
||||
if(strpos($this->server->http_referer, 'space') === false && strpos($this->server->http_referer, 'api') === false)
|
||||
if(helper::isAjaxRequest('fetch'))
|
||||
{
|
||||
setCookie("docSpaceParam", '', $this->config->cookieLife, $this->config->webRoot, '', false, true);
|
||||
$api = $this->api->getByID($apiID, $version, $release);
|
||||
|
||||
$this->view->api = $api;
|
||||
$this->view->typeList = $this->api->getTypeList($api->lib);
|
||||
$this->display();
|
||||
return;
|
||||
}
|
||||
|
||||
/* 获取文档目录列表和当前选中的文档目录. */
|
||||
$libs = $this->doc->getApiLibs($libID, $this->objectType, (int)$this->objectID);
|
||||
$api = $this->api->getByID($apiID, $version, $release);
|
||||
$libID = $api->lib;
|
||||
$lib = zget($libs, $libID);
|
||||
$api->desc = htmlspecialchars_decode($api->desc);
|
||||
|
||||
if($libID && !isset($libs[$libID])) return $this->send(array('result' => 'fail', 'load' => array('alert' => $this->lang->doc->accessDenied, 'locate' => $this->createLink('api', 'index'))));
|
||||
|
||||
/* 生成一些必要的参数。 */
|
||||
$type = $lib->product ? 'product' : ($lib->project ? 'project' : 'nolink');
|
||||
$objectID = $lib->product ? $lib->product : $lib->project;
|
||||
$linkObject = zget($lib, $type, 0);
|
||||
$spaceType = 'api';
|
||||
$moduleID = $api->module;
|
||||
$linkParams = "%s";
|
||||
if($this->app->tab != 'doc' && $type != 'nolink') $linkParams = "objectID=$linkObject&$linkParams";
|
||||
|
||||
/* 解析cookie并获取左侧目录树。 */
|
||||
$this->apiZen->parseDocSpaceParam($libs, $libID, $type, $objectID, $moduleID, $spaceType, $release);
|
||||
|
||||
$this->view->title = $this->lang->api->pageTitle;
|
||||
$this->view->isRelease = $release > 0;
|
||||
$this->view->release = $release;
|
||||
$this->view->version = $version;
|
||||
$this->view->apiID = $apiID;
|
||||
$this->view->api = $api;
|
||||
$this->view->linkParams = $linkParams;
|
||||
$this->view->typeList = $this->api->getTypeList($api->lib);
|
||||
$this->view->users = $this->user->getPairs('noclosed,noletter');
|
||||
$this->view->actions = $apiID ? $this->action->getList('api', $apiID) : array();
|
||||
$this->display();
|
||||
echo $this->fetch('api', 'index', "libID=$libID&moduleID=$moduleID&apiID=$apiID&version=$version&release=$release");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
.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; }
|
||||
|
||||
.scrollbar-hover { overflow-y: scroll; }
|
||||
#mainContent .panel+.panel {flex: none}
|
||||
#history{position: relative; width: 400px}
|
||||
#history .history-changes {max-width: 400px !important; word-wrap: break-word;}
|
||||
#history > #closeBtn { position: absolute; right: 10px; top: 10px;}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
/**
|
||||
* Display the document in full screen.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
window.fullScreen = function()
|
||||
{
|
||||
var element = document.getElementById('content');
|
||||
var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullscreen;
|
||||
if(requestMethod)
|
||||
{
|
||||
var afterEnterFullscreen = function()
|
||||
{
|
||||
$('#content').addClass('scrollbar-hover');
|
||||
$('#content').css('background', '#fff');
|
||||
$.cookie.set('isFullScreen', 1, {expires:config.cookieLife, path:config.webRoot});
|
||||
};
|
||||
|
||||
var whenFailEnterFullscreen = function(error)
|
||||
{
|
||||
$.cookie.set('isFullScreen', 0, {expires:config.cookieLife, path:config.webRoot});
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var result = requestMethod.call(element);
|
||||
if(result && (typeof result.then === 'function' || result instanceof window.Promise))
|
||||
{
|
||||
result.then(afterEnterFullscreen).catch(whenFailEnterFullscreen);
|
||||
}
|
||||
else
|
||||
{
|
||||
afterEnterFullscreen();
|
||||
}
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
whenFailEnterFullscreen(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit full screen.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function exitFullScreen()
|
||||
{
|
||||
$('#content').removeClass('scrollbar-hover');
|
||||
$.cookie.set('isFullScreen', 0, {expires:config.cookieLife, path:config.webRoot});
|
||||
}
|
||||
|
||||
document.addEventListener('fullscreenchange', function (e)
|
||||
{
|
||||
if(!document.fullscreenElement) exitFullScreen();
|
||||
});
|
||||
|
||||
document.addEventListener('webkitfullscreenchange', function (e)
|
||||
{
|
||||
if(!document.webkitFullscreenElement) exitFullScreen();
|
||||
});
|
||||
|
||||
document.addEventListener('mozfullscreenchange', function (e)
|
||||
{
|
||||
if(!document.mozFullScreenElement) exitFullScreen();
|
||||
});
|
||||
|
||||
document.addEventListener('msfullscreenChange', function (e)
|
||||
{
|
||||
if(!document.msfullscreenElement) exitFullScreen();
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
if($.cookie.get('isFullScreen') == 1) fullScreen();
|
||||
|
||||
/* Update doc content silently on switch doc version, story #40503 */
|
||||
$('.panel').on('click', '#closeBtn', function()
|
||||
{
|
||||
$('#history').addClass('hidden');
|
||||
$('#hisTrigger').removeClass('text-primary');
|
||||
});
|
||||
|
||||
$('#history').append('<a id="closeBtn" href="###" class="btn btn-link"><i class="icon icon-close"></i></a>');
|
||||
});
|
||||
|
||||
window.showHistory = function()
|
||||
{
|
||||
var $history = $('#history');
|
||||
var $icon = $('#hisTrigger');
|
||||
if($history.hasClass('hidden'))
|
||||
{
|
||||
$history.removeClass('hidden');
|
||||
$icon.addClass('text-primary');
|
||||
}
|
||||
else
|
||||
{
|
||||
$history.addClass('hidden');
|
||||
$icon.removeClass('text-primary');
|
||||
}
|
||||
}
|
||||
|
||||
+16
-160
@@ -10,18 +10,6 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace zin;
|
||||
|
||||
include '../../doc/ui/lefttree.html.php';
|
||||
|
||||
$versionList = array();
|
||||
for($itemVersion = $api->version; $itemVersion > 0; $itemVersion--)
|
||||
{
|
||||
$link = createLink('api', 'index', "libID={$libID}&moduleID=$moduleID&apiID={$apiID}&version={$itemVersion}");
|
||||
$versionList[] = array(
|
||||
'text' => "V$itemVersion",
|
||||
'onClick' => jsRaw("() => {loadPage('$link', '#docContent')}")
|
||||
);
|
||||
}
|
||||
|
||||
$apiHeader = $apiQuery = $apiParams = $apiResponse = array();
|
||||
$parseTree = function($data, $typeList, $level = 0) use(&$parseTree)
|
||||
{
|
||||
@@ -146,157 +134,25 @@ if($api->response)
|
||||
);
|
||||
}
|
||||
|
||||
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-size' => 'sm',
|
||||
'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 ml-2',
|
||||
'text' => $lang->api->createApi,
|
||||
'url' => createLink('api', 'create', "libID={$libID}&moduleID={$moduleID}"),
|
||||
'data-size' => 'lg',
|
||||
'data-toggle' => $spaceType != 'api' ? 'modal' : ''
|
||||
))) : null
|
||||
);
|
||||
|
||||
div
|
||||
(
|
||||
setID('docContent'),
|
||||
setClass('flex flex-wrap content-start'),
|
||||
setID('api-content'),
|
||||
setClass('article'),
|
||||
div
|
||||
(
|
||||
setClass('doc-content flex-initial w-full flex'),
|
||||
panel
|
||||
(
|
||||
setClass('flex-auto'),
|
||||
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 ajax-submit'),
|
||||
setData(array('confirm' => $lang->api->confirmDelete)),
|
||||
icon('trash')
|
||||
) : null,
|
||||
btn
|
||||
(
|
||||
setID('hisTrigger'),
|
||||
setClass('btn ghost'),
|
||||
icon('clock'),
|
||||
set('data-on', 'click'),
|
||||
set('data-call', 'showHistory')
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
div
|
||||
(
|
||||
setClass('panel-body'),
|
||||
setID('content'),
|
||||
h2($api->title),
|
||||
div(setClass('desc'), html($api->desc)),
|
||||
$apiHeader,
|
||||
$apiQuery,
|
||||
$apiParams,
|
||||
$api->paramsExample ? h3($lang->api->paramsExample) : null,
|
||||
$api->paramsExample ? html("<pre><code>" . $api->paramsExample . "</code></pre>") : null,
|
||||
$apiResponse,
|
||||
$api->responseExample ? h3($lang->api->responseExample) : null,
|
||||
$api->responseExample ? html("<pre><code>" . $api->responseExample . "</code></pre>") : null
|
||||
)
|
||||
),
|
||||
panel
|
||||
(
|
||||
setID('history'),
|
||||
setClass('hidden'),
|
||||
history
|
||||
(
|
||||
set::objectID($api->id),
|
||||
set::objectType('api')
|
||||
)
|
||||
)
|
||||
)
|
||||
setClass("api-list-item row items-center mb-1 gap-2 flex-auto is-$api->method rounded"),
|
||||
div(setClass('font-mono w-14 text-center api-method py-1 rounded rounded-r-none'), $api->method),
|
||||
div(setClass('font-mono font-bold text-md api-path'), $api->path)
|
||||
),
|
||||
h2($api->title),
|
||||
div(setClass('desc'), html($api->desc)),
|
||||
$apiHeader,
|
||||
$apiQuery,
|
||||
$apiParams,
|
||||
$api->paramsExample ? h3($lang->api->paramsExample) : null,
|
||||
$api->paramsExample ? html("<pre><code>" . $api->paramsExample . "</code></pre>") : null,
|
||||
$apiResponse,
|
||||
$api->responseExample ? h3($lang->api->responseExample) : null,
|
||||
$api->responseExample ? html("<pre><code>" . $api->responseExample . "</code></pre>") : null
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user