* code for task #2672.

This commit is contained in:
wangyidong
2016-10-26 14:28:55 +08:00
parent 000addf392
commit 0b4e00d77d
10 changed files with 347 additions and 6 deletions
+16 -3
View File
@@ -75,8 +75,9 @@ class doc extends control
/* Set browseType.*/
$browseType = strtolower($browseType);
if(($this->cookie->browseType == 'bymenu' or $this->cookie->browseType == 'bytree') and $browseType != 'bysearch') $browseType = $this->cookie->browseType;
$queryID = ($browseType == 'bysearch') ? (int)$param : 0;
$moduleID = ($browseType == 'bymodule') ? (int)$param : 0;
$moduleID = ($browseType == 'bymodule' or $browseType == 'bymenu') ? (int)$param : 0;
$type = 'custom';
if($libID)
@@ -121,11 +122,23 @@ class doc extends control
if($item->name == "custom$libID" and empty($item->hidden)) $this->view->fixedMenu = true;
}
if($this->cookie->browseType == 'bymenu')
{
$this->view->modules = $this->doc->getDocMenu($libID, $moduleID);
$this->view->parents = $this->loadModel('tree')->getParents($moduleID);
}
elseif($this->cookie->browseType == 'bytree')
{
$this->view->tree = $this->doc->getDocTree($libID);
}
else
{
$this->view->moduleTree = $this->loadModel('tree')->getTreeMenu($libID, $viewType = 'doc', $startModuleID = 0, array('treeModel', 'createDocLink'));
}
$this->view->libID = $libID;
$this->view->libName = $this->libs[$libID];
$this->view->moduleID = $moduleID;
$this->view->moduleTree = $this->loadModel('tree')->getTreeMenu($libID, $viewType = 'doc', $startModuleID = 0, array('treeModel', 'createDocLink'));
$this->view->parentModules = $this->tree->getParents($moduleID);
$this->view->docs = $docs;
$this->view->pager = $pager;
$this->view->users = $this->loadModel('user')->getPairs('noletter');
+7
View File
@@ -17,8 +17,15 @@ function browseBySearch()
$('#querybox').addClass('show');
}
function setBrowseType(type)
{
$.cookie('browseType', type, {expires:config.cookieLife, path:config.webRoot});
location.href = location.href;
}
$(function(){
$('#' + browseType + 'Tab').addClass('active');
if(fixedMenu) $('#modulemenu .nav li[data-id="custom' + libID + '"]').addClass('active');
if(browseType == "bysearch")
{
ajaxGetSearchForm();
+1
View File
@@ -19,5 +19,6 @@ function toggleAcl(acl)
$(document).ready(function()
{
$('[data-id="create"] a').modalTrigger({type: 'iframe', width: 800});
$('#modulemenu .nav li').removeClass('active');
if(typeof(type) != 'undefined') $('#modulemenu .nav li[data-id="' + type + '"]').addClass('active');
});
+5
View File
@@ -77,6 +77,11 @@ $lang->doc->aclList['private'] = '私有';
$lang->doc->contentTypeList['html'] = 'HTML';
$lang->doc->contentTypeList['markdown'] = 'MarkDown';
$lang->doc->browseType = '浏览方式';
$lang->doc->browseTypeList['list'] = '列表';
$lang->doc->browseTypeList['menu'] = '目录';
$lang->doc->browseTypeList['tree'] = '树状图';
$lang->doc->confirmDelete = "您确定删除该文档吗?";
$lang->doc->confirmDeleteLib = "您确定删除该文档库吗?";
$lang->doc->errorEditSystemDoc = "系统文档库无需修改。";
+105
View File
@@ -170,6 +170,20 @@ class docModel extends model
if($moduleID) $modules = $this->loadModel('tree')->getAllChildId($moduleID);
$docs = $this->getDocs($libID, $modules, $sort, $pager);
}
elseif($browseType == "bymenu")
{
$condition = $this->buildConditionSQL();
$docs = $this->dao->select('*')->from(TABLE_DOC)->where('deleted')->eq(0)->andWhere('lib')->in($libID)
->andWhere('module')->eq($moduleID)
->beginIF($condition)->andWhere("($condition)")->fi()
->orderBy($sort)
->page($pager)
->fetchAll();
}
elseif($browseType == 'bytree')
{
return array();
}
elseif($browseType == "bysearch")
{
if($queryID)
@@ -494,6 +508,22 @@ class docModel extends model
->fetchPairs('id', 'name');
}
/**
* Get doc menu.
*
* @param int $libID
* @param int $parent
* @access public
* @return void
*/
public function getDocMenu($libID, $parent)
{
return $this->dao->select('*')->from(TABLE_MODULE)->where('root')->eq($libID)
->andWhere('type')->eq('doc')
->andWhere('parent')->eq($parent)
->fetchAll('id');
}
/**
* Extract css styles for tables created in kindeditor.
*
@@ -788,4 +818,79 @@ class docModel extends model
}
return $condition;
}
/**
* Get doc tree.
*
* @param int $libID
* @access public
* @return array
*/
public function getDocTree($libID)
{
$fullTrees = $this->loadModel('tree')->getTreeStructure($libID, 'doc');
array_unshift($fullTrees, array('id' => 0, 'name' => '/', 'type' => 'doc', 'actions' => false, 'root' => $libID));
foreach($fullTrees as $i => $tree)
{
$tree = (object)$tree;
$fullTrees[$i] = $this->fillDocsInTree($tree, $libID);
}
if(empty($fullTrees[0]->children)) array_shift($fullTrees);
return $fullTrees;
}
/**
* Fill docs in tree.
*
* @param object $node
* @param int $libID
* @access public
* @return array
*/
public function fillDocsInTree($node, $libID)
{
$node = (object)$node;
static $docGroups;
if(empty($docGroups))
{
$condition = $this->buildConditionSQL();
$docs = $this->dao->select('*')->from(TABLE_DOC)
->where('lib')->eq((int)$libID)
->beginIF($condition)->andWhere("($condition)")->fi()
->andWhere('deleted')->eq(0)
->fetchAll();
$docGroups = array();
foreach($docs as $doc) $docGroups[$doc->module][$doc->id] = $doc;
}
if(!empty($node->children)) foreach($node->children as $i => $child) $node->children[$i] = $this->fillDocsInTree($child, $libID);
if(!isset($node->id))$node->id = 0;
$node->type = 'module';
$docs = isset($docGroups[$node->id]) ? $docGroups[$node->id] : array();
if(!empty($docs))
{
$docItems = array();
foreach($docs as $doc)
{
$docItem = new stdclass();
$docItem->type = 'doc';
$docItem->id = $doc->id;
$docItem->title = $doc->title;
$docItem->url = helper::createLink('doc', 'view', "doc=$doc->id");
$buttons = '';
$buttons .= common::buildIconButton('doc', 'edit', "docID=$doc->id", '', 'list');
if(common::hasPriv('doc', 'delete'))$buttons .= html::a(helper::createLink('doc', 'delete', "docID=$doc->id"), "<i class='icon icon-remove'></i>", 'hiddenwin', "class='btn-icon' title='{$this->lang->doc->delete}'");
$docItem->buttons = $buttons;
$docItem->actions = false;
$docItems[] = $docItem;
}
$node->docsCount = count($docItems);
$node->children = $docItems;
}
$node->actions = false;
return $node;
}
}
+18 -2
View File
@@ -12,11 +12,18 @@
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/datepicker.html.php';?>
<?php js::set('confirmDelete', $lang->doc->confirmDelete)?>
<?php if(!$fixedMenu) js::set('type', $type);?>;
<script language='Javascript'>
var browseType = '<?php echo $browseType;?>';
</script>
<?php js::set('confirmDelete', $lang->doc->confirmDelete)?>
<?php js::set('fixedMenu', $fixedMenu);?>
<?php js::set('libID', $libID);?>
<?php if(!$fixedMenu) js::set('type', $type);?>
<?php if($this->cookie->browseType == 'bymenu'):?>
<?php include __DIR__ . '/browsebymenu.html.php';?>
<?php elseif($this->cookie->browseType == 'bytree'):?>
<?php include __DIR__ . '/browsebytree.html.php';?>
<?php else:?>
<div id='featurebar'>
<ul class='nav'>
<li id='allTab'><?php echo html::a(inlink('browse', "libID=$libID&browseType=all&param=0&orderBy=$orderBy"), $lang->doc->allDoc)?></li>
@@ -25,6 +32,14 @@ var browseType = '<?php echo $browseType;?>';
<li id='bysearchTab'><a href='#'><i class='icon-search icon'></i>&nbsp;<?php echo $lang->doc->searchDoc;?></a></li>
</ul>
<div class='actions'>
<div class="btn-group">
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown"><i class='icon icon-list'></i> <?php echo $lang->doc->browseTypeList['list']?> <span class="caret"></span></button>
<ul class="dropdown-menu" role="menu">
<li><?php echo html::a('javascript:setBrowseType("bylist")', "<i class='icon icon-list'></i> {$lang->doc->browseTypeList['list']}");?></li>
<li><?php echo html::a('javascript:setBrowseType("bymenu")', "<i class='icon icon-th'></i> {$lang->doc->browseTypeList['menu']}");?></li>
<li><?php echo html::a('javascript:setBrowseType("bytree")', "<i class='icon icon-tags'></i> {$lang->doc->browseTypeList['tree']}");?></li>
</ul>
</div>
<?php common::printIcon('doc', 'create', "libID=$libID&moduleID=$moduleID&product=0&prject=0&from=doc");?>
</div>
<div id='querybox' class='<?php if($browseType == 'bysearch') echo 'show';?>'></div>
@@ -87,4 +102,5 @@ var browseType = '<?php echo $browseType;?>';
<tfoot><tr><td colspan='6'><?php $pager->show();?></td></tr></tfoot>
</table>
</div>
<?php endif;?>
<?php include '../../common/view/footer.html.php';?>
+75
View File
@@ -0,0 +1,75 @@
<style>
.menu,.file{text-align:center;}
.menu .menu-name .icon,.file .file-name .icon{display:block;font-size:60px;}
.menu .menu-name .name,.file .file-name .name{display:block; overflow:hidden;height:36px;}
</style>
<div id='featurebar'>
<ul class='nav'>
<li id='bysearchTab'><a href='#'><i class='icon-search icon'></i>&nbsp;<?php echo $lang->doc->searchDoc;?></a></li>
</ul>
<div class='actions'>
<div class="btn-group">
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown"><i class='icon icon-th'></i> <?php echo $lang->doc->browseTypeList['menu']?> <span class="caret"></span></button>
<ul class="dropdown-menu" role="menu">
<li><?php echo html::a('javascript:setBrowseType("bylist")', "<i class='icon icon-list'></i> {$lang->doc->browseTypeList['list']}");?></li>
<li><?php echo html::a('javascript:setBrowseType("bymenu")', "<i class='icon icon-th'></i> {$lang->doc->browseTypeList['menu']}");?></li>
<li><?php echo html::a('javascript:setBrowseType("bytree")', "<i class='icon icon-tags'></i> {$lang->doc->browseTypeList['tree']}");?></li>
</ul>
</div>
<?php common::printIcon('doc', 'create', "libID=$libID&moduleID=$moduleID&product=0&prject=0&from=doc");?>
</div>
<div id='querybox' class='<?php if($browseType == 'bysearch') echo 'show';?>'></div>
</div>
<div class='main'>
<div class='panel'>
<div class='panel-heading'>
<strong>
<?php echo html::a(inlink('browse', "libID=$libID"), $libName) . ' / ';?>
<?php foreach($parents as $module):?>
<?php echo html::a(inlink('browse', "libID=$libID&browseType=bymenu&param=$module->id"), $module->name) . ' / '?>
<?php endforeach;?>
</strong>
</div>
<div class='panel-body row'>
<?php foreach($modules as $module):?>
<div class='col-md-1 menu'>
<a href='<?php echo inlink('browse', "libID=$libID&browseType=bymenu&param=$module->id")?>'>
<div class='menu-name'>
<i class='icon icon-folder-open-alt'></i>
<div class='name' title='<?php echo $module->name?>'><?php echo $module->name?></div>
</div>
</a>
<div class='actions'>
<?php
if(common::hasPriv('tree', 'edit')) echo html::a($this->createLink('tree', 'edit', "moduleID={$module->id}&type=doc"), '<i class="icon-pencil"></i>', '', " class='btn-icon' data-toggle='modal' data-type='ajax' title='$lang->edit'");
if(common::hasPriv('tree', 'delete')) echo html::a($this->createLink('tree', 'delete', "rootID=$libID&moduleID=$module->id"), '<i class="icon-remove"></i>', 'hiddenwin', "class='btn-icon' title='{$lang->delete}'");
?>
</div>
</div>
<?php endforeach;?>
<?php foreach($docs as $doc):?>
<div class='col-md-1 file'>
<a href='<?php echo inlink('view', "docID=$doc->id")?>'>
<div class='file-name'>
<i class='icon icon-file'></i>
<div class='name' title='<?php echo $doc->title?>'><?php echo $doc->title?></div>
</div>
</a>
<div class='actions'>
<?php
if(common::hasPriv('doc', 'edit')) echo html::a($this->createLink('doc', 'edit', "docID={$doc->id}"), '<i class="icon-pencil"></i>', '', " class='btn-icon' data-toggle='tooltip' title='$lang->edit'");
if(common::hasPriv('doc', 'delete')) echo html::a($this->createLink('doc', 'delete', "docID=$doc->id"), '<i class="icon-remove"></i>', 'hiddenwin', "class='btn-icon' title='{$lang->delete}'");
?>
</div>
</div>
<?php endforeach;?>
</div>
<div class='panel-footer'>
<?php common::printLink('doc', 'editLib', "rootID=$libID", $lang->doc->editLib, '', "data-toggle='modal' data-type='iframe' data-width='600px'");?>
<?php common::printLink('doc', 'deleteLib', "rootID=$libID", $lang->doc->deleteLib, 'hiddenwin');?>
<?php common::printLink('tree', 'browse', "rootID=$libID&view=doc", $lang->doc->manageType);?>
<?php echo html::a(inlink('ajaxFixedMenu', "libID=$libID&type=" . ($fixedMenu ? 'remove' : 'fixed')), $fixedMenu ? $lang->doc->removeMenu : $lang->doc->fixedMenu, "hiddenwin");?>
<?php $pager->show();?>
</div>
</div>
</div>
+105
View File
@@ -0,0 +1,105 @@
<style>
#docTree {margin-bottom: 0}
#docTree > .tree-action-item {display: none!important}
#docTree li > .tree-item-wrapper > .tree-toggle {display: block}
#docTree li > .tree-item-wrapper:hover {background-color: #edf3fe; cursor: pointer; margin-left: -20px; padding-left: 20px;}
#docTree li {line-height: 30px; padding-top: 0; padding-bottom: 0}
#docTree > li.open > .tree-item-wrapper {border-bottom: none}
#docTree.tree li.has-list.open > ul:after {top: -10px; bottom: 17px; display: none}
#docTree.tree ul > li.has-list:after {top: 14px}
#docTree.tree ul > li:after {top: 13px}
#docTree.tree ul > li:before {display: block; content: ' '; border: none; border-left: 1px dotted #999; top: -11px; bottom: 12px; left: -11px; position: absolute; width: auto; height: auto}
#docTree.tree ul > li:last-child:before {bottom: auto; height: 25px}
#docTree.tree ul > li > .tree-item-wrapper:before {display: block; content: ' '; position: absolute; width: 7px; height: 7px; top: 10px; left: 8px; background-color: #ddd}
#docTree.tree ul > li.has-list > .tree-item-wrapper:before {display: none;}
#docTree.tree ul > li.item-type-doc > .tree-item-wrapper {padding-left: 15px; margin-left: -15px;}
#docTree.tree ul > li.item-type-doc > .tree-item-wrapper:hover {background-color: #edf3fe}
#docTree.tree ul > li.item-type-doc > .tree-item-wrapper:before {left: 0; z-index: 2}
#docTree.tree li>.list-toggle {top: 2px}
#docTree.tree li:before {display: none}
#docTree .doc-info {display: none;}
#docTree .doc-info > div {display: inline-block; margin: 0 5px;}
#docTree .doc-info > div.buttons {position: relative; top: 2px}
#docTree .item-type-doc:hover .doc-info {display: inline-block; margin-left:10px;}
</style>
<div id='featurebar'>
<ul class='nav'><li><?php echo $lang->doc->browseTypeList['tree']?></li></ul>
<div class='actions'>
<div class="btn-group">
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown"><i class='icon icon-tags'></i> <?php echo $lang->doc->browseTypeList['tree']?> <span class="caret"></span></button>
<ul class="dropdown-menu" role="menu">
<li><?php echo html::a('javascript:setBrowseType("bylist")', "<i class='icon icon-list'></i> {$lang->doc->browseTypeList['list']}");?></li>
<li><?php echo html::a('javascript:setBrowseType("bymenu")', "<i class='icon icon-th'></i> {$lang->doc->browseTypeList['menu']}");?></li>
<li><?php echo html::a('javascript:setBrowseType("bytree")', "<i class='icon icon-tags'></i> {$lang->doc->browseTypeList['tree']}");?></li>
</ul>
</div>
<?php common::printIcon('doc', 'create', "libID=$libID&moduleID=$moduleID&product=0&prject=0&from=doc");?>
</div>
</div>
<div class='main'>
<div class='panel'>
<div class='panel-heading'>
<i class='icon icon-folder-close-alt'></i> <strong><?php echo $libName;?></strong>
<div class='panel-actions pull-right'>
<?php common::printLink('doc', 'editLib', "rootID=$libID", $lang->doc->editLib, '', "class='btn btn-sm' data-toggle='modal' data-type='iframe' data-width='600px'");?>
<?php common::printLink('doc', 'deleteLib', "rootID=$libID", $lang->doc->deleteLib, 'hiddenwin', "class='btn btn-sm'");?>
<?php common::printLink('tree', 'browse', "rootID=$libID&view=doc", $lang->doc->manageType, '', "class='btn btn-sm'");?>
<?php echo html::a(inlink('ajaxFixedMenu', "libID=$libID&type=" . ($fixedMenu ? 'remove' : 'fixed')), $fixedMenu ? $lang->doc->removeMenu : $lang->doc->fixedMenu, "hiddenwin", "class='btn btn-sm'");?>
</div>
</div>
<div class='panel-body'>
<ul id='docTree' class='tree-lines'></ul>
</div>
</div>
</div>
<script>
var libID = <?php echo $libID?>;
$(function()
{
var data = $.parseJSON('<?php echo helper::jsonEncode4Parse($tree, JSON_HEX_QUOT | JSON_HEX_APOS);?>');
var $tree = $('#docTree');
$tree.tree(
{
name: 'docTree',
initialState: 'preserve',
data: data,
itemWrapper: true,
actions:
{
add:
{
title: '<?php echo $lang->doc->create ?>',
template: '<a data-toggle="tooltip" href="javascript:;"><i class="icon icon-sitemap"></i>',
templateInList: false,
linkTemplate: '<?php echo helper::createLink('tree', 'edit', "moduleID={0}&type=doc"); ?>'
},
},
itemCreator: function($li, item)
{
$li.toggleClass('tree-toggle', item.type !== 'doc').closest('li').addClass('item-type-' + item.type);
if(item.type === 'doc')
{
$li.append('<span class="text-muted">#' + item.id + ' </span>').append($('<a>').attr({href: item.url}).text(item.title));
var $info = $('<div class="doc-info clearfix"/>');
$info.append($('<div class="buttons"/>').html(item.buttons));
$li.append($info);
}
else
{
$li.append($('<span class="tree-toggle"><i class="icon icon-bookmark-empty text-muted"></i> ' + (item.title || item.name) + '</span>'));
}
}
});
$('[data-toggle="tooltip"]').tooltip({container: 'body'});
var tree = $tree.data('zui.tree');
// Expand all nodes when user visit at first time of this day.
if(!tree.store.time || tree.store.time < (new Date().getTime() - 24 * 40 * 60 * 1000))
{
tree.show($('.item-type-doc').parent().parent());
}
});
</script>
+1 -1
View File
@@ -183,7 +183,7 @@ class tree extends control
}
$module = $this->tree->getById($moduleID);
if($module->owner == null and $module->root != 0 and $module->type != 'task')
if($module->owner == null and $module->root != 0 and $module->type != 'task' and $type != 'doc')
{
$module->owner = $this->loadModel('product')->getById($module->root)->QD;
}
+14
View File
@@ -508,6 +508,20 @@ class treeModel extends model
return $fullTrees;
}
/**
* Get tree structure.
*
* @param int $rootID
* @param string $type
* @access public
* @return array
*/
public function getTreeStructure($rootID, $type)
{
$stmt = $this->dbh->query($this->buildMenuQuery($rootID, $type, $startModule = 0));
return $this->getDataStructure($stmt, $type);
}
/**
* Get project story tree menu.
*