diff --git a/js/json2htmltable.js b/js/json2htmltable.js new file mode 100644 index 0000000..e41b176 --- /dev/null +++ b/js/json2htmltable.js @@ -0,0 +1,42 @@ +// Thanks to https://stackoverflow.com/a/21065846 +var _table_ = document.createElement('table'), + _tr_ = document.createElement('tr'), + _th_ = document.createElement('th'), + _td_ = document.createElement('td'); + +// Builds the HTML Table out of myList json data from Ivy restful service. +function buildHtmlTable(arr) { + var table = _table_.cloneNode(false), + columns = addAllColumnHeaders(arr, table); + for (var i = 0, maxi = arr.length; i < maxi; ++i) { + var tr = _tr_.cloneNode(false); + for (var j = 0, maxj = columns.length; j < maxj; ++j) { + var td = _td_.cloneNode(false); + cellValue = arr[i][columns[j]]; + td.appendChild(document.createTextNode(arr[i][columns[j]] || '')); + tr.appendChild(td); + } + table.appendChild(tr); + } + return table; +} + +// Adds a header row to the table and returns the set of columns. +// Need to do union of keys from all records as some records may not contain +// all records +function addAllColumnHeaders(arr, table) { + var columnSet = [], + tr = _tr_.cloneNode(false); + for (var i = 0, l = arr.length; i < l; i++) { + for (var key in arr[i]) { + if (arr[i].hasOwnProperty(key) && columnSet.indexOf(key) === -1) { + columnSet.push(key); + var th = _th_.cloneNode(false); + th.appendChild(document.createTextNode(key)); + tr.appendChild(th); + } + } + } + table.appendChild(tr); + return columnSet; +} \ No newline at end of file diff --git a/js/table_styles.css b/js/table_styles.css new file mode 100644 index 0000000..e10c5b7 --- /dev/null +++ b/js/table_styles.css @@ -0,0 +1,16 @@ +table { + margin-bottom: 20px; + border: 1px solid #dddddd; + border-collapse: collapse; +} +table th { + font-weight: bold; + padding: 5px; + background: #efefef; + border: 1px solid #dddddd; +} +table td { + border: 1px solid #dddddd; + padding: 5px; + text-align:center; +} \ No newline at end of file diff --git a/web.py b/web.py index 3bcdd20..56e9b01 100644 --- a/web.py +++ b/web.py @@ -1,5 +1,3 @@ -import waitress - import model import json import falcon @@ -102,8 +100,6 @@ app.add_route('/api/diff/{action_id}', ActivityDiff()) app.add_route('/leaderboard/{leaderboard}/platform/{platform}', ActivityHtml()) app.add_route('/diff/{action_id}', ActivityDiffHtml()) -app.add_route('/js/{file}', JS()) - app.add_route('/{var}', MainPage()) app.add_route('/api/cache/{action}', Cache()) @@ -111,4 +107,7 @@ app.add_route('/api/cache/{action}', Cache()) application = app # for uwsgi if __name__ == '__main__': + import waitress + import os + app.add_static_route('/js', os.path.join(os.path.dirname(os.path.abspath(__file__)), 'js')) waitress.serve(app, host='127.0.0.1', port=9485)