Skip to content
This repository has been archived by the owner on Feb 20, 2020. It is now read-only.

Commit

Permalink
resolve service promise for bucket-list route, remove old BudgetLoade…
Browse files Browse the repository at this point in the history
…r.setBudgetByRoute
  • Loading branch information
Michael Williams committed Oct 27, 2014
1 parent 0ee9fbb commit 7ed5249
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 38 deletions.
3 changes: 3 additions & 0 deletions src/app/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ angular
url: '/groups/:groupId/buckets'
templateUrl: '/app/bucket-list/bucket-list.html'
controller: 'BucketListCtrl'
resolve:
latestRound: (RoundService, $stateParams) ->
RoundService.getLatestRound($stateParams.groupId)
$stateProvider.state 'bucketList.details',
url: '/:bucketId'
templateUrl: '/app/bucket-list/bucket-list.details.html'
Expand Down
61 changes: 30 additions & 31 deletions src/app/bucket-list/bucket-list.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('bucket-list', [])
.controller 'BucketListCtrl', ($scope, $stateParams, RoundService, BudgetLoader, ContributionService, AuthService, BucketService) ->
.controller 'BucketListCtrl', ($scope, $stateParams, RoundService, ContributionService, AuthService, BucketService, latestRound) ->

///Lots of this should be abstracted into a service///

Expand All @@ -11,48 +11,47 @@ angular.module('bucket-list', [])
$scope.round.myAllocationsLeftCents = details.fundsLeftCents
$scope.round.myAllocationsAmountCents = details.allocationAmountCents
$scope.status = $scope.round.getStatus()

$scope.saveContribution = (contribution) ->
contribution.save(ContributionService).then ->
$scope.loadContributorDetails()

$scope.groupId = $stateParams.groupId
$scope.status = null

RoundService.getLatestRound($stateParams.groupId).then (round) ->
$scope.round = round
$scope.loadContributorDetails()

_.each round.buckets, (bucket, index) ->
# get current user's contribution
myContribution = bucket.getMyContribution($scope.currentUserId)
bucket.getMyContributionPercentage()
bucket.getGroupContribution()
round = latestRound
$scope.round = round
$scope.loadContributorDetails()

$scope.$watch "round.buckets["+index+"].myContribution.amountDollars", (amountDollars) ->
round.getMyAllocationsLeftCents(round.myAllocationsAmountCents)
$scope.status = round.getStatus()
console.log($scope.round.buckets)

if amountDollars >= 0
bucket.getMyContributionPercentage()
_.each round.buckets, (bucket, index) ->
# get current user's contribution
myContribution = bucket.getMyContribution($scope.currentUserId)
bucket.getMyContributionPercentage()
bucket.getGroupContribution()

round.getMyContributions()
$scope.$watch "round.buckets["+index+"].myContribution.amountDollars", (amountDollars) ->
round.getMyAllocationsLeftCents(round.myAllocationsAmountCents)
$scope.status = round.getStatus()

#Find total cents contributed to round for bucket list sum
totalCentsContributed = 0
for bucket in $scope.round.buckets
totalCentsContributed += bucket.contributionTotalCents
if amountDollars >= 0
bucket.getMyContributionPercentage()

#Find total round funds for bucket list sum
roundFundsTotalCents = 0
for allocation in $scope.round.allocations
roundFundsTotalCents += allocation.amountCents
round.getMyContributions()

$scope.round.totalAllocable = roundFundsTotalCents / 100
console.log('round funds total', roundFundsTotalCents)
$scope.round.totalAllocated = totalCentsContributed / 100
$scope.round.timeLeftDays = 3
$scope.round.timeLeftHours = 72
#Find total cents contributed to round for bucket list sum
totalCentsContributed = 0
for bucket in $scope.round.buckets
totalCentsContributed += bucket.contributionTotalCents

BudgetLoader.setBudgetByRoute()
#Find total round funds for bucket list sum
roundFundsTotalCents = 0
for allocation in $scope.round.allocations
roundFundsTotalCents += allocation.amountCents

$scope.round.totalAllocable = roundFundsTotalCents / 100
console.log('round funds total', roundFundsTotalCents)
$scope.round.totalAllocated = totalCentsContributed / 100
$scope.round.timeLeftDays = 3
$scope.round.timeLeftHours = 72
14 changes: 7 additions & 7 deletions src/app/bucket-list/bucket-list.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<div class="row content-row">
<div class="col-md-6 buckets panel container">

<header class="" ng-if='currentBudget'>
<header class="">
<div class="row section titles">
<span class="col-md-4 yourFunds">YOUR FUNDS</span>
<span class="col-md-4 groupFunds">GROUP FUNDS</span>
<span class="col-md-4 timeLeft">TIME LEFT</span>
</div>

<div class="row section details">

<div class="col-md-4 yourDetails">
<span contribution-status="status" class="large">
${{round.myAllocationsLeftCents / 100 }}
<span class="small">/${{round.myAllocationsAmountCents / 100}}</span>
</span>
</div>

<div class="col-md-4 groupDetails">
<span class="large">
${{round.totalAllocated}}
Expand All @@ -29,14 +29,14 @@
{{round.timeLeftDays}}
<span class="small">DAYS</span>
</span>
</div>
</div>

</div>

</header>

<div class="bucket-list" ng-repeat="bucket in round.buckets">
<div class="bucket" ng-if='currentBudget'>
<div class="bucket">
<div class="allocation_amount allocated">
<!--<label>Allocate</label>-->
<input contribution-status="status" type="number" min="0" ng-model='bucket.myContribution.amountDollars' placeholder="0" ng-blur='saveContribution(bucket.myContribution)' >
Expand All @@ -57,7 +57,7 @@ <h2><a href='#/groups/{{groupId}}/buckets/{{bucket.id}}'>{{bucket.name}}</a></h2
</div>

<div contribution-status="status"
class="progress-bar progress-bar-warning"
class="progress-bar progress-bar-warning"
role="progressbar"
aria-valuenow="{{bucket.myContributionPercentage > 0 ? bucket.myContributionPercentage : ''}}"
aria-valuemin="0"
Expand All @@ -76,4 +76,4 @@ <h2><a href='#/groups/{{groupId}}/buckets/{{bucket.id}}'>{{bucket.name}}</a></h2
</div>

<div ui-view></div>
</div>
</div>

0 comments on commit 7ed5249

Please sign in to comment.