-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
183 lines (153 loc) · 6.93 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!doctype>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
.tab-pane {
border-left: 1px solid #ddd;
border-right: 1px solid #ddd;
border-bottom: 1px solid #ddd;
border-radius: 0px 0px 5px 5px;
padding: 10px;
margin: 0 auto;
height:300px;
}
.nav-tabs {
margin-bottom: 0;
}
</style>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/web3.js"></script>
<script type="text/javascript" src="js/bundle.js"></script>
<script type='text/javascript'>
var table=null;
var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
web3.eth.defaultAccount = web3.eth.accounts[0];
var bloodbankContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"addBlood","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"userName","type":"string"},{"name":"amount","type":"uint256"}],"name":"addBloodByUser","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"queryBloodRemaining","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"time","type":"uint256"},{"indexed":true,"name":"donorName","type":"string"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"BloodDonated","type":"event"}]).at('0x89c144aaf07dc9cbc579022e3e366e5cb3218443');
function get() {
var param = document.getElementById('query').value;
var res = bloodbankContract.queryBloodRemaining();
document.getElementById('queryres').innerText = res;
}
function set() {
var amount = document.getElementById('amount').value;
var name = document.getElementById('name').value;
var res = bloodbankContract.addBloodByUser(name,amount);
}
var fil =null;
function search(){
var donorName = document.getElementById('donrName').value;
if(donorName=='' || donorName==undefined)
alert("Donor Name required");
fil = web3.eth.filter({fromBlock:0,toBlock:"latest",address:"0x89c144aaf07dc9cbc579022e3e366e5cb3218443",topics:[null,web3.sha3(donorName)]});
$('#searchTable tbody').empty();
fil.get(function(a,b){
if(b.length==0){
console.log("NO data found");
html = "<tr>";
var str = "<td colspan='3' align='center'>No Data found for give user: <b>"+donorName+"</b></td>";
html = html + str + "</tr>";
table.append($(html));
}
for(i=0;i<b.length;i++){
console.log(b);
var dataDecoder=coder.decodeParams(["uint","uint"],b[i].data.replace("0x", ""));
var gridRowCount = b.length;
//var html="";
html = "<tr>";
var str = "<td>Name</td>"+"<td>"+new Date(dataDecoder[0].toNumber()*1000)+"</td><td>"+dataDecoder[1]+"</td>";
html = html + str + "</tr>";
table.append($(html));
}
}
);
}
</script>
</head>
<body bgcolor='#E6E6FA'>
<div class="container">
<ul class="nav nav-tabs">
<li class="active"><a href="#dblood">Donate Blood </a></li>
<li><a href="#qblood">Query Blood </a></li>
<li><a href="#slogs">Search Logs</a></li>
</ul>
<div class="tab-content">
<div id="dblood" class="tab-pane fade in active">
<h3> Donate your blood here</h3>
<form class="form-horizontal col-sm-2" role="form">
<div class="form-group">
<label class="control-label" for="amount">Amount of Blood(lts):</label>
<input type="amount" class="form-control" id="amount">
</div>
<div class="form-group">
<label class="control-label" for="name">Name of the donor:</label>
<input type="text" class="form-control" id="name">
</div>
<button type="button" onclick="set()" class="btn btn-default">Save</button>
</form>
</div>
<div id="qblood" class="tab-pane fade">
<h3> Findout how much left</h3>
<form class="form-horizontal col-sm-2" role="form">
<div class="form-group">
<label class="control-label" for="query">Fetch the amount of blood left:</label>
<button id="query" type="button" onclick="get()" class="btn btn-default">Fetch</button>
<div id='queryres'></div>
</div>
</form>
</div>
<div id="slogs" class="tab-pane fade">
Searchable
<form class="form-horizontal col-sm-2" role="form">
<div class="form-group">
<label class="control-label" for="donrName">Name of the donor:</label>
<input type="donrName" class="form-control" id="donrName">
</div>
<div class="form-group">
<label class="control-label" for="query">Search :</label>
<button id="query" type="button" onclick="search()" class="btn btn-default">Fetch</button>
<div id='queryres'></div>
</div>
</form>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(".nav-tabs a").click(function(){
$(this).tab('show');
});
$('.nav-tabs a').on('shown.bs.tab', function(event){
var x = $(event.target).text(); // active tab
var y = $(event.relatedTarget).text(); // previous tab
$(".act span").text(x);
$(".prev span").text(y);
});
var tableDiv = $("<div class='table-responsive'>");
$('#slogs').append(tableDiv);
table = $("<table id='searchTable' class='table table-striped table-bordered table-hover table-condensed small'>");
tableDiv.append(table);
///
/// Table head
///
html = "<thead>" +
" <tr>" +
" <th><strong>Name</strong></th>" +
" <th><strong>Time</strong></th>" +
" <th><strong>Donated Amount</strong></th>" +
" </tr>" +
"</thead>";
var tableHead = $(html);
table.append(tableHead);
///
/// Table data
///
});
</script>
</body>
</html>