added pagination on Blocks, Txs, Addresses

This commit is contained in:
arnaucode
2017-08-31 16:13:50 +02:00
parent 58393a26e9
commit 63a40a05b2
12 changed files with 148 additions and 38 deletions

View File

@@ -33,3 +33,12 @@ other
- fix error in exploreBlockchain.go, when getting the tx.Vin - fix error in exploreBlockchain.go, when getting the tx.Vin
tx 8f04960da36beaa928b9693f7dca4afae5a6122bb6874d409a1156e4c6c55024 has 4 vin, but exploreBlockchain is only getting the first tx 8f04960da36beaa928b9693f7dca4afae5a6122bb6874d409a1156e4c6c55024 has 4 vin, but exploreBlockchain is only getting the first
- pagination in address network generation
- stop rendering dots of sankey, when view change
- sidebar pages:
list of addresses in fairmarket (addresses of shops), to view statistics in time of the inputs and outputs in a timeline
- refresh blockchain database every minute

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

View File

@@ -35,16 +35,22 @@ var routes = Routes{
AllAddresses, AllAddresses,
}, },
Route{ Route{
"GetLastAddr", "Blocks",
"Get", "Get",
"/lastaddr", "/blocks/{page}/{count}",
GetLastAddr, Blocks,
}, },
Route{ Route{
"GetLastTx", "Txs",
"Get", "Get",
"/lasttx", "/txs/{page}/{count}",
GetLastTx, Txs,
},
Route{
"Addresses",
"Get",
"/addresses/{page}/{count}",
Addresses,
}, },
Route{ Route{
"Block", "Block",
@@ -171,24 +177,42 @@ func AllAddresses(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, string(jsonNodes)) fmt.Fprintln(w, string(jsonNodes))
} }
func GetLastAddr(w http.ResponseWriter, r *http.Request) { func Blocks(w http.ResponseWriter, r *http.Request) {
ipFilter(w, r) ipFilter(w, r)
vars := mux.Vars(r)
addresses := []AddressModel{} page, err := strconv.Atoi(vars["page"])
err := addressCollection.Find(bson.M{}).Limit(10).Sort("-$natural").All(&addresses)
check(err) check(err)
count, err := strconv.Atoi(vars["count"])
check(err)
blocks := []BlockModel{}
err = blockCollection.Find(bson.M{}).Skip((page - 1) * 20).Limit(count).Sort("-$natural").All(&blocks)
check(err)
for _, block := range blocks {
//blockheight := strconv.FormatInt(block.Height, 10)
blockheight := block.Height
txs := []TxModel{}
err = txCollection.Find(bson.M{"blockheight": blockheight}).All(&txs)
block.Txs = txs
}
//convert []resp struct to json //convert []resp struct to json
jsonResp, err := json.Marshal(addresses) jsonData, err := json.Marshal(blocks)
check(err) check(err)
fmt.Fprintln(w, string(jsonResp)) fmt.Fprintln(w, string(jsonData))
} }
func GetLastTx(w http.ResponseWriter, r *http.Request) { func Txs(w http.ResponseWriter, r *http.Request) {
ipFilter(w, r) ipFilter(w, r)
vars := mux.Vars(r)
page, err := strconv.Atoi(vars["page"])
check(err)
count, err := strconv.Atoi(vars["count"])
check(err)
txs := []TxModel{} txs := []TxModel{}
err := txCollection.Find(bson.M{}).Limit(10).Sort("-$natural").All(&txs) err = txCollection.Find(bson.M{}).Skip((page - 1) * 20).Limit(count).Sort("-$natural").All(&txs)
check(err) check(err)
//convert []resp struct to json //convert []resp struct to json
@@ -197,6 +221,24 @@ func GetLastTx(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, string(jsonData)) fmt.Fprintln(w, string(jsonData))
} }
func Addresses(w http.ResponseWriter, r *http.Request) {
ipFilter(w, r)
vars := mux.Vars(r)
page, err := strconv.Atoi(vars["page"])
check(err)
count, err := strconv.Atoi(vars["count"])
check(err)
addresses := []AddressModel{}
err = addressCollection.Find(bson.M{}).Skip((page - 1) * 20).Limit(count).Sort("-$natural").All(&addresses)
check(err)
//convert []resp struct to json
jsonResp, err := json.Marshal(addresses)
check(err)
fmt.Fprintln(w, string(jsonResp))
}
func Block(w http.ResponseWriter, r *http.Request) { func Block(w http.ResponseWriter, r *http.Request) {
ipFilter(w, r) ipFilter(w, r)

View File

@@ -10,6 +10,12 @@
<a ng-href="#!/address/{{address.hash}}" class="list-group-item-text">{{address.hash}}</a> <a ng-href="#!/address/{{address.hash}}" class="list-group-item-text">{{address.hash}}</a>
</div> </div>
</div> </div>
<ul class="pager">
<li><a class="withripple" ng-click="getPrev()">Previous</a></li>
Current page: {{page}}
<li><a class="withripple" ng-click="getNext()">Next</a></li>
</ul>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -13,12 +13,25 @@ angular.module('app.addresses', ['ngRoute'])
//last addr //last addr
$scope.addresses = []; $scope.addresses = [];
$http.get(urlapi + 'lastaddr') $scope.page = 1;
.then(function(data, status, headers, config) { $scope.count = 10;
console.log(data); $scope.getAddresses = function() {
$scope.addresses = data.data; $http.get(urlapi + 'addresses/' + $scope.page + '/' + $scope.count)
}, function(data, status, headers, config) { .then(function(data, status, headers, config) {
console.log('data error'); console.log(data);
}); $scope.addresses = data.data;
}, function(data, status, headers, config) {
console.log('data error');
});
};
$scope.getAddresses();
$scope.getPrev = function(){
$scope.page++;
$scope.getAddresses();
};
$scope.getNext = function(){
$scope.page--;
$scope.getAddresses();
};
}); });

