-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
executable file
·161 lines (109 loc) · 3.98 KB
/
client.js
File metadata and controls
executable file
·161 lines (109 loc) · 3.98 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
$.getJSON( "http://localhost:3000/latest", function( data ) {
var items = [];
$.each( data, function( key, val ) {
items.push( "<p>" + val + "</p>" );
});
$( "<tr/>", {
"class": "my-new-list",
html: items.join( "" )
}).appendTo( "#LatestDiv" );
});
$.getJSON( "http://localhost:3000/count", function( data1 ) {
var items = [];
$.each( data1, function( key, val ) {
items.push( "<h4>Total messages in DB: " + val + "</h4>" );
});
$( "<p/>", {
"class": "h1",
html: items.join( "**" )
}).appendTo( "#counter" );
});
$.getJSON("http://localhost:3000/api/testdata", function(data) {
$('#summary').text(data.result);
$('#summary').text("testiranje prijenosa putem getJSON-a u HTML");
});
var socket = io.connect('http://localhost:3020');
socket.on('latest', function (msg) {
console.log(msg);
$('#mydiv').html(msg);
$('#mydiv').html(msg);
var tr;
for (var i = 0; i < msg.length; i++) {
tr = $('<tbody>');
tr.append("<tr>" + msg[i].id + "</tr>");
tr.append("<tr>" + msg[i].client + "</tr>");
tr.append("<tr>" + msg[i].status + "</tr>");
$('#mydiv').html(msg);
}
});
socket.on('logline', function (msg) {
console.log(msg);
//$('#logline1').prepend($('<tr>').text(msg));
var returnString = (msg)
var jsondata = $.parseJSON(returnString);
id = "<b>" + jsondata.id + "</b>" + " > ";
client = "<b>" + jsondata.client + "</b>" + " > " ;
service = jsondata.service + " > ";
status = jsondata.status + " > ";
datetime = " ( " + jsondata.datetime + " ) ";
$('#logline1').empty();
$('#logline1').prepend($('<tr>').html(id + client + service + status + datetime));
});
socket.on('avgCnt', function(msg) {
console.log(msg);
$.each(msg, function (key, obj) {
console.log(key, obj)
$('<div />', {
id: key,
text: obj
}).appendTo('body')
});
var returnString = (msg)
var jsondata = $.parseJSON(returnString);
id = "<b>" + jsondata + "</b>" + " > ";
console.log(jsondata)
//$('#dashAvgCnt').append($('<h1>').html(id));
// $('#dashAvg').replaceWith.text(msg);
})
// Generiraj box za klijente
socket.on('clientList', function(msg) {
console.log(msg);
//var returnString = (msg)
//var jsondata = $.parseJSON(returnString);
$.each(msg, function (key, obj) {
console.log(key, obj)
$('<div />', {
id: key,
text: obj
}).appendTo('#clientList');
});
// var returnString = (msg)
// var jsondata = $.parseJSON(returnString);
// id = "<b>" + jsondata + "</b>" + " > ";
// console.log(jsondata)
// $('#dashAvgCnt').append($('<h1>').html(id));
// $('#dashAvg').replaceWith.text(msg);
})
socket.on('clientList', function (msg) {
console.log(msg);
//$('#logline1').prepend($('<tr>').text(msg));
var returnString = (msg)
var jsondata = $.parseJSON(returnString);
id = "<b>" + jsondata.id + "</b>" + " > ";
client = "<b>" + jsondata.client + "</b>" + " > " ;
//service = jsondata.service + " > ";
//status = jsondata.status + " > ";
//datetime = " ( " + jsondata.datetime + " ) ";
// $('#logline1').empty();
$('#clientList').append($('<p>').html(id + client));
//
// var json_obj = $.parseJSON(msg);//parse JSON
//
// var output="<ul>";
// for (var i in json_obj)
// {
// output+="<li>" + json_obj[i].client + ", " + json_obj[i].service + "</li>";
// }
// output+="</ul>";
///
});