summaryrefslogtreecommitdiff
path: root/app/views/tournaments
diff options
context:
space:
mode:
Diffstat (limited to 'app/views/tournaments')
-rw-r--r--app/views/tournaments/_form.html.erb187
-rw-r--r--app/views/tournaments/index.html.erb57
-rw-r--r--app/views/tournaments/join.html.erb2
-rw-r--r--app/views/tournaments/new.html.erb2
-rw-r--r--app/views/tournaments/show.html.erb166
-rw-r--r--app/views/tournaments/standings.html.erb51
6 files changed, 335 insertions, 130 deletions
diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb
index 340efab..c478ce6 100644
--- a/app/views/tournaments/_form.html.erb
+++ b/app/views/tournaments/_form.html.erb
@@ -1,49 +1,140 @@
-<%= form_for(@tournament) do |f| %>
- <% if @tournament.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@tournament.errors.count, "error") %> prohibited this tournament from being saved:</h2>
-
- <ul>
- <% @tournament.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div class="field">
- <%= f.label :game_id %><br>
- <%= f.text_field :game_id %>
- </div>
- <div class="field">
- <%= f.label :status %><br>
- <%= f.number_field :status %>
- </div>
- <div class="field">
- <%= f.label :name %><br>
- <%= f.text_field :name %>
- </div>
- <div class="field">
- <%= f.label :min_players_per_team %><br>
- <%= f.number_field :min_players_per_team %>
- </div>
- <div class="field">
- <%= f.label :max_players_per_team %><br>
- <%= f.number_field :max_players_per_team %>
- </div>
- <div class="field">
- <%= f.label :min_teams_per_match %><br>
- <%= f.number_field :min_teams_per_match %>
- </div>
- <div class="field">
- <%= f.label :max_teams_per_match %><br>
- <%= f.number_field :max_teams_per_match %>
- </div>
- <div class="field">
- <%= f.label :scoring_method %><br>
- <%= f.text_field :scoring_method %>
- </div>
- <div class="actions">
- <%= f.submit %>
- </div>
+<%
+# Copyright (C) 2014 Andrew Murrell
+# Copyright (C) 2014 Davis Webb
+# Copyright (C) 2014 Guntas Grewal
+# Copyright (C) 2014 Luke Shumaker
+# Copyright (C) 2014 Nathaniel Foy
+# Copyright (C) 2014 Tomer Kimia
+#
+# This file is part of Leaguer.
+#
+# Leaguer is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Leaguer is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the Affero GNU General Public License
+# along with Leaguer. If not, see <http://www.gnu.org/licenses/>.
+%>
+<%= render "common/error_messages", :target => @tournament %>
+<fieldset>
+ <legend>Basic information</legend>
+ <%= form_for(@tournament, url: new_tournament_path, method: "get") do |f| %>
+ <div class="field">
+ <%= f.label :game_id, "Select a Game Type" %>
+ <%= f.select(:game_id, Game.all.map{|game| [game.name, game.id]}) %>
+ </div>
+ <div class="field">
+ <label for="num_stages">Number of Tournament Stages</label>
+ <input type="number" id="num_stages" name="num_stages" min="1" value="<%= params[:num_stages].to_i %>">
+ </div>
+ <% if @tournament.game %>
+ <%= f.submit("Update (Will reset the rest of the form)", class: "btn-danger") %>
+ <% else %>
+ <%= f.submit("Submit") %>
+ <% end %>
+ <% end %>
+
+</fieldset>
+<% if @tournament.game %>
+ <%= form_for(@tournament, url: tournaments_path, method: "post") do |f| %>
+ <fieldset>
+ <legend>Attributes</legend>
+
+ <%= f.hidden_field(:game_id) %>
+ <div class="field">
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+ </div>
+
+ <table>
+ <tbody>
+ <tr>
+ <td></td>
+ <th>Minimum</th>
+ <th>Maximum</th>
+ </tr>
+ <tr>
+ <th>Players per Team: </th>
+ <td><%= f.number_field(:min_players_per_team, min: 1) %></td>
+ <td><%= f.number_field(:max_players_per_team, min: 1) %></td>
+ </tr>
+ <tr>
+ <th>Teams per Match: </th>
+ <td><%= f.number_field(:min_teams_per_match, min: 1) %></td>
+ <td><%= f.number_field(:max_teams_per_match, min: 1) %></td>
+ </tr>
+ </tbody>
+ </table>
+
+ <div class="field">
+ <%= f.label :scoring_method, :scoring_method.to_s.titleize %>
+ <%= f.select(:scoring_method, @tournament.scoring_methods.map{|method| [method.humanize.titleize, method]}) %>
+ </div>
+ </fieldset>
+
+ <fieldset>
+ <legend>Settings</legend>
+ <%= f.fields_for :settings do |setting_fields| %>
+ <% @tournament.tournament_settings.each do |setting| %>
+ <div class="field">
+ <%= setting_fields.label setting.name, setting.name.to_s.titleize %>
+ <br>
+ <% case setting.vartype %>
+ <% when 0 %>
+ <%= setting_fields.text_field( setting.name ) %>
+ <% when 1 %>
+ <%= setting_fields.text_area( setting.name ) %>
+ <% when 2 %>
+ <ul>
+ <% setting.type_opt.split(',').each do |option|%>
+ <li><label><%= setting_fields.radio_button( setting.name, option ) %><%= option.humanize.titleize %></label></li>
+ <% end %>
+ </ul>
+ <% when 3 %>
+ <ul>
+ <% setting.type_opt.split(',').each do |option|%>
+ <li><label><%= check_box_tag("tournament[settings][#{setting.name}][]", option, setting.value.split(',').include?(option)) %><%= option.humanize.titleize %></label></li>
+ <% end %>
+ </ul>
+ <% when 4 %>
+ <%= setting_fields.radio_button( setting.name, "true" ) %> <b>True</b>
+ <%= setting_fields.radio_button( setting.name, "false" ) %> <b>False</b>
+ <% when 5 %>
+ <%= setting_fields.select( setting.name, setting.type_opt.split(',').collect {|opt| opt.humanize.titleize} ) %>
+ <% end %>
+ </div>
+ <% end %>
+ <% end %>
+ </fieldset>
+
+ <%= f.fields_for :stages do |stages_fields| %>
+ <fieldset>
+ <legend>Stages</legend>
+ <% for i in 1..(params[:num_stages].to_i) do %>
+ <%= stages_fields.fields_for i.to_s do |stage_fields| %>
+ <fieldset>
+ <legend>Stage <%= i %></legend>
+ <div class="field">
+ <%= stage_fields.label :scheduling_method, :scheduling_method.to_s.titleize %>
+ <%= stage_fields.select(:scheduling_method, @tournament.scheduling_methods.map{|method| [method.humanize.titleize, method]}) %>
+ </div>
+ <div class="field">
+ <%= stage_fields.label :seeding_method, :seeding_method.to_s.titleize %>
+ <%= stage_fields.select(:seeding_method, @tournament.seeding_methods.map{|method| [method.humanize.titleize, method]}) %>
+ </div>
+ </fieldset>
+ <% end %>
+ <% end %>
+ </fieldset>
+ <% end %>
+
+ <%= f.submit %>
+
+ <% end %>
<% end %>
diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb
index 7bf8aa0..06e1b25 100644
--- a/app/views/tournaments/index.html.erb
+++ b/app/views/tournaments/index.html.erb
@@ -1,41 +1,24 @@
-<h1>Listing tournaments</h1>
+<h1>Listing Tournaments</h1>
-<table>
- <thead>
- <tr>
- <th>Game</th>
- <th>Status</th>
- <th>Name</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>Scoring method</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
- </thead>
+<div id="tournament-list">
+ <% if @tournaments.length > 0 %>
- <tbody>
- <% @tournaments.each do |tournament| %>
- <tr>
- <td><%= tournament.game %></td>
- <td><%= tournament.status %></td>
- <td><%= tournament.name %></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.scoring_method %></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>
+ <%# Each tournament has a div for its listing %>
+ <% @tournaments.each do |t| %>
+ <%= render "common/show_tournament", :target => t %>
+ <% end %>
-<br>
+ <% else %>
-<%= link_to 'New Tournament', new_tournament_path %>
+ <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>
+
+<% 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..9c741e0 100644
--- a/app/views/tournaments/new.html.erb
+++ b/app/views/tournaments/new.html.erb
@@ -1,4 +1,4 @@
-<h1>New tournament</h1>
+<h1>New Tournament</h1>
<%= render 'form' %>
diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb
index ca65ac6..55a8f14 100644
--- a/app/views/tournaments/show.html.erb
+++ b/app/views/tournaments/show.html.erb
@@ -1,44 +1,122 @@
-<p id="notice"><%= notice %></p>
-
-<p>
- <strong>Game:</strong>
- <%= @tournament.game %>
-</p>
-
-<p>
- <strong>Status:</strong>
- <%= @tournament.status %>
-</p>
-
-<p>
- <strong>Name:</strong>
- <%= @tournament.name %>
-</p>
-
-<p>
- <strong>Min players per team:</strong>
- <%= @tournament.min_players_per_team %>
-</p>
-
-<p>
- <strong>Max players per team:</strong>
- <%= @tournament.max_players_per_team %>
-</p>
-
-<p>
- <strong>Min teams per match:</strong>
- <%= @tournament.min_teams_per_match %>
-</p>
-
-<p>
- <strong>Max teams per match:</strong>
- <%= @tournament.max_teams_per_match %>
-</p>
-
-<p>
- <strong>Scoring method:</strong>
- <%= @tournament.scoring_method %>
-</p>
-
-<%= link_to 'Edit', edit_tournament_path(@tournament) %> |
-<%= link_to 'Back', tournaments_path %>
+<%
+# Copyright (C) 2014 Andrew Murrell
+# Copyright (C) 2014 Davis Webb
+# Copyright (C) 2014 Guntas Grewal
+# Copyright (C) 2014 Luke Shumaker
+# Copyright (C) 2014 Nathaniel Foy
+# Copyright (C) 2014 Tomer Kimia
+#
+# This file is part of Leaguer.
+#
+# Leaguer is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Leaguer is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the Affero GNU General Public License
+# along with Leaguer. If not, see <http://www.gnu.org/licenses/>.
+%>
+<%= link_to '« Back to all tournaments', tournaments_path, class: :breadcrumb %>
+
+<h2 id="tournament-name">
+ <%= @tournament.name %>
+</h2>
+
+<div class="progress">
+ <%# FIXME: What's up with this? Hardcoded 60%? %>
+ <%= 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>
+
+<div id="tournament-side-params">
+ <p>
+ <strong>Status:</strong>
+ <% if @tournament.status == 0 %>
+ Waiting for players...
+ <% else %>
+ Started
+ <% end %>
+ </p>
+
+ <p>
+ <strong>Name:</strong>
+ <%= @tournament.name %>
+ </p>
+
+ <p>
+ <strong>Min players per team:</strong>
+ <%= @tournament.min_players_per_team %>
+ </p>
+
+ <p>
+ <strong>Max players per team:</strong>
+ <%= @tournament.max_players_per_team %>
+ </p>
+
+ <p>
+ <strong>Min teams per match:</strong>
+ <%= @tournament.min_teams_per_match %>
+ </p>
+
+ <p>
+ <strong>Max teams per match:</strong>
+ <%= @tournament.max_teams_per_match %>
+ </p>
+
+ <p>
+ <strong>Scoring method:</strong>
+ <%= @tournament.scoring_method.titleize %>
+ </p>
+
+ <% @tournament.settings.each do |setting| %>
+ <p>
+ <strong><%= setting.name %></strong>
+ <%= setting.value %>
+ </p>
+ <% end %>
+</div>
+
+<div>
+ <% if @tournament.players.length > 0 %>
+ <h3>Players Here:</h3>
+ <ul id="tournament-users">
+ <% @tournament.players.each do |p| %>
+ <li><%= p.user_name %></li>
+ <% end %>
+ </ul>
+ <% else %>
+ <h3 div="players-needed">Hmmm.... nobody's here yet! You and your friends should join the tournament.</h3>
+ <% end %>
+</div>
+
+<div class="actions">
+ <%# If user can join, and user hasn't joined already, show a join tournment button %>
+ <% if @tournament.joinable_by?(current_user) && !@tournament.players.include?(current_user) %>
+ <%= form_tag(tournament_path(@tournament), method: "put", class: :button_to) 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", class: :button_to) 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.check_permission(current_user, :edit) %>
+ <%= form_tag(tournament_path(@tournament), method: "put", class: :button_to) do %>
+ <input type="hidden" name="update_action" value="start">
+ <%= submit_tag("Start Tournament", disabled: (@tournament.players.count < @tournament.min_players_per_team * @tournament.min_teams_per_match)) %>
+ <% end %>
+ <%= link_to 'Edit Tournament', edit_tournament_path(@tournament), role: :button %>
+ <%= button_to 'Cancel Tournament', @tournament, method: :delete, data: { confirm: 'Are you sure?' } %>
+ <% end %>
+</div>
diff --git a/app/views/tournaments/standings.html.erb b/app/views/tournaments/standings.html.erb
new file mode 100644
index 0000000..15dd325
--- /dev/null
+++ b/app/views/tournaments/standings.html.erb
@@ -0,0 +1,51 @@
+<%
+# Copyright (C) 2014 Andrew Murrell
+# Copyright (C) 2014 Davis Webb
+# Copyright (C) 2014 Guntas Grewal
+# Copyright (C) 2014 Luke Shumaker
+# Copyright (C) 2014 Nathaniel Foy
+# Copyright (C) 2014 Tomer Kimia
+#
+# This file is part of Leaguer.
+#
+# Leaguer is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Leaguer is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the Affero GNU General Public License
+# along with Leaguer. If not, see <http://www.gnu.org/licenses/>.
+%>
+<% playerscores = @tournament.players.collect {|player| player => @tournament.statistics.where(match: player.matches.last, user: player, name: :score) } %>
+<% teams = tournament_stage.matches.collect
+{ |match| match.teams.collect { |team| team.id => team.players.collect
+{ |player| player.user_name => @tournament.statistics.where(match: player.matches.last, user: player, name: :score } } } %>
+
+<table>
+ <tr>
+ <td>Standings:</td>
+ <% place = 0 %>
+ <% playerscores.sort {|player1, player2| playerscores[player1] <=> playerscores[player2] }.each |player| %>
+ <td><%= place.to_s + ":" %> <%= player.user_name %></td>
+ <% place += 1%>
+ <% end %>
+ </tr>
+</table>
+
+<% teams.each do |team| %>
+ <table>
+ <tr>
+ <td>Standings:</td>
+ <% place = 0 %>
+ <% team.values.sort {|player1, player2| playerscores[player1] <=> playerscores[player2] }.each |player| %>
+ <td><%= place.to_s + ":" %> <%= player.user_name %></td>
+ <% place += 1%>
+ <% end %>
+ </tr>
+ </table>
+<% end %>