1.Add delete buttonadd

2.add function:set competition file and project
This commit is contained in:
wrmswindmill 2018-09-29 11:50:45 +08:00
parent fbf100f187
commit a1476164d5
8 changed files with 128 additions and 20 deletions

View File

@ -387,6 +387,8 @@ class AddAnnotationView(View):
# 更新FileSummary
update_filesummary(file_id,"annotation")
# print(anno_content)
if file.project.is_competition_project and not file.is_competition_file:
return HttpResponse('{"status":"success_but_not_correct_file","msg":"注释成功,但请注意您标注的不是比赛模块","anno_content":"'+anno_content+'"}', content_type='application/json')
return HttpResponse('{"status":"success","msg":"注释成功","anno_content":"'+anno_content+'"}', content_type='application/json')
except Exception as e:
return HttpResponse('{"status":"fail","msg":"参数传递错误,注释失败"}', content_type='application/json')
@ -457,8 +459,7 @@ class DeleteView(View):
object_type = request.POST.get("object_type","")
if object_type=="Annotation":
annotation = Annotation.objects.get(id=object_id,is_latest=1)
annotation.is_latest = 0
annotation.save()
Annotation.objects.filter(linenum=annotation.linenum,file=annotation.file).delete()
elif object_type == "Question":
Question.objects.filter(id=object_id).delete()
elif object_type == "QuestionAnswer":

View File

