forked from lazzyfu/goInsight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_orders.html
More file actions
353 lines (330 loc) · 17.2 KB
/
export_orders.html
File metadata and controls
353 lines (330 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
{% extends 'base.html' %}
{% load staticfiles %}
{% block link_css %}
<style>
.CodeMirror {
border: 1px solid #eee;
height: 600px;
}
</style>
{% endblock %}
{% block right_content %}
<div class="row">
<div class="col-md-12">
<div class="box box-info">
<div class="box-header box-border">
<div class="mailbox-read-info">
<h3 class="box-title"><i class="fa fa-code"></i> 提交数据导出工单
</h3>
</div>
</div>
<div class="box-body box-border">
<form class="form-horizontal" id="sqlExportForm" action="{% url 'p_sql_orders_audit' %}"
method="post" data-toggle="validator">
<div class="col-md-4" id="left_input_height" style="padding-right: 2px">
<div class="box box-gray">
<div class="box-body no-padding">
<div class="mailbox-read-info">
<h5>选择环境</h5>
</div>
</div>
<div class="box-body box-profile">
<div class="form-group has-feedback">
<label class="control-label col-sm-3">标题 <span class="text-red">*</span></label>
<div class="col-sm-9">
<input type="text" name="title" data-minlength="5"
class="form-control" spellcheck="false"
placeholder="描述操作的目的" required>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-sm-3">需求 <span class="text-red">*</span></label>
<div class="col-sm-9">
<textarea name="description" rows="5" style="resize: none"
data-minlength="5"
class="form-control" spellcheck="false" required
placeholder="关联url链接或输入描述性文字"></textarea>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-sm-3">备注 <span class="text-red">*</span></label>
<div class="col-sm-9">
<select id="s_remark" style="width: 100%" name="remark" required
class="selectpicker form-control" title="请选择...">
<option data-icon="glyphicon-paperclip" selected value="数据导出">数据导出
</option>
</select>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-sm-3">操作 <span class="text-red">*</span></label>
<div class="col-sm-9">
<select name="sql_type" id="s_sql_type"
style="width: 100%" required
class="selectpicker form-control" title="请选择...">
<option data-icon="glyphicon-pushpin" selected value="DML">DML
</option>
</select>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-sm-3">环境 <span class="text-red">*</span></label>
<div class="col-sm-9">
<select id="s_envi" name="envi_id" style="width: 100%" required
class="form-control selectpicker" title="选择环境..."
onchange="getTargetSchema()">
</select>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-sm-3">库名 <span class="text-red">*</span></label>
<div class="col-sm-9">
<select id="s_schema" name="database" style="width: 100%" required
class="form-control selectpicker" title="选择库名..."
data-live-search="true" onchange="get_table_info()">
</select>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-sm-3">格式 <span class="text-red">*</span></label>
<div class="col-sm-9">
<select id="s_schema" name="export_file_format" style="width: 100%" required
class="form-control selectpicker" title="选择导出格式...">
<option data-icon="glyphicon-pushpin" selected value="xlsx">xlsx
</option>
<option data-icon="glyphicon-pushpin" value="csv">csv</option>
</select>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-sm-3">审核人 <span
class="text-red">*</span></label>
<div class="col-sm-9">
<select title="选择工单审核人..." id="s_operator" name="auditor"
style="width: 100%" required
class="selectpicker form-control">
</select>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-md-3">抄送 <span
class="text-red">*</span></label>
<div class="col-md-9">
<select id="s_email_cc" name="email_cc" data-live-search="true"
title="选择需要抄送的联系人..."
data-actions-box="true"
style="width: 100%" class="selectpicker form-control dropup"
multiple required>
</select>
</div>
<div class="help-block with-errors col-md-2"></div>
</div>
<div class="form-group">
<label class="control-label col-sm-3"></label>
<div class="col-sm-9">
<button type="button" onclick="beautifySQL()"
class="btn bg-info btn-sm">格式化SQL
</button>
<button type="submit" class="btn bg-info btn-sm">生成工单</button>
</div>
</div>
</div>
<!-- /.box-body -->
</div>
</div>
<div class="col-md-8">
<div class="box box-gray">
<div class="box-body no-padding">
<div class="mailbox-read-info">
<h5>填写SELECT语句
<small class="text-muted"><cite>每条SQL必须以 <span
class="text-danger"> 分号(;) </span>结尾</cite></small>
</h5>
</div>
</div>
<div class="box-body no-padding">
<div class="form-group">
<div class="col-md-12" id="right_code_hight">
<textarea title="" id="s_sql" autofocus class="form-control"></textarea>
</div>
</div>
</div>
</div>
</div>
{% csrf_token %}
</form>
<!-- /.col -->
</div>
</div>
<div class="box-size" id="typediv1" style="visibility: hidden">
<div class="box box-gray">
<div class="box-body no-padding">
<div class="table-responsive">
<table class="table table-striped table-condensed table-bordered">
<thead>
<tr>
<th class="col-sm-1 text-red">ID</th>
<th class="col-sm-1 text-red">阶段</th>
<th class="col-sm-1 text-red">状态</th>
<th class="col-sm-1 text-red">级别</th>
<th class="col-sm-2 text-red">信息</th>
<th class="col-sm-4 text-red">SQL</th>
<th class="col-sm-1 text-red">扫描/影响行数</th>
<th class="col-sm-1 text-red">耗时</th>
</tr>
</thead>
<tbody id="td_append">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block link_javascripts %}
<script>
let myTextarea = document.getElementById('s_sql');
let myCodeMirror = CodeMirror.fromTextArea(myTextarea, {
lineNumbers: true,
mode: "text/x-mysql",
autoRefresh: true,
smartIndent: true,
indentWithTabs: true,
styleActiveLine: true,
autofocus: true,
keyMap: "sublime",
autoCloseBrackets: true,
matchBrackets: true,
showCursorWhenSelecting: true,
extraKeys: {"Tab": "autocomplete"},
hint: CodeMirror.hint.sql
});
/**
* 获取指定环境的schema
*/
function getTargetSchema() {
let s_schema = $('#s_schema');
let envi_id = $('#s_envi').val();
let csrftoken = $.cookie('csrftoken');
$.ajax({
url: '{% url 'p_get_target_schemas' %}',
type: 'POST',
dataType: 'json',
data: {'envi_id': envi_id, 'purpose': 'export', 'csrfmiddlewaretoken': csrftoken},
timeout: 5000,
cache: false,
success: function (data) {
s_schema.empty();
let html = '';
$.each(data, function (index, row) {
let result = [row.host, row.port, row.schema].join(',');
let show_result = [row.comment, row.port, row.schema].join('_');
html += "<option data-icon='fa fa-database' value=" + result + ">" + show_result + "</option>"
});
s_schema.append(html);
$('.selectpicker').selectpicker('refresh')
}
})
}
/**
* 获取抄送的用户和邮箱
*/
$(function () {
$.ajax({
url: '{% url 'p_get_user_mail' %}',
type: 'GET',
dataType: 'json',
timeout: 5000,
cache: false,
success: function (data) {
let $this = $("#s_email_cc");
$this.empty();
$.each(data, function (index, row) {
$this.append(
"<option data-icon='glyphicon-user' data-subtext=" + row.email + " value=" + row.email + ">" + row.username + "</option>");
});
$('.selectpicker').selectpicker('refresh');
}
})
});
/**
* 提交数据导出工单
*/
$('#sqlExportForm').validator().on('submit', function (e) {
let contents = myCodeMirror.getValue();
if (contents.length < 10) {
displayPNotify(2, '审核内容不能为空或小于10个字符');
return false;
}
if (e.isDefaultPrevented()) {
// 验证不通过
displayPNotify(2, '表单无效,请完成填写');
} else {
// 验证通过
$(this).ajaxSubmit({
data: {'contents': contents},
dataType: 'json',
success: function (result) {
if (result.status === 0) {
window.parent.location.href = result.jump_url
} else {
displayPNotify(result.status, result.msg)
}
},
error: function (jqXHR) {
if (jqXHR.status === 403) {
displayPNotify(jqXHR.status)
}
}
});
return false;
}
});
/**
* 获取有审核权限的用户
*/
$(function () {
$.ajax({
url: '/sqlorders/get_audit_user/',
type: 'GET',
dataType: 'json',
timeout: 5000,
cache: false,
success: function (result) {
$("#s_operator").empty();
$.each(result, function (index, row) {
$("#s_operator").append(
"<option data-icon='glyphicon-user' data-subtext=" + row.displayname + " value=" + row.username + ">" + row.username + "</option>"
);
});
$('.selectpicker').selectpicker('refresh');
}
})
});
// 获取用户设置的环境
$(function () {
$.ajax({
url: '{% url 'p_get_sql_orders_envi' %}',
type: 'GET',
dataType: 'json',
timeout: 10000,
cache: false,
success: function (data) {
$("#s_envi").empty();
$.each(data, function (index, row) {
$("#s_envi").append(
"<option data-icon='glyphicon-record' value=" + row.envi_id + ">" + row.envi_name + "</option>"
);
});
$('.selectpicker').selectpicker('refresh')
}
});
});
/**
* 设置左右两边的宽度为一致
*/
$('#left_input_height').height($('#right_code_hight').height());
</script>
{% endblock %}