Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu committed Oct 13, 2011
1 parent bf7ea81 commit 9deaa54
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 74 deletions.
24 changes: 14 additions & 10 deletions app/controllers/users_controller.rb
@@ -1,16 +1,17 @@


class UsersController < Devise::SessionsController
def create
super
end

#user homepage
def index
logger.debug 'User HomePage actions'
@expired_bets_count = current_user.bets.where("expiration_date < ? AND state = 'OPEN' ", Time.now).count
end


#user homepage
def index
logger.debug 'User HomePage actions'
@expired_bets = current_user.bets.where("expiration_date < ? AND state = 'OPEN' ", Time.now)
@open_bets = current_user.bets.where("expiration_date > ? AND state = 'OPEN' ", Time.now)
@creation_bets = current_user.bets.where("state = 'CREATION' ", Time.now)
@closed_bets = current_user.bets.where("state = 'CLOSE' ", Time.now)
end

def show
logger.debug 'Public user display'
@user = User.find(params[:id])
Expand All @@ -19,5 +20,8 @@ def show
def list
@bidders = User.find(:all, :order => "brouzouf desc")
end


def expired_bets
return current_user.bets.where("expiration_date < ? AND state = 'OPEN' ", Time.now)
end
end
2 changes: 1 addition & 1 deletion app/views/bets/index.html.erb
@@ -1,6 +1,6 @@
<h1>Listing bets</h1>

<%= render 'list' %>
<%= render 'list' %>

<br />

23 changes: 5 additions & 18 deletions app/views/layouts/application.html.erb
Expand Up @@ -37,8 +37,12 @@

<div id="menu" >
<ul >
<li class="menuitem"><%= link_to 'Bidders', users_list_url %></li>
<li class="menuitem"><%= link_to 'Open Bets', root_path %></li>
<li class="menuitem"><%= link_to 'New Bet', new_bet_url %></li>
<% if user_signed_in? %>
<li class="menuitem"><%= link_to 'My Bets', user_url(current_user) %></li>
<% end %>

</ul>
</div>

Expand All @@ -53,23 +57,6 @@
</div>



<!-- 2 COLUMNS 66/33
<div class="yui-gc">
<div class="yui-u first">
1ER cloc
</div>
<div class="yui-u">
YOUR DATA GOES HERE
2iem bloc
</div>
</div>
-->





<div id="ft" role="contentinfo">
<!--<p>Copyright Brouzouf Corp 2011</p>-->
</div>
Expand Down
12 changes: 12 additions & 0 deletions app/views/users/_show_bet.html.erb
@@ -0,0 +1,12 @@
<tr>
<td><%= link_to bet.title, bet_path(bet) %> </td>
<td>
<% if bet.open? %>
<%=link_to "Close", close_bet_path(bet) %>,
<% end %>
<% if bet.editable? %>
<%=link_to "Edit", edit_bet_path(bet) %>,
<% end %>
<%= link_to 'Destroy', bet, :confirm => 'Are you sure?', :method => :delete %>
</td>
</tr>
56 changes: 56 additions & 0 deletions app/views/users/_show_bets.html.erb
@@ -0,0 +1,56 @@
<% expired_bets = current_user.expired_bets %>
<% if (expired_bets.count > 0) %>
<strong> You have <%= pluralize(expired_bets.count, 'bet') %> that needs to be closed !</strong>
<table>
<tr>
<th>Title</th>
<th>Actions</th>
</tr>
<% expired_bets.each do |bet| %>
<%= render :partial => 'show_bet', :locals => {:bet => bet} %>
<% end %>
</table>
<% end %>
<% if (current_user.bets.count == 0) %>
No bet created yet. <%= link_to "Create your first bet now !", new_bet_url %>
<% else %>
<% if (@creation_bets.count > 0) %>
<h2>Bets not yet opened</h2>
<table>
<tr>
<th>Title</th>
<th>Actions</th>
</tr>
<% @creation_bets.each do |bet| %>
<%= render :partial => 'show_bet', :locals => {:bet => bet} %>
<% end %>
</table>
<% end %>
<% if (@open_bets.count > 0) %>
<h2>Open Bets</h2>
<table>
<tr>
<th>Title</th>
<th>Actions</th>
</tr>
<% @open_bets.each do |bet| %>
<%= render :partial => 'show_bet', :locals => {:bet => bet} %>
<% end %>
</table>
<% end %>
<% if (@closed_bets.count > 0) %>
<h2>Closed Bets</h2>
<table>
<tr>
<th>Title</th>
<th>Actions</th>
</tr>
<% @closed_bets.each do |bet| %>
<%= render :partial => 'show_bet', :locals => {:bet => bet} %>
<% end %>
</table>
<% end %>
<% end %>
44 changes: 8 additions & 36 deletions app/views/users/index.html.erb
@@ -1,54 +1,26 @@

<h1>Your account</h1>


<ul>
<li><%= link_to 'Modify my info', edit_user_registration_path %></li>
<li><%= link_to 'New Bet', new_bet_path %></li>

<li><%= link_to 'Modify my info', edit_user_registration_path %></li>
<li><%= link_to 'New Bet', new_bet_path %></li>

</ul>

<p>
Your credit : <strong><%= pluralize(current_user.brouzouf, "brouzouf")%></strong>
Your credit : <strong><%= pluralize(current_user.brouzouf, "brouzouf") %></strong>
</p>

<h2>My Bets</h2>

<% if ( @expired_bets_count > 0 ) %>
<strong> You have <%= pluralize(@expired_bets_count, 'bet') %> that needs to be closed !</strong>
<% end %>
<% if(current_user.bets.count == 0 ) %>
No bet created yet. <%= link_to "Create your first bet now !", new_bet_url%>
<% else %>
<table>
<tr><th>Title</th><th>Status</th><th>Actions</th></tr>
<% current_user.bets.each do |bet| %>
<tr>
<td><%= bet.title %> </td>
<td><%= bet.state %>
<% if bet.expired? & !bet.closed? %>[EXPIRED]<% end %>
</td>
<td>
<% if bet.open? %>
<%=link_to "Close", close_bet_path(bet) %>,
<% end %>
<% if bet.editable? %>
<%=link_to "Edit", edit_bet_path(bet) %>,
<% end %>
<%=link_to "Show", bet_path(bet) %>, <%= link_to 'Destroy', bet, :confirm => 'Are you sure?', :method => :delete %>
</td>
</tr>
<% end %>
</table>
<% end %>
<% render :partial => 'show_bets' %>

<h2>My Bids</h2>
<ul>
<% current_user.bids.each do |bid| %>
<li> <%=I18n.l bid.created_at, :format => :short%> - <b><%= bid.choice.description %></b> on <%= link_to bid.choice.bet.title, bid.choice.bet %> </li>
<% end %>
<li> <%= I18n.l bid.created_at, :format => :short %> - <b><%= bid.choice.description %></b>
on <%= link_to bid.choice.bet.title, bid.choice.bet %> </li>
<% end %>
</ul>

10 changes: 1 addition & 9 deletions app/views/users/show.html.erb
Expand Up @@ -5,12 +5,4 @@

<h2>Bets listing</h2>

<%if(@user.bets.count == 0 )%>
No bet created yet.
<%else%>
<ul>
<% @user.bets.each do |bet| %>
<li><%=link_to bet.title, bet%></li>
<%end%>
</ul>
<%end%>
<% render :partial => 'show_bets' %>

0 comments on commit 9deaa54

Please sign in to comment.