fix jstree bug
This commit is contained in:
parent
e04533890e
commit
26bdb5f4e7
|
@ -27,35 +27,63 @@ class ProjectTree:
|
||||||
def genetree(self,path,parentdirs,project_name,project_id):
|
def genetree(self,path,parentdirs,project_name,project_id):
|
||||||
dirs,files=self.getindex(path)
|
dirs,files=self.getindex(path)
|
||||||
# 如果parentdir不为空,那么htmlstr应该为"",否则会有问题,建议上次提交时的文件
|
# 如果parentdir不为空,那么htmlstr应该为"",否则会有问题,建议上次提交时的文件
|
||||||
|
flag = False
|
||||||
if parentdirs =="":
|
if parentdirs =="":
|
||||||
isParentDirNull=True
|
isParentDirNull=True
|
||||||
else:
|
|
||||||
isParentDirNull=False
|
|
||||||
if isParentDirNull:
|
|
||||||
htmlstr = "<ul>"
|
htmlstr = "<ul>"
|
||||||
else:
|
else:
|
||||||
|
isParentDirNull=False
|
||||||
htmlstr = ""
|
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用来保存那个多级单文件父目录
|
# parentdir用来保存那个多级单文件父目录
|
||||||
if len(dirs)==1:
|
if len(dirs)==1 and len(files)==0:
|
||||||
parentdirs += (dirs[0] + os.sep)
|
parentdirs += (dirs[0] + os.sep)
|
||||||
current_dir = os.path.join(path, dirs[0])
|
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)
|
htmlstr += self.genetree(current_dir,parentdirs,project_name,project_id)
|
||||||
else:
|
else:
|
||||||
for dir in dirs:
|
if parentdirs!="":
|
||||||
# 合成ondbclick 字符串
|
flag = True
|
||||||
index = path.find(project_name)
|
index = path.find(project_name)
|
||||||
relative_path = path[index+len(project_name):]+"/"+dir
|
relative_path = path[index+len(project_name):]
|
||||||
dirname = parentdirs + dir
|
dirname = 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 = '<text ondblclick=add_tab("%s","%s","%s")>' %(project_id,relative_path,dirname)
|
||||||
ondbclick_str += (dirname +"</text>")
|
ondbclick_str += (dirname +"</text>")
|
||||||
self.record_path_and_id(relative_path)
|
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字符串
|
# 形成li字符串
|
||||||
htmlstr += "<li>"+ondbclick_str
|
htmlstr += "<li>"+ondbclick_str
|
||||||
dir = os.path.join(path, dir)
|
current_dir = os.path.join(path, current_dir)
|
||||||
htmlstr += self.genetree(dir,"",project_name,project_id)
|
htmlstr += self.genetree(current_dir,"",project_name,project_id)
|
||||||
htmlstr += "</li>"
|
htmlstr += "</li>"
|
||||||
# 循环遍历完毕,parentdirs应该设置为空
|
# 循环遍历完毕,parentdirs应该设置为空
|
||||||
if parentdirs != "":
|
if parentdirs != "":
|
||||||
|
@ -71,8 +99,14 @@ class ProjectTree:
|
||||||
htmlstr += "<li data-jstree='{\"icon\":\"fa fa-file-code-o color-blue\"}'>"+ ondbclick_str+"</li>"
|
htmlstr += "<li data-jstree='{\"icon\":\"fa fa-file-code-o color-blue\"}'>"+ ondbclick_str+"</li>"
|
||||||
self.record_path_and_id(relative_path)
|
self.record_path_and_id(relative_path)
|
||||||
|
|
||||||
|
if flag:
|
||||||
|
htmlstr+="</li></ul>"
|
||||||
|
|
||||||
if isParentDirNull:
|
if isParentDirNull:
|
||||||
htmlstr += "</ul>"
|
htmlstr += "</ul>"
|
||||||
|
# if flag:
|
||||||
|
# htmlstr += "</ul></li>"
|
||||||
|
# print(htmlstr)
|
||||||
return htmlstr
|
return htmlstr
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,6 +130,7 @@ class ProjectTree:
|
||||||
htmlstr += self.genetree(path,"",project_name,project_id)
|
htmlstr += self.genetree(path,"",project_name,project_id)
|
||||||
finally:
|
finally:
|
||||||
htmlstr += "</div>"
|
htmlstr += "</div>"
|
||||||
|
# print(htmlstr)
|
||||||
return htmlstr
|
return htmlstr
|
||||||
|
|
||||||
def record_path_and_id(self,path):
|
def record_path_and_id(self,path):
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
var flag = true;//左侧默认显示
|
var flag = true;//左侧默认显示
|
||||||
|
var jstree_load_complete = false
|
||||||
|
|
||||||
function hideModal(){
|
function hideModal(){
|
||||||
$("#popupAll").remove();
|
$("#popupAll").remove();
|
||||||
|
@ -1188,12 +1189,15 @@ function get_path_link_and_archor(path){
|
||||||
}
|
}
|
||||||
|
|
||||||
function change_jstree_position(path_after){
|
function change_jstree_position(path_after){
|
||||||
$('#jstree').jstree("deselect_all", true);
|
if(jstree_load_complete){
|
||||||
$('#jstree').jstree("select_node", tree_nodes[path_after]);
|
console.log(1111)
|
||||||
setTimeout(function timer() {
|
$('#jstree').jstree("deselect_all", true);
|
||||||
var offsettop=$("#"+tree_nodes[path_after]).position().top;
|
$('#jstree').jstree("select_node", tree_nodes[path_after]);
|
||||||
$("#filelist-content").scrollTop(offsettop);
|
// setTimeout(function timer() {
|
||||||
},500)
|
// var offsettop=$("#"+tree_nodes[path_after]).position().top;
|
||||||
|
// $("#filelist-content").scrollTop(offsettop);
|
||||||
|
// },500)
|
||||||
|
}
|
||||||
// var offsettop=$("#"+tree_nodes[path_after]).position().top;
|
// var offsettop=$("#"+tree_nodes[path_after]).position().top;
|
||||||
// $("#filelist-content").scrollTop(offsettop);
|
// $("#filelist-content").scrollTop(offsettop);
|
||||||
}
|
}
|
||||||
|
@ -2077,11 +2081,11 @@ function load_jstree(project_id,path){
|
||||||
// jstree_content = LZString.decompress(compressed_content)
|
// jstree_content = LZString.decompress(compressed_content)
|
||||||
// init_jstree(project_id,path,jstree_content)
|
// init_jstree(project_id,path,jstree_content)
|
||||||
// }
|
// }
|
||||||
jstree_content = getlocalStorage("jstree-"+projectName)
|
// jstree_content = getlocalStorage("jstree-"+projectName)
|
||||||
if(jstree_content != null){
|
// if(jstree_content != null){
|
||||||
init_jstree(project_id,path,jstree_content)
|
// init_jstree(project_id,path,jstree_content)
|
||||||
}
|
// }
|
||||||
else{
|
// else{
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
@ -2094,16 +2098,16 @@ function load_jstree(project_id,path){
|
||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.status === 'success') {
|
if (data.status === 'success') {
|
||||||
try{
|
// try{
|
||||||
// compressed_content = LZString.compress(data.jstree_content)
|
// // compressed_content = LZString.compress(data.jstree_content)
|
||||||
// setlocalStorage("jstree-"+projectName,compressed_content)
|
// // setlocalStorage("jstree-"+projectName,compressed_content)
|
||||||
remove_jstree_content()
|
// // remove_jstree_content()
|
||||||
setlocalStorage("jstree-"+projectName,data.jstree_content)
|
// setlocalStorage("jstree-"+projectName,data.jstree_content)
|
||||||
}catch(error){
|
// }catch(error){
|
||||||
console.log(error)
|
// console.log(error)
|
||||||
}finally{
|
// }finally{
|
||||||
init_jstree(project_id,path,data.jstree_content)
|
init_jstree(project_id,path,data.jstree_content)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
},error:function(jqXHR, textStatus, errorThrown){
|
},error:function(jqXHR, textStatus, errorThrown){
|
||||||
if(jqXHR.readyState===0&&jqXHR.status===0){
|
if(jqXHR.readyState===0&&jqXHR.status===0){
|
||||||
|
@ -2112,7 +2116,7 @@ function load_jstree(project_id,path){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
|
|
||||||
function init_jstree(project_id,path,content){
|
function init_jstree(project_id,path,content){
|
||||||
$("#filelist-content").html(content)
|
$("#filelist-content").html(content)
|
||||||
|
@ -2121,7 +2125,8 @@ function init_jstree(project_id,path,content){
|
||||||
$(".spinner").remove();
|
$(".spinner").remove();
|
||||||
$("#jstree").jstree("open_node", $("#j1_1"));
|
$("#jstree").jstree("open_node", $("#j1_1"));
|
||||||
$("#jstree").css("visibility","visible");
|
$("#jstree").css("visibility","visible");
|
||||||
// highlight_jstree_node(project_id,path)
|
jstree_load_complete = true
|
||||||
|
highlight_jstree_node(project_id,path)
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|
Loading…
Reference in New Issue