diff options
Diffstat (limited to 'app/views/tournaments')
-rw-r--r-- | app/views/tournaments/_form.html.erb | 174 | ||||
-rw-r--r-- | app/views/tournaments/index.html.erb | 57 | ||||
-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 | 83 | ||||
-rw-r--r-- | app/views/tournaments/standings.html.erb | 28 |
6 files changed, 251 insertions, 95 deletions
diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 340efab..38f01ee 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -1,49 +1,127 @@ -<%= 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> +<%= render "common/error_messages", :target => @tournament %> +<fieldset> + + <legend style="color:rgb(221, 145, 37)">Attributes + </legend> + + <%= form_for(@tournament, url: new_tournament_path, method: "get") do |f| %> + <%= render "common/error_messages", :target => @tournament %> + <p> + <%= f.label :game_id, "Select a game type" %> + <%= f.select(:game_id, Game.all.map{|game| [game.name, game.id]}) %> + <%= f.submit("Select") %> + </p> + <% end %> + + <% if @tournament.game.nil? %> +</fieldset> +<% else %> + <%= form_for(@tournament, url: tournaments_path, method: "post") do |f| %> + <%= f.hidden_field(:game_id) %> + <p> + <%= f.label :name %> + <%= f.text_field :name %> + </p> + <div> + <p> + <table> + <tbody> + <tr> + <td></td> + <th style="padding:5px">Minimum</th> + <th style="padding:5px">Maximum</th> + </tr> + <tr> + <th>Players per team: </th> + <td style="padding:5px"><%= f.text_field(:min_players_per_team, type: :number, min: 1) %></td> + <td style="padding:5px"><%= f.text_field(:max_players_per_team, type: :number, min: 1) %></td> + </tr> + </tbody> + </table> + </p> + </div> + + <div id="teams-table"> + <p> + <table><tbody> + <tr> + <th>Teams per match: </th> + <td style="padding:5px"><%= f.text_field(:min_teams_per_match, type: :number, min: 1) %></td> + <td style="padding:5px"><%= f.text_field(:max_teams_per_match, type: :number, min: 1) %></td> + </tr> + </tbody></table> + </P> + </div> + + <p> + <%= f.label :scoring_method %> + <%= f.select(:scoring_method, @tournament.scoring_methods.map{|method| [method.humanize.titleize, method]}) %> + </p> +</fieldset> + +<fieldset> + <legend style="color:rgb(221, 145, 37)">Settings + </legend> + <%= f.fields_for :settings do |setting_fields| %> + <% @tournament.tournament_settings.each do |setting| %><p> + <%= setting_fields.label setting.name %> + <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 %></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 %></label></li> + <% end %> + </ul> + <% when 4 %> + <%= setting_fields.radio_button( setting.name, "true" ) %> True + <%= setting_fields.radio_button( setting.name, "false" ) %> False + <% when 5 %> + <%= setting_fields.select( setting.name, setting.type_opt.split(',').collect {|opt| opt.humanize.titleize} ) %> + <% end %> + </p> + <% end %> + <% end %> +</fieldset> + + <%= f.fields_for :stages do |stages_fields| %> + <fieldset> + + <legend style="color:rgb(221, 145, 37)">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 %>"> + <%# stage_fields.submit("Set Stages") %> + <% for i in 1..(params[:num_stages].to_i) do %> + <p> + <%= stages_fields.fields_for i.to_s do |stage_fields| %> + <fieldset> + <legend style="color:rgb(221, 145, 37)">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 %> + </p> + <% 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..ec83dc0 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,8 +47,63 @@ <p> <strong>Scoring method:</strong> - <%= @tournament.scoring_method %> + <%= @tournament.scoring_method.titleize %> +</p> + +<% @tournament.settings.each do |setting| %> +<p> + <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..a04e132 --- /dev/null +++ b/app/views/tournaments/standings.html.erb @@ -0,0 +1,28 @@ +<% 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 %>
\ No newline at end of file |