forked from mirror/MrDoc
添加个人中心文档管理的文集筛选功能
This commit is contained in:
parent
d449796eb3
commit
9ff21c1c55
176
app_doc/views.py
176
app_doc/views.py
@ -700,6 +700,7 @@ def del_doc(request):
|
||||
doc = Doc.objects.get(id=doc_id)
|
||||
except ObjectDoesNotExist:
|
||||
return JsonResponse({'status': False, 'data': '文档不存在'})
|
||||
# 如果请求用户为文档创建者或为高级权限的协作者,可以删除
|
||||
if request.user == doc.create_user:
|
||||
# 删除
|
||||
doc.delete()
|
||||
@ -721,31 +722,74 @@ def del_doc(request):
|
||||
@logger.catch()
|
||||
def manage_doc(request):
|
||||
# 文档内容搜索参数
|
||||
search_kw = request.GET.get('kw',None)
|
||||
if search_kw:
|
||||
# 已发布文档数量
|
||||
published_doc_cnt = Doc.objects.filter(
|
||||
create_user=request.user, status=1
|
||||
).count()
|
||||
# 草稿文档数量
|
||||
draft_doc_cnt = Doc.objects.filter(
|
||||
create_user=request.user, status=0
|
||||
).count()
|
||||
# 所有文档数量
|
||||
all_cnt = published_doc_cnt + draft_doc_cnt
|
||||
# 获取文档状态筛选参数
|
||||
doc_status = request.GET.get('status', 'all')
|
||||
search_kw = request.GET.get('kw','')
|
||||
# 文档状态筛选参数
|
||||
doc_status = request.GET.get('status', 'all')
|
||||
# 文档文集筛选参数
|
||||
doc_pro_id = request.GET.get('pid','')
|
||||
|
||||
# 查询文档
|
||||
if doc_status == 'all':
|
||||
is_search = True if search_kw != '' else False
|
||||
is_status = doc_status
|
||||
is_project = True if doc_pro_id != '' else False
|
||||
|
||||
# 无搜索 - 无状态 - 无文集
|
||||
if (is_search is False) and (is_status == 'all') and (is_project is False):
|
||||
doc_list = Doc.objects.filter(create_user=request.user).order_by('-modify_time')
|
||||
|
||||
# 无搜索 - 无状态 - 有文集
|
||||
elif (is_search is False) and (is_status == 'all') and (is_project):
|
||||
doc_list = Doc.objects.filter(create_user=request.user,top_doc=int(doc_pro_id)).order_by('-modify_time')
|
||||
|
||||
# 无搜索 - 有状态 - 无文集
|
||||
elif (is_search is False) and (is_status != 'all') and (is_project is False):
|
||||
# 返回已发布文档
|
||||
if doc_status == 'published':
|
||||
doc_list = Doc.objects.filter(create_user=request.user, status=1).order_by('-modify_time')
|
||||
# 返回草稿文档
|
||||
elif doc_status == 'draft':
|
||||
doc_list = Doc.objects.filter(create_user=request.user, status=0).order_by('-modify_time')
|
||||
else:
|
||||
doc_list = Doc.objects.filter(create_user=request.user).order_by('-modify_time')
|
||||
|
||||
# 无搜索 - 有状态 - 有文集
|
||||
elif (is_search is False) and (is_status != 'all') and (is_project):
|
||||
# 返回已发布文档
|
||||
if doc_status == 'published':
|
||||
doc_list = Doc.objects.filter(
|
||||
Q(content__icontains=search_kw) | Q(name__icontains=search_kw), # 文本或文档标题包含搜索词
|
||||
create_user=request.user,
|
||||
status=1,
|
||||
top_doc=int(doc_pro_id)
|
||||
).order_by('-modify_time')
|
||||
elif doc_status == 'published':
|
||||
# 返回草稿文档
|
||||
elif doc_status == 'draft':
|
||||
doc_list = Doc.objects.filter(
|
||||
create_user=request.user,
|
||||
content__icontains=search_kw,
|
||||
status=0,
|
||||
top_doc = int(doc_pro_id)
|
||||
).order_by('-modify_time')
|
||||
else:
|
||||
doc_list = Doc.objects.filter(create_user=request.user,top_doc=int(doc_pro_id)).order_by('-modify_time')
|
||||
|
||||
# 有搜索 - 无状态 - 无文集
|
||||
elif (is_search) and (is_status == 'all') and (is_project is False):
|
||||
doc_list = Doc.objects.filter(
|
||||
Q(content__icontains=search_kw) | Q(name__icontains=search_kw), # 文本或文档标题包含搜索词
|
||||
create_user=request.user,
|
||||
).order_by('-modify_time')
|
||||
|
||||
# 有搜索 - 无状态 - 有文集
|
||||
elif (is_search) and (is_status == 'all') and (is_project):
|
||||
doc_list = Doc.objects.filter(
|
||||
Q(content__icontains=search_kw) | Q(name__icontains=search_kw), # 文本或文档标题包含搜索词
|
||||
create_user=request.user,top_doc=int(doc_pro_id)
|
||||
).order_by('-modify_time')
|
||||
|
||||
# 有搜索 - 有状态 - 无文集
|
||||
elif (is_search) and (is_status != 'all') and (is_project is False):
|
||||
if doc_status == 'published':
|
||||
doc_list = Doc.objects.filter(
|
||||
Q(content__icontains=search_kw) | Q(name__icontains=search_kw),
|
||||
create_user=request.user,
|
||||
status = 1
|
||||
).order_by('-modify_time')
|
||||
elif doc_status == 'draft':
|
||||
@ -754,58 +798,60 @@ def manage_doc(request):
|
||||
create_user=request.user,
|
||||
status = 0
|
||||
).order_by('-modify_time')
|
||||
# 分页处理
|
||||
paginator = Paginator(doc_list, 15)
|
||||
page = request.GET.get('page', 1)
|
||||
try:
|
||||
docs = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
docs = paginator.page(1)
|
||||
except EmptyPage:
|
||||
docs = paginator.page(paginator.num_pages)
|
||||
docs.kw = search_kw
|
||||
docs.status = doc_status
|
||||
else:
|
||||
# 已发布文档数量
|
||||
published_doc_cnt = Doc.objects.filter(
|
||||
create_user=request.user,status=1
|
||||
).count()
|
||||
# 草稿文档数量
|
||||
draft_doc_cnt = Doc.objects.filter(
|
||||
create_user=request.user,status=0
|
||||
).count()
|
||||
# 所有文档数量
|
||||
all_cnt = published_doc_cnt + draft_doc_cnt
|
||||
# 获取文档状态筛选参数
|
||||
doc_status = request.GET.get('status','all')
|
||||
if len(doc_status) == 0:
|
||||
doc_status = 'all'
|
||||
# print('status:', doc_status,type(doc_status))
|
||||
# 返回所有文档
|
||||
if doc_status == 'all':
|
||||
doc_list = Doc.objects.filter(create_user=request.user).order_by('-modify_time')
|
||||
# 返回已发布文档
|
||||
elif doc_status == 'published':
|
||||
else:
|
||||
doc_list = Doc.objects.filter(
|
||||
create_user=request.user,status=1
|
||||
Q(content__icontains=search_kw) | Q(name__icontains=search_kw), # 文本或文档标题包含搜索词
|
||||
create_user=request.user,
|
||||
).order_by('-modify_time')
|
||||
|
||||
# 有搜索 - 有状态 - 有文集
|
||||
elif (is_search) and (is_status != 'all') and (is_project):
|
||||
if doc_status == 'published':
|
||||
doc_list = Doc.objects.filter(
|
||||
Q(content__icontains=search_kw) | Q(name__icontains=search_kw),
|
||||
create_user=request.user,
|
||||
status = 1,
|
||||
top_doc=int(doc_pro_id)
|
||||
).order_by('-modify_time')
|
||||
# 返回草稿文档
|
||||
elif doc_status == 'draft':
|
||||
doc_list = Doc.objects.filter(
|
||||
create_user=request.user, status=0
|
||||
Q(content__icontains=search_kw) | Q(name__icontains=search_kw), # 文本或文档标题包含搜索词
|
||||
create_user=request.user,
|
||||
status = 0,
|
||||
top_doc=int(doc_pro_id)
|
||||
).order_by('-modify_time')
|
||||
else:
|
||||
doc_list = Doc.objects.filter(create_user=request.user).order_by('-modify_time')
|
||||
# 分页处理
|
||||
paginator = Paginator(doc_list, 15)
|
||||
page = request.GET.get('page', 1)
|
||||
try:
|
||||
docs = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
docs = paginator.page(1)
|
||||
except EmptyPage:
|
||||
docs = paginator.page(paginator.num_pages)
|
||||
docs.status = doc_status
|
||||
doc_list = Doc.objects.filter(
|
||||
Q(content__icontains=search_kw) | Q(name__icontains=search_kw), # 文本或文档标题包含搜索词
|
||||
create_user=request.user,
|
||||
top_doc=int(doc_pro_id)
|
||||
).order_by('-modify_time')
|
||||
|
||||
# 文集列表
|
||||
project_list = Project.objects.filter(create_user=request.user) # 自己创建的文集列表
|
||||
colla_project_list = ProjectCollaborator.objects.filter(user=request.user) # 协作的文集列表
|
||||
|
||||
# 文档数量
|
||||
# 已发布文档数量
|
||||
published_doc_cnt = Doc.objects.filter(create_user=request.user, status=1).count()
|
||||
# 草稿文档数量
|
||||
draft_doc_cnt = Doc.objects.filter(create_user=request.user, status=0).count()
|
||||
# 所有文档数量
|
||||
all_cnt = published_doc_cnt + draft_doc_cnt
|
||||
|
||||
|
||||
# 分页处理
|
||||
paginator = Paginator(doc_list, 15)
|
||||
page = request.GET.get('page', 1)
|
||||
try:
|
||||
docs = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
docs = paginator.page(1)
|
||||
except EmptyPage:
|
||||
docs = paginator.page(paginator.num_pages)
|
||||
docs.status = doc_status
|
||||
docs.pid = doc_pro_id
|
||||
docs.kw = search_kw
|
||||
return render(request,'app_doc/manage_doc.html',locals())
|
||||
|
||||
|
||||
|
1
static/editor.md/lib/marked.min.js
vendored
1
static/editor.md/lib/marked.min.js
vendored
File diff suppressed because one or more lines are too long
@ -95,6 +95,12 @@
|
||||
<li class="layui-nav-item layui-nav-itemed">
|
||||
<a href="{% url 'sys_setting' %}"><i class="layui-icon layui-icon-set-sm"></i> 站点设置</a>
|
||||
</li>
|
||||
<li class="layui-nav-item layui-nav-itemed">
|
||||
<a href="http://mrdoc.zmister.com/project-7/" target="_blank"><i class="layui-icon layui-icon-tips"></i> 配置手册</a>
|
||||
</li>
|
||||
<li class="layui-nav-item layui-nav-itemed">
|
||||
<a href="http://mrdoc.zmister.com/project-54/" target="_blank"><i class="layui-icon layui-icon-help"></i> 使用手册</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
@ -113,7 +119,9 @@
|
||||
<div class="layui-footer" style="text-align:center;">
|
||||
<!-- 底部固定区域 -->
|
||||
© <a href="https://gitee.com/zmister/MrDoc" target="_blank">MrDoc 2019-2020</a> -
|
||||
当前版本:<a href="https://gitee.com/zmister/MrDoc/tree/{{mrdoc_version}}/" target="_blank">{{mrdoc_version}}</a>
|
||||
当前版本:<a href="https://gitee.com/zmister/MrDoc/tree/{{mrdoc_version}}/" target="_blank">{{mrdoc_version}}</a> -
|
||||
<a href="https://github.com/zmister2016/MrDoc" target="_blank">GitHub</a> -
|
||||
<a href="https://gitee.com/zmister/MrDoc" target="_blank">码云</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -95,7 +95,7 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="create-doc-form">
|
||||
<div class="layui-form" style="">
|
||||
<div class="layui-form">
|
||||
<!-- 标题 -->
|
||||
<div style="padding-bottom:10px;">
|
||||
<div class="layui-input-block" style="margin-left:0px;">
|
||||
@ -116,7 +116,7 @@
|
||||
var tree = layui.tree;
|
||||
//选择文集
|
||||
form.on('select(project)', function(data){
|
||||
console.log(data.value); //得到被选中的值
|
||||
console.log('选择文集:',data.value); //得到被选中的值
|
||||
if(data.value == -1){ //新建文集
|
||||
layer.open({
|
||||
type:1,
|
||||
@ -190,7 +190,7 @@
|
||||
//带pid参数自动选择文集
|
||||
var sel_pro_list = $('dl.layui-anim dd');
|
||||
for(var i = 0;i < sel_pro_list.length; i++){
|
||||
if(sel_pro_list[i].getAttribute('lay-value') == {{pid}}){
|
||||
if(sel_pro_list[i].getAttribute('lay-value') == '{{pid}}'){
|
||||
var sel_pro = 'dd[lay-value=' + sel_pro_list[i].getAttribute('lay-value') + ']';
|
||||
$('#project').siblings("div.layui-form-select").find('dl').find(sel_pro).click();
|
||||
}
|
||||
@ -396,8 +396,6 @@
|
||||
<td class="layui-hide-xs">{{ temp.create_time }}</td>
|
||||
<td>
|
||||
<a class="layui-btn layui-btn-normal layui-btn-sm" href="javascript:void(0);" onclick="insertTemp('{{temp.id}}');">选择模板</a>
|
||||
{# <a href="javascript:void(0);" onclick="modifyTemp();">修改</a>#}
|
||||
{# <a href="javascript:void(0);" onclick="delTemp();">删除</a>#}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -44,6 +44,9 @@
|
||||
.layui-form-radio>i:hover, .layui-form-radioed>i{
|
||||
color: #1E9FFF;
|
||||
}
|
||||
.layui-form-select dl dd.layui-this{
|
||||
background-color: #1E9FFF !important;
|
||||
}
|
||||
/* 开关样式 */
|
||||
.layui-form-onswitch{
|
||||
border-color: #1E9FFF;
|
||||
@ -95,9 +98,12 @@
|
||||
<li class="layui-nav-item layui-nav-itemed">
|
||||
<a href="{% url 'manage_attachment' %}"><i class="layui-icon layui-icon-export"></i> 附件管理</a>
|
||||
</li>
|
||||
<li class="layui-nav-item layui-nav-itemed">
|
||||
<li class="layui-nav-item layui-nav-itemed">
|
||||
<a href="{% url 'manage_token' %}"><i class="layui-icon layui-icon-key"></i> 用户Token管理</a>
|
||||
</li>
|
||||
<li class="layui-nav-item layui-nav-itemed">
|
||||
<a href="http://mrdoc.zmister.com/project-54/" target="_blank"><i class="layui-icon layui-icon-help"></i> 使用手册</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -110,7 +116,9 @@
|
||||
<div class="layui-footer" style="text-align:center;">
|
||||
<!-- 底部固定区域 -->
|
||||
© <a href="https://gitee.com/zmister/MrDoc" target="_blank">MrDoc 2019-2020</a> -
|
||||
当前版本:<a href="https://gitee.com/zmister/MrDoc/tree/{{mrdoc_version}}/" target="_blank">{{mrdoc_version}}</a>
|
||||
当前版本:<a href="https://gitee.com/zmister/MrDoc/tree/{{mrdoc_version}}/" target="_blank">{{mrdoc_version}}</a> -
|
||||
<a href="https://github.com/zmister2016/MrDoc" target="_blank">GitHub</a> -
|
||||
<a href="https://gitee.com/zmister/MrDoc" target="_blank">码云</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -5,11 +5,13 @@
|
||||
<div class="layui-card-header" style="margin-bottom: 10px;">
|
||||
<div class="layui-row">
|
||||
<span style="font-size:18px;">文档管理</span>
|
||||
{% if search_kw %} - 搜索“{{search_kw}}”的结果{% endif %}
|
||||
{% if search_kw %} - 搜索“<span style="color: #FF5722;">{{search_kw}}</span>”的结果{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-row">
|
||||
<form action="{% url 'manage_doc' %}" method="get">
|
||||
<input name="pid" value="{{docs.pid}}" hidden>
|
||||
<div class="layui-form-item">
|
||||
<span class="layui-breadcrumb doc_status_condition" lay-separator="|">
|
||||
<a href="{% url 'manage_doc' %}?status=all" class="{% if doc_status == 'all' %}current{% endif %}">全部({{all_cnt}})</a>
|
||||
@ -24,8 +26,40 @@
|
||||
<a href="{% url 'create_doc' %}" target="_blank" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-addition"></i>新建文档</a>
|
||||
</div>
|
||||
</form>
|
||||
<div class="">
|
||||
<div class="layui-form">
|
||||
<div class="layui-input-inline">
|
||||
<select name="pro_id" lay-verify="required" lay-filter="project" id="project">
|
||||
<option value="">按文集筛选</option>
|
||||
<!-- 自己的文集 -->
|
||||
<optgroup label="自有文集" id="self-project">
|
||||
{% for p in project_list %}
|
||||
{% if p.role == 1 %}
|
||||
<option value="{{ p.id }}">[私密]《{{ p.name }}》</option>
|
||||
{% elif p.role == 2 %}
|
||||
<option value="{{ p.id }}" >[指定用户]《{{ p.name }}》</option>
|
||||
{% elif p.role == 3 %}
|
||||
<option value="{{ p.id }}" >[访问码]《{{ p.name }}》</option>
|
||||
{% else %}
|
||||
<option value="{{ p.id }}" >[公开]《{{ p.name }}》</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
<!-- 协作的文集 -->
|
||||
{% if colla_project_list.count > 0 %}
|
||||
<optgroup label="协作文集">
|
||||
{% for p in colla_project_list %}
|
||||
<option value="{{ p.project.id }}">[协作]《{{ p.project.name }}》</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-row" lay-skin="">
|
||||
<table class="layui-table" id="doctemp-list" lay-skin="" lay-even>
|
||||
<thead>
|
||||
@ -76,7 +110,7 @@
|
||||
<div class="layui-box layui-laypage layui-laypage-default">
|
||||
<!-- 上一页 -->
|
||||
{% if docs.has_previous %}
|
||||
<a href="?page={{ docs.previous_page_number }}&kw={{docs.kw}}&status={{docs.status}}" class="layui-btn layui-btn-xs layui-btn-normal">上一页</a>
|
||||
<a href="?page={{ docs.previous_page_number }}&kw={{docs.kw}}&status={{docs.status}}&pid={{docs.pid}}" class="layui-btn layui-btn-xs layui-btn-normal">上一页</a>
|
||||
{% else %}
|
||||
<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-disabled">上一页</a>
|
||||
{% endif %}
|
||||
@ -87,7 +121,7 @@
|
||||
</span>
|
||||
<!-- 下一页 -->
|
||||
{% if docs.has_next %}
|
||||
<a href="?page={{ docs.next_page_number }}&kw={{docs.kw}}&status={{docs.status}}" class="layui-btn layui-btn-xs layui-btn-normal">下一页</a>
|
||||
<a href="?page={{ docs.next_page_number }}&kw={{docs.kw}}&status={{docs.status}}&pid={{docs.pid}}" class="layui-btn layui-btn-xs layui-btn-normal">下一页</a>
|
||||
{% else %}
|
||||
<a class="layui-btn layui-btn-xs layui-btn-disabled">下一页</a>
|
||||
{% endif %}
|
||||
@ -96,6 +130,7 @@
|
||||
{% endblock %}
|
||||
{% block custom_script %}
|
||||
<script>
|
||||
// 删除文档
|
||||
delDoc = function(doc_id){
|
||||
layer.open({
|
||||
type:1,
|
||||
@ -125,5 +160,12 @@
|
||||
},
|
||||
});
|
||||
}
|
||||
//筛选文集
|
||||
form.on('select(project)', function(data){
|
||||
console.log('选择文集:',data.value); //得到被选中的值
|
||||
if(data.value != -1){//
|
||||
window.location.href = '?kw={{docs.kw}}&status={{docs.status}}&pid='+data.value;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user