From d2e4f58410c20f5e7b9e8e0dde3fd55d201af4bb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 13:18:00 -0400 Subject: run generate --- app/controllers/servers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 43999c4..4c12c7e 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -69,6 +69,6 @@ class ServersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def server_params - params[:server] + params.require(:server).permit(:default_user_permissions) end end -- cgit v1.2.3-54-g00ecf From a81c1ca571b0bb41f0acba6594559c7405fc2bb1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 13:58:00 -0400 Subject: Simplify the server controller and views, as it is a singular resource --- app/controllers/servers_controller.rb | 51 +++++------------------------------ app/views/servers/index.html.erb | 27 ------------------- app/views/servers/index.json.jbuilder | 4 --- app/views/servers/new.html.erb | 5 ---- 4 files changed, 7 insertions(+), 80 deletions(-) delete mode 100644 app/views/servers/index.html.erb delete mode 100644 app/views/servers/index.json.jbuilder delete mode 100644 app/views/servers/new.html.erb (limited to 'app/controllers') diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 27c6f9f..e3850b8 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -1,43 +1,15 @@ class ServersController < ApplicationController - - # GET /servers - # GET /servers.json - def index - @servers = Server.all - end - - # GET /servers/1 - # GET /servers/1.json + # GET /server + # GET /server.json def show end - # GET /servers/new - def new - @server = Server.new - end - - # GET /servers/1/edit + # GET /server/edit def edit end - # POST /servers - # POST /servers.json - def create - @server = Server.new(server_params) - - respond_to do |format| - if @server.save - format.html { redirect_to @server, notice: 'Server was successfully created.' } - format.json { render action: 'show', status: :created, location: @server } - else - format.html { render action: 'new' } - format.json { render json: @server.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /servers/1 - # PATCH/PUT /servers/1.json + # PATCH/PUT /server + # PATCH/PUT /server.json def update respond_to do |format| if @server.update(server_params) @@ -50,20 +22,11 @@ class ServersController < ApplicationController end end - # DELETE /servers/1 - # DELETE /servers/1.json - def destroy - @server.destroy - respond_to do |format| - format.html { redirect_to servers_url } - format.json { head :no_content } - end - end - private + # Use callbacks to share common setup or constraints between actions. def set_server - @server = Server.find(params[:id]) + @server = Server.first end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/views/servers/index.html.erb b/app/views/servers/index.html.erb deleted file mode 100644 index b3064f4..0000000 --- a/app/views/servers/index.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -

Listing servers

- - - - - - - - - - - - - <% @servers.each do |server| %> - - - - - - - <% end %> - -
Default user permissions
<%= server.default_user_permissions %><%= link_to 'Show', server %><%= link_to 'Edit', edit_server_path(server) %><%= link_to 'Destroy', server, method: :delete, data: { confirm: 'Are you sure?' } %>
- -
- -<%= link_to 'New Server', new_server_path %> diff --git a/app/views/servers/index.json.jbuilder b/app/views/servers/index.json.jbuilder deleted file mode 100644 index 3c9df60..0000000 --- a/app/views/servers/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@servers) do |server| - json.extract! server, :id, :default_user_permissions - json.url server_url(server, format: :json) -end diff --git a/app/views/servers/new.html.erb b/app/views/servers/new.html.erb deleted file mode 100644 index 0422009..0000000 --- a/app/views/servers/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New server

