forked from pythonzm/Ops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.html
408 lines (374 loc) · 16.5 KB
/
dashboard.html
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
{% extends 'base.html' %}
{% load staticfiles %}
{% block head %}
<link rel="stylesheet" href="{% static 'jquery-confirm/dist/jquery-confirm.min.css' %}">
<style>
.form-horizontal .form-group {
margin-right: -200px;
}
</style>
{% endblock %}
{% block content %}
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
<h3>{{ assets_count }}</h3>
<p>资产管理</p>
</div>
<div class="icon">
<i class="fa fa-server"></i>
</div>
<a href="{% url 'assets_list' %}" class="small-box-footer">查看所有 <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-green">
<div class="inner">
<h3>{{ project_count }}<sup style="font-size: 20px"></sup></h3>
<p>项目管理</p>
</div>
<div class="icon">
<i class="fa fa-github"></i>
</div>
<a href="{% url 'proj_list' %}" class="small-box-footer">查看所有 <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
<h3>{{ user_count }}</h3>
<p>用户管理</p>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
</div>
<a href="{% url 'user_list' %}" class="small-box-footer">查看所有 <i
class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-red">
<div class="inner">
<h3>{{ fort_server_count }}</h3>
<p>终端管理</p>
</div>
<div class="icon">
<i class="ion fa-location-arrow"></i>
</div>
<a href="{% url 'fort_server' %}" class="small-box-footer">查看所有 <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
</div>
<!-- 告警线图 -->
<div class="pad">
<div id="alert" style="height: 325px;"></div>
</div>
<!-- 常用网站 -->
<div class="row">
<div class="col-md-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title"><strong>常用网址导航</strong></h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-default" data-toggle="modal" id="add-website"
data-target="#WebSiteModal"> 添加网站
</button>
</div>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="row" id="website">
{% for website in websites %}
<div class="col-md-3">
<div class="box box-warning box-solid web-box">
<div class="box-header with-border" style="text-align: center">
<a href="{{ website.web_address }}" target="_blank"><h3
class="box-title">{{ website.web_name }}</h3></a>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i
class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool modify" data-toggle="modal"
data-target="#WebSiteModal"
data-id="{{ website.id }}"><i class="fa fa-wrench"></i>
</button>
<button type="button" class="btn btn-box-tool delete"
data-id="{{ website.id }}"><i class="fa fa-times"></i></button>
</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body">
{{ website.web_des }}
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
{% endfor %}
</div>
<!-- /.row -->
</div>
<!-- ./box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
<!-- WebSiteModal -->
<div class="modal fade" id="WebSiteModal" tabindex="-1" role="dialog"
aria-labelledby="WebSiteModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="WebSiteModalLabel">
</h4>
</div>
<div class="modal-body">
<form id="web_info" class="main form-horizontal">
<fieldset>
<div class="form-group">
<label for="web_name" class="col-sm-2 control-label">网站名称</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="web_name" id="web_name"
required/>
</div>
</div>
<div class="form-group">
<label for="web_address" class="col-sm-2 control-label">网站地址</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="web_address" id="web_address"
required/>
</div>
</div>
<div class="form-group">
<label for="web_des" class="col-sm-2 control-label">网站描述</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="web_des" id="web_des"
required/>
</div>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" id="web_ops"></button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
{% endblock %}
{% block js %}
<!-- ChartJS -->
<script src="{% static 'js/echarts.common.min.js' %}"></script>
<script src="{% static 'jquery-confirm/dist/jquery-confirm.min.js' %}"></script>
<script>
// 告警线图
function genData() {
let x_data = [];
let y_data = [];
{% for zabbix_alert in zabbix_alerts %}
x_data.push('{{ zabbix_alert.alert_date|date:"Y-m-d" }}');
y_data.push('{{ zabbix_alert.alert_num }}');
{% endfor %}
return {
x_data: x_data,
y_data: y_data,
};
}
let AlertChart = echarts.init(document.getElementById('alert'));
let data = genData();
option_alert = {
title: {
text: '历史告警线图'
},
tooltip: {
trigger: 'axis'
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: data.x_data.slice(-10, )
},
yAxis: {
type: 'value'
},
series: [
{
name: '当天告警数量',
type: 'line',
data: data.y_data.slice(-10, )
},
]
};
AlertChart.setOption(option_alert);
let web_ops = $('#web_ops');
let web_wrap = $('#website');
// 添加常用网站
$('#add-website').on('click', function () {
document.getElementById('web_info').reset();
$('.modal-title').text('新增网站');
web_ops.text('添加');
web_ops.unbind('click').on('click', function () {
let data = $('#web_info').serializeJson();
$.ajax({
url: '/api/website/',
type: 'POST',
data: JSON.stringify(data),
dataType: 'json',
contentType: "application/json",
success: function (res) {
web_wrap.append(
`<div class="col-md-3">
<div class="box box-warning box-solid web-box">
<div class="box-header with-border" style="text-align: center">
<a href="${res.web_address}" target="_blank"><h3
class="box-title">${res.web_name}</h3></a>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i
class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool modify" data-toggle="modal"
data-target="#WebSiteModal"
data-id="${res.id}"><i class="fa fa-wrench"></i>
</button>
<button type="button" class="btn btn-box-tool delete"
data-id="${res.id}"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
${res.web_des}
</div>
</div>
</div>`)
},
error: function (response) {
$.alert({
title: 'Tips',
type: 'red',
content: response.responseText,
})
}
})
})
});
// 更新常用网站
web_wrap.on('click', '.modify', function () {
let web_id = $(this).attr('data-id');
let web_box = $(this).parents('.web-box');
let web_address = web_box.find('a').attr('href');
let web_name = web_box.find('a').text();
let web_des = web_box.find('.box-body').text().trim();
$('.modal-title').text('修改网站信息');
web_ops.text('确认修改');
$('#web_name').val(web_name);
$('#web_address').val(web_address);
$('#web_des').val(web_des);
web_ops.unbind('click').on('click', function () {
let data = $('#web_info').serializeJson();
$.ajax({
url: '/api/website/' + web_id + '/',
type: 'PUT',
data: JSON.stringify(data),
dataType: 'json',
contentType: "application/json",
success: function (res) {
web_box.find('a').text(res.web_name);
web_box.find('a').attr('href', res.web_address);
web_box.find('.box-body').text(res.web_des);
$.alert({
title: 'Tips',
type: 'green',
content: '修改完成!',
})
},
error: function (response) {
$.alert({
title: 'Tips',
type: 'red',
content: response.responseText,
})
}
})
});
});
// 删除常用网站
web_wrap.on('click', '.delete', function () {
let pk = $(this).attr('data-id');
let this_web = $(this).parents('.col-md-3');
$.confirm({
title: 'Tips',
content: '确定要删除这条记录么?',
type: 'red',
buttons: {
Ok: function () {
$.ajax({
url: '/api/website/' + pk + '/',
method: 'DELETE',
success: function () {
this_web.remove()
},
error: function (data) {
$.alert({
title: 'Tips',
type: 'red',
content: '删除失败!' + data.responseText,
})
}
})
},
Cancel: function () {
//
}
}
});
});
// 将数据JSON化
(function ($) {
$.fn.serializeJson = function () {
let serializeObj = {};
let array = this.serializeArray();
$(array).each(function () {
if (serializeObj[this.name]) {
if ($.isArray(serializeObj[this.name])) {
serializeObj[this.name].push(this.value);
} else {
serializeObj[this.name] = [serializeObj[this.name], this.value];
}
} else {
serializeObj[this.name] = this.value;
}
});
return serializeObj;
};
})(jQuery);
</script>
{% endblock %}