Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debts are displayed on a bet #74

Open
wants to merge 3 commits into
base: bet_creators_can_resolve_a_bet_redone
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
//= require bootstrap-sprockets
//= require jquery_ujs
//= require lib/date_picker
//= require lib/underarrow
//= require turbolinks
//= require_tree .
21 changes: 21 additions & 0 deletions app/assets/javascripts/lib/underarrow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$(document).on('turbolinks:load', function() {
$('.debts-displayed-on-bet').ready(function() {
const debtAmounts = $('.debt-amount');
const debtAmountWidths = $.map(debtAmounts, function(element) {
return $(element).width();
});

const underarrows = $('.underarrow');
const underarrowWidths = $.map(underarrows, function(element) {
return $(element).width();
});

$.each(underarrows, function(index, underarrow) {
const debtAmountWidth = debtAmountWidths[index];
const underarrowWidth = underarrowWidths[index];
const scaleAmount = (debtAmountWidth / underarrowWidth).toFixed(2);
$(underarrow).css({'transform': 'scale(' + scaleAmount + ', 0.8)'});
$(underarrow).css({'transform-origin': 'left top'});
});
});
});
1 change: 1 addition & 0 deletions app/views/bets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<% end %>

<% if @bet.resolved? %>
<%= render 'debts/debts_per_bet', bet: @bet %>
<% else %>
<%= render 'display_unresolved_bets', bet: @bet, user_bet: @user_bet %>
<% end %>
23 changes: 23 additions & 0 deletions app/views/debts/_debt.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<tbody class="thead-default">
<tr>
<% if current_user == debt.debtor %>
<td class="col-md-3 text-danger"><h4>Me</h4></td>
<% else %>
<td class="col-md-3 text-muted"><%= debt.debtor.username %></td>
<% end %>
<td class="col-md-3">
<span class="debt-amount">$<%= debt.amount %></span>
<div><i class="underarrow text-danger fa fa-long-arrow-right"></i></div>
</td>
<td class="col-md-3 text-muted"><%= debt.creditor.username %></td>
<% if debt.payment_date.nil? %>
<td class="col-md-3 text-danger">
Not paid
</td>
<% else %>
<td class="col-md-3 text-success">
Paid on <%= debt.payment_date %>
</td>
<% end %>
</tr>
</tbody>
22 changes: 22 additions & 0 deletions app/views/debts/_debts_per_bet.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<hr>
<div class="row debts-displayed-on-bet">
<div class="col col-lg-6 offset-lg-3">
<div class="card">
<div class="card-header text-muted">
<div class="row">
<div class="col col-lg-3">Debtor</div>
<div class="col col-lg-3">Amount</div>
<div class="col col-lg-3">Creditor</div>
<div class="col col-lg-3">Status</div>
</div>
</div>
<div class="card-block">
<table class="table table-hover">
<% @bet.debts.each do |debt| %>
<%= render 'debts/debt', debt: debt %>
<% end %>
</table>
</div>
</div>
</div>
</div>