diff options
author | tkimia <tkimia@purdue.edu> | 2014-04-28 01:30:48 -0400 |
---|---|---|
committer | tkimia <tkimia@purdue.edu> | 2014-04-28 01:30:48 -0400 |
commit | 85c74dac1f82dc1869a2875a9354be0b4b3361ac (patch) | |
tree | 4154815d3e5896ee6d68712f08a4dcac2b84872b /app | |
parent | b0b2a235f02b95058aa7bfbf817d5dd1d85b6730 (diff) | |
parent | 9a8d183f6896a92b84a15599323b32e73b5868b9 (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/pms/show.js.coffee | 25 | ||||
-rw-r--r-- | app/models/match.rb | 71 | ||||
-rw-r--r-- | app/models/tournament_stage.rb | 2 | ||||
-rw-r--r-- | app/views/pms/index.html.erb | 69 | ||||
-rw-r--r-- | app/views/pms/show.html.erb | 1 | ||||
-rw-r--r-- | app/views/tournaments/_form.html.erb | 1 |
6 files changed, 153 insertions, 16 deletions
diff --git a/app/assets/javascripts/pms/show.js.coffee b/app/assets/javascripts/pms/show.js.coffee index e69de29..559513c 100644 --- a/app/assets/javascripts/pms/show.js.coffee +++ b/app/assets/javascripts/pms/show.js.coffee @@ -0,0 +1,25 @@ +json_url = window.location.href.replace(/\.[^/]*$/,'')+".json" + +page_visited_pms = false +starting_size_pms = 0 +update = (pms) -> + if !page_visited_pms + starting_size_pms = pms.conversation.count_messages + page_visited_pms = true + + if pms.convesation.count_messages > starting_size_pms + window.location.reload true + return + + console.log("hey we got here!") + console.log(starting_size_pms) + console.log(pms.convesation.count_messages) + + setTimeout (-> + $.ajax(url: json_url).done update + return + ), 2000 + +# Now kick off the whole process +window.onload = -> + $.ajax(url: json_url).done update
\ No newline at end of file diff --git a/app/models/match.rb b/app/models/match.rb index ff81d68..3cbe0da 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -20,15 +20,76 @@ class Match < ActiveRecord::Base winner.players.include? player end - def handle_sampling(params) - # TODO + def users + ret = [] + self.teams.each{|t| ret.concat(t.users)} + return ret + end + + def stats_from(sampling_class) + figure_sampling_methods.map{|stat,klass| (sampling_class==klass) ? stat : nil}.select{|s| not s.nil?} + end + + def handle_sampling(user, params) + method_classes.each do |klass| + klass.new(self).handle_user_interaction(user, params) + end end def render_sampling(user) - # TODO + require 'set' + html = '' + + method_classes.each do |klass| + html += '<div>' + html += klass.new(self).render_user_interaction(user) + html += '</div>' + end + + return html.html_safe end - def finished? - # TODO + private + def figure_sampling_methods + if @sampling_methods.nil? + data = {} + needed = self.tournament_stage.scoring.stats_needed + methods_names = self.tournament_stage.tournament.sampling_methods + methods_names.each do |method_name| + method_class = "Sampling::#{sampling_name.camelcase}".constantize + if method_class.works_with(self.tournament_stage.tournament.game) + needed.each do |stat| + data[stat] ||= {} + data[stat][method] = method.can_get?(user, stat) + end + end + end + + needed.each do |stat| + max_val = nil + max_pri = 0 + data[stat].each do |method,priority| + if priority > max_pri + max_val = method + max_pri = priority + end + end + data[stat] = max_val + end + @sampling_methods = data + end + return @sampling_methods end + + def method_classes + if @method_classes.nil? + data = Set.new + figure_sampling_methods.each do |stat,method| + data.push(method) + end + @method_classes = data + end + return @method_classes + end + end diff --git a/app/models/tournament_stage.rb b/app/models/tournament_stage.rb index 9352137..caf5a8a 100644 --- a/app/models/tournament_stage.rb +++ b/app/models/tournament_stage.rb @@ -40,6 +40,6 @@ class TournamentStage < ActiveRecord::Base end def seeding - @seeding ||= "Seeding::#{self.seeding_method.camelcase}".constantize.new(self) + @seeding ||= "Seeding::#{self.seeding_method.camelcase}".constantize end end diff --git a/app/views/pms/index.html.erb b/app/views/pms/index.html.erb index 056b371..fec6db2 100644 --- a/app/views/pms/index.html.erb +++ b/app/views/pms/index.html.erb @@ -23,6 +23,9 @@ <% if conversation.is_unread?(current_user) && receipts.last.message.sender != current_user %> <% message = receipts.last.message %> <tr> + <% if conversation.subject == "Pay Attention!" %> + <% conversation.mark_as_read(current_user) %> + <% end %> <td> <% people = conversation.participants %> <% people.each do |person| %> @@ -65,17 +68,63 @@ <% if conversation.is_read?(current_user) || receipts.last.message.sender == current_user %> <% message = receipts.last.message %> <tr> - <td> - <% people = conversation.participants %> - <% people.each do |person| %> - <% unless person == current_user %> - <%= truncate(person.user_name, length: 20) %> + <% if conversation.subject != "Pay Attention!" %> + <td> + <% people = conversation.participants %> + <% people.each do |person| %> + <% unless person == current_user %> + <%= truncate(person.user_name, length: 20) %> + <% end %> <% end %> - <% end %> - </td> - <td><%= truncate(conversation.subject, length: 30) %></td> - <td><%= truncate(message.body, length: 42) %></td> - <td><%= link_to 'View', @pms.find_by(conversation: conversation) %></td> + </td> + <td><%= truncate(conversation.subject, length: 30) %></td> + <td><%= truncate(message.body, length: 42) %></td> + <td><%= link_to 'View', @pms.find_by(conversation: conversation) %></td> + <% end %> + </tr> + <% end %> + <% end %> + </tr> + <% #else %> + + <% #end %> + </tbody> +</table> + +<br> +<h3>Alerts</h3> +<% conversations = current_user.mailbox.conversations %> + +<table> + <col width="150"> + <col width="250"> + <col width="300"> + <tbody> + <%# if conversations.reject { |c| c.is_read?(current_user) || (c.receipts_for current_user).last.message.sender == current_user }.empty? %> + <tr> + <tr> + <td><b>With</b></td> + <td><b>Subject</b></td> + <td><b>Body</b></td> + </tr> + <% conversations.each do |conversation| %> + <% receipts = conversation.receipts_for current_user %> + <% if conversation.is_read?(current_user) || receipts.last.message.sender == current_user %> + <% message = receipts.last.message %> + <tr> + <% if conversation.subject == "Pay Attention!" %> + <td> + <% people = conversation.participants %> + <% people.each do |person| %> + <% unless person == current_user %> + <%= truncate(person.user_name, length: 20) %> + <% end %> + <% end %> + </td> + <td><%= truncate(conversation.subject, length: 30) %></td> + <td><%= truncate(message.body, length: 42) %></td> + <td><%= link_to 'View', @pms.find_by(conversation: conversation) %></td> + <% end %> </tr> <% end %> <% end %> diff --git a/app/views/pms/show.html.erb b/app/views/pms/show.html.erb index ca8d9bf..2c93102 100644 --- a/app/views/pms/show.html.erb +++ b/app/views/pms/show.html.erb @@ -31,6 +31,7 @@ <p> ________________________________________________ </p> <p> + <% @pm.message = "" %> <%= form_for(@pm) do |f| %> <div class="field"> <%= f.text_area :message %> diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 2a871ea..a5eba7a 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -17,6 +17,7 @@ </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 %> |