Skip to content

Commit

Permalink
Implemented Add/Edit/Delete Coins functionality
Browse files Browse the repository at this point in the history
Dashboard will now load Coins & Pools from respective services
  • Loading branch information
brandon-barker committed Feb 12, 2014
1 parent 5140cce commit d73bdcd
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 120 deletions.
86 changes: 78 additions & 8 deletions app/scripts/controllers/CoinsCtrl.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,91 @@
'use strict';

angular.module('nodeminerApp')
.controller('CoinsCtrl', function ($scope, socket) {
$scope.coins = []
.controller('CoinsCtrl', function ($scope, CoinsSvc, PoolsSvc, socket) {
$scope.coin = {
pools: []
};
$scope.coins = [];

$scope.add = function (coin) {
var _defaults = {
"allowEdit": false,
"showDetails": false
};

$scope.coins.push(_.merge(coin, _defaults));
$scope.save($scope.coins);
};

$scope.addPool = function (coin, pool) {
if (coin) {
if (!coin.pools) coin.pools = [];

coin.pools.push(pool);
} else {
$scope.coin.pools.push(pool);
}
};

$scope.deletePool = function (coin, pool) {
if (coin) {
_.remove(coin.pools, pool);
} else {
_.remove($scope.coin.pools, pool);
}
};

$scope.toggleCoinDetails = function (coin) {
coin.showDetails = !coin.showDetails;
}
};

socket.on('coins:init', function (coins) {
$scope.coins = coins;
});
$scope.togglePoolDetails = function (pool) {
pool.showDetails = !pool.showDetails;
};

socket.emit('init:coins', function () {
});
$scope.allowEdit = function (coin) {
coin.allowEdit = true;
coin.showDetails = true;
};

$scope.disableEdit = function (coin) {
coin.allowEdit = false;
};

$scope.saveEdit = function (coin) {
$scope.disableEdit(coin);
$scope.save($scope.coins);
};

$scope.save = function (coins) {
CoinsSvc.save(coins);
};

$scope.delete = function (coin) {
CoinsSvc.delete(coin);
};

$scope.$on('$destroy', function (event) {
socket.removeAllListeners('init:coins');
});

$scope.$on('init:coins', function (coins) {
$scope.coins = CoinsSvc.coins;
});

$scope.$on('init:pools', function (pools) {
$scope.pools = PoolsSvc.pools;
});

$scope.$on('saved:coins', function () {
$scope.coins = CoinsSvc.coins;
toastr.success('Coin configuration saved!');

// Reset our scope object
$scope.coin = {
pools: []
};
});

if ($scope.coins.length == 0) $scope.coins = CoinsSvc.coins;
});
24 changes: 9 additions & 15 deletions app/scripts/controllers/DashboardCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object.size = function (obj) {
};

angular.module('nodeminerApp')
.controller('DashboardCtrl', function ($scope, $rootScope, MinerSvc, socket) {
.controller('DashboardCtrl', function ($scope, $rootScope, MinerSvc, CoinsSvc, PoolsSvc, socket) {
$scope.showSummary = true;
$scope.miners = [];

Expand Down Expand Up @@ -124,14 +124,6 @@ angular.module('nodeminerApp')
miner.collapsed = !miner.collapsed;
}

socket.on('coins:init', function (coins) {
$scope.coins = coins;
});

socket.on('pools:init', function (pools) {
$scope.pools = pools;
});

socket.on('socket:init', function (socketId) {
$scope.socketId = socketId;
});
Expand Down Expand Up @@ -205,12 +197,6 @@ angular.module('nodeminerApp')
toastr.success('Successfully zeroed "' + miner.name + '" statistics.');
});

socket.emit('init:pools', function () {
});

socket.emit('init:coins', function () {
});

$scope.$on('$destroy', function (event) {
socket.removeAllListeners('init:miners');
socket.removeAllListeners('init:pools');
Expand All @@ -222,6 +208,14 @@ angular.module('nodeminerApp')
$scope.miners = MinerSvc.miners;
});

$scope.$on('init:coins', function (coins) {
$scope.coins = CoinsSvc.coins;
});

$scope.$on('init:pools', function (pools) {
$scope.pools = PoolsSvc.pools;
});

if ($scope.miners.length == 0) {
$scope.miners = MinerSvc.miners;
$scope.calculateDashboardOverview();
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/controllers/MinerCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ angular.module('nodeminerApp')
"list": []
},
"showDetails": false,
"allowEdit": false,
"collapsed": false,
"interval": 5000,
"intervalCount": 0,
Expand Down Expand Up @@ -60,6 +61,9 @@ angular.module('nodeminerApp')
$scope.$on('saved:miners', function () {
$scope.miners = MinerSvc.miners;
toastr.success('Miner configuration saved!');

// Reset our scope object
$scope.miner = {};
});

if ($scope.miners.length == 0) $scope.miners = MinerSvc.miners;
Expand Down
10 changes: 9 additions & 1 deletion app/scripts/controllers/PoolsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ angular.module('nodeminerApp')
$scope.pools = []

$scope.add = function (pool) {
$scope.pools.push(pool);
var _defaults = {
"allowEdit": false,
"showDetails": false
};

$scope.pools.push(_.merge(pool, _defaults));
$scope.save($scope.pools);
};

Expand Down Expand Up @@ -46,6 +51,9 @@ angular.module('nodeminerApp')
$scope.$on('saved:pools', function () {
$scope.pools = PoolsSvc.pools;
toastr.success('Pool configuration saved!');

// Reset our scope object
$scope.pool = {};
});

if ($scope.pools.length == 0) $scope.pools = PoolsSvc.pools;
Expand Down
37 changes: 37 additions & 0 deletions app/scripts/services/CoinsSvc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'

angular.module('nodeminerApp').factory('CoinsSvc', function ($rootScope, $route, socket) {
var CoinsSvc = {
coins: [],

init: function (coins) {
if (CoinsSvc.coins.length == 0) {
CoinsSvc.coins = coins;

$rootScope.$broadcast('init:coins');
}
},
save: function (coins) {
CoinsSvc.coins = coins;
socket.emit('save:coins', coins);
},
delete: function (coin) {
_.remove(CoinsSvc.coins, coin);

CoinsSvc.save(CoinsSvc.coins);
}
};

socket.on('coins:init', function (coins) {
CoinsSvc.init(coins);
});

socket.emit('init:coins', function () {
});

socket.on('saved:coins', function () {
$rootScope.$broadcast('saved:coins');
});

return CoinsSvc;
});
1 change: 1 addition & 0 deletions app/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<script src="scripts/app.js"></script>
<script src="scripts/services/MinerSvc.js"></script>
<script src="scripts/services/PoolsSvc.js"></script>
<script src="scripts/services/CoinsSvc.js"></script>
<script src="scripts/controllers/MainCtrl.js"></script>
<script src="scripts/controllers/DashboardCtrl.js"></script>
<script src="scripts/controllers/NavbarCtrl.js"></script>
Expand Down
Loading

0 comments on commit d73bdcd

Please sign in to comment.