summaryrefslogtreecommitdiff
path: root/app/views/tournaments/show.html.erb
diff options
context:
space:
mode:
Diffstat (limited to 'app/views/tournaments/show.html.erb')
-rw-r--r--app/views/tournaments/show.html.erb111
1 files changed, 95 insertions, 16 deletions
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>