diff --git a/CHANGES.md b/CHANGES.md
index caaf5e4..6b59d08 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,15 @@
## 版本更新记录
+### v0.5.7 2020-08
+
+- 修复搜索的权限问题
+- 修复文集协作的权限问题;
+- 优化文档目录显示;
+- 优化文集协作管理;
+
+
+- 优化文档编辑器排版;
+
### v0.5.6 2020-07-31
- 修复Markdown编辑器插入图片、表格、音视频等内容时光标丢失的问题;
diff --git a/MrDoc/settings.py b/MrDoc/settings.py
index 094dd5c..b0bce77 100644
--- a/MrDoc/settings.py
+++ b/MrDoc/settings.py
@@ -40,7 +40,7 @@ SECRET_KEY = '5&71mt9@^58zdg*_!t(x6g14q*@84d%ptr%%s6e0l50zs0we3d'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = CONFIG.getboolean('site','debug')
-VERSIONS = '0.5.6'
+VERSIONS = '0.5.7'
ALLOWED_HOSTS = ['*']
diff --git a/README.md b/README.md
index bf707c0..db5f856 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
## MrDoc觅道文档 - 记录文档,汇聚思想 - [English](./README_ENG.md)
-  
+  

diff --git a/README_ENG.md b/README_ENG.md
index 905c446..cd4797e 100644
--- a/README_ENG.md
+++ b/README_ENG.md
@@ -1,6 +1,6 @@
## MrDoc - Writing documents, gathering ideas
-  
+  