@ -0,0 +1,23 @@
# Generated by Django 2.0.6 on 2018-09-29 10:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('projects', '0018_auto_20180904_1055'),
]
operations = [
migrations.AddField(
model_name='file',
name='is_competition_file',
field=models.BooleanField(default=False, verbose_name='是否是竞赛文件'),
),
migrations.AlterField(
model_name='file',
name='issue_num',
field=models.IntegerField(default=0, verbose_name='问题数量'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 2.0.6 on 2018-09-29 11:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('projects', '0019_auto_20180929_1047'),
]
operations = [
migrations.AddField(
model_name='project',
name='is_competition_project',
field=models.BooleanField(default=False, verbose_name='是否是竞赛项目'),
),
]

View File

@ -37,6 +37,7 @@ class Project(models.Model):
state = models.CharField(max_length=3, choices=STATE_CHOICE, default='1')
create_time = models.DateTimeField(auto_now_add=True)
update_time = models.DateTimeField(auto_now=True)
is_competition_project = models.BooleanField(default=False, verbose_name='是否是竞赛项目')
class Meta:
db_table = 'Source_Project'
@ -63,6 +64,7 @@ class File(models.Model):
('2', '删除'),
('3', '即将上线'),
]
name = models.CharField(max_length=255, verbose_name='文件名称')
path = models.CharField(max_length=512, verbose_name='文件路径')
super_path = models.ForeignKey("self", null=True, blank=True, verbose_name='上级目录', on_delete=models.CASCADE)
@ -78,9 +80,9 @@ class File(models.Model):
create_time = models.DateTimeField(auto_now_add=True)
update_time = models.DateTimeField(auto_now=True)
anno_num = models.IntegerField(default=0, verbose_name='注释数量')
issue_num = models.IntegerField(default=0, verbose_name='注释数量')
issue_num = models.IntegerField(default=0, verbose_name='问题数量')
has_annotation = models.BooleanField(default=False, verbose_name='是否有标注')
is_competition_file = models.BooleanField(default=False, verbose_name='是否是竞赛文件')
class Meta:
db_table = 'Source_File'

View File

@ -15,7 +15,7 @@ Including another URLconf
"""
from django.urls import path
from .views import NewProjectView, ProjectListView, ProjectInfoView, ProjectSourceView, ScannerProjectView,RemoveProjectView,GetProjectJstreeView
from .views import NewProjectView, ProjectListView, ProjectInfoView, ProjectSourceView, ScannerProjectView,RemoveProjectView,GetProjectJstreeView,SetCompetitionProjectView
app_name = "projects"
urlpatterns = [
@ -24,6 +24,7 @@ urlpatterns = [
path('remove', RemoveProjectView.as_view(), name='remove_project'),
path('scanner_project', ScannerProjectView.as_view(), name="scanner_project"),
path('get_project_jstree/',GetProjectJstreeView.as_view(),name="get_project_jstree/"),
path('set_competition_project',SetCompetitionProjectView.as_view(),name="set_competition_project/"),
# path('<slug:name>/', ProjectInfoView.as_view(), name='info'),
# path('<slug:name>/xref<path:path>', ProjectSourceView.as_view(), name='source')
path('<str:name><path:path>', ProjectSourceView.as_view(), name='source')

View File

@ -72,6 +72,39 @@ class NewProjectView(View):
# logging.info(str(datetime.now()) + '删除完成稍后重新导入')
# error_msg = '导入失败,请查看日志发现错误后重新导入'
# return render(request, 'projects/new.html', locals())
class SetCompetitionProjectView(View):
def get(self,request):
try:
project_name = request.GET.get('project_name','')
strategy = int(request.GET.get('strategy',''))
path = request.GET.get('path',None)
project = Project.objects.get(name=project_name)
if not project.is_competition_project:
project.is_competition_project=True
project.save()
if strategy>=0 and strategy<=2:
anno_strategy = AnnotationStrategy.objects.get(project=project)
anno_strategy.choice = strategy
anno_strategy.save()
if path is not None:
self.set_competition_files(path,project)
return HttpResponse("Successful")
except Exception as e:
return HttpResponse(str(e))
def set_competition_files(self,path,project):
file = File.objects.get(path=path,project=project)
file.is_competition_file=True
file.save()
file_ids = [file.id]
while len(file_ids)>0:
file_id = file_ids.pop(0)
for file in File.objects.filter(super_path_id=file_id):
file.is_competition_file=True
file.save()
file_ids.append(file.id)
class RemoveProjectView(View):
def get(self, request):

View File

@ -470,6 +470,35 @@ function show_new_question_answer(item, content, username) {
$(item).parent().siblings(".responseInput").val("");
}
function delete_anno(file_id,line_num,anno_id){
$.ajax({
cache: false,
type: "POST",
url: '/operations/delete/',
data: {'object_id':anno_id,"object_type":"Annotation"},
dataType: 'json',
async: true,
beforeSend: function (xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
},
success: function (data) {
if (data.status == 'success') {
$("#ItemcommentPanel").remove()
$("."+file_id+line_num).remove()
$("#codeopration_anno_"+file_id+"_"+line_num).remove();
show_annotation(file_id,line_num);
layer.msg(data.msg);
}else{
layer.msg(data.msg);
}
},error:function(jqXHR, textStatus, errorThrown){
if(jqXHR.readyState===0&&jqXHR.status===0){
alert('网络故障,提交失败!请联网后重新提交');
}
}
});
}
function add_annotation(item,file_id, line_num) {
@ -506,20 +535,20 @@ function add_annotation(item,file_id, line_num) {
}
function submit_annotation(file_id, line_num, content) {
// 因为可能注释或问题没有值的时候不会为该代码块添加html代码所以首先判断
// 然后将注释数+1
var codeopration_anno_div = $("#codeopration_anno_"+file_id+"_" + line_num).html()
var str = '<span id="annonums_' + line_num + '" class="annonums" onclick="show_annotation(' + file_id + ',' + line_num + ')">';
str +='</span>';
$("#codeopration_anno_" + +file_id + "_" + line_num).html(str);
$(".addno-panel").hide();
$(".source-addno-panel").remove();
// show_annotation(file_id,line_num);
//将注释添加到当前行的上一行
var contenthtml ='<div class="linenum"></div>'+'<div class="sourcecode">'+'<div class="mypre newaddmypre hljs-comment ' + file_id+line_num + '">'+"//"+ content+'</div>'+'</div>'+'<div class="linestatus"></div>';
var html = '<div class="newcodeline newcodelinebox">'+contenthtml+'</div>';
var id=file_id+'_'+"L"+line_num;
$("#"+id).before(html);
// 因为可能注释或问题没有值的时候不会为该代码块添加html代码所以首先判断
// 然后将注释数+1
var codeopration_anno_div = $("#codeopration_anno_"+file_id+"_" + line_num).html()
var str = '<span id="annonums_' + line_num + '" class="annonums" onclick="show_annotation(' + file_id + ',' + line_num + ')">';
str +='</span>';
$("#codeopration_anno_" + +file_id + "_" + line_num).html(str);
$(".addno-panel").hide();
$(".source-addno-panel").remove();
// show_annotation(file_id,line_num);
//将注释添加到当前行的上一行
var contenthtml ='<div class="linenum"></div>'+'<div class="sourcecode">'+'<div class="mypre newaddmypre hljs-comment ' + file_id+line_num + '">'+"//"+ content+'</div>'+'</div>'+'<div class="linestatus"></div>';
var html = '<div class="newcodeline newcodelinebox">'+contenthtml+'</div>';
var id=file_id+'_'+"L"+line_num;
$("#"+id).before(html);
$.ajax({
cache: false,
type: "POST",
@ -534,7 +563,7 @@ function submit_annotation(file_id, line_num, content) {
if (data.status == 'success') {
layer.msg('提交成功');
}else{
layer.msg(data.msg);
layer.msg(data.msg);
}
},error:function(jqXHR, textStatus, errorThrown){
if(jqXHR.readyState===0&&jqXHR.status===0){

View File

@ -47,6 +47,7 @@
<div class="fl commentparthalf">
<div class="parthalf_con clearfix">
<textarea id="modify_anno_textarea" class="fl break_word color-grey-des colorblack inlineBlock wi216" oninput="Input_modifyAnno(this,{{self_anno.file_id}},{{self_anno.linenum}},{{self_anno.id}})" style="border:none" readonly>{{ self_anno.content }}</textarea>
<a class="modify-anno btn fr mt10 mb10" style="background-color:brown;margin-left:5px" id="delete_anno" href="javascript:void(0)" onclick="delete_anno({{self_anno.file_id}},{{self_anno.linenum}},{{self_anno.id}})">删除</a>
{% if allow_modify %}
<a class="modify-anno btn btn-blue fr mt10 mb10" id="modification" href="javascript:void(0)" onclick="inject_modifyAnno_html(this,{{self_anno.file_id}},{{self_anno.linenum}},{{self_anno.id}})">修改</a>
{% endif %}