- -<%= render 'form' %> - -<%= link_to 'Back', servers_path %> -- cgit v1.2.3-54-g00ecf From cfaff7870d0348b25b3b4b2597950894ab25d989 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 14:32:38 -0400 Subject: implement editing the default user permissions --- app/controllers/servers_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- app/models/server.rb | 36 +++++++++++++++++++++++++++++++++++ app/views/servers/_form.html.erb | 23 ++++++++++------------ app/views/servers/edit.html.erb | 2 +- app/views/servers/show.html.erb | 2 +- 6 files changed, 50 insertions(+), 17 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index e3850b8..83a9f31 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -31,6 +31,6 @@ class ServersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def server_params - params.require(:server).permit(:default_user_permissions) + params.require(:server).permit(:default_user_permissions, :default_user_abilities => User.permission_bits.keys) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index dd66c18..637480f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -33,7 +33,7 @@ class UsersController < ApplicationController return end - @user.permissions = 0 + @user.permissions = Server.first.default_user_permissions respond_to do |format| if @user.save sign_in @user diff --git a/app/models/server.rb b/app/models/server.rb index 120f0fa..5ba7524 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -1,2 +1,38 @@ class Server < ActiveRecord::Base + def default_user_abilities + @abilities ||= User::Abilities.new(DefaultUser.new(self)) + end + def default_user_abilities=(new) + new.each do |k,v| + if v == "0" + v = false + end + default_user_abilities[k] = v + end + end + class DefaultUser + def initialize(server) + @server = server + end + def can?(action) + bit = User.permission_bits[action] + if bit.nil? + return false + else + return (@server.default_user_permissions & bit != 0) + end + end + def add_ability(action) + bit = User.permission_bits[action.to_sym] + unless bit.nil? + @server.default_user_permissions |= bit + end + end + def remove_ability(action) + bit = User.permission_bits[action.to_sym] + unless bit.nil? + @server.default_user_permissions &= ~ bit + end + end + end end diff --git a/app/views/servers/_form.html.erb b/app/views/servers/_form.html.erb index 6211f9a..1afde11 100644 --- a/app/views/servers/_form.html.erb +++ b/app/views/servers/_form.html.erb @@ -1,20 +1,17 @@ <%= form_for(@server) do |f| %> - <% if @server.errors.any? %> -
-

<%= pluralize(@server.errors.count, "error") %> prohibited this server from being saved:

+ <%= render "common/error_messages", :target => @server %> -
    - <% @server.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • +
    + Default permissions for new users +
      + <%= fields_for "server[default_user_abilities]", @server.default_user_abilities do |a| %> + <% @server.default_user_abilities.keys.each do |ability| %> +
    • <% end %> -
    -
- <% end %> + <% end %> + + -
- <%= f.label :default_user_permissions %>
- <%= f.number_field :default_user_permissions %> -
<%= f.submit %>
diff --git a/app/views/servers/edit.html.erb b/app/views/servers/edit.html.erb index 99f7faa..d37864f 100644 --- a/app/views/servers/edit.html.erb +++ b/app/views/servers/edit.html.erb @@ -2,4 +2,4 @@ <%= render 'form' %> -<%= link_to 'Show', @server %> +<%= link_to server_path %> diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb index 875be5d..54aaf66 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -3,4 +3,4 @@ <%= @server.default_user_permissions %>

