Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Schedule single gameday view #310

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions app/assets/javascripts/eventscripts/schedule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

$(function() {
var $container = $("#gameday-slider");

var $arrowLeft = $container.find(".arrow-left");
var $arrowRight = $container.find(".arrow-right");

var $items = $(".gameday-slider-item");
var $selected = $items.filter(".selected");

var disableArrowsIfRequired = function() {
var index = $items.index($selected);

if(index === 0)
$arrowLeft.prop("disabled", true);
else if($arrowLeft.prop("disabled", true)) {
$arrowLeft.prop("disabled", false);
}

if(index === $items.length - 1)
$arrowRight.prop("disabled", true);
else if($arrowRight.prop("disabled", true)) {
$arrowRight.prop("disabled", false);
}
};

$arrowLeft.click(function() {
if($items.index($selected) === 0)
return false;

$selected = $selected
.removeClass("selected")
.prev()
.addClass("selected");

disableArrowsIfRequired();
});

$arrowRight.click(function() {
if($items.index($selected) === $items.length - 1)
return false;

$selected = $selected
.removeClass("selected")
.next()
.addClass("selected");

disableArrowsIfRequired();
});

disableArrowsIfRequired();
});

$(function() {
var $switchToAll = $(".to-schedule-all-view");
var $switchToSingle = $(".to-schedule-single-view");

var $allContainer = $(".schedule-all-view");
var $singleContainer = $(".schedule-single-view");

$switchToAll.click(function() {
$allContainer.show();
$singleContainer.hide();
$switchToSingle.show();
$(this).hide();
});

$switchToSingle.click(function() {
$allContainer.hide();
$singleContainer.show();
$switchToAll.show();
$(this).hide();
});
});
34 changes: 32 additions & 2 deletions app/assets/stylesheets/matches.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,37 @@
They will automatically be included in application.css.
*/

.matches-table > tbody > tr.gameday {
.matches-table tr.gameday {
background-color: #eeeeee;
border-bottom: 4px solid #ddd;
}
}

.schedule-single-view {
display: none;
}

.schedule-view-switches {
text-align: right;
margin-bottom: 20px;
}
.to-schedule-all-view {
display: none;
}

#gameday-slider {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
#gameday-slider .gameday {
font-weight: bold;
font-size: 14pt;
}
#gameday-slider :disabled {
opacity: 0.3;
}

.gameday-slider-item:not(.selected) {
display: none;
}
24 changes: 24 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ def start_after_deadline
errors.add(:startdate, I18n.t('activerecord.validations.must_be_after', other: Event.human_attribute_name(:deadline))) if startdate < deadline
end

def matches_per_gameday
gamedays = []

matches.each do |match|
if gamedays.has_key? match.gameday
gamedays[match.gameday] << match
else
gamedays[match.gameday] = []
end
end

gamedays
end

def gamedays
gamedays = []

matches.each do |match|
gamedays << match.gameday
end

gamedays.uniq
end

def deadline_has_passed?
deadline < Date.current
end
Expand Down
70 changes: 24 additions & 46 deletions app/views/events/_schedule_league.html.erb
Original file line number Diff line number Diff line change
@@ -1,47 +1,25 @@
<% last_gameday = nil %>
<% @matches.each do |match| %>
<% if match.gameday != last_gameday %>
<tr class="gameday">
<th colspan="6">
<b>
<%= t 'events.schedule.gameday' %> <%= match.gameday %>
</b>
<b>
<%= "- #{ (@event.startdate_for_gameday match.gameday).to_s(:day_and_month) } " %>
<%= t 'events.schedule.to' %>
<%= " #{(@event.enddate_for_gameday match.gameday).to_s(:day_and_month)}" %>
</b>
</th>
</tr>
<% last_gameday = match.gameday %>
<% end %>
<tr>
<td><%= match.place %></td>
<td><%= match.team_home ? link_to(match.team_home.name, team_path(match.team_home)) : '---' %></td>
<td><%= match.team_away ? link_to(match.team_away.name, team_path(match.team_away)) : '---' %></td>
<td>
<%= match.score_home ? match.score_home : '-' %>
:
<%= match.score_away ? match.score_away : '-' %>
</td>
<td>
<%= form_for match, url: update_points_match_path(match), html: {method: "put"} do |f| %>
<%= f.text_field :points_away, class: 'input-sm', style: 'width: 50px' %>
:
<%= f.text_field :points_home, class: 'input-sm', style: 'width: 50px' %>
<%= f.submit t('helpers.links.save'), :class => 'btn btn-default btn-xs' %>

