* Adjust for type of doc library.

This commit is contained in:
chenfeiCF
2018-10-17 11:20:49 +08:00
parent d0981de17d
commit 24a5fb6f35
4 changed files with 59 additions and 167 deletions
+13 -14
View File
@@ -85,14 +85,10 @@ class doc extends control
$projectID = 0;
if($libID)
{
$type = 'custom';
$lib = $this->doc->getLibByID($libID);
if($lib->product or $lib->project)
{
$type = $lib->product ? 'product' : 'project';
$productID = $lib->product;
$projectID = $lib->project;
}
$lib = $this->doc->getLibByID($libID);
$type = $lib->type;
$productID = $lib->product;
$projectID = $lib->project;
}
$this->libs = $this->doc->getLibs($type);
@@ -317,7 +313,7 @@ class doc extends control
}
$lib = $this->doc->getLibByID($libID);
$type = $lib->product ? 'product' : ($lib->project ? 'project' : 'custom');
$type = $lib->type;
/* According the from, set menus. */
if($this->from == 'product')
@@ -393,8 +389,8 @@ class doc extends control
if($doc->contentType == 'markdown') $this->config->doc->markdown->edit = array('id' => 'content', 'tools' => 'toolbar');
$lib = $this->doc->getLibByID($libID);
$type = $lib->product ? 'product' : ($lib->project ? 'project' : 'custom');
$lib = $this->doc->getLibByID($libID);
$type = $lib->type;
$this->doc->setMenu($type, $libID, $doc->module, $lib->product, $lib->project);
$this->view->title = $lib->name . $this->lang->colon . $this->lang->doc->edit;
@@ -431,7 +427,7 @@ class doc extends control
/* Check priv when lib is product or project. */
$lib = $this->doc->getLibByID($doc->lib);
$type = $lib->product ? 'product' : ($lib->project ? 'project' : 'custom');
$type = $lib->type;
/* Set menu. */
$this->doc->setMenu($type, $doc->lib, $doc->module, $lib->product, $lib->project);
@@ -626,7 +622,7 @@ class doc extends control
{
setcookie('product', $product, $this->config->cookieLife, $this->config->webRoot);
$libName = isset($this->lang->doc->systemLibs[$type]) ? $this->lang->doc->systemLibs[$type] : $this->lang->doc->customAB;
$libName = $this->lang->doc->libTypeList[$type];
$crumb = html::a(inlink('allLibs', "type=$type&product=$product"), $libName);
if($product and $type == 'project') $crumb = $this->doc->getProductCrumb($product);
@@ -646,7 +642,10 @@ class doc extends control
$subLibs = $this->doc->getSubLibGroups($type, array_keys($libs));
if($this->cookie->browseType == 'bylist') $this->view->users = $this->loadModel('user')->getPairs('noletter');
}
if($type == 'custom') $this->view->itemCounts = $this->doc->statLibCounts(array_keys($libs));
else
{
$this->view->itemCounts = $this->doc->statLibCounts(array_keys($libs));
}
$this->view->type = $type;
$this->view->libs = $libs;
+4
View File
@@ -100,6 +100,10 @@ $lang->doc->libTypeList['product'] = $lang->productCommon . '文档库';
$lang->doc->libTypeList['project'] = $lang->projectCommon . '文档库';
$lang->doc->libTypeList['custom'] = '自定义文档库';
$lang->doc->libIconList['product'] = 'icon-cube';
$lang->doc->libIconList['project'] = 'icon-stack';
$lang->doc->libIconList['custom'] = 'icon-folder-o';
$lang->doc->systemLibs['product'] = $lang->productCommon;
$lang->doc->systemLibs['project'] = $lang->projectCommon;
+34 -143
View File
@@ -43,13 +43,10 @@ class docModel extends model
die(js::locate('back'));
}
$type = $lib->product ? 'product' : 'custom';
$type = $lib->project ? 'project' : $type;
$type = $lib->type;
}
$mainLib = $type == 'custom' ? $this->lang->doc->customAB : $mainLib;
$mainLib = $type == 'product' ? $this->lang->productCommon : $mainLib;
$mainLib = $type == 'project' ? $this->lang->projectCommon : $mainLib;
$mainLib = isset($this->lang->doc->libTypeList[$type]) ? $this->lang->doc->libTypeList[$type] : $mainLib;
$selectHtml .= "<div class='btn-group angle-btn'>";
$selectHtml .= "<div class='btn-group'>";
@@ -61,17 +58,19 @@ class docModel extends model
$selectHtml .= '<li>' . html::a($link, "<i class='icon {$this->lang->doc->fastMenuIconList[$key]}'></i> {$fastMenu}") . '</li>';
}
$selectHtml .= "<li class='divider'></li>";
$selectHtml .= '<li>' . html::a(helper::createLink('doc', 'allLibs', "type=product"), "<i class='icon icon-cube'></i> {$this->lang->productCommon}") . '</li>';
$selectHtml .= '<li>' . html::a(helper::createLink('doc', 'allLibs', "type=project"), "<i class='icon icon-stack'></i> {$this->lang->projectCommon}") . '</li>';
$selectHtml .= '<li>' . html::a(helper::createLink('doc', 'allLibs', "type=custom"), "<i class='icon icon-folder-o'></i> {$this->lang->doc->customAB}") . '</li>';
foreach($this->lang->doc->libTypeList as $libType => $libName)
{
$selectHtml .= '<li>' . html::a(helper::createLink('doc', 'allLibs', "type=$libType"), "<i class='icon {$this->lang->doc->libIconList[$libType]}'></i> {$this->lang->doc->libTypeList[$libType]}") . '</li>';
}
$selectHtml .='</ul></div></div>';
$currentLib = 0;
if(strpos('product,project,custom', $type) !== false)
{
if($type == 'custom') $currentLib = $libID;
if($type == 'product') $currentLib = $productID;
if($type == 'project') $currentLib = $projectID;
if($type != 'product' and $type != 'project') $currentLib = $libID;
if($currentLib)
{
$allLibGroups = $this->getAllLibGroups();
@@ -82,93 +81,31 @@ class docModel extends model
$selectHtml .= "<div class='btn-group'>";
$selectHtml .= "<a data-toggle='dropdown' class='btn btn-limit' title=$currentLibName>" . $currentLibName . ' <span class="caret"></span></a>';
$selectHtml .='<ul class="dropdown-menu">';
if($type == 'custom')
{
foreach($currentGroups as $groupID => $groupName)
{
if($type == 'custom')
{
$link = helper::createLink('doc', 'browse', "libID=$groupID");
$icon = 'icon-folder-o';
}
elseif($type == 'product')
{
$link = helper::createLink('doc', 'objectLibs', "type=product&objectID=$groupID");
$icon = 'icon-cube';
}
else
{
$link = helper::createLink('doc', 'objectLibs', "type=project&objectID=$groupID");
$icon = 'icon-stack';
}
$active = $currentLib == $groupID ? "class='active'" : '';
$selectHtml .= "<li $active>" . html::a(helper::createLink('doc', 'browse', "libID=$groupID"), "<i class='icon icon-folder-o'></i> {$groupName}") . '</li>';
}
}
else
if($type == 'product' or $type == 'project')
{
foreach($currentGroups as $groupID => $libGroups)
{
$link = helper::createLink('doc', 'objectLibs', "type=$type&objectID=$groupID");
$icon = $type == 'product' ? 'icon-cube' : 'icon-stack';
$icon = $this->lang->doc->libIconList[$type];
$active = $currentLib == $groupID ? "class='active'" : '';
$selectHtml .= "<li $active>" . html::a($link, "<i class='icon {$icon}'></i> {$libGroups['name']}") . '</li>';
}
}
else
{
foreach($currentGroups as $groupID => $groupName)
{
$active = $currentLib == $groupID ? "class='active'" : '';
$selectHtml .= "<li $active>" . html::a(helper::createLink('doc', 'browse', "libID=$groupID"), "<i class='icon {$this->lang->doc->libIconList[$type]}'></i> {$groupName}") . '</li>';
}
}
$selectHtml .= '</ul></div></div>';
}
}
$actions = '';
$customMenuKey = $this->config->global->flow . '_doc';
if(isset($this->config->customMenu->{$customMenuKey}))
{
$customMenu = json_decode($this->config->customMenu->{$customMenuKey}, true);
$menuLibIdList = array();
foreach($customMenu as $i => $menu)
{
if(strpos($menu['name'], 'custom') === 0)
{
$menuLibID = (int)substr($menu['name'], 6);
if($menuLibID) $menuLibIdList[$i] = $menuLibID;
}
}
$productIdList = array();
$projectIdList = array();
if($menuLibIdList)
{
$libs = $this->dao->select('id,name,product,project')->from(TABLE_DOCLIB)->where('id')->in($menuLibIdList)->fetchAll('id');
foreach($libs as $lib)
{
if($lib->product) $productIdList[] = $lib->product;
if($lib->project) $projectIdList[] = $lib->project;
}
}
$products = $productIdList ? $this->dao->select('id,name')->from(TABLE_PRODUCT)->where('id')->in($productIdList)->fetchPairs('id', 'name') : array();
$projects = $projectIdList ? $this->dao->select('id,name')->from(TABLE_PROJECT)->where('id')->in($projectIdList)->fetchPairs('id', 'name') : array();
foreach($menuLibIdList as $i => $menuLibID)
{
$lib = $libs[$menuLibID];
$libName = '';
if($lib->product) $libName = isset($products[$lib->product]) ? '[' . $products[$lib->product] . ']' : '';
if($lib->project) $libName = isset($projects[$lib->project]) ? '[' . $projects[$lib->project] . ']' : '';
$libName .= $lib->name;
$customMenu[$i]['link'] = "{$libName}|doc|browse|libID={$menuLibID}";
}
foreach($customMenu as $menu)
{
if(isset($menu['link']))
{
list($menuLabel, $module, $method, $vars) = explode('|', $menu['link']);
$actions .= html::a(helper::createLink($module, $method, $vars), $menuLabel, '', "class='btn'");
}
}
}
$actions = '';
$actions .= common::hasPriv('doc', 'createLib') ? html::a(helper::createLink('doc', 'createLib', "type={$type}&objectID={$currentLib}"), "<i class='icon icon-folder-plus'></i> " . $this->lang->doc->createLib, '', "class='btn btn-secondary iframe'") : '';
if($libID and common::hasPriv('doc', 'create')) $actions .= html::a(helper::createLink('doc', 'create', "libID=$libID"), "<i class='icon icon-plus'></i> " . $this->lang->doc->create, '', "class='btn btn-primary'");
@@ -215,7 +152,10 @@ class docModel extends model
}
else
{
$stmt = $this->dao->select('*')->from(TABLE_DOCLIB)->where('deleted')->eq(0)->andWhere('product')->eq('0')->andWhere('project')->eq(0)->orderBy('`order`, id desc')->query();
$stmt = $this->dao->select('*')->from(TABLE_DOCLIB)
->where('deleted')->eq(0)
->beginIF($type)->andWhere('type')->eq($type)->fi()
->orderBy('`order`, id desc')->query();
}
$libPairs = array();
@@ -957,7 +897,7 @@ class docModel extends model
}
else
{
$stmt = $stmt->andWhere('project')->eq(0)->andWhere('product')->eq(0);
$stmt = $stmt->andWhere('type')->eq($type);
}
if(isset($projects)) $stmt = $stmt->andWhere('project')->in($projects);
@@ -986,7 +926,7 @@ class docModel extends model
public function getAllLibGroups()
{
$libs = $this->getLibs('all');
$stmt = $this->dao->select("id,product,project,name")->from(TABLE_DOCLIB)
$stmt = $this->dao->select("id,type,product,project,name")->from(TABLE_DOCLIB)
->where('deleted')->eq(0)
->andWhere("id")->in(array_keys($libs))
->orderBy("product desc,project desc, `order` asc, id asc")
@@ -995,21 +935,24 @@ class docModel extends model
$customLibs = array();
$productLibs = array();
$projectLibs = array();
$otherLibs = array();
while($lib = $stmt->fetch())
{
if($lib->product)
if($lib->type == 'product')
{
$productLibs[$lib->product][$lib->id] = $lib->name;
}
elseif($lib->project)
elseif($lib->type == 'project')
{
$projectLibs[$lib->project][$lib->id] = $lib->name;
}
else
{
$customLibs[$lib->id] = $lib->name;
$otherLibs[$lib->type][$lib->id] = $lib->name;
}
}
$productIdList = array_keys($productLibs);
$products = $this->dao->select('id,name,status')->from(TABLE_PRODUCT)->where('id')->in($productIdList)->andWhere('deleted')->eq('0')->orderBy('`order`_desc')->fetchAll();
if($this->config->global->flow == 'onlyStory' or $this->config->global->flow == 'onlyTest')
@@ -1058,7 +1001,7 @@ class docModel extends model
}
}
return array('product' => $productOrderLibs, 'project' => $projectOrderLibs, 'custom' => $customLibs);
return array('product' => $productOrderLibs, 'project' => $projectOrderLibs) + $otherLibs;
}
/**
@@ -1085,7 +1028,7 @@ class docModel extends model
}
else
{
$stmt = $this->dao->select('*')->from(TABLE_DOCLIB)->where('deleted')->eq(0)->andWhere('project')->eq(0)->andWhere('product')->eq(0)->orderBy('`order`, id desc')->query();
$stmt = $this->dao->select('*')->from(TABLE_DOCLIB)->where('deleted')->eq(0)->andWhere('type')->eq($type)->orderBy('`order`, id desc')->query();
}
$i = 1;
@@ -1389,58 +1332,6 @@ class docModel extends model
return $node;
}
/**
* Get crumbs.
*
* @param int $libID
* @param int $moduleID
* @param int $docID
* @access public
* @return string
*/
public function getCrumbs($libID, $moduleID = 0)
{
if(empty($libID)) return '';
$lib = $this->getLibById($libID);
if(!$this->checkPrivLib($lib))
{
echo(js::alert($this->lang->doc->accessDenied));
$loginLink = $this->config->requestType == 'GET' ? "?{$this->config->moduleVar}=user&{$this->config->methodVar}=login" : "user{$this->config->requestFix}login";
if(strpos($this->server->http_referer, $loginLink) !== false) die(js::locate(inlink('index')));
die(js::locate('back'));
}
$type = $lib->product ? 'product' : 'custom';
$type = $lib->project ? 'project' : $type;
$mainLib = $type == 'product' ? $this->lang->productCommon : $this->lang->doc->customAB;
$mainLib = $type == 'project' ? $this->lang->projectCommon : $mainLib;
$crumb = '';
$productID = $this->cookie->product ? $this->cookie->product : '0';
if($productID and $type == 'project' and $this->config->global->flow != 'onlyTask')
{
$crumb .= $this->getProductCrumb($productID, $lib->project);
}
else
{
$crumb .= html::a(helper::createLink('doc', 'allLibs', "type=$type&product=$productID"), $mainLib) . $this->lang->doc->separator;
}
if($lib->product or $lib->project)
{
$table = $lib->product ? TABLE_PRODUCT : TABLE_PROJECT;
$objectID = $lib->product ? $lib->product : $lib->project;
$object = $this->dao->select('id,name')->from($table)->where('id')->eq($objectID)->fetch();
if($object) $crumb .= html::a(helper::createLink('doc', 'objectLibs', "type=$type&objectID=$objectID"), $object->name) . $this->lang->doc->separator;
}
$parents = $moduleID ? $this->loadModel('tree')->getParents($moduleID) : array();
$crumb .= html::a(helper::createLink('doc', 'browse', "libID=$libID&browseType=all&param=0&orderBy=id_desc"), $lib->name);
foreach($parents as $module) $crumb .= $this->lang->doc->separator . html::a(helper::createLink('doc', 'browse', "libID=$libID&browseType=byModule&param=$module->id&orderBy=id_desc"), $module->name);
return $crumb;
}
/**
* Get product crumb.
*
+8 -10
View File
@@ -23,9 +23,7 @@
<div class="panel block-files block-sm no-margin">
<div class="panel-heading">
<div class="panel-title font-normal">
<?php if($type == 'custom') $panelTitle = $lang->doc->custom;?>
<?php if($type == 'product') $panelTitle = $lang->productCommon;?>
<?php if($type == 'project') $panelTitle = $lang->projectCommon;?>
<?php $panelTitle = $lang->doc->libTypeList[$type];?>
<i class="icon icon-folder-open-o text-muted"></i> <?php echo $panelTitle;?>
</div>
<nav class="panel-actions btn-toolbar">
@@ -39,20 +37,20 @@
<div class="row row-grid files-grid" data-size="300">
<?php if($type == 'product') $icon = 'icon-product text-secondary';?>
<?php if($type == 'project') $icon = 'icon-project text-green';?>
<?php if($type == 'custom') $icon = 'icon-folder text-yellow';?>
<?php if($type != 'product' and $type != 'project') $icon = 'icon-folder text-yellow';?>
<?php foreach($libs as $lib):?>
<?php $link = $type != 'custom' ? $this->createLink('doc', 'objectLibs', "type=$type&objectID=$lib->id") : $this->createLink('doc', 'browse', "libID=$lib->id");?>
<?php $link = ($type == 'product' or $type == 'project') ? $this->createLink('doc', 'objectLibs', "type=$type&objectID=$lib->id") : $this->createLink('doc', 'browse', "libID=$lib->id");?>
<div class="col">
<a class="file" href="<?php echo $link;?>">
<i class="file-icon icon <?php echo $icon;?>"></i>
<div class="file-name"><?php echo ($type == 'custom' && strpos($lib->collector, $this->app->user->account) !== false ? "<i class='icon icon-star text-yellow'></i> " : '') . $lib->name;?></div>
<?php if($type == 'custom'):?>
<div class="text-primary file-info"><?php echo $itemCounts[$lib->id] . $lang->doc->item;?></div>
<?php else:?>
<div class="file-name"><?php echo ($type != 'product' && $type != 'project' && strpos($lib->collector, $this->app->user->account) !== false ? "<i class='icon icon-star text-yellow'></i> " : '') . $lib->name;?></div>
<?php if($type == 'product' or $type == 'project'):?>
<div class="text-primary file-info"><?php echo count($subLibs[$lib->id]) . $lang->doc->item;?></div>
<?php else:?>
<div class="text-primary file-info"><?php echo $itemCounts[$lib->id] . $lang->doc->item;?></div>
<?php endif;?>
</a>
<?php if($type == 'custom'):?>
<?php if($type != 'product' and $type != 'project'):?>
<div class="actions">
<?php $star = strpos($lib->collector, ',' . $this->app->user->account . ',') !== false ? 'icon-star text-yellow' : 'icon-star-empty';?>
<?php $collectTitle = strpos($lib->collector, ',' . $this->app->user->account . ',') !== false ? $lang->doc->cancelCollection : $lang->doc->collect;?>