Commit 4e5599d778d20304e6d32d7d2723419f2fb2439b
1 parent
1a631d48d6
Exists in
master
html data
Showing 1 changed file with 20 additions and 2 deletions Side-by-side Diff
httpserver.js
... | ... | @@ -32,7 +32,25 @@ function toArrayOfObject(obj) { |
32 | 32 | } |
33 | 33 | |
34 | 34 | function formatDataAsHtml(data) { |
35 | - return JSON.stringify(data); | |
35 | + var total = 0; | |
36 | + var result = '<html><table><tr><th>DOMPUL</th><th>STOCK</th></tr>'; | |
37 | + | |
38 | + var count = data.length; | |
39 | + for (var i = 0; i < count; i++) { | |
40 | + result += '<tr>'; | |
41 | + result += '<td>'; | |
42 | + result += data[i]['name']; | |
43 | + result += '</td>'; | |
44 | + result += '<td style="text-align: right;">'; | |
45 | + result += data[i]['stock']; | |
46 | + result += '</td>'; | |
47 | + result += '</tr>'; | |
48 | + | |
49 | + total += parseInt(data[i]['stock']); | |
50 | + } | |
51 | + result += '<tr><td style="font-weight: bold;">TOTAL</td><td style="font-weight: bold; text-align: right;">' + total + '</td></tr>'; | |
52 | + result += '</table></html>'; | |
53 | + return result; | |
36 | 54 | } |
37 | 55 | |
38 | 56 | function formatData(_data, format) { |
... | ... | @@ -43,7 +61,7 @@ function formatData(_data, format) { |
43 | 61 | else if (format == 'json') { |
44 | 62 | return JSON.stringify(data); |
45 | 63 | } |
46 | - | |
64 | + | |
47 | 65 | return formatDataAsHtml(data); |
48 | 66 | } |
49 | 67 |