modify right area And add annoted_method
This commit is contained in:
parent
e30f722b1e
commit
91745b6870
|
@ -211,30 +211,33 @@ class ShowIssueQuestionView(View):
|
|||
else:
|
||||
return HttpResponse(json.dumps({"status": "success", "html_str": html_str}))
|
||||
|
||||
def get_navigation_content(project_path,file_path):
|
||||
navigation_url = settings.OPENGROK_NAVIGATION_URL
|
||||
navigation_url = navigation_url +project_path + file_path
|
||||
response = requests.get(navigation_url).text
|
||||
project_id = Project.objects.get(name=project_path)
|
||||
file_id = File.objects.get(project_id=project_id,path=file_path).pk
|
||||
response = response.replace("]],[","]]|[")
|
||||
if response:
|
||||
all_symbols = []
|
||||
for symbol in response.split("|"):
|
||||
symbol = json.loads(symbol)
|
||||
del symbol[1]
|
||||
all_symbols.append(symbol)
|
||||
return all_symbols,file_id
|
||||
|
||||
class ShowNavigationView(View):
|
||||
"""
|
||||
获取当前文件的Structure,也就是Package,Class,Method信息。
|
||||
"""
|
||||
def post(self, request):
|
||||
navigation_url = settings.OPENGROK_NAVIGATION_URL
|
||||
project_path = request.POST.get('project_path', '')
|
||||
file_path = request.POST.get('file_path', '')
|
||||
|
||||
navigation_url = navigation_url +project_path + file_path
|
||||
response = requests.get(navigation_url).text
|
||||
project_id = Project.objects.get(name=project_path)
|
||||
file_id = File.objects.get(project_id=project_id,path=file_path).pk
|
||||
response = response.replace("]],[","]]|[")
|
||||
if response:
|
||||
all_symbols = []
|
||||
for symbol in response.split("|"):
|
||||
try:
|
||||
symbol = json.loads(symbol)
|
||||
del symbol[1]
|
||||
all_symbols.append(symbol)
|
||||
except:
|
||||
return HttpResponse(json.dumps({"status": "failed", "msg": 'null'}), content_type='application/json')
|
||||
try:
|
||||
project_path = request.POST.get('project_path', '')
|
||||
file_path = request.POST.get('file_path', '')
|
||||
all_symbols,file_id = get_navigation_content(project_path,file_path)
|
||||
return HttpResponse(json.dumps({"status": "success", "msg": all_symbols,"file_id":file_id}), content_type='application/json')
|
||||
except:
|
||||
return HttpResponse(json.dumps({"status": "failed", "msg": 'null'}), content_type='application/json')
|
||||
else:
|
||||
return HttpResponse(json.dumps({"status": "failed", "msg": 'null'}), content_type='application/json')
|
||||
|
||||
|
@ -342,7 +345,7 @@ def get_currentfile_comment_anno(file,anno_content):
|
|||
def get_currentfile_language(file):
|
||||
if file.name.endswith(".py"):
|
||||
return "python"
|
||||
elif file.name.endswith(".html") or file.name.endswith(".xml") :
|
||||
elif file.name.endswith(".html"):
|
||||
return "html"
|
||||
elif file.name.endswith(".css"):
|
||||
return "css"
|
||||
|
@ -356,7 +359,8 @@ def get_currentfile_language(file):
|
|||
return "markdown"
|
||||
elif file.name.endswith(".go"):
|
||||
return "go"
|
||||
|
||||
else:
|
||||
return "txt"
|
||||
|
||||
|
||||
|
||||
|
@ -888,6 +892,9 @@ def get_code(request,project_id,path):
|
|||
|
||||
project = Project.objects.filter(id=project_id).first()
|
||||
file = File.objects.filter(path=path, project_id=project_id).first()
|
||||
file.views += 1
|
||||
file.save()
|
||||
|
||||
fileid = file.pk
|
||||
|
||||
annos = Annotation.objects.filter(file=file).values('linenum').annotate(nums=Count('linenum'))
|
||||
|
@ -989,6 +996,37 @@ def get_project_info(project_id):
|
|||
html_str = render_to_string('projects/filesub/dir_info.html', locals())
|
||||
return html_str
|
||||
|
||||
def get_files_method_lines(file_id):
|
||||
file = File.objects.get(id=file_id)
|
||||
file_path = file.path
|
||||
project_path = file.project.name
|
||||
lines=[]
|
||||
try:
|
||||
all_symbols,_ =get_navigation_content(project_path,file_path)
|
||||
for i in range(len(all_symbols)):
|
||||
symbol = all_symbols[i]
|
||||
if symbol[0]=='Method' or symbol[0]=='Function':
|
||||
for j in range(len(symbol[1])):
|
||||
lines.append(symbol[1][j][1])
|
||||
return lines
|
||||
except:
|
||||
return lines
|
||||
|
||||
def get_annoted_method_num(file_ids):
|
||||
# 获取annoted_method
|
||||
# 以file为基本单位
|
||||
# 1.获取method对应的行
|
||||
# 2.获取该行是否有注释
|
||||
annoted_method_num=0
|
||||
for i in range(len(file_ids)):
|
||||
file_id = file_ids[i]
|
||||
method_lines = get_files_method_lines(file_id)
|
||||
for j in range(len(method_lines)):
|
||||
current_line = method_lines[j]
|
||||
if Annotation.objects.filter(linenum=current_line) is not None:
|
||||
annoted_method_num = annoted_method_num + 1
|
||||
return annoted_method_num
|
||||
# 调用api接口
|
||||
|
||||
def get_dir_info(project_id,path):
|
||||
# 获取当前文件的注释总数以及问题总数
|
||||
|
@ -1009,9 +1047,10 @@ def get_dir_info(project_id,path):
|
|||
fileid_questionnum = Question.objects.filter(file_id__in=file_ids).values('file_id').annotate(question_num=Count('file_id'))
|
||||
usersum = len(annos.values('user_id').annotate(user_num=Count('user_id')))
|
||||
|
||||
annoted_method_num= get_annoted_method_num(file_ids)
|
||||
|
||||
anno_sum,issue_sum,question_sum=0,0,0
|
||||
anno_filenum=0
|
||||
|
||||
for i in range(len(fileid_annonum)):
|
||||
anno_filenum +=1
|
||||
current_file_id = fileid_annonum[i]['file_id']
|
||||
|
@ -1028,9 +1067,12 @@ def get_dir_info(project_id,path):
|
|||
for i in range(len(fileid_questionnum)):
|
||||
question_sum += fileid_questionnum[i]['question_num']
|
||||
|
||||
issue_question_sum = issue_sum + question_sum
|
||||
|
||||
anno_num = len(Annotation.objects.filter(file_id=file_id))
|
||||
question_num = len(Question.objects.filter(file_id=file_id))
|
||||
|
||||
|
||||
current_file_summary = FileSummary.objects.get(project_id=project_id,current_path=path)
|
||||
line_sum = current_file_summary.line_num
|
||||
method_sum = current_file_summary.method_num
|
||||
|
@ -1105,9 +1147,49 @@ def getFileLineNum(project_path,file_path):
|
|||
|
||||
class RightView(View):
|
||||
|
||||
def get_file_right_content(self,project_path,file_path,file_id):
|
||||
# 获取方法个数
|
||||
def get_dir_right_content(self,file_id):
|
||||
isdir = True
|
||||
file = File.objects.get(id=file_id)
|
||||
project_id = file.project.id
|
||||
path = file.path
|
||||
anno_issue_summarys = FileSummary.objects.filter(project_id=project_id,parent_path=path)
|
||||
|
||||
#当前文件夹下所有的file_ids以及fileid与filename的映射
|
||||
file_ids = []
|
||||
for summary in anno_issue_summarys:
|
||||
file_ids.append(summary.file_id)
|
||||
|
||||
anno_num,issue_num,question_num=0,0,0
|
||||
|
||||
annos = Annotation.objects.filter(file_id__in=file_ids)
|
||||
fileid_annonum = annos.values('file_id').annotate(anno_num=Count('file_id'))
|
||||
for i in range(len(fileid_annonum)):
|
||||
anno_num += fileid_annonum[i]['anno_num']
|
||||
|
||||
fileid_issuenum = Issue.objects.filter(file_id__in=file_ids).values('file_id').annotate(issue_num=Count('file_id'))
|
||||
for i in range(len(fileid_issuenum)):
|
||||
issue_num += fileid_issuenum[i]['issue_num']
|
||||
|
||||
fileid_questionnum = Question.objects.filter(file_id__in=file_ids).values('file_id').annotate(question_num=Count('file_id'))
|
||||
for i in range(len(fileid_questionnum)):
|
||||
question_num += fileid_questionnum[i]['question_num']
|
||||
|
||||
view_num = 0
|
||||
for i in range(len(file_ids)):
|
||||
view_num += File.objects.get(id=file_ids[i]).views
|
||||
|
||||
issue_question_num = issue_num + question_num
|
||||
|
||||
current_file_summary = FileSummary.objects.get(project_id=project_id,current_path=path)
|
||||
filelinenum = current_file_summary.line_num
|
||||
create_time = file.create_time
|
||||
file_num = current_file_summary.file_num
|
||||
html_str = render_to_string('projects/filesub/file-right.html', locals())
|
||||
return html_str
|
||||
|
||||
def get_file_right_content(self,project_path,file_path,file_id):
|
||||
isdir = False
|
||||
# 获取方法个数
|
||||
method_num = getMethodNum(project_path,file_path);
|
||||
if method_num == -1:
|
||||
return ""
|
||||
|
@ -1123,8 +1205,17 @@ class RightView(View):
|
|||
issue_num = len(Issue.objects.filter(file_id=file_id))
|
||||
except:
|
||||
issue_num = 0
|
||||
try:
|
||||
question_num = len(Question.objects.filter(file_id=file_id))
|
||||
except:
|
||||
question_num = 0
|
||||
issue_question_num = issue_num + question_num
|
||||
|
||||
# 获得观看数
|
||||
view_num = 0
|
||||
file = File.objects.get(id=file_id)
|
||||
view_num = file.views
|
||||
create_time = file.create_time
|
||||
|
||||
# 观看数应该放在File_id中
|
||||
html_str = render_to_string('projects/filesub/file-right.html', locals())
|
||||
return html_str
|
||||
|
@ -1137,6 +1228,11 @@ class RightView(View):
|
|||
project_path = Project.objects.get(id=project_id).path
|
||||
file = File.objects.get(project_id=project_id,path=file_path)
|
||||
|
||||
html_str = self.get_file_right_content(project_path,file_path,file.pk)
|
||||
isDir = (len(FileSummary.objects.filter(project_id=project_id,parent_path=file_path))>0)
|
||||
if isDir:
|
||||
html_str = self.get_dir_right_content(file.id)
|
||||
else:
|
||||
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')
|
||||
|
|
@ -33,39 +33,40 @@
|
|||
<div class="clearfix filePathline">
|
||||
<span>
|
||||
<label>Num.of Files:</label>
|
||||
<label>{{line_sum}}</label>
|
||||
<label>{{file_sum}}</label>
|
||||
</span>
|
||||
<span>
|
||||
<label>Num.of Methods:</label>
|
||||
<label>{{method_sum}}</label>
|
||||
</span>
|
||||
<span>
|
||||
|
||||
<label>Lines of Code:</label>
|
||||
<label>{{file_sum}}</label>
|
||||
<label>{{line_sum}}</label>
|
||||
</span>
|
||||
</div>
|
||||
<div class="clearfix filePathline">
|
||||
<span>
|
||||
<label>Involved Users:</label>
|
||||
<label>{{anno_filenum}}</label>
|
||||
<label>{{usersum}}</label>
|
||||
</span>
|
||||
<span>
|
||||
<label>Annotated Files:</label>
|
||||
<label>{{issue_sum}}</label>
|
||||
<label>{{anno_filenum}}</label>
|
||||
</span>
|
||||
<span>
|
||||
<label>Annotated Methods:</label>
|
||||
<label>{{usersum}}</label>
|
||||
<label>{{annoted_method_num}}</label>
|
||||
</span>
|
||||
</div>
|
||||
<div class="clearfix filePathline">
|
||||
<span>
|
||||
<label>Num.of Questions:</label>
|
||||
<label>{{anno_sum}}</label>
|
||||
<label>{{ issue_question_sum }}</label>
|
||||
</span>
|
||||
<span>
|
||||
<label>Num.of Comments:</label>
|
||||
<label>{{question_sum}}</label>
|
||||
<label>Num.of Annotations:</label>
|
||||
<label>{{anno_sum}}</label>
|
||||
</span>
|
||||
{# <span>#}
|
||||
{# <label>最新标注文件数</label>#}
|
||||
|
@ -74,19 +75,18 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix mb10 mt10">
|
||||
<!-- <div class="clearfix mb10 mt10">
|
||||
<span class="fl font-20 colorFFF">Annotated Files</span>
|
||||
<p class="fr">
|
||||
<span class="fl mt7 info-nav active">Questions</span>
|
||||
<em class="ver-line"></em>
|
||||
<span class="fl mt7 info-nav">Comments</span>
|
||||
</p>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="filePathInfo">
|
||||
<div class="clearfix filePathline fileinfo-item">
|
||||
<span>File Name</span>
|
||||
<span>Num.of Annotations</span>
|
||||
<span>Num.of Comments</span>
|
||||
<span>Num.of Questions</span>
|
||||
</div>
|
||||
{% for fileid, name_anno_issue in fileid_name_anno_issue.items %}
|
||||
|
@ -100,7 +100,7 @@
|
|||
|
||||
|
||||
|
||||
<div class="clearfix mb10 mt10">
|
||||
<!-- <div class="clearfix mb10 mt10">
|
||||
<span class="fl font-20 colorFFF">Hot Questions</span>
|
||||
</div>
|
||||
<div class="filePathInfo">
|
||||
|
@ -113,5 +113,5 @@
|
|||
<span class="panel-left00">2</span>
|
||||
<span class="panel-left">测试测试测试测试测试测试</span>
|
||||
</p>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
|
@ -1,6 +1,10 @@
|
|||
<!-- 这个是文件的信息 -->
|
||||
<div class="middle-right-item">
|
||||
<p class="right-item-title">File Summary</p>
|
||||
{% if isdir %}
|
||||
<p class="right-item-title">Module Summary</p>
|
||||
{% else %}
|
||||
<p class="right-item-title">File Summary</p>
|
||||
{% endif %}
|
||||
|
||||
<p class="fr">
|
||||
<span class="fl mr15 mt7">
|
||||
|
@ -31,21 +35,27 @@
|
|||
</p>
|
||||
<p class="clearfix">
|
||||
<span class="panel-leftfontnew">Created:</span>
|
||||
<span class="panel-right">2018/06/06</span>
|
||||
<span class="panel-right">{{create_time}}</span>
|
||||
</p>
|
||||
<p class="clearfix">
|
||||
<div style="width:52%; float:left">
|
||||
<span class="panel-leftfontnew">lines:</span>
|
||||
<span class="panel-leftfontnew">Lines:</span>
|
||||
<span class="panel-right">{{filelinenum}}</span>
|
||||
</div>
|
||||
|
||||
<div style="width:48%; float:left">
|
||||
<span class="panel-leftfont">methods:</span>
|
||||
{% if isdir %}
|
||||
<div style="width:48%; float:left">
|
||||
<span class="panel-leftfont">Files:</span>
|
||||
<span class="panel-right">{{file_num}}</span>
|
||||
</div>
|
||||
{% else %}
|
||||
<div style="width:48%; float:left">
|
||||
<span class="panel-leftfont">Methods:</span>
|
||||
<span class="panel-right">{{method_num}}</span>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
<div style="width:52%; float:left">
|
||||
<span class="panel-leftfontnew">views:</span>
|
||||
<span class="panel-leftfontnew">Views:</span>
|
||||
<span class="panel-right">{{view_num}}</span>
|
||||
</div>
|
||||
|
||||
|
@ -56,7 +66,7 @@
|
|||
|
||||
<div style="width:52%; float:left">
|
||||
<span class="panel-leftfontnew">Ques:</span>
|
||||
<span class="panel-right">{{issue_num}}</span>
|
||||
<span class="panel-right">{{ issue_question_num}}</span>
|
||||
</div>
|
||||
<div class="both"></div>
|
||||
</p>
|
||||
|
|
Loading…
Reference in New Issue