-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Grain-Yu/dev
添加编辑优化详情的功能。
- Loading branch information
Showing
8 changed files
with
343 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: UTF-8 -*- | ||
import logging | ||
import traceback | ||
import MySQLdb | ||
import pymysql | ||
import re | ||
|
||
|
||
|
||
# -*- coding: UTF-8 -*- | ||
|
||
import simplejson as json | ||
from django.contrib.auth.decorators import permission_required | ||
|
||
|
||
from django.http import HttpResponse, JsonResponse | ||
from sql.utils.instance_management import ( | ||
SUPPORTED_MANAGEMENT_DB_TYPE, | ||
) | ||
from common.utils.extend_json_encoder import ExtendJSONEncoder | ||
from sql.engines import get_engine, ResultSet | ||
from sql.utils.resource_group import user_instances | ||
from .models import Instance, InstanceAccount | ||
|
||
from sql.engines.mysql import MysqlEngine | ||
|
||
|
||
|
||
@permission_required("sql.menu_slowquery", raise_exception=True) | ||
def listreview(request): | ||
"""获取优化详情列表""" | ||
checksum = request.POST.get("review_checksum") | ||
|
||
if not checksum: | ||
return JsonResponse({"status": 0, "msg": "", "data": []}) | ||
try: | ||
instance = user_instances( | ||
request.user, db_type=SUPPORTED_MANAGEMENT_DB_TYPE | ||
).get(instance_name="archery_internal") | ||
except Instance.DoesNotExist: | ||
return JsonResponse({"status": 1, "msg": "你所在组未关联该实例", "data": []}) | ||
|
||
#获取checksum对应的优化详情 | ||
query_engine = MysqlEngine(instance=instance) | ||
query_result = query_engine.get_review_status_summary(checksum) | ||
if not query_result.error: | ||
rows = query_result.rows | ||
result = {"status": 0, "msg": "ok", "rows": rows} | ||
else: | ||
result = {"status": 1, "msg": query_result.error} | ||
return HttpResponse( | ||
json.dumps(result, cls=ExtendJSONEncoder, bigint_as_string=True), | ||
content_type="application/json", | ||
) | ||
|
||
@permission_required("sql.menu_slowquery", raise_exception=True) | ||
def editreview(request): | ||
"""编辑优化详情""" | ||
checksum = request.POST.get("checksum") | ||
reviewed_by = request.POST.get("reviewed_by", "") | ||
reviewed_on = request.POST.get("reviewed_on", "") | ||
comments = request.POST.get("comments", "") | ||
reviewed_status = request.POST.get("reviewed_status", "") | ||
|
||
if ( | ||
not all([checksum, reviewed_by, reviewed_on, comments,reviewed_status]) | ||
): | ||
return JsonResponse({"status": 1, "msg": "参数不完整,请确认后提交", "data": []}) | ||
|
||
try: | ||
instance = user_instances( | ||
request.user, db_type=SUPPORTED_MANAGEMENT_DB_TYPE | ||
).get(instance_name="archery_internal") | ||
except Instance.DoesNotExist: | ||
return JsonResponse({"status": 1, "msg": "你所在组未关联该实例", "data": []}) | ||
|
||
exec_engine = MysqlEngine(instance=instance) | ||
exec_result = exec_engine.set_review_details( | ||
checksum=checksum, reviewed_by=reviewed_by, reviewed_on=reviewed_on,comments=comments,reviewed_status=reviewed_status | ||
) | ||
return JsonResponse({"status": 0, "msg": "", "data": []}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
{% extends "base.html" %} | ||
|
||
|
||
|
||
|
||
{% block content %} | ||
|
||
<!-- 表格--> | ||
<div class="table-responsive"> | ||
<table id="user-list" data-toggle="table" class="table table-striped table-hover" | ||
style="table-layout:inherit;overflow:hidden;text-overflow:ellipsis;"> | ||
</table> | ||
</div> | ||
<!-- 修改密码模态框 --> | ||
<div class="modal fade" id="edit-review" tabindex="-1" role="dialog"> | ||
<div class="modal-dialog" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span | ||
aria-hidden="true">×</span></button> | ||
<h4 class="modal-title">编辑详情</h4> | ||
</div> | ||
<div class="modal-body form-group"> | ||
<div class="form-group row"> | ||
<label for="comments" class="col-sm-3 col-form-label"> | ||
<span style="color:red">*</span>内容</label> | ||
<div class="col-sm-9"> | ||
<input type="text" id="comments" class="form-control" | ||
placeholder="请填写详情"> | ||
</small> | ||
</div> | ||
</div> | ||
<div class="form-group row"> | ||
<label for="reviewed-status" class="col-sm-3 col-form-label"> | ||
<span style="color:red">*</span>状态</label> | ||
<div class="col-sm-9"> | ||
<input type="text" id="reviewed-status" class="form-control" | ||
aria-describedby="editrewHelpBlock" | ||
placeholder="请填写当前状态"> | ||
<small id="editrewHelpBlock" class="form-text text-muted"> | ||
请输入:open/resolved/pending/closed | ||
</small> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button> | ||
<button type="button" class="btn btn-danger" id="editRevBtn">修改</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{% endblock content %} | ||
{% block js %} | ||
{% load static %} | ||
<script src="{% static 'bootstrap-table/js/bootstrap-table-export.min.js' %}"></script> | ||
<script src="{% static 'bootstrap-table/js/tableExport.min.js' %}"></script> | ||
<script> | ||
//获取优化详情列表 | ||
function review_list() { | ||
var pathname = window.location.pathname; | ||
if (pathname == "/sqlreview/") { | ||
var review_checksum = sessionStorage.getItem('review_checksum'); | ||
} | ||
//初始化table | ||
$('#user-list').bootstrapTable('destroy').bootstrapTable({ | ||
escape: false, | ||
method: 'post', | ||
contentType: "application/x-www-form-urlencoded", | ||
url: "/sqlreview/list/", | ||
striped: true, //是否显示行间隔色 | ||
cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*) | ||
pagination: true, //是否显示分页(*) | ||
sortable: true, //是否启用排序 | ||
sortOrder: "asc", //排序方式 | ||
sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*) | ||
pageNumber: 1, //初始化加载第一页,默认第一页,并记录 | ||
pageSize: 14, //每页的记录行数(*) | ||
pageList: [20, 30, 50, 100], //可供选择的每页的行数(*) | ||
showExport: true, //是否显示导出按钮 | ||
exportOptions: { | ||
fileName: 'checksum' //文件名称设置 | ||
}, | ||
search: true, //是否显示表格搜索 | ||
strictSearch: false, //是否全匹配搜索 | ||
showColumns: true, //是否显示所有的列(选择显示的列) | ||
showRefresh: true, //是否显示刷新按钮 | ||
minimumCountColumns: 2, //最少允许的列数 | ||
clickToSelect: true, //是否启用点击选中行 | ||
uniqueId: 'checksum', //每一行的唯一标识,一般为主键列 | ||
showToggle: true, //是否显示详细视图和列表视图的切换按钮 | ||
cardView: false, //是否显示详细视图 | ||
detailView: false, //是否显示父子表 | ||
locale: 'zh-CN', //本地化 | ||
toolbar: "#toolbar", //指明自定义的toolbar | ||
queryParamsType: 'limit', | ||
//请求服务数据时所传参数 | ||
queryParams: | ||
function (params) { | ||
if (review_checksum) { | ||
return { | ||
search: params.search, | ||
review_checksum: review_checksum | ||
} | ||
} | ||
}, | ||
columns: [{ | ||
title: 'SQLID', | ||
field: 'checksum' | ||
},{ | ||
title: '提交人', | ||
field: 'reviewed_by' | ||
},{ | ||
title: '更新日期', | ||
field: 'reviewed_on' | ||
},{ | ||
title: '内容', | ||
field: 'comments', | ||
width: "30", | ||
widthUnit: "%" | ||
},{ | ||
title: '状态', | ||
field: 'reviewed_status' | ||
},{ | ||
title: '操作', | ||
field: '', | ||
formatter: function (value, row, index) { | ||
let btn_edit_review = "<button class=\"btn btn-warning btn-xs\" review_checksum=\"" + row.checksum + "\" onclick=\"review_edit(this)" + "\">编辑</button>\n"; | ||
return btn_edit_review | ||
} | ||
}], | ||
onLoadSuccess: function (data) { | ||
if (data.status !== 0) { | ||
alert("数据加载失败!" + data.msg); | ||
}}, | ||
onLoadError: onLoadErrorCallback, | ||
onSearch: function (e) { | ||
//传搜索参数给服务器 | ||
queryParams(e) | ||
} | ||
}); | ||
|
||
} | ||
|
||
//编辑页面 | ||
function review_edit(obj) { | ||
review_checksum = $(obj).attr("review_checksum"); | ||
$("#edit-review").modal('show'); | ||
//编辑详情 | ||
$("#editRevBtn").unbind("click").click(function () { | ||
var dt = new Date(+new Date()+8*3600*1000); | ||
currenttime = dt.toISOString().slice(0, 19).replace('T', ' '); | ||
$.ajax({ | ||
type: "post", | ||
url: "/sqlreview/edit/", | ||
dataType: "json", | ||
data: { | ||
checksum: review_checksum, | ||
reviewed_by: 'admin', | ||
reviewed_on: currenttime, | ||
comments: $("#comments").val(), | ||
reviewed_status: $("#reviewed-status").val(), | ||
}, | ||
complete: function () { | ||
}, | ||
success: function (data) { | ||
if (data.status === 0) { | ||
$('#edit-review').modal('hide'); | ||
$("#edit-review input").val(""); | ||
review_list() | ||
} else { | ||
alert(data.msg); | ||
} | ||
}, | ||
error: function (XMLHttpRequest, textStatus, errorThrown) { | ||
alert(errorThrown); | ||
} | ||
}); | ||
}); | ||
} | ||
//初始化数据 | ||
$(document).ready(function () { | ||
review_list(); | ||
}); | ||
</script> | ||
{% endblock %} |
Oops, something went wrong.