From aa4c7bdea49d9b19740ff636bd2f6ca44f0b04df Mon Sep 17 00:00:00 2001 From: wrmswindmill Date: Wed, 15 Aug 2018 09:53:44 +0800 Subject: [PATCH] =?UTF-8?q?FIXBUG=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=89=93?= =?UTF-8?q?=E5=BC=80=E7=AC=AC=E4=B8=80=E4=B8=AA=E6=A0=87=E7=AD=BE=E5=90=8E?= =?UTF-8?q?=E5=B7=A6=E4=BE=A7=E6=96=87=E6=A1=A3=E6=A0=91=E4=B8=8D=E5=B1=95?= =?UTF-8?q?=E5=BC=80=E7=9A=84BUG=20=E8=A7=A3=E5=86=B3=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=9A=20=E7=94=B1=E4=BA=8Ejstree=E5=9C=A8=E6=9C=AA=E6=8C=87?= =?UTF-8?q?=E5=AE=9Ali=E7=9A=84id=E6=97=B6=EF=BC=8Cid=E7=94=9F=E6=98=AF?= =?UTF-8?q?=E7=94=B1=E8=A7=84=E5=BE=8B=E7=9A=84=EF=BC=8C=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=94=9F=E6=88=90=E7=9A=84li=E4=B8=BAj1=5F1=EF=BC=8C?= =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E4=B8=AA=E4=B8=BAj1=5F2,=E4=BB=A5=E6=AD=A4?= =?UTF-8?q?=E7=B1=BB=E6=8E=A8=20jstree=E6=98=AF=E9=80=9A=E8=BF=87=E6=B7=B1?= =?UTF-8?q?=E5=BA=A6=E4=BC=98=E5=85=88=E6=90=9C=E7=B4=A2=E9=81=8D=E5=8E=86?= =?UTF-8?q?=E7=9A=84=EF=BC=8C=E5=9C=A8=E9=81=8D=E5=8E=86=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E5=8F=88=E4=BC=9A=E6=8F=90=E4=BE=9B=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E7=9A=84relative=5Fpath=20=E5=9B=A0=E6=AD=A4?= =?UTF-8?q?=E5=9C=A8=E9=81=8D=E5=8E=86=E6=97=B6=E8=AE=B0=E5=BD=95=E4=BA=86?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=AF=B9=E5=BA=94=E7=9A=84jstree=5Fid?= =?UTF-8?q?=EF=BC=8C=E7=84=B6=E5=90=8E=E8=BF=94=E5=9B=9E=20=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/operations/views.py | 3 - apps/projects/views.py | 6 +- apps/utils/get_project_tree.py | 164 +++++++++++++++++---------------- static/js/source.js | 6 ++ templates/projects/source.html | 2 + 5 files changed, 98 insertions(+), 83 deletions(-) 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 = "" - 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 += "" + 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 += "" - 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 }} + \ No newline at end of file