diff --git a/app_doc/views.py b/app_doc/views.py
index 9748f82..2160388 100644
--- a/app_doc/views.py
+++ b/app_doc/views.py
@@ -454,7 +454,9 @@ def manage_project_collaborator(request,pro_id):
if request.method == 'GET':
pro = project[0]
- collaborator = ProjectCollaborator.objects.filter(project=pro)
+ collaborator = ProjectCollaborator.objects.filter(project=pro) # 获取文集的协作者
+ colla_user_list = [i.user for i in collaborator] # 文集协作用户的ID
+ colla_docs = Doc.objects.filter(top_doc=pro.id,create_user__in=colla_user_list) # 获取文集协作用户创建的文档
return render(request, 'app_doc/manage_project_collaborator.html', locals())
elif request.method == 'POST':
@@ -637,9 +639,18 @@ def modify_doc(request,doc_id):
doc = Doc.objects.get(id=doc_id) # 查询文档信息
project = Project.objects.get(id=doc.top_doc) # 查询文档所属的文集信息
pro_colla = ProjectCollaborator.objects.filter(project=project,user=request.user) # 查询用户的协作文集信息
+ if pro_colla.count() == 0:
+ is_pro_colla = False
+ elif pro_colla[0].role == 1:
+ is_pro_colla = True
+ else:
+ is_pro_colla = False
project_list = Project.objects.filter(create_user=request.user) # 自己创建的文集列表
colla_project_list = ProjectCollaborator.objects.filter(user=request.user) # 协作的文集列表
- if (request.user == doc.create_user) or (pro_colla[0].role == 1):
+ # 判断用户是否有权限进行修改
+ if (request.user == doc.create_user) or \
+ (is_pro_colla is True) or \
+ (request.user == project.create_user):
doc_list = Doc.objects.filter(top_doc=project.id)
doctemp_list = DocTemp.objects.filter(create_user=request.user)
history_list = DocHistory.objects.filter(doc=doc).order_by('-create_time')
@@ -652,7 +663,7 @@ def modify_doc(request,doc_id):
elif request.method == 'POST':
try:
doc_id = request.POST.get('doc_id','') # 文档ID
- project = request.POST.get('project', '') # 文集ID
+ project_id = request.POST.get('project', '') # 文集ID
parent_doc = request.POST.get('parent_doc', '') # 上级文档ID
doc_name = request.POST.get('doc_name', '') # 文档名称
doc_content = request.POST.get('content', '') # 文档内容
@@ -660,11 +671,18 @@ def modify_doc(request,doc_id):
sort = request.POST.get('sort', '') # 文档排序
status = request.POST.get('status',1) # 文档状态
- if doc_id != '' and project != '' and doc_name != '' and project != '-1':
+ if doc_id != '' and project_id != '' and doc_name != '' and project_id != '-1':
doc = Doc.objects.get(id=doc_id)
+ project = Project.objects.get(id=project_id)
pro_colla = ProjectCollaborator.objects.filter(project=project, user=request.user)
+ if pro_colla.count() == 0:
+ is_pro_colla = False
+ elif pro_colla[0].role == 1:
+ is_pro_colla = True
+ else:
+ is_pro_colla = False
# 验证用户有权限修改文档 - 文档的创建者或文集的高级协作者
- if (request.user == doc.create_user) or (pro_colla[0].role == 1):
+ if (request.user == doc.create_user) or (is_pro_colla is True) or (request.user == project.create_user):
# 将现有文档内容写入到文档历史中
DocHistory.objects.create(
doc = doc,
diff --git a/static/editor.md/editormd.js b/static/editor.md/editormd.js
index df8dfd9..81f29ae 100644
--- a/static/editor.md/editormd.js
+++ b/static/editor.md/editormd.js
@@ -3720,15 +3720,17 @@
text = trim(text);
+ var isChinese = /^[\u4e00-\u9fa5]+$/.test(text);
+ //var id = (isChinese) ? escape(text).replace(/\%/g, "") : text.toLowerCase().replace(/[^\w]+/g, "-");
+ var id = escape(text.toLowerCase().replace(' ','')).replace(/\%/g, "") // 生成包含中文编码的标题ID
+
var escapedText = text.toLowerCase().replace(/[^\w]+/g, "-");
var toc = {
text : text,
level : level,
- slug : escapedText
+ slug : escapedText,
+ id : "h"+ level + "-" + this.options.headerPrefix + id
};
-
- var isChinese = /^[\u4e00-\u9fa5]+$/.test(text);
- var id = (isChinese) ? escape(text).replace(/\%/g, "") : text.toLowerCase().replace(/[^\w]+/g, "-");
markdownToC.push(toc);
@@ -3884,6 +3886,7 @@
{
var text = toc[i].text;
var level = toc[i].level;
+ var id = toc[i].id;
if (level < startLevel) {
continue;
@@ -3902,7 +3905,8 @@
html += "";
}
- html += "
" + text + "";
+ //html += "- " + text + "
";
+ html += "- " + text + "
";
lastLevel = level;
}
diff --git a/static/mrdoc-admin.css b/static/mrdoc/mrdoc-admin.css
similarity index 100%
rename from static/mrdoc-admin.css
rename to static/mrdoc/mrdoc-admin.css
diff --git a/static/mrdoc.css b/static/mrdoc/mrdoc.css
similarity index 97%
rename from static/mrdoc.css
rename to static/mrdoc/mrdoc.css
index 9d2efe3..73123a8 100644
--- a/static/mrdoc.css
+++ b/static/mrdoc/mrdoc.css
@@ -188,7 +188,7 @@ body, html {
.project-title{
font-size: 20px;
font-weight: 700;
- margin:0 20px;
+ margin:10px 20px 0px 20px;
text-align: center;
}
.doc-summary {
@@ -376,6 +376,31 @@ li.active > a,li.active > div > a{
cursor: pointer;
color: red;
}
+/* 文档目录 */
+.tocMenu{
+ width: 50px;
+ height: 50px;
+ border-radius: 50%;
+ background: #f6f6f6;
+ text-align: center;
+ line-height: 50px;
+ /*返回顶部标签固定定位*/
+ position: fixed;
+ right: 35px;
+ bottom: 90px;
+ z-index: 999;
+ font-size: 14px;
+}
+.tocMenu:hover {
+ background: #eeeeee;
+ font-size: 16px;
+ cursor: pointer;
+ color: red;
+}
+.doc-toc-hide{
+ display: none;
+}
+
/*切换字号*/
.switch-font{
font-family: Serif;
diff --git a/static/mrdoc.editor.js b/static/mrdoc/mrdoc.editor.js
similarity index 100%
rename from static/mrdoc.editor.js
rename to static/mrdoc/mrdoc.editor.js
diff --git a/static/mrdoc.js b/static/mrdoc/mrdoc.js
similarity index 100%
rename from static/mrdoc.js
rename to static/mrdoc/mrdoc.js
diff --git a/static/toc/doctoc.js b/static/toc/doctoc.js
new file mode 100644
index 0000000..50b8c44
--- /dev/null
+++ b/static/toc/doctoc.js
@@ -0,0 +1,240 @@
+(function () {
+ 'use strict';
+ var toc_cnt = $(".markdown-toc-list").children().length;
+ if(toc_cnt > 0){
+ // console.log('显示文档目录')
+ $(".tocMenu").show();
+ initSidebar('.sidebar', '.doc-content');
+ }
+})();
+
+/**
+* 左侧目录生成插件
+* 代码参考了 https://github.com/vuejs/vuejs.org/blob/master/themes/vue/source/js/common.js
+* @param {string} sidebarQuery - 目录 Element 的 query 字符串
+* @param {string} contentQuery - 正文 Element 的 query 字符串
+*/
+function initSidebar(sidebarQuery, contentQuery) {
+ addAllStyle();
+ var sidebar = document.querySelector(sidebarQuery)
+
+ // 遍历文章中的所有 h1或 h2(取决于最大的 h 是多大) , 编辑为li.h3插入 ul
+ var allHeaders = []
+ var content = document.querySelector(contentQuery)
+ for(var i = 1;i < 7; i++){
+ //console.log(i,content.querySelectorAll('h' + i))
+ allHeaders.push.apply(allHeaders,content.querySelectorAll('h' + i))
+ }
+ // console.log('目录列表:',allHeaders)
+
+ //增加 click 点击处理,使用 scrollIntoView,增加控制滚动的 flag
+ var scrollFlag = 0
+ var scrollFlagTimer
+ sidebar.addEventListener('click', function (e) {
+ e.preventDefault()
+ if (e.target.href) {
+ scrollFlag = 1
+ clearTimeout(scrollFlagTimer)
+ scrollFlagTimer = setTimeout(() => scrollFlag = 0, 1500)
+ setActive(e.target, sidebar)
+ var target = document.getElementById(e.target.getAttribute('href').slice(1))
+ //console.log(e,target)
+ //console.log(e.target.getAttribute('href').slice(1))
+ target.scrollIntoView({ behavior: 'smooth', block: "start" })
+ }
+ });
+
+ //监听窗口的滚动和缩放事件
+ //window.addEventListener('scroll', updateSidebar)
+ //window.addEventListener('resize', throttle(updateSidebar))
+ function updateSidebar() {
+ if (scrollFlag) return // 如果存在scrollFlag,直接返回
+ var doc = document.documentElement // 定义doc变量值为页面文档元素
+ var top = doc && doc.scrollTop || document.body.scrollTop // 获取当前页面滚动条纵坐标
+ if (!allHeaders.length) return // 如果allHeaders的列表长度为空,直接返回
+ var last // 定义一个变量last
+ // 按照allHeaders的列表长度进行遍历
+ for (var i = 0; i < allHeaders.length; i++) {
+ var link = allHeaders[i] // 按索引取出一个目录link
+ console.log("滚动条高度",top,document.body.clientHeight)
+ // link.offsetTop 表示元素距离上方的距离
+ // top 表示当前页面滚动条的纵坐标
+ // document.body.clientHeight 表示页面可视区域高度
+ // if (link.offsetTop > (top + document.body.clientHeight / 2 - 73)) {
+ if (link.offsetTop > (top + document.body.clientHeight / 6)) {
+ if (!last) { last = link }
+ break
+ } else {
+ last = link
+ }
+ }
+ if (last) {
+ console.log(last.offsetTop)
+ setActive(last.id, sidebar)
+ }
+ }
+}
+
+
+/**
+*设置目录的激活状态,按既定规则添加 active 和 current 类
+*>无论对h2还是 h3进行操作,首先都要移除所有的 active 和 current 类, 然后对 h2添加 active 和 current, 或对 h3添加 active 对其父目录添加 current
+@param {String|HTMLElement} id - HTML标题节点或 querySelector 字符串
+@param {HTMLElement} sidebar - 边栏的 HTML 节点
+*/
+function setActive(id, sidebar) {
+ //1.无论对h2还是 h3进行操作,首先都要移除所有的 active 和 current 类
+
+ // 遍历目录中所有包含active类的HTMl元素,移除其active类
+ var previousActives = sidebar.querySelectorAll(`.active`)
+ ;[].forEach.call(previousActives, function (h) {
+ h.classList.remove('active')
+ })
+ // 遍历目录中所有包含current类的HTML元素,移除其current类
+ previousActives = sidebar.querySelectorAll(`.current`)
+ ;[].forEach.call(previousActives, function (h) {
+ h.classList.remove('current')
+ })
+
+ //获取要操作的目录节点
+ var currentActive = typeof id === 'string'
+ ? sidebar.querySelector('a[href="#' + id + '"]')
+ : id
+ //console.log(currentActive)
+
+ // h2标题
+ if (currentActive.classList.contains('h2') != -1) {
+ // 添加 active 和 current
+ currentActive.classList.add('active', 'current')
+ }
+ // h3标题
+ if ([].indexOf.call(currentActive.classList, 'h3') != -1) {
+ console.log("H3标题")
+ // 添加 active 且对其父目录添加 current
+ currentActive.classList.add('active')
+ var parent = currentActive
+ while (parent && parent.tagName != 'UL') {
+ parent = parent.parentNode
+ }
+ parent.parentNode.querySelector('.h2-link').classList.add('current', 'active')
+ }
+
+ //左侧目录太长时的效果
+ currentActive.scrollIntoView({ behavior: 'smooth' })
+}
+/**
+>增加 sidebar 需要的全部样式
+@param {string} highlightColor - 高亮颜色, 默认为'#c7254e'
+*/
+function addAllStyle(highlightColor) {
+ highlightColor = highlightColor || "#c7254e"
+ var sheet = newStyleSheet()
+ /**
+ >创建一个新的``标签插入``中
+ @return {Object} style.sheet,`它具有方法insertRule`
+ */
+ function newStyleSheet() {
+ var style = document.createElement("style");
+ // 对WebKit hack :(
+ style.appendChild(document.createTextNode(""));
+ // 将
diff --git a/template/app_doc/manage_project.html b/template/app_doc/manage_project.html
index 649964a..7e976a2 100644
--- a/template/app_doc/manage_project.html
+++ b/template/app_doc/manage_project.html
@@ -74,7 +74,7 @@
{% endif %}
- | {{ pro.id | project_collaborator_cnt }} |
+ {{ pro.id | project_collaborator_cnt }} |
修改
diff --git a/template/app_doc/manage_project_collaborator.html b/template/app_doc/manage_project_collaborator.html
index b233a57..25760e8 100644
--- a/template/app_doc/manage_project_collaborator.html
+++ b/template/app_doc/manage_project_collaborator.html
@@ -12,7 +12,7 @@
@@ -41,39 +41,82 @@
{% if collaborator.count != 0 %}
-
-
-
-
- | 用户名 |
- 协作权限 |
- 操作 |
-
-
-
- {% for colla in collaborator %}
-
- | {{ colla.user }} |
-
- {% if colla.role == 0 %}
- 新建文档,修改、删除新建的文档
- {% else %}
- 可操作所有文档
- {% endif %}
- |
-
-
- 修改
-
-
- 删除
-
- |
-
- {% endfor %}
-
-
-
+
+
+
+
+
+
+
+
+
+ | 用户名 |
+ 协作权限 |
+ 操作 |
+
+
+
+ {% for colla in collaborator %}
+
+ | {{ colla.user }} |
+
+ {% if colla.role == 0 %}
+ 新建文档,修改、删除新建的文档
+ {% else %}
+ 可操作所有文档
+ {% endif %}
+ |
+
+
+ 修改
+
+
+ 删除
+
+ |
+
+ {% endfor %}
+
+
+
+
+
+
+
+
+
+
+ | 文档名称 |
+ 创建用户 |
+ 创建时间 |
+ 操作 |
+
+
+
+ {% for doc in colla_docs %}
+
+ | {{ doc.name }} |
+ {{ doc.create_user }} |
+ {{ doc.create_time }} |
+
+
+ 修改
+
+
+ 删除
+
+ |
+
+ {% endfor %}
+
+
+
+
+
+
{% endif %}
{% endblock %}
{% block custom_script %}
@@ -181,6 +224,36 @@
},
})
};
+ // 删除文档
+ delDoc = function(doc_id){
+ layer.open({
+ type:1,
+ title:'删除文档',
+ area:'300px;',
+ id:'delPro',//配置ID
+ content:'警告:此操作将删除此文档! ',
+ btn:['确定','取消'], //添加按钮
+ btnAlign:'c', //按钮居中
+ yes:function (index,layero) {
+ layer.load(1);
+ data = {
+ 'doc_id':doc_id,
+ }
+ $.post("{% url 'del_doc' %}",data,function(r){
+ layer.closeAll('loading')
+ if(r.status){
+ //修改成功
+ window.location.reload();
+ //layer.close(index)
+ }else{
+ //修改失败,提示
+ console.log(r)
+ layer.msg(r.data)
+ }
+ })
+ },
+ });
+ };
diff --git a/template/app_doc/pro_list.html b/template/app_doc/pro_list.html
index d20c35b..0a51e84 100644
--- a/template/app_doc/pro_list.html
+++ b/template/app_doc/pro_list.html
@@ -12,7 +12,7 @@
MrDoc觅道文档 - 一个简单的开源在线文档系统
-
+
|