Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Merge 0646aa2 into d45b6a0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Harris committed Oct 20, 2016
2 parents d45b6a0 + 0646aa2 commit acc9930
Show file tree
Hide file tree
Showing 31 changed files with 395 additions and 212 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Expand Up @@ -40,5 +40,6 @@
@import 'components/sign-up';
@import 'components/slabs';
@import 'components/striped-table';
@import 'components/users-header';

@import 'junk_drawer';
4 changes: 1 addition & 3 deletions app/assets/stylesheets/components/_profile.scss
@@ -1,8 +1,6 @@
.profile-wrapper {
.profile-form {
@include span-columns(8);
@include shift(2);
border: 1px solid $color-gray-neutral;
margin-top: 1em;
padding-left: 1em;
padding-right: 1em;

Expand Down
35 changes: 35 additions & 0 deletions app/assets/stylesheets/components/_users-header.scss
@@ -0,0 +1,35 @@
.user-header-wrapper {
background: $color-gray-lightest;
border-bottom: 1px solid $color-gray-light;
}

.user-subnav {
clear: both;
display: block;

.active {
background: $color-white;
border: 1px solid $color-gray-light;
border-bottom: none;
text-decoration: none;
}

a {
margin-top: 1rem;
margin-bottom: -1px;
border-bottom: 1px solid $color-gray-light;
padding: 1rem;
background: $color-gray-lightest;
display: inline-block;
line-height: $base-line-height;
vertical-align: middle;
}

a:focus {
box-shadow: none;
}
}

.user-body-wrapper {
margin-top: 1em;
}
9 changes: 4 additions & 5 deletions app/controllers/bids_controller.rb
@@ -1,11 +1,6 @@
class BidsController < ApplicationController
before_filter :require_authentication

def index
bids = Bid.where(bidder: current_user).includes(:auction)
@bids = bids.map { |bid| MyBidListItem.new(bid) }
end

def create
@bid = PlaceBid.new(params: params, bidder: current_user, via: via)

Expand All @@ -17,4 +12,8 @@ def create

redirect_to auction_path(@bid.auction)
end

def index
@view_model = AccountBidsPlacedViewModel.new(current_user: current_user)
end
end
4 changes: 4 additions & 0 deletions app/controllers/users_controller.rb
Expand Up @@ -15,4 +15,8 @@ def update
render :edit
end
end

def bids_placed
@view_model = AccountBidsPlacedViewModel.new(current_user: current_user)
end
end
21 changes: 21 additions & 0 deletions app/view_models/account_bids_placed_view_model.rb
@@ -0,0 +1,21 @@
class AccountBidsPlacedViewModel
attr_reader :current_user

def initialize(current_user:)
@current_user = current_user
end

def bids_table_partial
if auctions.empty?
'bids/bids_table_none'
else
'bids/bids_table'
end
end

def auctions
@_auctions ||= AuctionQuery.new.with_bid_from_user(current_user.id).map do |auction|
UserAuctionViewModel.new(auction, current_user)
end
end
end
54 changes: 1 addition & 53 deletions app/view_models/admin/user_auction_view_model.rb
@@ -1,44 +1,8 @@
class Admin::UserAuctionViewModel
attr_reader :auction, :user

DATE_FORMAT = '%m/%d/%Y'.freeze
NA_RESPONSE_STRING = '-'.freeze

def initialize(auction, user)
@auction = auction
@user = user
end

def title
auction.title
end

def id
auction.id
end

def bidding_status
BiddingStatusPresenterFactory.new(auction).create.label
end

class Admin::UserAuctionViewModel < UserAuctionViewModel
def skills
auction.sorted_skill_names.join(', ')
end

def user_bid_count
user_bids.count
end

def user_won_label
if user_won?
'Yes'
elsif auction_over?
'No'
else
NA_RESPONSE_STRING
end
end

def accepted_label
if user_won? && auction_accepted?
'Yes'
Expand All @@ -51,23 +15,7 @@ def accepted_label

private

def user_won?
auction_over? && WinningBid.new(auction).find.bidder == user
end

def auction_over?
BiddingStatus.new(auction).over?
end

def auction_accepted?
auction.accepted?
end

def auction_rules
RulesFactory.new(auction).create
end

def user_bids
auction.bids.where(bidder: user).sort_by(&:amount)
end
end
59 changes: 59 additions & 0 deletions app/view_models/user_auction_view_model.rb
@@ -0,0 +1,59 @@
class UserAuctionViewModel
attr_reader :auction, :user

DATE_FORMAT = '%m/%d/%Y'.freeze
NA_RESPONSE_STRING = '-'.freeze

def initialize(auction, user)
@auction = auction
@user = user
end

def title
auction.title
end

def id
auction.id
end

def bidding_status
BiddingStatusPresenterFactory.new(auction).create.label
end

def user_bid_count
user_bids.count
end

def user_won_label
if user_won?
'Yes'
elsif auction_over?
'No'
else
NA_RESPONSE_STRING
end
end

def user_lowest_bid
Currency.new(user_bids.first.amount)
end

private

def user_won?
auction_over? && WinningBid.new(auction).find.bidder == user
end

def auction_over?
BiddingStatus.new(auction).over?
end

def auction_rules
RulesFactory.new(auction).create
end

def user_bids
auction.bids.where(bidder: user).sort_by(&:amount)
end
end
22 changes: 22 additions & 0 deletions app/views/bids/_bids_table.html.erb
@@ -0,0 +1,22 @@
<table class="striped-table">
<thead>
<tr>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.auction' %></th>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.status' %></th>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.number_bids' %></th>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.lowest_bid' %></th>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.won' %></th>
</tr>
</thead>
<tbody>
<% view_model.auctions.each do |auction| %>
<tr>
<td><%= link_to(auction.title, auction_path(auction.id)) %></td>
<td><%= auction.bidding_status %></td>
<td><%= auction.user_bid_count %></td>
<td><%= auction.user_lowest_bid %></td>
<td><%= auction.user_won_label %></td>
</tr>
<% end %>
</tbody>
</table>
2 changes: 2 additions & 0 deletions app/views/bids/_bids_table_none.html.erb
@@ -0,0 +1,2 @@
<%= t('labels.vendor.account.bids_placed.no_bids_html',
index_url: Url.new(link_text: 'current and upcoming auctions', path_name: 'root')) %>
50 changes: 13 additions & 37 deletions app/views/bids/index.html.erb
@@ -1,39 +1,15 @@
<div class="usa-grid">
<div>
<%= link_to(
"<icon class='fa fa-angle-double-left'></icon> Back to all auctions".html_safe,
root_path,
class: 'breadcrumb-link') %>
<div class="user-profile">
<div class="user-header-wrapper">
<div class="usa-grid">
<div class="user-header-title">
<h1><%= t 'labels.vendor.account.title' %></h1>
</div>
<%= render partial: 'users/subnav', locals: {active: :bids_placed} %>
</div>
</div>
<div class="user-body-wrapper">
<div class="usa-grid">
<%= render partial: @view_model.bids_table_partial, locals: {view_model: @view_model} %>
</div>
</div>

<h1>My Bids</h1>

<table>
<thead>
<tr>
<th scope="col">Auction</th>
<th scope="col">Auction type</th>
<th scope="col">Auction running?</th>
<th scope="col">Amount</th>
<th scope="col">Winning bid?</th>
<th scope="col">Auction start time</th>
<th scope="col">Auction end time</th>
<th scope="col">Auction delivery deadline</th>
</tr>
</thead>
<tbody>
<% @bids.each do |bid| %>
<tr>
<td><%= link_to(bid.auction_title, auction_path(bid.auction)) %></td>
<td><%= bid.formatted_type %></td>
<td><%= bid.availability %></td>
<td><%= bid.amount %></td>
<td><%= bid.winning_status %></td>
<td><%= bid.started_at %></td>
<td><%= bid.ended_at %></td>
<td><%= bid.delivery_due_at %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
4 changes: 1 addition & 3 deletions app/views/components/_user_nav_drawer.html.erb
@@ -1,9 +1,7 @@
<%= render partial: current_user.decorate.nav_drawer_admin_link %>
<li class="nav-link">
<%= link_to 'My profile', profile_path %>
<%= link_to 'Account', profile_path %>
</li>
<li class="nav-link">
<%= link_to 'My bids', bids_path %>
</li>
<li class="nav-link">
<%= link_to 'Logout', logout_path %>
Expand Down
22 changes: 22 additions & 0 deletions app/views/users/_bids_table.html.erb
@@ -0,0 +1,22 @@
<table class="striped-table">
<thead>
<tr>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.auction' %></th>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.status' %></th>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.number_bids' %></th>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.lowest_bid' %></th>
<th scope="col"><%= t 'labels.vendor.account.bids_placed.columns.won' %></th>
</tr>
</thead>
<tbody>
<% view_model.auctions.each do |auction| %>
<tr>
<td><%= link_to(auction.title, auction_path(auction.id)) %></td>
<td><%= auction.bidding_status %></td>
<td><%= auction.user_bid_count %></td>
<td><%= auction.user_lowest_bid %></td>
<td><%= auction.user_won_label %></td>
</tr>
<% end %>
</tbody>
</table>
2 changes: 2 additions & 0 deletions app/views/users/_bids_table_none.html.erb
@@ -0,0 +1,2 @@
<%= t('labels.vendor.account.bids_placed.no_bids_html',
index_url: Url.new(link_text: 'current and upcoming auctions', path_name: 'root')) %>
8 changes: 8 additions & 0 deletions app/views/users/_subnav.html.erb
@@ -0,0 +1,8 @@
<div class="user-subnav">
<%= link_to I18n.t('labels.vendor.account.tabs.profile'),
profile_path,
class: "nav-auction #{ 'active' if active == :profile }" %>
<%= link_to I18n.t('labels.vendor.account.tabs.bids_placed'),
bids_placed_path,
class: "nav-auction #{ 'active' if active == :bids_placed }" %>
</div>
15 changes: 15 additions & 0 deletions app/views/users/bids_placed.html.erb
@@ -0,0 +1,15 @@
<div class="user-profile">
<div class="user-header-wrapper">
<div class="usa-grid">
<div class="user-header-title">
<h1><%= t 'labels.vendor.account.title' %></h1>
</div>
<%= render partial: 'users/subnav', locals: {active: :bids_placed} %>
</div>
</div>
<div class="user-body-wrapper">
<div class="usa-grid">
<%= render partial: @view_model.bids_table_partial, locals: {view_model: @view_model} %>
</div>
</div>
</div>

0 comments on commit acc9930

Please sign in to comment.