diff options
Diffstat (limited to 'lib/sampling')
-rw-r--r-- | lib/sampling/manual.html.erb | 30 | ||||
-rw-r--r-- | lib/sampling/manual.rb | 28 |
2 files changed, 46 insertions, 12 deletions
diff --git a/lib/sampling/manual.html.erb b/lib/sampling/manual.html.erb index 187f002..2bbd6da 100644 --- a/lib/sampling/manual.html.erb +++ b/lib/sampling/manual.html.erb @@ -1,12 +1,30 @@ <% if @tournament.hosts.include? @current_user %> - <input type="hidden" name="update_action" value="finish" > + <fieldset><legend>Winner</legend> + <ul> + <% @match.teams.each do |team| %> + <li><label> + <input type="radio" name="manual[winner]" value="<%= team.id %>"> + Team <%= team.id %> + </label></li> + <% end %> + </ul> + </fieldset> <% @match.teams.each do |team| %> - <label> - <input type="radio", name="win", value="<%= team.id %>" > - <%= "Team #{team.id} Won" %> - </label> + <fieldset><legend>Statistics for Team <%= team.id %></legend> + <% team.users.each do |user| %> + <fieldset><legend><%= user.name %></legend> + <% @stats.reject{|s|s=="win"}.each do |stat| %> + <p> + <label> + <%= stat.titleize %> + <input type="numeric" name="manual[statistics][<%= user.id %>][<%= stat %>]"> + </label> + </p> + <% end %> + </fieldset> + <% end %> + </fieldset> <% end %> - <br> <input type="submit", value="Finish match" > <% else %> <p>The match is running; the host has yet to post the scores of the match.</p> diff --git a/lib/sampling/manual.rb b/lib/sampling/manual.rb index 01f6835..a9f9de4 100644 --- a/lib/sampling/manual.rb +++ b/lib/sampling/manual.rb @@ -33,7 +33,6 @@ module Sampling def render_user_interaction(user) @tournament = @match.tournament_stage.tournament @current_user = user - @users = @match.users @stats = @match.stats_from(self.class) require 'erb' @@ -43,11 +42,28 @@ module Sampling return erb.result(binding).html_safe end - def handle_user_interaction(user, sampling_params) + def handle_user_interaction(user, params) # => Save sampling_params as statistics - sampling_params.select {|name, value| @match.stats_from(self.class).include? name }.each do |name, value| - Statistic.create(name: value, user: user, match: @match) - end - end + require 'pp' + puts('>'*80) + pp @match + puts('>'*80) + if (@match.tournament_stage.tournament.hosts.include? user) + manual_params = params.require(:manual) + winner = Team.find(manual_params[:winner]) + @match.users.each do |user| + puts('>'*80) + pp "MAKING statistics BIIIIIIIITCH" + puts('>'*80) + Statistic.create(match: @match, user: user, + name: "win", value: winner.users.include?(user)) + @match.stats_from(self.class).reject{|s|s=="win"}.each do |stat| + Statistic.create(match: @match, user: user, + name: stat, value: manual_params[:statistics][user.id][stat].to_i) + end # stats + end # users + end # permission + end # def + end end |