FIXBUG
修复了打开第一个标签后左侧文档树不展开的BUG 解决方法: 由于jstree在未指定li的id时,id生是由规律的,第一个生成的li为j1_1,第二个为j1_2,以此类推 jstree是通过深度优先搜索遍历的,在遍历的时候又会提供当前节点的relative_path 因此在遍历时记录了节点对应的jstree_id,然后返回 “
This commit is contained in:
parent
83651aa687
commit
aa4c7bdea4
|
@ -625,7 +625,6 @@ class AddVoteView(View):
|
|||
object.voteup = object.voteup -1
|
||||
object.save()
|
||||
exist_records.delete()
|
||||
print(-vote_before)
|
||||
return HttpResponse(json.dumps({"status": "success", "info": "cancel", "value": -(vote_before), "msg": "cancel success"}),
|
||||
content_type='application/json')
|
||||
vote = Vote()
|
||||
|
@ -640,7 +639,6 @@ class AddVoteView(View):
|
|||
else:
|
||||
object.voteup = object.voteup + 1
|
||||
object.save()
|
||||
print(vote_value)
|
||||
return HttpResponse(json.dumps({"status": "success", "msg": "vote success", "value": vote_value}), content_type='application/json')
|
||||
else:
|
||||
return HttpResponse('{"status":"fail","msg":"参数传递错误"}', content_type='application/json')
|
||||
|
@ -1016,7 +1014,6 @@ class RightView(View):
|
|||
return html_str
|
||||
|
||||
def post(self, request):
|
||||
print(1111)
|
||||
# 先判断他是文件还是文件夹
|
||||
project_id = request.POST.get('project_id', '')
|
||||
file_path = request.POST.get('path', '')
|
||||
|
|
|
@ -150,9 +150,9 @@ class ProjectInfoView(View):
|
|||
class ProjectSourceView(View):
|
||||
def get(self, request, name, path):
|
||||
project = Project.objects.filter(name=name).first()
|
||||
# print(request.user)
|
||||
project_tree = get_project_tree.getHtml(settings.SOURCEPATH+project.path)
|
||||
print(path)
|
||||
project_tree_obj = get_project_tree.ProjectTree()
|
||||
project_tree = project_tree_obj.getHtml(settings.SOURCEPATH+project.path)
|
||||
first_tabs_jstree_id = project_tree_obj.path_id_map[path]
|
||||
return render(request, 'projects/source.html', locals())
|
||||
|
||||
#文件列表页
|
||||
|
|
|
@ -7,87 +7,97 @@ from projects.models import Project
|
|||
# ondbclick的参数为:project_id,relative_path,以及文件名
|
||||
# 其中relative_path是相对于项目根路径的
|
||||
|
||||
project_name = ""
|
||||
project_id = ""
|
||||
#######获取当前层的文件夹和文件
|
||||
def getindex(path):
|
||||
dirs=[]
|
||||
files=[]
|
||||
for file in os.listdir(path):
|
||||
if os.path.isdir(os.path.join(path, file)):
|
||||
dirs.append(file)
|
||||
else:
|
||||
files.append(file)
|
||||
return dirs,files
|
||||
class ProjectTree:
|
||||
def __init__(self):
|
||||
self.count = 1;
|
||||
self.path_id_map = {}
|
||||
|
||||
#####生成节点树##########
|
||||
def genetree(path,parentdirs):
|
||||
dirs,files=getindex(path)
|
||||
# 如果parentdir不为空,那么htmlstr应该为"",否则会有问题,建议上次提交时的文件
|
||||
if parentdirs =="":
|
||||
isParentDirNull=True
|
||||
else:
|
||||
isParentDirNull=False
|
||||
if isParentDirNull:
|
||||
htmlstr = "<ul>"
|
||||
else:
|
||||
htmlstr = ""
|
||||
# 处理多级单文件夹目录
|
||||
# parentdir用来保存那个多级单文件父目录
|
||||
if len(dirs)==1:
|
||||
parentdirs += (dirs[0] + os.sep)
|
||||
current_dir = os.path.join(path, dirs[0])
|
||||
htmlstr += genetree(current_dir,parentdirs)
|
||||
else:
|
||||
for dir in dirs:
|
||||
#######获取当前层的文件夹和文件
|
||||
def getindex(self,path):
|
||||
dirs=[]
|
||||
files=[]
|
||||
for file in os.listdir(path):
|
||||
if os.path.isdir(os.path.join(path, file)):
|
||||
dirs.append(file)
|
||||
else:
|
||||
files.append(file)
|
||||
return dirs,files
|
||||
|
||||
#####生成节点树##########
|
||||
def genetree(self,path,parentdirs,project_name,project_id):
|
||||
dirs,files=self.getindex(path)
|
||||
# 如果parentdir不为空,那么htmlstr应该为"",否则会有问题,建议上次提交时的文件
|
||||
if parentdirs =="":
|
||||
isParentDirNull=True
|
||||
else:
|
||||
isParentDirNull=False
|
||||
if isParentDirNull:
|
||||
htmlstr = "<ul>"
|
||||
else:
|
||||
htmlstr = ""
|
||||
# 处理多级单文件夹目录
|
||||
# parentdir用来保存那个多级单文件父目录
|
||||
if len(dirs)==1:
|
||||
parentdirs += (dirs[0] + os.sep)
|
||||
current_dir = os.path.join(path, dirs[0])
|
||||
htmlstr += self.genetree(current_dir,parentdirs,project_name,project_id)
|
||||
else:
|
||||
for dir in dirs:
|
||||
# 合成ondbclick 字符串
|
||||
index = path.find(project_name)
|
||||
relative_path = path[index+len(project_name):]+"/"+dir
|
||||
dirname = parentdirs + dir
|
||||
# ondbclick_str = '<text ondbclick=add_tab("%s","%s","%s")>' %(project_id,relative_path,dirname)
|
||||
ondbclick_str = '<text ondblclick=add_tab("%s","%s","%s")>' %(project_id,relative_path,dirname)
|
||||
ondbclick_str += (dirname +"</text>")
|
||||
self.record_path_and_id(relative_path)
|
||||
|
||||
# 形成li字符串
|
||||
htmlstr += "<li>"+ondbclick_str
|
||||
dir = os.path.join(path, dir)
|
||||
htmlstr += self.genetree(dir,"",project_name,project_id)
|
||||
htmlstr += "</li>"
|
||||
# 循环遍历完毕,parentdirs应该设置为空
|
||||
if parentdirs != "":
|
||||
parentdirs = ""
|
||||
|
||||
for file in files:
|
||||
# 合成ondbclick 字符串
|
||||
index = path.find(project_name)
|
||||
relative_path = path[index+len(project_name):]+"/"+dir
|
||||
dirname = parentdirs + dir
|
||||
# ondbclick_str = '<text ondbclick=add_tab("%s","%s","%s")>' %(project_id,relative_path,dirname)
|
||||
ondbclick_str = '<text ondblclick=add_tab("%s","%s","%s")>' %(project_id,relative_path,dirname)
|
||||
ondbclick_str += (dirname +"</text>")
|
||||
|
||||
# 形成li字符串
|
||||
htmlstr += "<li>"+ondbclick_str
|
||||
|
||||
dir = os.path.join(path, dir)
|
||||
htmlstr += genetree(dir,"")
|
||||
htmlstr += "</li>"
|
||||
# 循环遍历完毕,parentdirs应该设置为空
|
||||
if parentdirs != "":
|
||||
parentdirs = ""
|
||||
|
||||
for file in files:
|
||||
# 合成ondbclick 字符串
|
||||
index = path.find(project_name)
|
||||
relative_path = path[index+len(project_name):]+"/"+file
|
||||
ondbclick_str = '<text ondblclick=add_tab("%s","%s","%s")>' %(project_id,relative_path,file)
|
||||
ondbclick_str += (file +"</text>")
|
||||
# 合成li
|
||||
htmlstr += "<li data-jstree='{\"icon\":\"fa fa-file-code-o color-blue\"}'>"+ ondbclick_str+"</li>"
|
||||
relative_path = path[index+len(project_name):]+"/"+file
|
||||
ondbclick_str = '<text ondblclick=add_tab("%s","%s","%s")>' %(project_id,relative_path,file)
|
||||
ondbclick_str += (file +"</text>")
|
||||
# 合成li
|
||||
htmlstr += "<li data-jstree='{\"icon\":\"fa fa-file-code-o color-blue\"}'>"+ ondbclick_str+"</li>"
|
||||
self.record_path_and_id(relative_path)
|
||||
|
||||
if isParentDirNull:
|
||||
htmlstr += "</ul>"
|
||||
return htmlstr
|
||||
|
||||
|
||||
if isParentDirNull:
|
||||
htmlstr += "</ul>"
|
||||
return htmlstr
|
||||
def getHtml(self,path):
|
||||
htmlstr = '<div id="jstree">'
|
||||
try:
|
||||
# 在这里把最开始的目录给加上
|
||||
project_name = path.split("/")[-1]
|
||||
project_id = str(Project.objects.get(name=project_name).pk)
|
||||
|
||||
relative_path = ""
|
||||
ondbclick_str = '<text ondblclick=add_tab("%s","%s","%s")>' %(project_id,relative_path,project_name)
|
||||
ondbclick_str += (project_name+"</text>")
|
||||
|
||||
htmlstr += "<ul><li>"+ ondbclick_str
|
||||
self.record_path_and_id(relative_path)
|
||||
htmlstr += self.genetree(path,"",project_name,project_id)
|
||||
htmlstr += "</li></ul>"
|
||||
except:
|
||||
self.record_path_and_id(relative_path)
|
||||
htmlstr += self.genetree(path,"",project_name,project_id)
|
||||
finally:
|
||||
htmlstr += "</div>"
|
||||
return htmlstr
|
||||
|
||||
def getHtml(path):
|
||||
htmlstr = '<div id="jstree">'
|
||||
try:
|
||||
# 在这里把最开始的目录给加上
|
||||
global project_name,project_id
|
||||
project_name = path.split("/")[-1]
|
||||
project_id = str(Project.objects.get(name=project_name).pk)
|
||||
|
||||
ondbclick_str = '<text ondblclick=add_tab("%s","%s","%s")>' %(project_id,"",project_name)
|
||||
ondbclick_str += (project_name+"</text>")
|
||||
htmlstr += "<ul><li>"+ ondbclick_str
|
||||
htmlstr += genetree(path,"")
|
||||
htmlstr += "</li></ul>"
|
||||
except:
|
||||
htmlstr += genetree(path,"")
|
||||
finally:
|
||||
htmlstr += "</div>"
|
||||
return htmlstr
|
||||
def record_path_and_id(self,path):
|
||||
self.path_id_map[path] = "j1_"+str(self.count)
|
||||
self.count = self.count + 1
|
|
@ -1299,7 +1299,13 @@ window.onload = function () {
|
|||
// 展开当前标签对应的节点
|
||||
// $('#jstree').jstree("deselect_all", true);
|
||||
// $('#jstree').jstree("select_node", "j1_1355554");
|
||||
// 第一个标签页对应的id,保存在first_tabs_jstree_id中
|
||||
var first_tabs_jstree_id = $("#first_tabs_jstree_id").text()
|
||||
path_after = path_predeal(data.path)
|
||||
tree_nodes[path_after] = first_tabs_jstree_id
|
||||
add_tab(data.project_id, data.path, data.filename)
|
||||
tree_nodes[path_after] = first_tabs_jstree_id
|
||||
//
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -139,6 +139,8 @@
|
|||
</div>
|
||||
</div>
|
||||
<span id="projectName">{{ project.name }}</span>
|
||||
<span id="first_tabs_jstree_id">{{ first_tabs_jstree_id }}</span>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue