-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Add/Edit/Delete Coins functionality
Dashboard will now load Coins & Pools from respective services
- Loading branch information
1 parent
5140cce
commit d73bdcd
Showing
9 changed files
with
367 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.