From aa6e8f12a24e33d88a5751cee5e93bf4a038e2ef Mon Sep 17 00:00:00 2001 From: Tomer Kimia Date: Tue, 1 Apr 2014 18:51:03 -0400 Subject: AJAX is now working in the tournament loading page --- app/assets/stylesheets/tournaments.css.scss | 7 +++++++ app/controllers/tournaments_controller.rb | 18 ++++++++++++++---- app/views/matches/index.html.erb | 4 ++-- app/views/tournaments/show.html.erb | 29 +++++++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/tournaments.css.scss b/app/assets/stylesheets/tournaments.css.scss index 8857d38..2074783 100644 --- a/app/assets/stylesheets/tournaments.css.scss +++ b/app/assets/stylesheets/tournaments.css.scss @@ -73,4 +73,11 @@ div.tournament-listing { padding: 5px 0 0 0; } } +} + +div.leave-buttons { + margin-top: 50px; + form { + display: inline; + } } \ No newline at end of file diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 2f04e1f..4455ad2 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -11,10 +11,20 @@ class TournamentsController < ApplicationController # GET /tournaments/1 # GET /tournaments/1.json def show - case @tournament.status - when 0 - when 1..2 - redirect_to "/tournaments/" + @tournament.id.to_s + "/matches" #tournament_matches_page(@tournament) + respond_to do |format| + format.html { + case @tournament.status + when 0 + render action: 'show' + when 1..2 + redirect_to "/tournaments/" + @tournament.id.to_s + "/matches" #tournament_matches_page(@tournament) + end + } + format.json { + data = JSON.parse(@tournament.to_json) + data["players"] = @tournament.players; + render :json => data.to_json + } end end diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index f1019ec..e8d304a 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -38,9 +38,9 @@ width="<%= 300 * @matches.count / 2 + 50 %>" height="<%= 200 * @matches.count + 50 %>" xmlns="http://www.w3.org/2000/svg"> - <% @matches.each do |tournament | %> + <% (1..@matches.count).each do |i| %> - + <% end %> diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index df85dcf..7bdbdc0 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -3,7 +3,7 @@
- <%= tag("div", {: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"}) %> + <%= 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"}) %> 60% Complete (warning)
@@ -65,6 +65,7 @@

Hmmm.... nobody's here yet! You and your friends should join the tournament.

<% end %> +
<%# 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 %> @@ -94,8 +95,32 @@ <%= link_to 'Back', tournaments_path %> | <%= link_to 'Cancel Tournament', @tournament, method: :delete, data: { confirm: 'Are you sure?' } %> <% end %> - +
<%end %> + \ No newline at end of file -- cgit v1.1-4-g5e80