<table class="matches-table table" id="matches-table">
<%= render partial: "events/schedule/table_head" %>
<tbody>
<% last_gameday = nil %>
<% @matches.each do |match| %>
<% if match.gameday != last_gameday %>
<tr class="gameday">
<th colspan="6">
<b>
<%= t 'events.schedule.gameday' %> <%= match.gameday %>
</b>
<b>
<%= "- #{ (@event.startdate_for_gameday match.gameday).to_s(:day_and_month) } " %>
<%= t 'events.schedule.to' %>
<%= " #{(@event.enddate_for_gameday match.gameday).to_s(:day_and_month)}" %>
</b>
</th>
</tr>
<% last_gameday = match.gameday %>
<% end %>
</td>
<td>
<%= link_to t('.show', default: t('helpers.links.show')),
match_path(match), :class => 'btn btn-default btn-xs' %>
<%= link_to t('.edit', default: t('helpers.links.edit')),
edit_match_path(match), :class => 'btn btn-default btn-xs' %>
<%= link_to t('.destroy', default: t('helpers.links.destroy')),
match_path(match),
:method => :delete,
:data => { :confirm => t('.confirm', default: t('helpers.links.confirm')) },
:class => 'btn btn-xs btn-danger' %>
</td>
</tr>
<% end %>
<%= render partial: "events/schedule/league/match_row", locals: { match: match } %>
<% end %>
</tbody>
</table>
109 changes: 56 additions & 53 deletions app/views/events/_schedule_tournament.html.erb
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
<% level = 0 %>
<% while true %>
<% this_level_matches = @matches.select { |match| match.gameday == level } %>
<% if this_level_matches.length == 0 %>
<% break %>
<% end %>
<table class="matches-table table" id="matches-table">>
<% render partial: "events/schedule/table_head" %>
<tbody>
<% level = 0 %>
<% while true %>
<% this_level_matches = @matches.select { |match| match.gameday == level } %>
<% if this_level_matches.length == 0 %>
<% break %>
<% end %>

<tr class="gameday">
<th colspan="6">
<b>
<% if this_level_matches[0].depth == 0 %>
<%= t('events.schedule.finale') %>
<% elsif this_level_matches[0].depth == 1 %>
<%= t('events.schedule.semifinale') %>
<% elsif this_level_matches[0].depth == 2 %>
<%= t('events.schedule.quarterfinale') %>
<% elsif this_level_matches[0].depth == 3 %>
<%= t('events.schedule.eighthfinale') %>
<% else %>
<%= t('events.schedule.preliminaries', round: (level + 1).to_s) %>
<% end %>
</b>
</th>
</tr>

