add url get_project_tree
This commit is contained in:
parent
70fcf931fa
commit
b28fdf8edf
|
@ -17,7 +17,7 @@ Including another URLconf
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from .views import ShowIssueQuestionView, ShowAnnotationView, ShowNavigationView
|
from .views import ShowIssueQuestionView, ShowAnnotationView, ShowNavigationView
|
||||||
from .views import AddAnnotationView, AddArticleView, AddQuestionView, AddIssueAnswerView, AddCommentView
|
from .views import AddAnnotationView, AddArticleView, AddQuestionView, AddIssueAnswerView, AddCommentView
|
||||||
from .views import UpdateAnnotationView, UpdateArticleView, UpdateQuestionView, UpdateAnswerView, UpdateCommentView,RightView
|
from .views import UpdateAnnotationView, UpdateArticleView, UpdateQuestionView, UpdateAnswerView, UpdateCommentView,RightView,GetProjectTreeView
|
||||||
from .views import AddVoteView, AcceptAnswerView, ShowMethodInfo, GetHotestIssuesView, Get_CodeReading_Content_View, AddQuestionAnswerView, GetAddtabParasView,ModifyAnnotationView
|
from .views import AddVoteView, AcceptAnswerView, ShowMethodInfo, GetHotestIssuesView, Get_CodeReading_Content_View, AddQuestionAnswerView, GetAddtabParasView,ModifyAnnotationView
|
||||||
|
|
||||||
app_name = "operations"
|
app_name = "operations"
|
||||||
|
@ -43,5 +43,8 @@ urlpatterns = [
|
||||||
path('add_question_answer/',AddQuestionAnswerView.as_view(), name='add_question_answer/'),
|
path('add_question_answer/',AddQuestionAnswerView.as_view(), name='add_question_answer/'),
|
||||||
path('get_addtab_paras/', GetAddtabParasView.as_view(),name='get_addtab_paras/'),
|
path('get_addtab_paras/', GetAddtabParasView.as_view(),name='get_addtab_paras/'),
|
||||||
path('modify_anno/', ModifyAnnotationView.as_view(),name='modify_anno/'),
|
path('modify_anno/', ModifyAnnotationView.as_view(),name='modify_anno/'),
|
||||||
path('right/',RightView.as_view(),name='right/')
|
path('right/',RightView.as_view(),name='right/'),
|
||||||
|
path('get_project_tree/',GetProjectTreeView.as_view(),name='get_project_tree/'),
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1141,7 +1141,7 @@ def get_fileid_name_anno_issue(files):
|
||||||
for file in files:
|
for file in files:
|
||||||
anno_length = len(Annotation.objects.filter(file=file,is_latest=1))
|
anno_length = len(Annotation.objects.filter(file=file,is_latest=1))
|
||||||
annoted_file_annonum_map[file]=anno_length
|
annoted_file_annonum_map[file]=anno_length
|
||||||
print(anno_length)
|
# print(anno_length)
|
||||||
|
|
||||||
annoted_file_annonum_list = sorted(annoted_file_annonum_map.items(), key=lambda annoted_file_annonum_map:annoted_file_annonum_map[1],reverse=True)
|
annoted_file_annonum_list = sorted(annoted_file_annonum_map.items(), key=lambda annoted_file_annonum_map:annoted_file_annonum_map[1],reverse=True)
|
||||||
# 返回前5个
|
# 返回前5个
|
||||||
|
@ -1167,38 +1167,47 @@ def getQuestionByFileId():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def get_url_mapping_project(url):
|
||||||
|
index = url.find("projects/")
|
||||||
|
# 获取projects/后面的字符串
|
||||||
|
url = url[index+len("projects/"):]
|
||||||
|
|
||||||
|
index1 = url.find("/")
|
||||||
|
|
||||||
|
projectName = url[0:index1]
|
||||||
|
index = url.rfind("/")
|
||||||
|
if url.endswith("/"):
|
||||||
|
path = url[index1:-1]
|
||||||
|
if path=="":
|
||||||
|
filename=projectName
|
||||||
|
else:
|
||||||
|
filename = url[index+1:-1]
|
||||||
|
else:
|
||||||
|
path = url[index1:]
|
||||||
|
filename = url[index+1:]
|
||||||
|
|
||||||
|
project = Project.objects.get(name=projectName)
|
||||||
|
return project,path,filename
|
||||||
|
|
||||||
class GetAddtabParasView(View):
|
class GetAddtabParasView(View):
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
url = request.POST.get('url','')
|
url = request.POST.get('url','')
|
||||||
index = url.find("projects/")
|
project,path,filename = get_url_mapping_project(url)
|
||||||
# 获取projects/后面的字符串
|
path_id_map = projectTreeObj.get_project_pathidmap_by_projectid(project.id)
|
||||||
url = url[index+len("projects/"):]
|
|
||||||
|
|
||||||
index1 = url.find("/")
|
|
||||||
|
|
||||||
projectName = url[0:index1]
|
|
||||||
index = url.rfind("/")
|
|
||||||
if url.endswith("/"):
|
|
||||||
path = url[index1:-1]
|
|
||||||
if path=="":
|
|
||||||
filename=projectName
|
|
||||||
else:
|
|
||||||
filename = url[index+1:-1]
|
|
||||||
else:
|
|
||||||
path = url[index1:]
|
|
||||||
filename = url[index+1:]
|
|
||||||
|
|
||||||
project = Project.objects.get(name=projectName)
|
|
||||||
|
|
||||||
from utils import get_project_tree
|
|
||||||
project_tree_obj = get_project_tree.ProjectTree()
|
|
||||||
project_tree = project_tree_obj.getHtml(settings.SOURCEPATH+project.path)
|
|
||||||
if path == "/":
|
if path == "/":
|
||||||
first_tabs_jstree_id = project_tree_obj.path_id_map[""]
|
first_tabs_jstree_id = path_id_map[""]
|
||||||
else:
|
else:
|
||||||
first_tabs_jstree_id = project_tree_obj.path_id_map[path]
|
first_tabs_jstree_id = path_id_map[path]
|
||||||
|
return HttpResponse(json.dumps({"status": "success", "project_id": project.id,"path":path,"filename":filename,"project_jstree_map":path_id_map,"first_tabs_jstree_id":first_tabs_jstree_id}), content_type='application/json')
|
||||||
|
|
||||||
return HttpResponse(json.dumps({"status": "success", "project_id": project.id,"path":path,"filename":filename,"project_jstree_map":project_tree_obj.path_id_map,"first_tabs_jstree_id":first_tabs_jstree_id}), content_type='application/json')
|
# from utils import get_project_tree
|
||||||
|
# project_tree_obj = get_project_tree.ProjectTree()
|
||||||
|
# project_tree = project_tree_obj.getHtml(settings.SOURCEPATH+project.path)
|
||||||
|
# if path == "/":
|
||||||
|
# first_tabs_jstree_id = project_tree_obj.path_id_map[""]
|
||||||
|
# else:
|
||||||
|
# first_tabs_jstree_id = project_tree_obj.path_id_map[path]
|
||||||
|
# return HttpResponse(json.dumps({"status": "success", "project_id": project.id,"path":path,"filename":filename,"project_jstree_map":project_tree_obj.path_id_map,"first_tabs_jstree_id":first_tabs_jstree_id}), content_type='application/json')
|
||||||
|
|
||||||
# 可能len(all_symbol)==3对于除了java外其他编程语言会有问题
|
# 可能len(all_symbol)==3对于除了java外其他编程语言会有问题
|
||||||
def getMethodNum(project_path,file_path):
|
def getMethodNum(project_path,file_path):
|
||||||
|
@ -1300,4 +1309,18 @@ class RightView(View):
|
||||||
html_str = self.get_file_right_content(project_path,file_path,file.pk)
|
html_str = self.get_file_right_content(project_path,file_path,file.pk)
|
||||||
|
|
||||||
return HttpResponse(json.dumps({"status": "success", "html_str": html_str}), content_type='application/json')
|
return HttpResponse(json.dumps({"status": "success", "html_str": html_str}), content_type='application/json')
|
||||||
|
|
||||||
|
|
||||||
|
from utils.models import projectTreeObj
|
||||||
|
class GetProjectTreeView(View):
|
||||||
|
def post(self, request):
|
||||||
|
# 先判断他是文件还是文件夹
|
||||||
|
try:
|
||||||
|
url = request.POST.get('url', '')
|
||||||
|
project,_,_= get_url_mapping_project(url)
|
||||||
|
project_jstree = projectTreeObj.get_project_tree_by_projectid(project.id)
|
||||||
|
path_id_map = projectTreeObj.get_project_pathidmap_by_projectid(project.id)
|
||||||
|
return HttpResponse(json.dumps({"status": "success","project_jstree":project_jstree}), content_type='application/json')
|
||||||
|
except:
|
||||||
|
return HttpResponse(json.dumps({"status": "fail"}), content_type='application/json')
|
||||||
|
|
|
@ -163,8 +163,8 @@ class ProjectInfoView(View):
|
||||||
class ProjectSourceView(View):
|
class ProjectSourceView(View):
|
||||||
def get(self, request, name, path):
|
def get(self, request, name, path):
|
||||||
project = Project.objects.filter(name=name).first()
|
project = Project.objects.filter(name=name).first()
|
||||||
project_tree_obj = get_project_tree.ProjectTree()
|
# project_tree_obj = get_project_tree.ProjectTree()
|
||||||
project_tree = project_tree_obj.getHtml(settings.SOURCEPATH+project.path)
|
# project_tree = project_tree_obj.getHtml(settings.SOURCEPATH+project.path)
|
||||||
return render(request, 'projects/source.html', locals())
|
return render(request, 'projects/source.html', locals())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
from utils import get_project_tree,scanner_project
|
||||||
|
from django.conf import settings
|
||||||
|
from projects.models import Project
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectTreeMap:
|
||||||
|
def __init__(self):
|
||||||
|
print("init")
|
||||||
|
self._tree_map = {}
|
||||||
|
|
||||||
|
def get_project_tree_by_projectid(self,project_id):
|
||||||
|
if project_id in self._tree_map:
|
||||||
|
return self._tree_map[project_id]["tree"]
|
||||||
|
else:
|
||||||
|
obj = get_project_tree.ProjectTree()
|
||||||
|
project = Project.objects.get(id=project_id)
|
||||||
|
tree = obj.getHtml(settings.SOURCEPATH+project.path)
|
||||||
|
path_id_map = obj.path_id_map
|
||||||
|
self._tree_map[project_id]={"tree":tree,"path_id_map":path_id_map}
|
||||||
|
return self._tree_map[project_id]["tree"]
|
||||||
|
|
||||||
|
def get_project_pathidmap_by_projectid(self,project_id):
|
||||||
|
if project_id in self._tree_map:
|
||||||
|
return self._tree_map[project_id]["path_id_map"]
|
||||||
|
else:
|
||||||
|
obj = get_project_tree.ProjectTree()
|
||||||
|
project = Project.objects.get(id=project_id)
|
||||||
|
tree = obj.getHtml(settings.SOURCEPATH+project.path)
|
||||||
|
path_id_map = obj.path_id_map
|
||||||
|
self._tree_map[project_id]={"tree":tree,"path_id_map":path_id_map}
|
||||||
|
return self._tree_map[project_id]["path_id_map"]
|
||||||
|
|
||||||
|
projectTreeObj = ProjectTreeMap()
|
|
@ -1446,7 +1446,35 @@ var project_jstree_map={}
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
url = window.location.href;
|
url = window.location.href;
|
||||||
$('#jstree').jstree();
|
var project_id=-1
|
||||||
|
var path = ""
|
||||||
|
var filename = ""
|
||||||
|
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
cache: false,
|
||||||
|
type: "POST",
|
||||||
|
url: '/operations/get_project_tree/',
|
||||||
|
data: { 'url': url },
|
||||||
|
dataType: 'json',
|
||||||
|
async: true,
|
||||||
|
beforeSend: function (xhr, settings) {
|
||||||
|
xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
if (data.status === 'success') {
|
||||||
|
// 展开当前标签对应的节点
|
||||||
|
project_tree_html = data.project_jstree
|
||||||
|
document.getElementById("filelist-content").innerHTML = project_tree_html
|
||||||
|
// while(project_id==-1){
|
||||||
|
|
||||||
|
// }
|
||||||
|
$('#jstree').jstree();
|
||||||
|
add_tab(project_id,path,filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
|
@ -1461,9 +1489,6 @@ window.onload = function () {
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.status === 'success') {
|
if (data.status === 'success') {
|
||||||
// 展开当前标签对应的节点
|
// 展开当前标签对应的节点
|
||||||
// $('#jstree').jstree("deselect_all", true);
|
|
||||||
// $('#jstree').jstree("select_node", "j1_1355554");
|
|
||||||
// 第一个标签页对应的id,保存在first_tabs_jstree_id中
|
|
||||||
project_jstree_map=data.project_jstree_map
|
project_jstree_map=data.project_jstree_map
|
||||||
|
|
||||||
var first_tabs_jstree_id = data.first_tabs_jstree_id
|
var first_tabs_jstree_id = data.first_tabs_jstree_id
|
||||||
|
@ -1477,6 +1502,11 @@ window.onload = function () {
|
||||||
path_after = path_predeal(path_input)
|
path_after = path_predeal(path_input)
|
||||||
// 加入tree_nodes中
|
// 加入tree_nodes中
|
||||||
tree_nodes[path_after] = first_tabs_jstree_id
|
tree_nodes[path_after] = first_tabs_jstree_id
|
||||||
|
|
||||||
|
project_id=data.project_id
|
||||||
|
path = data.path
|
||||||
|
filename = data.filename
|
||||||
|
|
||||||
add_tab(data.project_id, data.path, data.filename)
|
add_tab(data.project_id, data.path, data.filename)
|
||||||
// 特殊处理,因为add_tab的逻辑会影响tree_nodes(),所以进行了处理
|
// 特殊处理,因为add_tab的逻辑会影响tree_nodes(),所以进行了处理
|
||||||
tree_nodes[path_after] = first_tabs_jstree_id
|
tree_nodes[path_after] = first_tabs_jstree_id
|
||||||
|
|
Loading…
Reference in New Issue