summaryrefslogtreecommitdiff
path: root/app/views/tournaments
diff options
context:
space:
mode:
Diffstat (limited to 'app/views/tournaments')
-rw-r--r--app/views/tournaments/_selected.html.erb44
-rw-r--r--app/views/tournaments/index.html.erb91
-rw-r--r--app/views/tournaments/join.html.erb2
-rw-r--r--app/views/tournaments/new.html.erb15
-rw-r--r--app/views/tournaments/show.html.erb111
5 files changed, 204 insertions, 59 deletions
diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb
new file mode 100644
index 0000000..2ab8379
--- /dev/null
+++ b/app/views/tournaments/_selected.html.erb
@@ -0,0 +1,44 @@
+<%= form_for(@tournament) do |f| %>
+ <%= render "common/error_messages", :target => @tournament %>
+ <%= f.hidden_field(:game_id) %>
+
+ <% @game = Game.find(params[:game]) %>
+ <% @tournament.attributes.each do |name, value| %>
+ <% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "status") or (name == "set_rounds") %>
+ <% next %>
+ <% end %>
+ <p>
+ <%= f.label name %><br>
+ <% if !@game.attributes[name].nil? %>
+ <%= f.text_field(name, :value => @game.attributes[name] ) %>
+ <% else %>
+ <%= f.text_field name %>
+ <% end %>
+ </p>
+ <% end %>
+
+ <%= fields_for "tournament[settings]", @tournament.settings do |setting_fields| %>
+ <% @game.settings.each do |setting| %>
+ <p>
+ <%= setting_fields.label setting.name %>
+ <br>
+ <% case setting.stype %>
+ <% when 0 %>
+ <%= setting_fields.text_field( setting.name ) %>
+ <% when 1 %>
+ <%= setting_fields.text_area( setting.name ) %>
+ <% when 2 %>
+ <%= setting_fields.collection_radio_buttons( setting.name, setting.type_opt.split(','), :first, :last, { item_wrapper_tag: false } ) %>
+ <% when 3 %>
+ <%= setting_fields.collection_check_boxes( setting.name, setting.type_opt.split(','), :first, :last, { item_wrapper_tag: false } ) %>
+ <% when 4 %>
+ <%= setting_fields.radio_button( setting.name, "true" ) %>
+ <%= setting_fields.radio_button( setting.name, "false" ) %>
+ <% when 5 %>
+ <%= setting_fields.select( setting.name, setting.type_opt.split(',') ) %>
+ <% end %>
+ <% end %>
+ </p>
+ <% end %>
+ <%= f.submit %>
+<% end %>
diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb
index f8f21e7..7957042 100644
--- a/app/views/tournaments/index.html.erb
+++ b/app/views/tournaments/index.html.erb
@@ -1,43 +1,52 @@
-<h1>Listing tournaments</h1>
+<h1>Listing Tournaments</h1>
-<table>
- <thead>
- <tr>
- <th>Name</th>
- <th>Game</th>
- <th>Status</th>
- <th>Min players per team</th>
- <th>Max players per team</th>
- <th>Min teams per match</th>
- <th>Max teams per match</th>
- <th>Set rounds</th>
- <th>Randomized teams</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
- </thead>
+<div id="tournament-list">
+ <% if @tournaments.length > 0 %>
+ <%# Each tournament has a div for its listing %>
+ <% @tournaments.each do |t| %>
+ <div class="row tournament-listing">
+ <div class="col-md-2 "><%= image_tag 'http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(t.hosts.first.email) + '?s=100&d=mm' %></div>
+ <div class="col-md-8">
+ <%# "header" %>
+ <%= link_to(t) do %><h3><%= t.name %></h3><% end %>
+ <div class="row" style="margin-left:2%;">
+ <div class="col-md-4 host">
+ Hosted by: <%= t.hosts.first.name %>
+ </div>
+ <div class="col-md-4 things">
+ <p> Players per team: <%= t.min_players_per_team %></p>
+ <p> Players signed up: <%= t.players.count %> </p>
+ </div>
+ <div class="col-md-4 things">
+ <p> <%= (t.randomized_teams)? "Teams are Random" : "Teams are Chosen" %></p>
+ <p> Players signed up: <%= t.players.count %> </p>
+ </div>
+ </div>
+ </div>
+ <div class="col-md-2">
+ <% if signed_in? %>
+ <% if !t.players.include?(current_user) %>
+ <%= form_tag(tournament_path(t), method: "put") do %>
+ <input type="hidden" name="update_action" value="join">
+ <%= submit_tag("Join")
+ %>
+ <% end %>
+ <% else %>
+ <p style="margin-top:10px;"> You've signed up for this tournament! </p>
+ <% end %>
+ <% end %>
+ </div>
+ </div>
+ <% end %>
+ <% else %>
+ <p class="no-entries"> No tournaments going on right now...
+ <% if current_user.can?(:create_tournament) %>
+ Why not start your own?
+ <% end %>
+ </p>
+ <% end %>
+</div>
- <tbody>
- <% @tournaments.each do |tournament| %>
- <tr>
- <td><%= tournament.name %></td>
- <td><%= tournament.game %></td>
- <td><%= tournament.status %></td>
- <td><%= tournament.min_players_per_team %></td>
- <td><%= tournament.max_players_per_team %></td>
- <td><%= tournament.min_teams_per_match %></td>
- <td><%= tournament.max_teams_per_match %></td>
- <td><%= tournament.set_rounds %></td>
- <td><%= tournament.randomized_teams %></td>
- <td><%= link_to 'Show', tournament %></td>
- <td><%= link_to 'Edit', edit_tournament_path(tournament) %></td>
- <td><%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' } %></td>
- </tr>
- <% end %>
- </tbody>
-</table>
-
-<br>
-
-<%= link_to 'New Tournament', new_tournament_path %>
+<% if current_user.can?(:create_tournament) %>
+ <div><%= link_to 'New Tournament', new_tournament_path, :class => "btn btn-warning btn-lg" %></div>
+<% end %>
diff --git a/app/views/tournaments/join.html.erb b/app/views/tournaments/join.html.erb
new file mode 100644
index 0000000..1d38d68
--- /dev/null
+++ b/app/views/tournaments/join.html.erb
@@ -0,0 +1,2 @@
+ <%= @user.name %>
+
diff --git a/app/views/tournaments/new.html.erb b/app/views/tournaments/new.html.erb
index 2a60539..8c74068 100644
--- a/app/views/tournaments/new.html.erb
+++ b/app/views/tournaments/new.html.erb
@@ -1,5 +1,16 @@
-<h1>New tournament</h1>
+<h1>New Tournament</h1>
-<%= render 'form' %>
+<%= form_tag(new_tournament_path, method: "get") do %>
+ <%= select_tag('game',
+ options_from_collection_for_select(@games, 'id', 'name', @tournament.game.nil? || @tournament.game.id),
+ :prompt => "Select a Game Type") %>
+ <%= submit_tag("Select", :class => "btn btn-success btn-xs") %>
+<% end %>
+
+<div id='ajax-form'>
+ <% if not @tournament.game.nil? %>
+ <%= render 'selected' %>
+ <% end %>
+</div>
<%= link_to 'Back', tournaments_path %>
diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb
index 3cb6179..e80e0e8 100644
--- a/app/views/tournaments/show.html.erb
+++ b/app/views/tournaments/show.html.erb
@@ -1,18 +1,23 @@
-<p id="notice"><%= notice %></p>
-
-<p>
- <strong>Name:</strong>
+<h2 id="tournament-name">
<%= @tournament.name %>
-</p>
+</h2>
-<p>
- <strong>Game:</strong>
- <%= @tournament.game %>
-</p>
+<div class="progress">
+ <%= tag("div", {:id => "prog-bar", :class => "progress-bar progress-bar-warning", :style => "width: " +(@tournament.players.count * 100 / (@tournament.min_players_per_team * @tournament.min_teams_per_match)).to_s + "%", "aria-valuemax" => "100", "aria-valuemin" => "0", "aria-valuenow" => (@tournament.players.count * 100 / (@tournament.min_players_per_team * @tournament.min_teams_per_match)).to_s, "role" => "progressbar"}) %>
+ <span class="sr-only">60% Complete (warning)</span>
+ </div>
+</div>
+<p id="players-needed"><%= pluralize(@tournament.players.count, "player has", "players have") %> signed up. <%= @tournament.min_players_per_team * @tournament.min_teams_per_match %> needed. </p>
+
+<span id="tournament-side-params">
<p>
<strong>Status:</strong>
- <%= @tournament.status %>
+ <% if @tournament.status == 0 %>
+ Waiting for players...
+ <% else %>
+ Started
+ <% end %>
</p>
<p>
@@ -35,15 +40,89 @@
<%= @tournament.max_teams_per_match %>
</p>
-<p>
- <strong>Set rounds:</strong>
- <%= @tournament.set_rounds %>
-</p>
<p>
<strong>Randomized teams:</strong>
<%= @tournament.randomized_teams %>
</p>
-<%= link_to 'Edit', edit_tournament_path(@tournament) %> |
-<%= link_to 'Back', tournaments_path %>
+</span>
+
+<div >
+<%# Show all players in the tournament %>
+<% if @tournament.players.length > 0 %>
+<h3> Players Here: </h3>
+ <ul id="tournament-users">
+ <% @tournament.players.each do |p| %>
+ <li><span class="black"> <%= p.user_name %> </span> </li>
+ <% end %>
+ </ul>
+ <% else %>
+ <h3 div="players-needed">Hmmm.... nobody's here yet! You and your friends should join the tournament.</h3>
+<% end %>
+
+<div class="leave-buttons">
+<%# If user can join, and user hasn't joined already, show the join tournment tag %>
+<% if @tournament.joinable_by?(current_user) && !@tournament.players.include?(current_user) %>
+ <%= form_tag(tournament_path(@tournament), method: "put") do %>
+ <input type="hidden" name="update_action" value="join">
+ <%= submit_tag("Join Tournament") %>
+ <% end %>
+
+<% elsif @tournament.players.include?(current_user) %>
+ <%= form_tag(tournament_path(@tournament), method: "put") do %>
+ <input type="hidden" name="update_action" value="leave">
+ <%= submit_tag("Leave Tournament") %>
+ <% end %>
+<% end %>
+
+<%# If user is the host, let them start the tournment %>
+<% if @tournament.hosts.include?(current_user) %>
+
+ <%= form_tag(tournament_path(@tournament), method: "put") do %>
+ <input type="hidden" name="update_action" value="start">
+ <% if @tournament.players.count >= @tournament.min_players_per_team * @tournament.min_teams_per_match %>
+ <%= submit_tag("Start Tournament") %>
+ <% else %>
+ <%= submit_tag("Start Tournament", disabled: true) %>
+ <% end %>
+ <br />
+ <%= link_to 'Edit', edit_tournament_path(@tournament) %> |
+ <%= link_to 'Back', tournaments_path %> |
+ <%= link_to 'Cancel Tournament', @tournament, method: :delete, data: { confirm: 'Are you sure?' } %>
+ <% end %>
+</div>
+
+<%end %>
+</div>
+
+<script>
+function donehandle( tournament ) {
+ if ( console && console.log ) {
+ var here = tournament["players"].length;
+ var needed = (tournament["min_teams_per_match"] * tournament["min_players_per_team"]);
+ var pct_complete = here / needed;
+ $("#prog-bar").width( (pct_complete * 100) +"%");
+ $("#players-needed").text(here + " " + (here==1?"player has":"players have") + " signed up. " + needed + " players needed. ");
+ players = "";
+
+ //creates the present user list
+ for (var i = 0; i < tournament["players"].length; i++) {
+ players = players+"<li><span class=\"black\">"+tournament["players"][i]["user_name"]+"</span></li>"
+ }
+
+ //updates the user list
+ $("#tournament-users").html(players);
+
+ //if there are enough players to start, enable the button, else disable it.
+ $("input[value=\"Start Tournament\"]").prop('disabled', (pct_complete >= 1)? false : true);
+
+ if (tournament["status"] == 1)
+ window.location.reload(true);
+ }
+ setTimeout(function(){$.ajax({url: "<%= url_for @tournament %>.json"}).done(donehandle)}, 2000);
+}
+
+$.ajax({url: "<%= url_for @tournament %>.json"})
+ .done(donehandle);
+</script>