-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
executable file
·161 lines (127 loc) · 4.72 KB
/
index.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Spread JS</title>
<script type="text/javascript" src="js/jquery-3.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.editinplace-v2.2.1.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="js/graph.js"></script>
<script type="text/javascript" src="js/dynamic-formula.js"></script>
</head>
<body>
<table id="data-table" style="border: 1px solid; border-collapse: collapse" border="1" cellspacing="5px"
cellpadding="5px">
</table>
<script src="http://localhost:8888/socket.io/socket.io.js"></script>
<script type="text/javascript">
// <![CDATA[
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages': ['corechart']});
var json;
var graphOptions;
$.getJSON("data.json").done(function (data) {
json = data;
renderGrid();
prepareEditInPlace();
displayChart();
});
function renderGrid() {
var dataTableElement = $('#data-table');
var rows = json.rows;
for (var i = 0; i < rows.length; i++) {
var tdString = "";
var columns = rows[i].cell;
for (var colModelIndex = 0; colModelIndex < json.colModel.length; colModelIndex++) {
tdString += '<td id="' + rows[i].id + "_" + json.colModel[colModelIndex].name + '">'
+ dynamic_formula(json, columns[json.colModel[colModelIndex].name])
+ "</td>";
}
dataTableElement.append("<tr>" + tdString + "</tr>");
}
}
function prepareEditInPlace() {
$("#data-table").find("td").editInPlace(
{
url: "http://com.examplesite.www/users",
callback: function (id, newValue, originalValue) {
if (newValue == originalValue) {
return newValue;
}
updateJsonData(id, newValue);
emitData();
refreshGraphData();
return dynamic_formula(json, enteredText);
},
clickEvent: 'dblclick',
show_buttons: false
}
);
}
function emitData(cellId, newValue) {
socket.emit("cell_update", {id: cellId, value: newValue});
}
function displayChart() {
graphOptions = {
cols: ["name", "employeeID"],
block: "chart_div",
type: "bar",
opt: {
'title': 'Graph',
'width': 400,
'height': 300
}
};
drawChart(json, graphOptions);
var options2 = {
cols: ["name", "employeeID"],
block: "chart_div_2",
type: "pie",
opt: {
'title': 'Pie Chart of Name vs EmployeeID',
'width': 400,
'height': 300
}
}
drawChart(json, options2);
}
function updateJsonData(cellId, newValue) {
var rowNoInJsonData;
for (var i = 0; i < json.rows.length; i++) {
if (json.rows[i].id == cellId.substring(0, cellId.indexOf('_'))) {
rowNoInJsonData = i;
}
}
var row = rowNoInJsonData;
var column = cellId.substring(cellId.indexOf('_') + 1);
json.rows[row].cell[column] = newValue;
}
function refreshGraphData() {
displayChart();
}
function getColumnList() {
var columnList = array();
for (var i = 0; i < json.colModel.length; i++) {
columnList[i] = json.colModel[i].name;
}
return columnList;
}
// ]]>
</script>
<div id="chart_div" style="margin-top: 10px"></div>
<div id="chart_div_2" style="margin-top: 10px"></div>
<script type="text/javascript">
var socket = io('http://localhost:8888');
socket.on('row_add', function (data) {
console.log("Someone added a row");
});
socket.on('row_delete', function (data) {
console.log("Someone deleted a row");
});
socket.on('cell_update', function (data) {
var selectorid = '#'+data.id;
$(selectorid).html(data.value);
});
</script>
</body>
</html>