<tr class="gameday">
<th colspan="6">
<b>
<% if this_level_matches[0].depth == 0 %>
<%= t('events.schedule.finale') %>
<% elsif this_level_matches[0].depth == 1 %>
<%= t('events.schedule.semifinale') %>
<% elsif this_level_matches[0].depth == 2 %>
<%= t('events.schedule.quarterfinale') %>
<% elsif this_level_matches[0].depth == 3 %>
<%= t('events.schedule.eighthfinale') %>
<% else %>
<%= t('events.schedule.preliminaries', round: (level + 1).to_s) %>
<% end %>
</b>
</th>
</tr>
<% this_level_matches.each do |match| %>
<tr>
<td><%= match.place %> <%= match.index %></td>
<td><%= match.team_home.winner != nil ? link_to(match.team_home.name, team_path(match.team_home.winner)) : link_to('Gewinner ' + match.team_home.name, match_path(match.team_home)) %></td>
<td><%= match.team_away.winner != nil ? link_to(match.team_away.name, team_path(match.team_away.winner)) : link_to('Gewinner ' + match.team_away.name, match_path(match.team_away)) %></td>
<td>
<%= match.score_home ? match.score_home : '-' %>
:
<%= match.score_away ? match.score_away : '-' %>
</td>
<td>
<%= form_for match, url: update_points_match_path(match), html: {method: "put"}, namespace: "match_#{match.id}" do |f| %>
<%= f.text_field :points_home, class: 'input-sm', style: 'width: 50px' %>
:
<%= f.text_field :points_away, class: 'input-sm', style: 'width: 50px' %>
<%= f.submit t('helpers.links.save'), class: 'btn btn-default btn-xs', id: "save_points_#{match.id}" %>
<% end %>
</td>
<td>
<%= link_to t('.show', default: t('helpers.links.show')),
match_path(match), :class => 'btn btn-default btn-xs' %>
<%= link_to t('.edit', default: t('helpers.links.edit')),
edit_match_path(match), :class => 'btn btn-default btn-xs' %>
</td>
</tr>
<% end %>

<% this_level_matches.each do |match| %>

<tr>
<td><%= match.place %> <%= match.index %></td>
<td><%= match.team_home.winner != nil ? link_to(match.team_home.name, team_path(match.team_home.winner)) : link_to('Gewinner ' + match.team_home.name, match_path(match.team_home)) %></td>
<td><%= match.team_away.winner != nil ? link_to(match.team_away.name, team_path(match.team_away.winner)) : link_to('Gewinner ' + match.team_away.name, match_path(match.team_away)) %></td>
<td>
<%= match.score_home ? match.score_home : '-' %>
:
<%= match.score_away ? match.score_away : '-' %>
</td>
<td>
<%= form_for match, url: update_points_match_path(match), html: {method: "put"}, namespace: "match_#{match.id}" do |f| %>
<%= f.text_field :points_home, class: 'input-sm', style: 'width: 50px' %>
:
<%= f.text_field :points_away, class: 'input-sm', style: 'width: 50px' %>
<%= f.submit t('helpers.links.save'), class: 'btn btn-default btn-xs', id: "save_points_#{match.id}" %>
<% end %>
</td>
<td>
<%= link_to t('.show', default: t('helpers.links.show')),
match_path(match), :class => 'btn btn-default btn-xs' %>
<%= link_to t('.edit', default: t('helpers.links.edit')),
edit_match_path(match), :class => 'btn btn-default btn-xs' %>
</td>
</tr>
<% end %>

<% level += 1 %>
<% end %>
<% level += 1 %>
<% end %>
</tbody>
</table>
29 changes: 14 additions & 15 deletions app/views/events/schedule.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
<h1><%= t '.title' %></h1>
</div>

<table class="matches-table table" id="matches-table">
<thead>
<tr>
<th><%= t '.place' %></th>
<th><%= t '.home' %></th>
<th><%= t '.away' %></th>
<th><%= t '.score' %></th>
<th><%= t '.points' %></th>
<th><%= t '.actions', default: t('helpers.actions') %></th>
</tr>
</thead>
<tbody>
<%= render ('schedule_' + @schedule_type), back_path: events_path %>
</tbody>
</table>
<% if @schedule_type == 'league' %>
<div class="schedule-view-switches">
<button class="btn to-schedule-all-view"><%= t '.show_all' %></button>
<button class="btn to-schedule-single-view"><%= t '.show_single' %></button>
</div>

<div class="schedule-single-view">
<%= render partial: "events/schedule/league/single" %>
</div>
<% end %>

<div class="schedule-all-view">
<%= render ('schedule_' + @schedule_type), back_path: events_path %>
</div>
10 changes: 10 additions & 0 deletions app/views/events/schedule/_table_head.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<thead>
<tr>
<th><%= t '.place' %></th>
<th><%= t '.home' %></th>
<th><%= t '.away' %></th>
<th><%= t '.score' %></th>
<th><%= t '.points' %></th>
<th><%= t '.actions', default: t('helpers.actions') %></th>
</tr>
</thead>
Loading