Commit 9da14a5d authored by Vivek's avatar Vivek

updated spreadsheet data model. made state-transfer methods same for all type of gadgets.

parent 65d0dbd8
......@@ -288,7 +288,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>945.32516.10981.40311</string> </value>
<value> <string>945.32551.59996.17425</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -306,7 +306,7 @@
</tuple>
<state>
<tuple>
<float>1441288577.91</float>
<float>1441714251.16</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -139,7 +139,7 @@
var current_state = {},\n
gadget = this;\n
return RSVP.Queue()\n
.push(function(){\n
.push(function() {\n
return gadget.getContent();\n
})\n
.push(function(content) {\n
......@@ -148,8 +148,8 @@
});\n
})\n
.declareMethod(\'finishStateTransfer\', function (current_state) {\n
return this.setContent(current_state.content);\n
})\n
return this.setContent(current_state.content);\n
})\n
.declareMethod(\'initSubGadget\', function () {\n
var data = {\n
labels: [\'Mon\', \'Tue\', \'Wed\', \'Thu\', \'Fri\'],\n
......@@ -303,7 +303,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>945.33714.48637.10274</string> </value>
<value> <string>945.39610.42841.21043</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -321,7 +321,7 @@
</tuple>
<state>
<tuple>
<float>1441361996.21</float>
<float>1441714262.07</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -141,7 +141,7 @@
var current_state = {},\n
gadget = this;\n
return RSVP.Queue()\n
.push(function(){\n
.push(function() {\n
return gadget.getContent();\n
})\n
.push(function(content) {\n
......@@ -150,7 +150,7 @@
});\n
})\n
.declareMethod(\'finishStateTransfer\', function (current_state) {\n
return this.setContent(current_state.content);\n
return this.setContent(current_state.content);\n
})\n
.declareMethod(\'initSubGadget\', function () {\n
var gadget = this,\n
......@@ -319,7 +319,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>945.33781.46058.13073</string> </value>
<value> <string>945.33788.56308.37819</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -337,7 +337,7 @@
</tuple>
<state>
<tuple>
<float>1441364931.54</float>
<float>1441714291.87</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -109,10 +109,46 @@
\n
rJS(window)\n
.declareMethod(\'getContent\', function () {\n
var gadget = this;\n
return gadget.props.hot.getData();\n
var gadget = this,\n
temp_data = gadget.props.hot.getData(),\n
temp_columns = gadget.props.hot.getColHeader(),\n
data = [],\n
columns = [],\n
content = {},\n
i, j;\n
for(i = 0; i < temp_columns.length; i += 1) {\n
var title = (temp_columns[i] === null ? \'\' : temp_columns[i]);\n
columns.push({\n
title: title\n
});\n
}\n
for(i = 0; i < temp_data.length; i += 1) {\n
var d = (data[i] = {}),\n
temp_row = temp_data[i];\n
for(j = 0; j < temp_row.length; j += 1) { \n
d[j] = temp_row[j];\n
}\n
}\n
content.columns = columns;\n
content.data = data;\n
return content;\n
})\n
.declareMethod(\'setContent\', function (content) {\n
var gadget = this,\n
temp_columns = content.columns,\n
temp_data = content.data,\n
hot = gadget.props.hot,\n
data = [],\n
temp_row = [],\n
i, j;\n
for(i = 0; i < temp_data.length; i += 1) {\n
var d = (data[i] = []);\n
temp_row = temp_data[i];\n
for(j = 0; j < Object.keys(temp_row).length; j += 1) {\n
d.push(temp_row[j]);\n
}\n
}\n
hot.loadData(data);\n
return;\n
})\n
.declareMethod(\'clearContent\', function () {\n
......@@ -126,52 +162,15 @@
return gadget.getContent();\n
})\n
.push(function(content) {\n
var columns = [],\n
data = [],\n
temp_columns = content[0],\n
temp_row, \n
i, j;\n
for(i = 0; i < temp_columns.length; i += 1) {\n
var title = (temp_columns[i] === null ? \'\' : temp_columns[i]);\n
columns.push({\n
title: title\n
});\n
}\n
for(i = 1; i < content.length; i += 1) {\n
var d = (data[i - 1] = {});\n
temp_row = content[i];\n
for(j = 0; j < temp_row.length; j += 1) { \n
d[j] = temp_row[j];\n
}\n
}\n
current_state.columns = columns;\n
current_state.content = data;\n
current_state.content = content;\n
return current_state;\n
});\n
})\n
.declareMethod(\'finishStateTransfer\', function (current_state) {\n
var gadget = this,\n
content = current_state.content,\n
temp_columns = current_state.columns,\n
hot = gadget.props.hot,\n
data = [],\n
temp_row = [],\n
i, j;\n
for(i = 0; i < temp_columns.length; i += 1) {\n
temp_row.push(temp_columns[i].title);\n
}\n
data.push(temp_row);\n
for(i = 0; i < content.length; i += 1) {\n
var d = (data[i + 1] = []);\n
temp_row = content[i];\n
for(j = 0; j < Object.keys(temp_row).length; j += 1) {\n
d.push(temp_row[j]);\n
}\n
}\n
hot.loadData(data);\n
return;\n
return this.setContent(current_state.content);\n
})\n
.declareMethod(\'initSubGadget\', function () {\n
// hard coded data for demo purpose.\n
var data = [["", "Ford", "Volvo", "Toyota", "Honda"],\n
["2014", 10, 11, 12, 13],\n
["2015", 20, 11, 14, 13],\n
......@@ -329,7 +328,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>945.32551.63779.17083</string> </value>
<value> <string>945.39661.40347.63863</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -347,7 +346,7 @@
</tuple>
<state>
<tuple>
<float>1441293672.51</float>
<float>1441717677.15</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -102,10 +102,10 @@
<value> <string encoding="cdata"><![CDATA[
/*jslint indent: 2 */\n
/*global window, jQuery, rJS, Slick*/\n
/*global window, jQuery, rJS, RSVP, Slick*/\n
"use strict";\n
\n
(function (window, $, rJS, Slick) {\n
(function (window, $, rJS, RSVP, Slick) {\n
\n
function requiredFieldValidator(value) {\n
if (value === null || value === undefined || !value.length) {\n
......@@ -123,27 +123,15 @@
} else {\n
return letter;\n
}\n
}\n
}\n
\n
rJS(window).\n
declareMethod(\'getContent\', function () {\n
return this.props.grid.getData();\n
})\n
\n
.declareMethod(\'setContent\', function (content) {\n
return;\n
})\n
\n
.declareMethod(\'clearContent\', function () {\n
return;\n
})\n
\n
.declareMethod(\'initStateTransfer\', function () {\n
var gadget = this,\n
current_state = {},\n
grid = gadget.props.grid,\n
temp_data = grid.getData(),\n
temp_columns = grid.getColumns(),\n
content = {},\n
columns = [],\n
data = [],\n
column_index_dict = {},\n
......@@ -165,15 +153,15 @@
d[column_index_dict[item]] = temp_row[item];\n
}\n
}\n
current_state.columns = columns;\n
current_state.content = data;\n
return current_state;\n
content.columns = columns;\n
content.data = data;\n
return content;\n
})\n
\n
.declareMethod(\'finishStateTransfer\', function (current_state) {\n
.declareMethod(\'setContent\', function (content) {\n
var gadget = this,\n
content = current_state.content,\n
temp_columns = current_state.columns,\n
temp_columns = content.columns,\n
temp_data = content.data,\n
grid = gadget.props.grid,\n
columns = [],\n
data = [],\n
......@@ -188,9 +176,9 @@
"editor": Slick.Editors.Text \n
});\n
}\n
for(i = 0; i < content.length; i += 1) {\n
for(i = 0; i < temp_data.length; i += 1) {\n
var d = (data[i] = {});\n
temp_row = content[i];\n
temp_row = temp_data[i];\n
for(j = 0; j < Object.keys(temp_row).length; j += 1) {\n
d[columns[j].field] = temp_row[j];\n
}\n
......@@ -200,6 +188,28 @@
grid.render();\n
return;\n
})\n
\n
.declareMethod(\'clearContent\', function () {\n
return;\n
})\n
\n
.declareMethod(\'initStateTransfer\', function () {\n
var current_state = {},\n
gadget = this;\n
return RSVP.Queue()\n
.push(function() {\n
return gadget.getContent();\n
})\n
.push(function(content) {\n
current_state.content = content;\n
return current_state;\n
});\n
})\n
\n
.declareMethod(\'finishStateTransfer\', function (current_state) {\n
return this.setContent(current_state.content);\n
})\n
\n
.declareMethod(\'initSubGadget\', function () {\n
var gadget = this;\n
var grid,\n
......@@ -242,7 +252,7 @@
g.props = {};\n
});\n
\n
}(window, jQuery, rJS, Slick));\n
}(window, jQuery, rJS, RSVP, Slick));\n
]]></string> </value>
......@@ -380,7 +390,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>945.33860.24768.49083</string> </value>
<value> <string>945.39646.6878.42018</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -398,7 +408,7 @@
</tuple>
<state>
<tuple>
<float>1441369486.01</float>
<float>1441716413.3</float>
<string>GMT</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment