This commit is contained in:
parent
788c917766
commit
35b5c53b11
|
@ -0,0 +1,32 @@
|
|||
# Generated by Django 2.0.6 on 2018-09-05 15:06
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('projects', '0018_auto_20180904_1055'),
|
||||
('operations', '0016_annotation_modify_user_id'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Search_Answer',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('path_and_lineno', models.CharField(max_length=255)),
|
||||
('answer_type', models.CharField(choices=[('right', '正确'), ('wrong', '错误')], default='right', max_length=5)),
|
||||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.Project', verbose_name='项目')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='用户')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '搜索结果',
|
||||
'verbose_name_plural': '搜索结果',
|
||||
'db_table': 'Search_Answer',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,25 @@
|
|||
# Generated by Django 2.0.6 on 2018-09-05 16:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('operations', '0017_search_answer'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='search_answer',
|
||||
name='function_name',
|
||||
field=models.CharField(default='\x08\x081', max_length=100),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='search_answer',
|
||||
name='line_num',
|
||||
field=models.IntegerField(default=1, verbose_name='Search Answer对应的源搜索的行'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.0.6 on 2018-09-05 16:14
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('operations', '0018_auto_20180905_1605'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='search_answer',
|
||||
old_name='line_num',
|
||||
new_name='linenum',
|
||||
),
|
||||
]
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 2.0.6 on 2018-09-05 16:25
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('projects', '0018_auto_20180904_1055'),
|
||||
('operations', '0019_auto_20180905_1614'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='search_answer',
|
||||
name='file',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='projects.File', verbose_name='文件'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 2.0.6 on 2018-09-05 16:27
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('operations', '0020_search_answer_file'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='search_answer',
|
||||
name='project',
|
||||
),
|
||||
]
|
|
@ -42,6 +42,24 @@ class NotAllowModify(models.Model):
|
|||
def __str__(self):
|
||||
return 'NotAllowModify{0}'.format(self.id)
|
||||
|
||||
class Search_Answer(models.Model):
|
||||
STATE_CHOICE = [
|
||||
('right', '正确'),
|
||||
('wrong', '错误'),
|
||||
]
|
||||
|
||||
path_and_lineno = models.CharField(max_length=255)
|
||||
answer_type = models.CharField(max_length=5, choices=STATE_CHOICE,default='right')
|
||||
user = models.ForeignKey(User, verbose_name='用户',on_delete=models.CASCADE)
|
||||
linenum = models.IntegerField(verbose_name='Search Answer对应的源搜索的行')
|
||||
function_name = models.CharField(max_length=100)
|
||||
file = models.ForeignKey(File, verbose_name='文件',on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
db_table = 'Search_Answer'
|
||||
verbose_name = "搜索结果"
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
class Annotation(models.Model):
|
||||
"""
|
||||
标注类
|
||||
|
|
|
@ -16,7 +16,7 @@ Including another URLconf
|
|||
|
||||
from django.urls import path
|
||||
from .views import ShowIssueQuestionView, ShowAnnotationView, ShowNavigationView
|
||||
from .views import AddAnnotationView, AddArticleView, AddQuestionView, AddIssueAnswerView, AddCommentView
|
||||
from .views import AddAnnotationView, AddArticleView, AddQuestionView, AddIssueAnswerView, AddCommentView,Collect_Search_Answer
|
||||
from .views import UpdateAnnotationView, UpdateArticleView, UpdateQuestionView, UpdateAnswerView, UpdateCommentView,RightView,GetJstreeIdView
|
||||
from .views import AddVoteView, AcceptAnswerView, ShowMethodInfo, GetHotestIssuesView, Get_CodeReading_Content_View, AddQuestionAnswerView, GetAddtabParasView,ModifyAnnotationView
|
||||
|
||||
|
@ -44,5 +44,6 @@ urlpatterns = [
|
|||
path('get_addtab_paras/', GetAddtabParasView.as_view(),name='get_addtab_paras/'),
|
||||
path('modify_anno/', ModifyAnnotationView.as_view(),name='modify_anno/'),
|
||||
path('right/',RightView.as_view(),name='right/'),
|
||||
path('get_jstree_id/',GetJstreeIdView.as_view(),name='get_jstree_id/')
|
||||
path('get_jstree_id/',GetJstreeIdView.as_view(),name='get_jstree_id/'),
|
||||
path('submit_search_answer/',Collect_Search_Answer.as_view(),name='submit_search_answer/'),
|
||||
]
|
||||
|
|
|
@ -10,7 +10,7 @@ from django.db.models import Count
|
|||
# Create your views here.
|
||||
|
||||
|
||||
from .models import Annotation, Question, QuestionAnswer, Article, Issue, IssueAnswer, IssueStandardAnswers, IssueChoices
|
||||
from .models import Annotation, Question, QuestionAnswer, Article, Issue, IssueAnswer, IssueStandardAnswers, IssueChoices,Search_Answer
|
||||
from .models import AnnotationComment, QuestionComment, QuestionAnswerComment, ArticleComment, IssueComment, AnnotationStrategy,Competition
|
||||
from .models import Vote
|
||||
from users.models import User
|
||||
|
@ -278,13 +278,15 @@ class ShowMethodInfo(View):
|
|||
def post(self, request):
|
||||
method_query_url = settings.OPENGROK_SEARCH_URL
|
||||
query_str = request.POST.get('args','')
|
||||
source_linenum = request.POST.get('line_num')
|
||||
source_function_name = request.POST.get('function_name')
|
||||
# query_str = "refs=Note&file_id =12"
|
||||
for arg_str in query_str.split("&"):
|
||||
para_value = arg_str.split("=")
|
||||
if len(para_value)==2 and para_value[0]=='file_id':
|
||||
file_id = para_value[1]
|
||||
project = File.objects.get(id=file_id).project
|
||||
file_id_str="file_id="+file_id
|
||||
current_file_id = para_value[1]
|
||||
project = File.objects.get(id=current_file_id).project
|
||||
file_id_str="file_id="+current_file_id
|
||||
project_str="project="+project.name
|
||||
|
||||
query_str = query_str.replace(file_id_str,project_str)
|
||||
|
@ -306,7 +308,7 @@ class ShowMethodInfo(View):
|
|||
results = []
|
||||
|
||||
for i in range(len(tmp_results)):
|
||||
print(tmp_results)
|
||||
# print(tmp_results)
|
||||
path_origin = tmp_results[i]['path'][1:]
|
||||
index = path_origin.find("/")
|
||||
project_name = path_origin[0:index]
|
||||
|
@ -314,10 +316,11 @@ class ShowMethodInfo(View):
|
|||
line_no = tmp_results[i]['lineno']
|
||||
code = tmp_results[i]['line']
|
||||
code = str(base64.b64decode(code), 'utf-8')
|
||||
|
||||
file_id = File.objects.get(project=project,path=path_origin[index:]).id
|
||||
|
||||
relative_path = path_origin[index:]+"#"+str(file_id)+"_L"+line_no
|
||||
results.append([filename, relative_path,path_origin,code])
|
||||
html_str = render_to_string('projects/filesub/search-response.html', {'results': results, 'project_id': project.pk, })
|
||||
html_str = render_to_string('projects/filesub/search-response.html', {'results': results, 'current_file_id': current_file_id,"line_num":source_linenum,"function_name":source_function_name})
|
||||
return HttpResponse(json.dumps({"status": "success", "html_str":html_str}), content_type='application/json')
|
||||
|
||||
from utils import git
|
||||
|
@ -1221,6 +1224,48 @@ def get_url_mapping_project(url):
|
|||
project = Project.objects.get(name=projectName)
|
||||
return project,path,filename,path_origin
|
||||
|
||||
|
||||
|
||||
class Collect_Search_Answer(View):
|
||||
|
||||
def post(self, request):
|
||||
try:
|
||||
file_id = request.POST.get('file_id','')
|
||||
path_and_lineno = request.POST.get('path_and_lineno','')
|
||||
answer_type = request.POST.get('answer_type','')
|
||||
linenum = request.POST.get('line_num','')
|
||||
function_name = request.POST.get('function_name','')
|
||||
if not request.user.is_authenticated:
|
||||
answer = Search_Answer()
|
||||
answer.file = File.objects.get(id=file_id)
|
||||
print("project")
|
||||
answer.path_and_lineno = path_and_lineno
|
||||
answer.answer_type = answer_type
|
||||
answer.linenum = linenum
|
||||
answer.function_name = function_name
|
||||
answer.user = None
|
||||
answer.save()
|
||||
else:
|
||||
try:
|
||||
# 目前只记录最后一次
|
||||
answer = Search_Answer.objects.get(file_id=file_id,path_and_lineno=path_and_lineno,user=request.user,function_name=function_name,linenum=linenum)
|
||||
if answer.answer_type != answer_type:
|
||||
answer.answer_type = answer_type
|
||||
answer.save()
|
||||
except:
|
||||
answer = Search_Answer()
|
||||
answer.file = File.objects.get(id=file_id)
|
||||
answer.path_and_lineno = path_and_lineno
|
||||
answer.answer_type = answer_type
|
||||
answer.user = request.user
|
||||
answer.linenum = int(linenum)
|
||||
answer.function_name = function_name
|
||||
answer.save()
|
||||
return HttpResponse(json.dumps({"status": "success", "msg":"存储answer成功"}), content_type='application/json')
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return HttpResponse(json.dumps({"status": "fail", "msg":"存储answer失败"}), content_type='application/json')
|
||||
|
||||
class GetAddtabParasView(View):
|
||||
def post(self, request):
|
||||
url = request.POST.get('url','')
|
||||
|
|
|
@ -397,7 +397,7 @@ function closeX_search(){
|
|||
$("#search_response").hide();
|
||||
}
|
||||
|
||||
function search_symbol(args) {
|
||||
function search_symbol(args,line_num,function_name) {
|
||||
|
||||
// ev = window.event
|
||||
ev = window.event;
|
||||
|
@ -407,10 +407,10 @@ function search_symbol(args) {
|
|||
var mousePos = mouseCoords(ev)
|
||||
|
||||
$.ajax({
|
||||
cache: false,
|
||||
cache: true,
|
||||
type: "POST",
|
||||
url: '/operations/show_method_info/',
|
||||
data: { 'args': args },
|
||||
data: { 'args': args,"line_num":line_num,"function_name":function_name },
|
||||
dataType: 'json',
|
||||
async: true,
|
||||
beforeSend: function (xhr, settings) {
|
||||
|
@ -430,14 +430,23 @@ function search_symbol(args) {
|
|||
}
|
||||
});
|
||||
}
|
||||
function onClick_FeedbackButton(key) {
|
||||
if(key==1){
|
||||
//key =1 正确路径
|
||||
|
||||
}else{
|
||||
//key=0 错误路径
|
||||
|
||||
}
|
||||
function onClick_FeedbackButton(answer_type,file_id,path_and_lineno,line_num,function_name) {
|
||||
// 获取到当前的答案
|
||||
$.ajax({
|
||||
cache: false,
|
||||
type: "POST",
|
||||
url: '/operations/submit_search_answer/',
|
||||
data: {'file_id':file_id,"path_and_lineno":path_and_lineno,"answer_type":answer_type,"line_num":line_num,"function_name":function_name},
|
||||
dataType: 'json',
|
||||
async: true,
|
||||
beforeSend: function (xhr, settings) {
|
||||
xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
},
|
||||
success: function (data) {
|
||||
alert("Thanks for your support for the improvement of Accuracy of search results")
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -786,13 +795,13 @@ function generate_codereading_line(fileid,linenum,annos_count,issues_count,quest
|
|||
return htmlstr
|
||||
}
|
||||
|
||||
function add_hrefTag_into_line(line,file_id){
|
||||
function add_hrefTag_into_line(line,file_id,line_num){
|
||||
var regex = /\w+\(/g
|
||||
var strs = line.match(regex)
|
||||
if(strs!=null){
|
||||
for(var i=0;i<strs.length;i++){
|
||||
function_name = strs[i].substring(0,strs[i].length-1)
|
||||
var search_symbol_str = '<text onclick="search_symbol(\'file_id='+String(file_id)+"&defs="+String(function_name)+'\')">'+function_name+"</text>"
|
||||
var search_symbol_str = '<text onclick="search_symbol(\'file_id='+String(file_id)+"&defs="+String(function_name)+'\','+String(line_num)+',\''+String(function_name)+'\')">'+function_name+"</text>"
|
||||
var replace_str = '<a href="javascript:void(0)">'+search_symbol_str+'</a>('
|
||||
line=line.replace(strs[i],replace_str)
|
||||
}
|
||||
|
@ -804,7 +813,7 @@ function add_hrefTag_into_line(line,file_id){
|
|||
|
||||
|
||||
function generate_codereading_linenum_and_codeline(linenum,line,language,file_id){
|
||||
var line= add_hrefTag_into_line(line,file_id)
|
||||
var line= add_hrefTag_into_line(line,file_id,linenum)
|
||||
var htmlstr = ''
|
||||
htmlstr += '<div class="linenum">'
|
||||
htmlstr += linenum.toString()
|
||||
|
@ -1554,7 +1563,6 @@ $(function(){
|
|||
|
||||
url_deal(get_path_link_and_archor(path)[0],null)
|
||||
|
||||
|
||||
add_tab(data.project_id, data.path, data.filename)
|
||||
// 特殊处理,因为add_tab的逻辑会影响tree_nodes(),所以进行了处理
|
||||
// tree_nodes[path_after] = first_tabs_jstree_id
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
<span class="fl">{{ forloop.counter }}. </span>
|
||||
<a class="fl" href="javascript:void(0)" class="re-path" title="{{item.2}}" onclick='add_tab({{project_id}},"{{item.1}}","{{item.0}}")'>{{ item.2|safe }}</a>
|
||||
<a class="fl" href="javascript:void(0)" class="path-content" title="{{item.3}}" onclick='add_tab({{project_id}},"{{item.1}}","{{item.0}}")'>{{ item.3|safe }}</a>
|
||||
<div class="fr FontFatimes" onclick="onClick_FeedbackButton(0);"><i class="fa fa-times" aria-hidden="true"></i></div>
|
||||
<div class="fr FontFaCheck" onclick="onClick_FeedbackButton(1);"><i class="fa fa-check" aria-hidden="true"></i></div>
|
||||
<div class="fr FontFatimes" onclick='onClick_FeedbackButton(0,{{current_file_id}},"{{item.1}}",{{line_num}},"{{function_name}}");'><i class="fa fa-times" aria-hidden="true"></i></div>
|
||||
<div class="fr FontFaCheck" onclick='onClick_FeedbackButton(1,{{current_file_id}},"{{item.1}}",{{line_num}},"{{function_name}}");'><i class="fa fa-check" aria-hidden="true"></i></div>
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in New Issue