summaryrefslogtreecommitdiff
path: root/app/views/tournaments/show.html.erb
blob: 8d56f46b34bed098ad2db358db03831cc4db942f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<%
# Copyright (C) 2014 Andrew Murrell
# Copyright (C) 2014 Davis Webb
# Copyright (C) 2014 Guntas Grewal
# Copyright (C) 2014 Luke Shumaker
# Copyright (C) 2014 Nathaniel Foy
# Copyright (C) 2014 Tomer Kimia
#
# This file is part of Leaguer.
#
# Leaguer is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Leaguer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the Affero GNU General Public License
# along with Leaguer.  If not, see <http://www.gnu.org/licenses/>.
%>
<%= link_to '« Back to all tournaments', tournaments_path, class: :breadcrumb %>

<h2 id="tournament-name"> 
	<%= @tournament.name %>
</h2>

<div class="progress">
	<%# FIXME: What's up with this? Hardcoded 60%? %>
	<%= 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>

<div id="tournament-side-params">
	<p>
		<strong>Status:</strong>
		<% if @tournament.status == 0 %>
			Waiting for players...
		<% else %>
			Started
		<% end %>
	</p>

	<p>
		<strong>Name:</strong>
		<%= @tournament.name %>
	</p>

	<p>
		<strong>Min players per team:</strong>
		<%= @tournament.min_players_per_team %>
	</p>

	<p>
		<strong>Max players per team:</strong>
		<%= @tournament.max_players_per_team %>
	</p>

	<p>
		<strong>Min teams per match:</strong>
		<%= @tournament.min_teams_per_match %>
	</p>

	<p>
		<strong>Max teams per match:</strong>
		<%= @tournament.max_teams_per_match %>
	</p>

	<p>
		<strong>Scoring method:</strong>
		<%= @tournament.scoring_method.titleize %>
	</p>

	<% @tournament.settings.each do |setting| %>
		<p>
			<strong><%= setting.name %></strong>
			<%= setting.value %>
		</p>
	<% end %>
</div>

<div>
	<% if @tournament.players.length > 0 %>
		<h3>Players Here:</h3>
		<ul id="tournament-users">
			<% @tournament.players.each do |p| %>
			<li><%= p.user_name %></li>
			<% end %>
		</ul>
	<% else %>
		<h3 div="players-needed">Hmmm.... nobody's here yet! You and your friends should join the tournament.</h3>
	<% end %>
</div>

<div class="actions">
	<%# If user can join, and user hasn't joined already, show a join tournment button %>
	<% if @tournament.joinable_by?(current_user) && !@tournament.players.include?(current_user) %>
		<%= form_tag(tournament_path(@tournament), method: "put", role: :button) 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", role: :button) 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.check_permission(current_user, :edit) %>
		<%= form_tag(tournament_path(@tournament), method: "put", role: :button) do %>
			<input type="hidden" name="update_action" value="start">
			<%= submit_tag("Start Tournament", disabled: (@tournament.players.count < @tournament.min_players_per_team * @tournament.min_teams_per_match)) %>
		<% end %>
		<%= link_to 'Edit Tournament', edit_tournament_path(@tournament), role: :button %>
		<%= link_to 'Cancel Tournament', @tournament, method: :delete, data: { confirm: 'Are you sure?' }, role: :button %>
	<% end %>
</div>