fix jstree bug

This commit is contained in:
wrmswindmill 2018-10-08 11:50:20 +08:00
parent e04533890e
commit 26bdb5f4e7
2 changed files with 76 additions and 36 deletions

View File

@ -27,35 +27,63 @@ class ProjectTree:
def genetree(self,path,parentdirs,project_name,project_id):
dirs,files=self.getindex(path)
# 如果parentdir不为空那么htmlstr应该为"",否则会有问题,建议上次提交时的文件
flag = False
if parentdirs =="":
isParentDirNull=True
else:
isParentDirNull=False
if isParentDirNull:
htmlstr = "<ul>"
else:
isParentDirNull=False
htmlstr = ""
# if len(dirs)==0:
# index = path.find(project_name)
# relative_path = path[index+len(project_name):]
# dirname = parentdirs
# 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)
# htmlstr += ("<li>"+ondbclick_str+"<ul>")
# flag = True
# 处理多级单文件夹目录
# parentdir用来保存那个多级单文件父目录
if len(dirs)==1:
if len(dirs)==1 and len(files)==0:
parentdirs += (dirs[0] + os.sep)
current_dir = os.path.join(path, dirs[0])
# tmp_dirs,tmp_files=self.getindex(path)
# if len(tmp_dirs)==1 and len(tmp_files)!=0:
# htmlstr += self.genetree(current_dir,"",project_name,project_id)
# else:
htmlstr += self.genetree(current_dir,parentdirs,project_name,project_id)
else:
for dir in dirs:
# 合成ondbclick 字符串
if parentdirs!="":
flag = True
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)
relative_path = path[index+len(project_name):]
dirname = parentdirs
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)
htmlstr += "<li>"+ondbclick_str+"<ul>"
for current_dir in dirs:
# 合成ondbclick 字符串
index = path.find(project_name)
relative_path = path[index+len(project_name):]+"/"+current_dir
if not flag:
dirname = parentdirs + current_dir
else:
dirname = current_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)
# dirname = dirname.replace("/","%2F")
# relative_path = relative_path.replace("/","%2F")
ondbclick_str += (dirname +"</text>")
self.record_path_and_id(relative_path)
# if parentdirs!="":
# print(dirname)
# print(relative_path)
# 形成li字符串
htmlstr += "<li>"+ondbclick_str
dir = os.path.join(path, dir)
htmlstr += self.genetree(dir,"",project_name,project_id)
current_dir = os.path.join(path, current_dir)
htmlstr += self.genetree(current_dir,"",project_name,project_id)
htmlstr += "</li>"
# 循环遍历完毕parentdirs应该设置为空
if parentdirs != "":
@ -71,8 +99,14 @@ class ProjectTree:
htmlstr += "<li data-jstree='{\"icon\":\"fa fa-file-code-o color-blue\"}'>"+ ondbclick_str+"</li>"
self.record_path_and_id(relative_path)
if flag:
htmlstr+="</li></ul>"
if isParentDirNull:
htmlstr += "</ul>"
# if flag:
# htmlstr += "</ul></li>"
# print(htmlstr)
return htmlstr
@ -96,6 +130,7 @@ class ProjectTree:
htmlstr += self.genetree(path,"",project_name,project_id)
finally:
htmlstr += "</div>"
# print(htmlstr)
return htmlstr
def record_path_and_id(self,path):

View File

@ -1,4 +1,5 @@
var flag = true;//左侧默认显示
var jstree_load_complete = false
function hideModal(){
$("#popupAll").remove();
@ -1188,12 +1189,15 @@ function get_path_link_and_archor(path){
}
function change_jstree_position(path_after){
$('#jstree').jstree("deselect_all", true);
$('#jstree').jstree("select_node", tree_nodes[path_after]);
setTimeout(function timer() {
var offsettop=$("#"+tree_nodes[path_after]).position().top;
$("#filelist-content").scrollTop(offsettop);
},500)
if(jstree_load_complete){
console.log(1111)
$('#jstree').jstree("deselect_all", true);
$('#jstree').jstree("select_node", tree_nodes[path_after]);
// setTimeout(function timer() {
// var offsettop=$("#"+tree_nodes[path_after]).position().top;
// $("#filelist-content").scrollTop(offsettop);
// },500)
}
// var offsettop=$("#"+tree_nodes[path_after]).position().top;
// $("#filelist-content").scrollTop(offsettop);
}
@ -2077,11 +2081,11 @@ function load_jstree(project_id,path){
// jstree_content = LZString.decompress(compressed_content)
// init_jstree(project_id,path,jstree_content)
// }
jstree_content = getlocalStorage("jstree-"+projectName)
if(jstree_content != null){
init_jstree(project_id,path,jstree_content)
}
else{
// jstree_content = getlocalStorage("jstree-"+projectName)
// if(jstree_content != null){
// init_jstree(project_id,path,jstree_content)
// }
// else{
$.ajax({
cache: false,
type: "POST",
@ -2094,16 +2098,16 @@ function load_jstree(project_id,path){
},
success: function (data) {
if (data.status === 'success') {
try{
// compressed_content = LZString.compress(data.jstree_content)
// setlocalStorage("jstree-"+projectName,compressed_content)
remove_jstree_content()
setlocalStorage("jstree-"+projectName,data.jstree_content)
}catch(error){
console.log(error)
}finally{
init_jstree(project_id,path,data.jstree_content)
}
// try{
// // compressed_content = LZString.compress(data.jstree_content)
// // setlocalStorage("jstree-"+projectName,compressed_content)
// // remove_jstree_content()
// setlocalStorage("jstree-"+projectName,data.jstree_content)
// }catch(error){
// console.log(error)
// }finally{
init_jstree(project_id,path,data.jstree_content)
// }
}
},error:function(jqXHR, textStatus, errorThrown){
if(jqXHR.readyState===0&&jqXHR.status===0){
@ -2112,7 +2116,7 @@ function load_jstree(project_id,path){
}
});
}
}
// }
function init_jstree(project_id,path,content){
$("#filelist-content").html(content)
@ -2121,7 +2125,8 @@ function init_jstree(project_id,path,content){
$(".spinner").remove();
$("#jstree").jstree("open_node", $("#j1_1"));
$("#jstree").css("visibility","visible");
// highlight_jstree_node(project_id,path)
jstree_load_complete = true
highlight_jstree_node(project_id,path)
}
$(function(){