diff --git a/apps/operations/views.py b/apps/operations/views.py
index 9383096..51d6cc1 100644
--- a/apps/operations/views.py
+++ b/apps/operations/views.py
@@ -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', '')
diff --git a/apps/projects/views.py b/apps/projects/views.py
index ea9214b..37f530f 100644
--- a/apps/projects/views.py
+++ b/apps/projects/views.py
@@ -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())
#文件列表页
diff --git a/apps/utils/get_project_tree.py b/apps/utils/get_project_tree.py
index 5266518..9d37bea 100644
--- a/apps/utils/get_project_tree.py
+++ b/apps/utils/get_project_tree.py
@@ -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 = "
"
- 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 = ""
+ 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 = '' %(project_id,relative_path,dirname)
+ ondbclick_str = '' %(project_id,relative_path,dirname)
+ ondbclick_str += (dirname +"")
+ self.record_path_and_id(relative_path)
+
+ # 形成li字符串
+ htmlstr += "- "+ondbclick_str
+ dir = os.path.join(path, dir)
+ htmlstr += self.genetree(dir,"",project_name,project_id)
+ htmlstr += "
"
+ # 循环遍历完毕,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 = '' %(project_id,relative_path,dirname)
- ondbclick_str = '' %(project_id,relative_path,dirname)
- ondbclick_str += (dirname +"")
-
- # 形成li字符串
- htmlstr += "- "+ondbclick_str
-
- dir = os.path.join(path, dir)
- htmlstr += genetree(dir,"")
- htmlstr += "
"
- # 循环遍历完毕,parentdirs应该设置为空
- if parentdirs != "":
- parentdirs = ""
-
- for file in files:
- # 合成ondbclick 字符串
- index = path.find(project_name)
- relative_path = path[index+len(project_name):]+"/"+file
- ondbclick_str = '' %(project_id,relative_path,file)
- ondbclick_str += (file +"")
- # 合成li
- htmlstr += "- "+ ondbclick_str+"
"
+ relative_path = path[index+len(project_name):]+"/"+file
+ ondbclick_str = '' %(project_id,relative_path,file)
+ ondbclick_str += (file +"")
+ # 合成li
+ htmlstr += "- "+ ondbclick_str+"
"
+ self.record_path_and_id(relative_path)
+
+ if isParentDirNull:
+ htmlstr += "
"
+ return htmlstr
- if isParentDirNull:
- htmlstr += "
"
- return htmlstr
+ def getHtml(self,path):
+ htmlstr = ''
+ try:
+ # 在这里把最开始的目录给加上
+ project_name = path.split("/")[-1]
+ project_id = str(Project.objects.get(name=project_name).pk)
+ relative_path = ""
+ ondbclick_str = '
' %(project_id,relative_path,project_name)
+ ondbclick_str += (project_name+"")
+
+ htmlstr += "
- "+ ondbclick_str
+ self.record_path_and_id(relative_path)
+ htmlstr += self.genetree(path,"",project_name,project_id)
+ htmlstr += "
"
+ except:
+ self.record_path_and_id(relative_path)
+ htmlstr += self.genetree(path,"",project_name,project_id)
+ finally:
+ htmlstr += "
"
+ return htmlstr
-def getHtml(path):
- htmlstr = ''
- try:
- # 在这里把最开始的目录给加上
- global project_name,project_id
- project_name = path.split("/")[-1]
- project_id = str(Project.objects.get(name=project_name).pk)
-
- ondbclick_str = '
' %(project_id,"",project_name)
- ondbclick_str += (project_name+"")
- htmlstr += "
- "+ ondbclick_str
- htmlstr += genetree(path,"")
- htmlstr += "
"
- except:
- htmlstr += genetree(path,"")
- finally:
- htmlstr += "
"
- return htmlstr
\ No newline at end of file
+ def record_path_and_id(self,path):
+ self.path_id_map[path] = "j1_"+str(self.count)
+ self.count = self.count + 1
\ No newline at end of file
diff --git a/static/js/source.js b/static/js/source.js
index ec95108..195b1a3 100644
--- a/static/js/source.js
+++ b/static/js/source.js
@@ -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
+ //
}
}
});
diff --git a/templates/projects/source.html b/templates/projects/source.html
index c74b3ae..4e6bf1b 100644
--- a/templates/projects/source.html
+++ b/templates/projects/source.html
@@ -139,6 +139,8 @@
{{ project.name }}
+ {{ first_tabs_jstree_id }}
+