-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestapi.html
91 lines (85 loc) · 3.07 KB
/
restapi.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://w2ui.com/src/w2ui-1.4.3.min.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="http://w2ui.com/src/w2ui-1.4.3.min.js"></script>
<style>
body {
background: #114;
padding: 1em;
}
#grid {
box-shadow: 0px 2px 15px 0px #fff;
}
h1 {
color: white;
font-family: arial, sans;
}
</style>
</head>
<body>
<h1>Server log overview</h1>
<div id="grid" style="width: 100%; height: 500px;"></div>
<script>
// fetch records from API
// todo: catch network errors
$.get("http://it4se.com:3333/api/agents", function(data){
// inject record id for w2ui and split time/date
for (i=0;i<data.length;i++) {
data[i].recid=i;
/*
var d = data[i].date.split('T');
data[i].date = d[0];
data[i].time = d[1].substring(0,5);
*/
if (data[i].severity == "Error") data[i].style = "background: #fcc"
if (data[i].severity == "Warning") data[i].style = "background: #ffc"
}
$('#grid').w2grid({
name: 'grid',
header: 'Reported database server incidents',
show: {
lineNumbers : true,
header: true,
toolbar: true,
toolbarDelete: true,
expandColumn: true,
footer: true
},
multiSelect : false,
onDelete: function (event) {
if (event.force) { // user confirmed deletion
var rec = w2ui['grid'].getSelection();
$.ajax({
url: 'http://sqldba.no:3333/api/agents/' + data[rec]["_id"],
type: 'DELETE',
success: function(result) {
w2alert('Record deleted');
}
});
}
},
onExpand: function (event) {
$('#'+event.box_id).html('<div style="padding: 10px">' + (data[event.recid].body || "No details available.") + '</div>').animate({ 'height': 50 }, 50);
},
columns: [
{ field: 'date', caption: 'Date', sortable: true, size: '90px' },
{ field: 'severity', caption: 'Severity', sortable: true, size: '60px' },
{ field: 'event', caption: 'Subject', sortable: true, size: '200px' },
{ field: 'company', caption: 'Company', sortable: true, size: '120px' },
{ field: 'address', caption: 'Address', sortable: true, size: '120px' },
{ field: 'parent', caption: 'Parent', sortable: true, size: '120px' }
],
searches: [
{ field: 'event', caption: 'Subject', type: 'text' },
{ field: 'body', caption: 'Details', type: 'text' },
{ field: 'company', caption: 'Company', type: 'text' }
],
records: data
});
w2ui['grid'].sort('date', 'desc')
});
</script>
</body>
</html>