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,10 +7,13 @@ from projects.models import Project
|
|||
# ondbclick的参数为:project_id,relative_path,以及文件名
|
||||
# 其中relative_path是相对于项目根路径的
|
||||
|
||||
project_name = ""
|
||||
project_id = ""
|
||||
#######获取当前层的文件夹和文件
|
||||
def getindex(path):
|
||||
class ProjectTree:
|
||||
def __init__(self):
|
||||
self.count = 1;
|
||||
self.path_id_map = {}
|
||||
|
||||
#######获取当前层的文件夹和文件
|
||||
def getindex(self,path):
|
||||
dirs=[]
|
||||
files=[]
|
||||
for file in os.listdir(path):
|
||||
|
@ -20,9 +23,9 @@ def getindex(path):
|
|||
files.append(file)
|
||||
return dirs,files
|
||||
|
||||
#####生成节点树##########
|
||||
def genetree(path,parentdirs):
|
||||
dirs,files=getindex(path)
|
||||
#####生成节点树##########
|
||||
def genetree(self,path,parentdirs,project_name,project_id):
|
||||
dirs,files=self.getindex(path)
|
||||
# 如果parentdir不为空,那么htmlstr应该为"",否则会有问题,建议上次提交时的文件
|
||||
if parentdirs =="":
|
||||
isParentDirNull=True
|
||||
|
@ -37,7 +40,7 @@ def genetree(path,parentdirs):
|
|||
if len(dirs)==1:
|
||||
parentdirs += (dirs[0] + os.sep)
|
||||
current_dir = os.path.join(path, dirs[0])
|
||||
htmlstr += genetree(current_dir,parentdirs)
|
||||
htmlstr += self.genetree(current_dir,parentdirs,project_name,project_id)
|
||||
else:
|
||||
for dir in dirs:
|
||||
# 合成ondbclick 字符串
|
||||
|
@ -47,12 +50,12 @@ def genetree(path,parentdirs):
|
|||
# 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 += genetree(dir,"")
|
||||
htmlstr += self.genetree(dir,"",project_name,project_id)
|
||||
htmlstr += "</li>"
|
||||
# 循环遍历完毕,parentdirs应该设置为空
|
||||
if parentdirs != "":
|
||||
|
@ -66,28 +69,35 @@ def genetree(path,parentdirs):
|
|||
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
|
||||
|
||||
|
||||
def getHtml(path):
|
||||
def getHtml(self,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)
|
||||
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
|
||||
htmlstr += genetree(path,"")
|
||||
self.record_path_and_id(relative_path)
|
||||
htmlstr += self.genetree(path,"",project_name,project_id)
|
||||
htmlstr += "</li></ul>"
|
||||
except:
|
||||
htmlstr += genetree(path,"")
|
||||
self.record_path_and_id(relative_path)
|
||||
htmlstr += self.genetree(path,"",project_name,project_id)
|
||||
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