forked from lazzyfu/goInsight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_orders.html
More file actions
373 lines (355 loc) · 16.1 KB
/
my_orders.html
File metadata and controls
373 lines (355 loc) · 16.1 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
{% extends 'base.html' %}
{% load staticfiles %}
{% block right_content %}
<div class="row">
<div class="col-md-12">
<div class="box box-info">
<div class="box-header">
<div class="mailbox-read-info">
<h3 class="box-title"><i class="fa fa-code"></i> <span
class="text-red">我的工单</span></h3>
</div>
</div>
<div class="box-body">
<table id="demo-table"></table>
</div>
</div>
</div>
</div>
<!-- 钩子模态框 -->
<div class="modal fade" id="hook_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form class="form-horizontal" id="hook_form" action="{% url 'p_hook_sql_orders' %}"
method="post">
<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"><i class="fa fa-magnet"></i> 请选择需要勾到环境的库名
</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="form-group" style="display: none">
<label class="control-label col-md-2 col-sm-2 col-xs-12">id</label>
<div class="col-sm-8">
<input title="" type="text" id="s_id" class="form-control" name="id">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-sm-2 col-xs-12">目标环境*</label>
<div class="col-sm-8">
<select id="s_envi" name="envi_id" style="width: 100%" required
class="form-control selectpicker" title="选择目标环境..."
data-live-search="true" onchange="getTargetSchema()">
</select>
</div>
</div>
<div class="form-group" id="is_show_schema">
<label class="control-label col-sm-2 col-sm-2 col-xs-12">目标库名*</label>
<div class="col-sm-8">
<select id="s_schema" name="database" style="width: 100%" required
class="form-control selectpicker" title="选择目标库名..."
data-live-search="true">
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="submit" class="btn btn-primary">提交</button>
</div>
{% csrf_token %}
</form>
</div>
</div>
</div>
<!-- 任务进度模态框 -->
<div class="modal fade" id="modal_tasks_show" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" 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>
<h5>
<small><cite>
<i class="fa fa-check" style="color: green"></i>: 表示已经执行,
<i class="fa fa-close" style="color: red"></i>: 表示未推到该环境,
其他状态: 表示当前工单的进度
</cite></small>
</h5>
</div>
<div class="modal-body">
<div class="row">
<div class="box-body">
<table id="tasks-table"></table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block link_javascripts %}
<script>
/**
* 初始化bootstrap-table,生成表格
*/
$(function () {
let $table = $('#demo-table');
$table.bootstrapTable({
method: 'get',
dataType: 'json',
contentType: "application/x-www-form-urlencoded",
url: "{% url 'p_get_my_orders' %}",
cache: false,
queryParams: function (params) {
return {
limit_size: params.limit + params.offset,
offset_size: params.offset,
search_content: params.search
}
},
sidePagination: "server",
showColumns: true,
pagination: true,
search: true,
showRefresh: true,
singleSelect: true,
minimumCountColumns: 2,
pageNumber: 1,
pageSize: 10,
locale: 'zh-CN',
pageList: [10, 20],
uniqueId: "id",
autoRefresh: true,
autoRefreshInterval: 5,
autoRefreshSilent: true,
rowStyle: render_row_style,
classes: 'table table-hover table-no-bordered',
columns: [
{
field: 'progress_value',
title: '进度',
formatter: function (value, row) {
return "<button type='button' class='btn " + row.progress_color + " btn-sm'>" + value + "</button>"
}
},
{
field: 'title',
title: '标题',
formatter: function (value, row) {
return '<a href="/sqlorders/sql_orders_details/' + row.id + '" title=\"' + value + '\">' + value.slice(0, 12) + '</a>' +
'<br>At: ' + moment(row.created_at).format('YYYY-MM-DD HH:mm:ss') + ''
}
},
{
field: 'sql_type',
title: '类型'
},
{
field: 'remark',
title: '备注',
formatter: function (value) {
if (value === '数据导出') {
return "<span class='text-primary'>" + value + "</span>"
}
else if (value === '紧急上线') {
return "<span class='text-danger'>" + value + "</span>"
}
else if (value === '例行上线') {
return "<span class='text-success'>" + value + "</span>"
} else {
return "<span class='text-muted'>" + value + "</span>"
}
}
},
{
field: 'task_version',
title: '任务',
formatter: function (value) {
return "<a href='#' onclick='deploy_tasks_table(" + "\"" + value + "\"" + ")'>" + value + "</a>"
}
},
{
field: 'host',
title: '主机/库',
formatter: function (value, row) {
return value + ':' + row.port + '<br>' + row.database
}
},
{
field: 'proposer',
title: '申请人'
},
{
field: 'auditor',
title: '审批人'
},
{
field: 'approve',
title: '审批',
formatter: function (value, row) {
return "<a href='#' onclick='sql_orders_audit(" + row.id + "," + '\"/sqlorders/sql_orders_approve/\"' + ",\"通过\", \"不通过\")'><i class='fa fa-pencil-square-o fa-lg'></i></a>"
}
},
{
field: 'execute',
title: '执行',
formatter: function (value, row) {
return "<a href='#' onclick='general_perform_tasks(" + row.id + "," + row.envi_id + ")'><i class='fa fa-check-square-o fa-lg'></i></a>"
}
},
{
field: 'id',
title: '钩子',
formatter: function (value, row) {
return "<a href='#' type='button' data-toggle='modal' data-target='#hook_modal' data-whatever_id=\"" + row.id + "\" data-whatever_sqltype=\"" + row.sql_type + "\"><i class='fa fa-magnet fa-lg'></i></a>"
}
},
{
field: 'feedback',
title: '反馈',
formatter: function (value, row) {
return "<a href='#' onclick='sql_orders_audit(" + row.id + "," + '\"/sqlorders/sql_orders_feedback/\"' + ",\"处理中\", \"已完成\")'><i class='fa fa-mail-reply-all fa-lg'></i></a>"
}
},
{
field: 'id',
title: '关闭',
formatter: function (value, row) {
return "<a href='#' onclick='sql_orders_audit(" + row.id + "," + '\"/sqlorders/sql_orders_close/\"' + ",\"提交\", \"结束\")'><i class='fa fa-close fa-lg'></i></a>"
}
},
],
onLoadSuccess: function (value) {
// 权限视图隐藏
// 此处即使可以看见,后台也有权限进行控制
if (value.total > 0) {
let view_permission = value.rows[0].permissions;
if (view_permission.indexOf('can_audit_sql') < 0) {
// 隐藏审批权限的显示
$('#demo-table').bootstrapTable('hideColumn', 'approve')
}
if (view_permission.indexOf('can_execute_sql') < 0) {
// 隐藏执行和反馈权限的显示
$table.bootstrapTable('hideColumn', 'execute');
$table.bootstrapTable('hideColumn', 'feedback')
}
}
}
})
});
// 获取用户设置的环境
$(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')
}
});
});
/**
* 获取指定环境的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': 'dml', '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')
}
})
}
/**
* 提交钩子数据
*/
let hook_modal_selector = $('#hook_modal');
$('#hook_form').submit(function () {
$(this).ajaxSubmit({
dataType: 'json',
resetForm: true,
success: function (result) {
hook_modal_selector.modal('hide');
if (result.status === 0) {
window.parent.location.href = result.jump_url
} else {
displayPNotify(result.status, result.msg);
}
},
error: function (jqXHR) {
if (jqXHR.status === 403) {
hook_modal_selector.modal('hide');
displayPNotify(jqXHR.status);
}
}
});
return false
});
<!-- 当模态框打开时 -->
hook_modal_selector.on('show.bs.modal', function (event) {
let button = $(event.relatedTarget);
// 获取值
let recipient_id = button.data('whatever_id');
let recipient_sqltype = button.data('whatever_sqltype');
if (recipient_sqltype === 'OPS') {
document.getElementById("is_show_schema").style.display = "none";
$('#s_schema').prop('required', false);
} else {
document.getElementById("is_show_schema").style.display = "";
$('#s_schema').prop('required', true);
}
let modal = $(this);
let id = $('.modal-body input')[0];
modal.find(id).val(recipient_id);
});
<!-- 当模态框关闭时 -->
hook_modal_selector.on('hidden.bs.modal', function (event) {
$('.selectpicker').selectpicker('refresh')
});
/**
* 渲染行的样式
* 已完成的自动标记为:绿色(success)
* 关闭的自动标记为:红色(danger)
*/
function render_row_style(row, index) {
let finish_status = ['已完成', '已关闭', '已勾住'];
if (finish_status.indexOf(row.progress_value) < 0) {
return {classes: 'danger'}
} else {
return {};
}
}
</script>
{% endblock %}