Skip to content
Snippets Groups Projects
Commit b15e6783 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix: display network in last tab

parent 6df44567
Branches feature/agent_architecture
Tags
No related merge requests found
...@@ -70,7 +70,7 @@ angular.module('cesium', ['ionic', 'cesium.controllers']) ...@@ -70,7 +70,7 @@ angular.module('cesium', ['ionic', 'cesium.controllers'])
views: { views: {
'menuContent': { 'menuContent': {
templateUrl: "templates/explore/explore_currency.html", templateUrl: "templates/explore/explore_currency.html",
controller: 'ExploreCtrl' controller: 'CurrenciesCtrl'
} }
} }
}) })
......
...@@ -8,8 +8,7 @@ function PeerController($scope, $rootScope, $ionicSlideBoxDelegate, $ionicModal, ...@@ -8,8 +8,7 @@ function PeerController($scope, $rootScope, $ionicSlideBoxDelegate, $ionicModal,
$scope.showPeer = function(server) { $scope.showPeer = function(server) {
$scope.node = BMA.instance(server); $scope.node = BMA.instance(server);
// Get the peers // Get the peers
BMA.network.peers.get() $scope.node.network.peers()
.$promise
.then(function(json){ .then(function(json){
$scope.loaded = true; $scope.loaded = true;
var peers = json.peers.map(function(p) { var peers = json.peers.map(function(p) {
......
angular.module('cesium.controllers', ['cesium.services']) angular.module('cesium.controllers', ['cesium.services'])
.config(function($httpProvider) {
//Enable cross domain calls
$httpProvider.defaults.useXDomain = true;
//Remove the header used to identify ajax call that would prevent CORS from working
delete $httpProvider.defaults.headers.common['X-Requested-With'];
})
.controller('HomeCtrl', HomeController) .controller('HomeCtrl', HomeController)
.controller('CurrenciesCtrl', CurrenciesController) .controller('CurrenciesCtrl', CurrenciesController)
...@@ -50,7 +58,7 @@ angular.module('cesium.controllers', ['cesium.services']) ...@@ -50,7 +58,7 @@ angular.module('cesium.controllers', ['cesium.services'])
}) })
; ;
function CurrenciesController($scope) { function CurrenciesController($scope, $state) {
$scope.selectedCurrency = ''; $scope.selectedCurrency = '';
$scope.knownCurrencies = ['meta_brouzouf']; $scope.knownCurrencies = ['meta_brouzouf'];
...@@ -58,12 +66,14 @@ function CurrenciesController($scope) { ...@@ -58,12 +66,14 @@ function CurrenciesController($scope) {
// Called to navigate to the main app // Called to navigate to the main app
$scope.selectCurrency = function(currency) { $scope.selectCurrency = function(currency) {
$scope.selectedCurrency = currency; $scope.selectedCurrency = currency;
$scope.$emit('currencySelected', currency); $state.go('app.explore_tabs');
}; };
} }
function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interval, $timeout) { function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interval, $timeout) {
var USE_RELATIVE_DEFAULT = true;
CurrenciesController.call(this, $scope); CurrenciesController.call(this, $scope);
LookupController.call(this, $scope, BMA); LookupController.call(this, $scope, BMA);
PeersController.call(this, $scope, $rootScope, BMA, UIUtils, $q, $interval); PeersController.call(this, $scope, $rootScope, BMA, UIUtils, $q, $interval);
...@@ -74,12 +84,33 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv ...@@ -74,12 +84,33 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv
$scope.knownCurrencies = ['meta_brouzouf']; $scope.knownCurrencies = ['meta_brouzouf'];
$scope.formData = { useRelative: false }; $scope.formData = { useRelative: false };
$scope.knownBlocks = []; $scope.knownBlocks = [];
$scope.entered = false;
$scope.$on('currencySelected', function(e) { $scope.$on('$ionicView.enter', function(e, $state) {
$state.go('app.explore_tabs'); if (!$scope.entered) {
e.stopPropagation(); $scope.entered = true;
$scope.startListeningOnSocket();
} else {
//$scope.updateExploreView();
}
}); });
$scope.startListeningOnSocket = function() {
// Currency OK
BMA.websocket.block().on('block', function(block) {
var theFPR = fpr(block);
if ($scope.knownBlocks.indexOf(theFPR) === -1) {
$scope.knownBlocks.push(theFPR);
// We wait 2s when a new block is received, just to wait for network propagation
var wait = $scope.knownBlocks.length === 1 ? 0 : 2000;
$timeout(function() {
$scope.updateExploreView();
}, wait);
}
});
};
$scope.$watch('formData.useRelative', function() { $scope.$watch('formData.useRelative', function() {
if ($scope.formData.useRelative) { if ($scope.formData.useRelative) {
$scope.M = $scope.M / $scope.currentUD; $scope.M = $scope.M / $scope.currentUD;
...@@ -96,18 +127,6 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv ...@@ -96,18 +127,6 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv
} }
}, true); }, true);
BMA.websocket.block().on('block', function(block) {
var theFPR = fpr(block);
if ($scope.knownBlocks.indexOf(theFPR) === -1) {
$scope.knownBlocks.push(theFPR);
// We wait 2s when a new block is received, just to wait for network propagation
var wait = $scope.knownBlocks.length === 1 ? 0 : 2000;
$timeout(function() {
$scope.updateExploreView();
}, wait);
}
});
$scope.doUpdate = function() { $scope.doUpdate = function() {
$scope.updateExploreView(); $scope.updateExploreView();
}; };
...@@ -120,9 +139,7 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv ...@@ -120,9 +139,7 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv
$q.all([ $q.all([
// Get the currency parameters // Get the currency parameters
BMA.currency.parameters.get() BMA.currency.parameters()
.$promise
.then(function(json){ .then(function(json){
$scope.c = json.c; $scope.c = json.c;
$scope.baseUnit = json.currency; $scope.baseUnit = json.currency;
...@@ -130,8 +147,7 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv ...@@ -130,8 +147,7 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv
}), }),
// Get the current block informations // Get the current block informations
BMA.blockchain.current.get() BMA.blockchain.current()
.$promise
.then(function(block){ .then(function(block){
$scope.M = block.monetaryMass; $scope.M = block.monetaryMass;
$scope.N = block.membersCount; $scope.N = block.membersCount;
...@@ -140,13 +156,11 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv ...@@ -140,13 +156,11 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv
}), }),
// Get the UD informations // Get the UD informations
BMA.blockchain.stats.ud.get() BMA.blockchain.stats.ud()
.$promise
.then(function(res){ .then(function(res){
if (res.result.blocks.length) { if (res.result.blocks.length) {
var lastBlockWithUD = res.result.blocks[res.result.blocks.length - 1]; var lastBlockWithUD = res.result.blocks[res.result.blocks.length - 1];
return BMA.blockchain.block.get({ block: lastBlockWithUD }) return BMA.blockchain.block({ block: lastBlockWithUD })
.$promise
.then(function(block){ .then(function(block){
$scope.currentUD = block.dividend; $scope.currentUD = block.dividend;
$scope.UD = block.dividend; $scope.UD = block.dividend;
...@@ -161,9 +175,11 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv ...@@ -161,9 +175,11 @@ function ExploreController($scope, $rootScope, $state, BMA, $q, UIUtils, $interv
$scope.M = $scope.M - $scope.UD*$scope.Nprev; $scope.M = $scope.M - $scope.UD*$scope.Nprev;
$scope.MoverN = $scope.M / $scope.Nprev; $scope.MoverN = $scope.M / $scope.Nprev;
$scope.cactual = 100 * $scope.UD / $scope.MoverN; $scope.cactual = 100 * $scope.UD / $scope.MoverN;
$scope.formData.useRelative = USE_RELATIVE_DEFAULT;
UIUtils.loading.hide(); UIUtils.loading.hide();
}) })
.catch(function() { .catch(function(err) {
console.error('>>>>>>>' , err);
UIUtils.alert.error('Could not fetch informations from remote uCoin node.'); UIUtils.alert.error('Could not fetch informations from remote uCoin node.');
UIUtils.loading.hide(); UIUtils.loading.hide();
}) })
...@@ -180,8 +196,7 @@ function LookupController($scope, BMA) { ...@@ -180,8 +196,7 @@ function LookupController($scope, BMA) {
$scope.search.text = $scope.search.text.toLowerCase(); $scope.search.text = $scope.search.text.toLowerCase();
if ($scope.search.text.length > 1) { if ($scope.search.text.length > 1) {
$scope.search.looking = true; $scope.search.looking = true;
return BMA.wot.lookup.get({ search: $scope.search.text }) return BMA.wot.lookup({ search: $scope.search.text })
.$promise
.then(function(res){ .then(function(res){
$scope.search.looking = false; $scope.search.looking = false;
$scope.search.results = res.results.reduce(function(idties, res) { $scope.search.results = res.results.reduce(function(idties, res) {
...@@ -262,10 +277,9 @@ function PeersController($scope, $rootScope, BMA, UIUtils, $q, $interval) { ...@@ -262,10 +277,9 @@ function PeersController($scope, $rootScope, BMA, UIUtils, $q, $interval) {
$rootScope.members = []; $rootScope.members = [];
$scope.search.peers = []; $scope.search.peers = [];
$scope.search.lookingForPeers = true; $scope.search.lookingForPeers = true;
return BMA.network.peering.peers.get({ leaves: true }) return BMA.network.peering.peers({ leaves: true })
.$promise
.then(function(res){ .then(function(res){
return BMA.wot.members.get().$promise return BMA.wot.members()
.then(function(json){ .then(function(json){
$rootScope.members = json.results; $rootScope.members = json.results;
return res; return res;
...@@ -273,8 +287,7 @@ function PeersController($scope, $rootScope, BMA, UIUtils, $q, $interval) { ...@@ -273,8 +287,7 @@ function PeersController($scope, $rootScope, BMA, UIUtils, $q, $interval) {
}) })
.then(function(res){ .then(function(res){
return $q.all(res.leaves.map(function(leaf) { return $q.all(res.leaves.map(function(leaf) {
return BMA.network.peering.peers.get({ leaf: leaf }) return BMA.network.peering.peers({ leaf: leaf })
.$promise
.then(function(subres){ .then(function(subres){
var peer = subres.leaf.value; var peer = subres.leaf.value;
if (peer) { if (peer) {
...@@ -287,8 +300,7 @@ function PeersController($scope, $rootScope, BMA, UIUtils, $q, $interval) { ...@@ -287,8 +300,7 @@ function PeersController($scope, $rootScope, BMA, UIUtils, $q, $interval) {
peer.uid = member && member.uid; peer.uid = member && member.uid;
newPeers.push(peer); newPeers.push(peer);
var node = BMA.instance(peer.getURL()); var node = BMA.instance(peer.getURL());
return node.blockchain.current.get() return node.blockchain.current()
.$promise
.then(function(block){ .then(function(block){
peer.current = block; peer.current = block;
peer.online = true; peer.online = true;
......
angular.module('cesium.services', ['ngResource']) angular.module('cesium.services', ['ngResource'])
.factory('BMA', function($resource) { .factory('BMA', function($http, $q) {
function BMA(server) { function BMA(server) {
function getResource(uri) { function getResource(uri) {
return $resource(uri, null, null, { return function(params) {
return $q(function(resolve, reject) {
var config = {
timeout: 4000 timeout: 4000
}, suffix = '', pkeys = [], queryParams = {};
if (typeof params == 'object') {
pkeys = _.keys(params);
}
pkeys.forEach(function(pkey){
var prevURI = uri;
uri = uri.replace(new RegExp(':' + pkey), params[pkey]);
if (prevURI == uri) {
queryParams[pkey] = params[pkey];
}
}); });
config.params = queryParams;
$http.get(uri + suffix, config)
.success(function(data, status, headers, config) {
resolve(data);
})
.error(function(data, status, headers, config) {
reject(data);
});
});
}
} }
return { return {
......
...@@ -7,11 +7,6 @@ ...@@ -7,11 +7,6 @@
<div class="scroll"> <div class="scroll">
<ion-tabs class="tabs-icon-top tabs-positive has-header"> <ion-tabs class="tabs-icon-top tabs-positive has-header">
<ion-tab title="Network" icon="ion-network">
<ion-nav-view name="network-tab"/>
<ng-include src="'templates/explore/tabs/explore_tab_network.html'"/>
</ion-tab>
<ion-tab title="Currency" icon="ion-stats-bars"> <ion-tab title="Currency" icon="ion-stats-bars">
<ion-nav-view name="currency-tab"/> <ion-nav-view name="currency-tab"/>
<ng-include src="'templates/explore/tabs/explore_tab_currency.html'"/> <ng-include src="'templates/explore/tabs/explore_tab_currency.html'"/>
...@@ -22,6 +17,11 @@ ...@@ -22,6 +17,11 @@
<ng-include src="'templates/explore/tabs/explore_tab_wot.html'"/> <ng-include src="'templates/explore/tabs/explore_tab_wot.html'"/>
</ion-tab> </ion-tab>
<ion-tab title="Network" icon="ion-network">
<ion-nav-view name="network-tab"/>
<ng-include src="'templates/explore/tabs/explore_tab_network.html'"/>
</ion-tab>
</ion-tab> </ion-tab>
</ion-tabs> </ion-tabs>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment