diff options
Diffstat (limited to 'app/views/tournaments')
-rw-r--r-- | app/views/tournaments/_form.html.erb | 152 | ||||
-rw-r--r-- | app/views/tournaments/index.html.erb | 59 | ||||
-rw-r--r-- | app/views/tournaments/join.html.erb | 2 | ||||
-rw-r--r-- | app/views/tournaments/new.html.erb | 2 | ||||
-rw-r--r-- | app/views/tournaments/show.html.erb | 81 | ||||
-rw-r--r-- | app/views/tournaments/standings.html.erb | 12 |
6 files changed, 206 insertions, 102 deletions
diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index be5cf56..95bb7c7 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -1,53 +1,101 @@ -<%= 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 :sampling_method %><br> - <%= f.text_field :sampling_method %> - </div> - <div class="field"> - <%= f.label :scoring_method %><br> - <%= f.text_field :scoring_method %> - </div> - <div class="actions"> - <%= f.submit %> - </div> +<%= form_for(@tournament, + url: (@tournament.game.nil? ? new_tournament_path : tournaments_path), + method: (@tournament.game.nil? ? "get" : "post")) do |f| %> + <%= render "common/error_messages", :target => @tournament %> + + <fieldset><legend>Attributes</legend> + <p> + <%= f.label :game_id, "Select a game type" %> + <%= f.select(:game_id, Game.all.map{|game| [game.name, game.id]}) %> + </p> + + <% if @tournament.game.nil? %> + <%= submit_tag("Select", :class => "btn") %> + </fieldset> + <% else %> + + <p> + <%= f.label :name %> + <%= f.text_field :name %> + </p> + + <table><tbody> + <tr> + <td></td> + <th>Minimum</th> + <th>Maximum</th></tr> + <tr> + <th>Players per team</th> + <td><%= f.text_field(:min_players_per_team, type: :number, min: 1) %></td> + <td><%= f.text_field(:max_players_per_team, type: :number, min: 1) %></td> + </tr> + <tr> + <th>Teams per match</th> + <td><%= f.text_field(:min_teams_per_match, type: :number, min: 1) %></td> + <td><%= f.text_field(:max_teams_per_match, type: :number, min: 1) %></td> + </tr> + </tbody></table> + + <p> + <%= f.label :scoring_method %> + <%= f.select(:scoring_method, @tournament.scoring_methods.map{|method| [method.humanize, method]}) %> + </p> + + <p> + <%= f.label :sampling_method %> + <%= f.select(:sampling_method, @tournament.sampling_methods.map{|method| [method.humanize, method]}) %> + </p> + + </fieldset> + + <fieldset><legend>Settings</legend> + <%= f.fields_for :settings do |setting_fields| %> + <% (@tournament.settings.empty? ? @tournament.game.settings : @tournament.settings).each do |setting| %><p> + <% name = setting.name.parameterize.underscore %> + <%= setting_fields.label name %> + <br> + <% case setting.vartype %> + <% when 0 %> + <%= setting_fields.text_field( name ) %> + <% when 1 %> + <%= setting_fields.text_area( name ) %> + <% when 2 %> + <ul> + <% setting.type_opt.split(',').each do |option|%> + <li><label><%= setting_fields.radio_button( name, option ) %><%= option %></label></li> + <% end %> + </ul> + <% when 3 %> + <ul> + <% setting.type_opt.split(',').each do |option|%> + <li><label><%= check_box_tag(name, value = option, checked = false, options = {}) %><%= option %></label></li> + <% end %> + </ul> + <% when 4 %> + <%= setting_fields.radio_button( name, "true" ) %> True + <%= setting_fields.radio_button( name, "false" ) %> False + <% when 5 %> + <%= setting_fields.select( name, setting.type_opt.split(',') ) %> + <% end %> + </p><% end %> + <% end %> + </fieldset> + + <%= f.fields_for :stages do |stages_fields| %><fieldset><legend>Stages</legend> + <label for="num_stages">Number of tournament stages</label> + <input type="number" name="num_stages" min="1" value="<%= params[:num_stages].to_i %>"> + <% 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> + <%= stage_fields.label :scheduling_method %> + <%= stage_fields.select(:scheduling_method, @tournament.scheduling_methods.map{|method| [method.humanize, method]}) %> + <%= stage_fields.label :seeding_method %> + <%= stage_fields.select(:seeding_method, @tournament.seeding_methods.map{|method| [method.humanize, method]}) %> + </fieldset><% end %> + <% end %> + </fieldset><% end %> + + <%= f.submit %> + + <%# render 'stages' %> + <% end %> <% end %> diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index 1dddd5d..06e1b25 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -1,43 +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>Sampling method</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.sampling_method %></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 f407295..53389bb 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -1,13 +1,23 @@ -<p id="notice"><%= notice %></p> +<h2 id="tournament-name"> + <%= @tournament.name %> +</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> @@ -37,13 +47,64 @@ <p> <strong>Sampling method:</strong> + <!-- TODO --> <%= @tournament.sampling_method %> </p> +<% @tournament.settings.each do |setting| %> <p> - <strong>Scoring method:</strong> - <%= @tournament.scoring_method %> + <strong><%= setting.name %></strong> + <%= setting.value %> </p> +<% end %> + +</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> -<%= link_to 'Edit', edit_tournament_path(@tournament) %> | -<%= link_to 'Back', tournaments_path %> +<%end %> +</div> +</div> diff --git a/app/views/tournaments/standings.html.erb b/app/views/tournaments/standings.html.erb new file mode 100644 index 0000000..28d3c22 --- /dev/null +++ b/app/views/tournaments/standings.html.erb @@ -0,0 +1,12 @@ +<% playerscores = @tournament.players.collect {|player| player => tournament.statistics.getStatistic(player.matches.last, player, :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>
\ No newline at end of file |