View File

@@ -2,7 +2,10 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="panel"> <div class="panel">
<div class="panel-heading c_deepPurpleG300to500"> <div class="panel-heading c_deepPurpleG300to500">
<h3 class="panel-title">Last Tx with amount</h3> <h3 class="panel-title">
Last Blocks with amount
<div ng-click="getBlocks()" class="btn btn-default pull-right">Previous</div>
</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<table class="table table-hover"> <table class="table table-hover">
@@ -45,6 +48,11 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<ul class="pager">
<li><a class="withripple" ng-click="getPrev()">Previous</a></li>
Current page: {{page}}
<li><a class="withripple" ng-click="getNext()">Next</a></li>
</ul>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -13,12 +13,26 @@ angular.module('app.blocks', ['ngRoute'])
//last tx //last tx
$scope.txs = []; $scope.txs = [];
$http.get(urlapi + 'lasttx') $scope.page = 1;
.then(function(data, status, headers, config) { $scope.count = 10;
console.log(data); $scope.getBlocks = function() {;
$scope.txs = data.data; $http.get(urlapi + 'blocks/' + $scope.page + '/' + $scope.count)
}, function(data, status, headers, config) { .then(function(data, status, headers, config) {
console.log('data error'); console.log(data);
}); $scope.txs = data.data;
}, function(data, status, headers, config) {
console.log('data error');
});
};
$scope.getBlocks();
$scope.getPrev = function(){
$scope.page++;
$scope.getBlocks();
};
$scope.getNext = function(){
$scope.page--;
$scope.getBlocks();
};
}); });

View File

@@ -32,7 +32,7 @@ angular.module('app.main', ['ngRoute'])
//last addr //last addr
$scope.addresses = []; $scope.addresses = [];
$http.get(urlapi + 'lastaddr') $http.get(urlapi + 'addresses/1/10')
.then(function(data, status, headers, config) { .then(function(data, status, headers, config) {
console.log(data); console.log(data);
$scope.addresses = data.data; $scope.addresses = data.data;
@@ -42,7 +42,7 @@ angular.module('app.main', ['ngRoute'])
//last tx //last tx
$scope.txs = []; $scope.txs = [];
$http.get(urlapi + 'lasttx') $http.get(urlapi + 'txs/1/10')
.then(function(data, status, headers, config) { .then(function(data, status, headers, config) {
console.log(data); console.log(data);
$scope.txs = data.data; $scope.txs = data.data;

View File

@@ -45,6 +45,11 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<ul class="pager">
<li><a class="withripple" ng-click="getPrev()">Previous</a></li>
Current page: {{page}}
<li><a class="withripple" ng-click="getNext()">Next</a></li>
</ul>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -13,12 +13,25 @@ angular.module('app.txs', ['ngRoute'])
//last tx //last tx
$scope.txs = []; $scope.txs = [];
$http.get(urlapi + 'lasttx') $scope.page = 1;
.then(function(data, status, headers, config) { $scope.count = 10;
console.log(data); $scope.getTxs = function() {
$scope.txs = data.data; $http.get(urlapi + 'txs/' + $scope.page + '/' + $scope.count)
}, function(data, status, headers, config) { .then(function(data, status, headers, config) {
console.log('data error'); console.log(data);
}); $scope.txs = data.data;
}, function(data, status, headers, config) {
console.log('data error');
});
};
$scope.getTxs();
$scope.getPrev = function(){
$scope.page++;
$scope.getTxs();
};
$scope.getNext = function(){
$scope.page--;
$scope.getTxs();
};
}); });