Skip to content

Commit 4162d7b

Browse files
committed
Add Data Table
1 parent 3b8172b commit 4162d7b

File tree

4 files changed

+185
-1
lines changed

4 files changed

+185
-1
lines changed

db/models/transactionData.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ TransactionData.prototype.APPROVED = 'APPROVED';
1717
TransactionData.prototype.FAILED = 'FAILED';
1818

1919
TransactionData.prototype.readAll = function() {
20+
console.log('123');
2021
return pool.query('SELECT * FROM transactiondata');
2122
};
2223

public/stylesheets/style.css

+137
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,141 @@ input[type="text"]:focus {
9494
position:relative;
9595
top:1px;
9696
}
97+
@import url(http://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100);
98+
99+
div.table-title {
100+
display: block;
101+
margin: auto;
102+
max-width: 600px;
103+
padding:5px;
104+
width: 100%;
105+
}
106+
107+
.table-title h3 {
108+
color: #fafafa;
109+
font-size: 30px;
110+
font-weight: 400;
111+
font-style:normal;
112+
font-family: "Roboto", helvetica, arial, sans-serif;
113+
text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
114+
text-transform:uppercase;
115+
}
116+
117+
118+
/*** Table Styles **/
119+
120+
.table-fill {
121+
background: white;
122+
border-radius:3px;
123+
border-collapse: collapse;
124+
height: 320px;
125+
margin: auto;
126+
max-width: 600px;
127+
padding:5px;
128+
width: 100%;
129+
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
130+
animation: float 5s infinite;
131+
}
132+
133+
th {
134+
color:#D5DDE5;;
135+
background:#1b1e24;
136+
border-bottom:4px solid #9ea7af;
137+
border-right: 1px solid #343a45;
138+
font-size:23px;
139+
font-weight: 100;
140+
padding:24px;
141+
text-align:left;
142+
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
143+
vertical-align:middle;
144+
}
145+
146+
th:first-child {
147+
border-top-left-radius:3px;
148+
}
149+
150+
th:last-child {
151+
border-top-right-radius:3px;
152+
border-right:none;
153+
}
154+
155+
tr {
156+
border-top: 1px solid #C1C3D1;
157+
border-bottom-: 1px solid #C1C3D1;
158+
color:#666B85;
159+
font-size:16px;
160+
font-weight:normal;
161+
text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);
162+
}
163+
164+
tr:hover td {
165+
background:#4E5066;
166+
color:#FFFFFF;
167+
border-top: 1px solid #22262e;
168+
border-bottom: 1px solid #22262e;
169+
}
170+
171+
tr:first-child {
172+
border-top:none;
173+
}
174+
175+
tr:last-child {
176+
border-bottom:none;
177+
}
178+
179+
tr:nth-child(odd) td {
180+
background:#EBEBEB;
181+
}
182+
183+
tr:nth-child(odd):hover td {
184+
background:#4E5066;
185+
}
186+
187+
tr:last-child td:first-child {
188+
border-bottom-left-radius:3px;
189+
}
190+
191+
tr:last-child td:last-child {
192+
border-bottom-right-radius:3px;
193+
}
194+
195+
td {
196+
background:#FFFFFF;
197+
padding:20px;
198+
text-align:left;
199+
vertical-align:middle;
200+
font-weight:300;
201+
font-size:18px;
202+
text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
203+
border-right: 1px solid #C1C3D1;
204+
}
205+
206+
td:last-child {
207+
border-right: 0px;
208+
}
209+
210+
th.text-left {
211+
text-align: left;
212+
}
213+
214+
th.text-center {
215+
text-align: center;
216+
}
217+
218+
th.text-right {
219+
text-align: right;
220+
}
221+
222+
td.text-left {
223+
text-align: left;
224+
}
225+
226+
td.text-center {
227+
text-align: center;
228+
}
229+
230+
td.text-right {
231+
text-align: right;
232+
}
233+
97234

routes/api.js

+16
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ router.put('/v1/data', function(req, res, next) {
5151
}
5252
});
5353

54+
/**
55+
* Get All Data
56+
* 拿table中全部的資料,初始化實用
57+
*/
58+
router.get('/v1/all', function(req, res, next) {
59+
transactionData.readAll().then(function(result){
60+
// console.log('typeof: ' + typeof result);
61+
// console.log('object: ' + JSON.parse(JSON.stringify(result)));
62+
res.json(result.rows);
63+
})
64+
.catch(function (err) {
65+
console.log(err.message, err.stack);
66+
res.json({'error': {'message': err.message}});
67+
});
68+
69+
});
5470
/**
5571
* Get txHash information
5672
* Example:

views/index.jade

+31-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ block content
1313
br
1414
br
1515
p(id="txnHash")
16+
br
17+
br
18+
table.table-fill(id="dataTable")
19+
thead
20+
tr
21+
th.text-left txHash
22+
th.text-left transactionHash
23+
th.text-left data
24+
th.text-left timestamp
25+
th.text-left status
26+
tbody.table-hover
1627
script(type="text/javascript").
1728
$(function(){
1829
$('#send').click(function(e){
@@ -29,6 +40,25 @@ block content
2940
$('#txnHash').text('your txHash: ' + object.data.txHash);
3041
}
3142
});
32-
});
43+
});
44+
$.ajax({
45+
type: 'GET',
46+
contentType: 'application/json',
47+
url: 'http://localhost:3000/api/v1/all',
48+
success: function(data) {
49+
console.log(data);
50+
51+
for (index = 0; index < data.length; index++) {
52+
var tableContent = '<tr>';
53+
tableContent += "<td>" + data[index].txhash + "</td>";
54+
tableContent += "<td>" + data[index].transactionhash + "</td>";
55+
tableContent += "<td>" + data[index].data + "</td>";
56+
tableContent += "<td>" + data[index].txtimestamp + "</td>";
57+
tableContent += "<td>" + data[index].status + "</td>";
58+
tableContent += '</tr>';
59+
$('#dataTable tr:last').after(tableContent);
60+
}
61+
}
62+
});
3363
});
3464

0 commit comments

Comments
 (0)