-<%= link_to 'Edit', edit_server_path(@server) %> +<%= link_to 'Edit', edit_server_path %> -- cgit v1.2.3-54-g00ecf From 8f1a442b8f647ddca49572c8deb63f035d85ccf8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 17:32:34 -0400 Subject: I swear I have fixed this before --- app/controllers/tournaments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index a9e91b0..2fc82ed 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -99,7 +99,7 @@ class TournamentsController < ApplicationController format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } format.json { head :no_content } else - format.html { render action: 'permission_denied', status: :forbidden } + format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." } format.json { render json: "Permission denied", status: :forbidden } end end -- cgit v1.2.3-54-g00ecf From f85943114dba527a1f87abb03229553472f57c0c Mon Sep 17 00:00:00 2001 From: tkimia Date: Sun, 6 Apr 2014 18:45:41 -0400 Subject: started SVG generation --- app/controllers/matches_controller.rb | 4 ++++ app/models/tournament.rb | 4 ++-- app/views/matches/index.html.erb | 32 +++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 7 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 31fc9ad..e773667 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -8,6 +8,10 @@ class MatchesController < ApplicationController def index @matches = @tournament.matches + # width of SVG + @width = 300 * (Math.log2(@matches.count).floor + 1) + 300; + # height of SVG + @height = 200 * 2**Math.log2(@matches.count).floor + 100; end def get_riot_info diff --git a/app/models/tournament.rb b/app/models/tournament.rb index e408cfe..0029de7 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -31,7 +31,7 @@ class Tournament < ActiveRecord::Base for i in 1..num_matches self.matches.create(name: "Match #{i}", status: 0) end - match_num = 0 + match_num = num_matches-1 team_num = 0 #for each grouping of min_players_per_team self.players.each_slice(min_players_per_team) do |players| @@ -39,7 +39,7 @@ class Tournament < ActiveRecord::Base self.matches[match_num].teams.push(Team.create(users: players)) #if the match is full, move to the next match, otherwise move to the next team if (team_num != 0 and team_num % max_teams_per_match == 0) - match_num += 1 + match_num -= 1 team_num = 0 else team_num += 1 diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 219507d..031b2a9 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -26,17 +26,39 @@
- +
- + <% (1..@matches.count).each do |i| %> - + <% when 0 %> + <% if @matches[i-1].teams.count < @tournament.min_teams_per_match %> + stroke="red" + fill-opacity="0.6" + <% else %> + stroke="green" + <% end %> + <% when 1 %> + stroke="orange" + <% when 2 %> + stroke="yellow" + <% when 3 %> + stroke="grey" + <% end %> + /> <% end %> + +
\ No newline at end of file -- cgit v1.2.3-54-g00ecf From 7b5bf825a8174712f3ef6e9ea7f6180e7d230f99 Mon Sep 17 00:00:00 2001 From: nfoy Date: Sun, 6 Apr 2014 20:18:17 -0400 Subject: Auto-Checking for a match's end is implemented. --- app/controllers/matches_controller.rb | 32 +++++++++++++++++++++++++++++++- app/views/matches/show.html.erb | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index e773667..c369717 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -5,6 +5,7 @@ class MatchesController < ApplicationController # GET /matches.json require 'httparty' require 'json' + require 'delayed_job' def index @matches = @tournament.matches @@ -14,6 +15,8 @@ class MatchesController < ApplicationController @height = 200 * 2**Math.log2(@matches.count).floor + 100; end + + def get_riot_info if signed_in? @@ -118,14 +121,41 @@ class MatchesController < ApplicationController end #end def # GET /matches/1 # GET /matches/1.json + + def is_match_over + response = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{@first}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + riot_id = response["#{@first}"]['id'] + #recent game information + game_info = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{riot_id}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + first_id = game_info["games"][0]["gameId"] + + while true do + sleep(240) #wait four minutes + + recent = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{riot_id}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + current_id = recent["games"][0]["gameId"] + + if current_id != first_id + @match.status = 2 + end + end #while + end + handle_asynchronously :is_match_over + def show + if @match.id == 1 + is_match_over + end + + end private # Use callbacks to share common setup or constraints between actions. def set_match set_tournament - @match = @tournament.matches.find(params[:id]); + @match = @tournament.matches.find(params[:id]) + @first = @match.teams.first.users.first.user_name.downcase end def set_tournament @tournament = Tournament.find(params[:tournament_id]) diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 20860e2..44fe9ee 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -61,7 +61,7 @@ Players see the Peer Review Page Host see the Game Status --> -<% if @match.status == 0 %> +if (@match.status==0) %> <% if @tournament.players.include?(current_user) %> <% @match.teams.each do |team| %>
    -- cgit v1.2.3-54-g00ecf From 0f982ba511d4f38322f69a6aaed768181b4e2852 Mon Sep 17 00:00:00 2001 From: tkimia Date: Sun, 6 Apr 2014 21:10:46 -0400 Subject: some more graphics --- app/assets/stylesheets/matches.css.scss | 8 ++++ app/controllers/matches_controller.rb | 2 +- app/models/tournament.rb | 2 +- app/views/matches/index.html.erb | 80 +++++++++++++++++++-------------- 4 files changed, 56 insertions(+), 36 deletions(-) (limited to 'app/controllers') diff --git a/app/assets/stylesheets/matches.css.scss b/app/assets/stylesheets/matches.css.scss index 4c396e3..e0bed85 100644 --- a/app/assets/stylesheets/matches.css.scss +++ b/app/assets/stylesheets/matches.css.scss @@ -1,3 +1,11 @@ // Place all the styles related to the matches controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +#match-tree{ + float: right; +} + +#hovered-info-text { + +} \ No newline at end of file diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index e773667..28bc512 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -9,7 +9,7 @@ class MatchesController < ApplicationController def index @matches = @tournament.matches # width of SVG - @width = 300 * (Math.log2(@matches.count).floor + 1) + 300; + @width = 300 * (Math.log2(@matches.count).floor + 1); # height of SVG @height = 200 * 2**Math.log2(@matches.count).floor + 100; end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 0029de7..859518c 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -38,7 +38,7 @@ class Tournament < ActiveRecord::Base #create a new team in the current match self.matches[match_num].teams.push(Team.create(users: players)) #if the match is full, move to the next match, otherwise move to the next team - if (team_num != 0 and team_num % max_teams_per_match == 0) + if (team_num > max_teams_per_match) match_num -= 1 team_num = 0 else diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 031b2a9..6fd831f 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -27,38 +27,50 @@
    - - - <% (1..@matches.count).each do |i| %> - - - <% when 0 %> - <% if @matches[i-1].teams.count < @tournament.min_teams_per_match %> - stroke="red" - fill-opacity="0.6" - <% else %> - stroke="green" - <% end %> - <% when 1 %> - stroke="orange" - <% when 2 %> - stroke="yellow" - <% when 3 %> - stroke="grey" - <% end %> - /> - - <% end %> - - + + + <% (1..@matches.count).each do |i| %> + + + <% when 0 %> + <% if @matches[i-1].teams.count < @tournament.min_teams_per_match %> + stroke="red" + fill-opacity="0.6" + <% else %> + stroke="green" + <% end %> + <% when 1 %> + stroke="orange" + <% when 2 %> + stroke="yellow" + <% when 3 %> + stroke="grey" + <% end %> + /> + + <% if i > 1 %> + + <% end %> + <% end %> -
    \ No newline at end of file + -- cgit v1.2.3-54-g00ecf From 546b5895e7fe48d7f2e3c1032622805ee8fba090 Mon Sep 17 00:00:00 2001 From: tkimia Date: Sun, 6 Apr 2014 22:16:05 -0400 Subject: matches start --- app/controllers/matches_controller.rb | 25 ++++++++++++++++++++++++- app/views/matches/index.html.erb | 10 +++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index e9fe727..ee68e11 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,5 +1,5 @@ class MatchesController < ApplicationController - before_action :set_tournament, only: [:index] + before_action :set_tournament, only: [:index, :update] # GET /matches # GET /matches.json @@ -150,6 +150,29 @@ class MatchesController < ApplicationController end + def update + case params[:update_action] + when "start" + check_permission(:edit, @tournament) + status = 1 + respond_to do |format| + if @match + format.html { redirect_to tournament_match_path(@tournament, self), notice: 'Match has started.' } + format.json { head :no_content } + else + format.html { redirect_to @tournament, notice: "You don't have permission to start this match." } + format.json { render json: "Permission denied", status: :forbidden } + end + end + else + respond_to do |format| + format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } + format.json { render json: @tournament.errors, status: :unprocessable_entity } + end + end + + end + private # Use callbacks to share common setup or constraints between actions. def set_match diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 6fd831f..052d176 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -18,7 +18,15 @@ <%= match.id%> <%= match.name %> <%= link_to "Show", tournament_match_path(@tournament, match) %> - <%= submit_tag("Start Match") %> + <%# If user is the host, let them start the tournment %> + <% if @tournament.hosts.include?(current_user) %> + + <%= form_tag(tournament_match_path(@tournament, match), method: "put") do %> + + <%= submit_tag("Start Match") %> + <% end %> + <% end %> + <% end %> -- cgit v1.2.3-54-g00ecf