Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding "upcoming contests" section to the home page. #68

Merged
merged 2 commits into from

2 participants

@antonrd

No description provided.

antonrd added some commits
@antonrd antonrd Adding upcoming contests section to the home page.
Signed-off-by: Anton Dimitrov <anton@takeofflabs.com>
ff4e66b
@antonrd antonrd Adding scope for upcoming contests to 'contest' model.
Signed-off-by: Anton Dimitrov <anton@takeofflabs.com>
2cac4f2
@valo valo merged commit 73ea10c into valo:master
@valo
Owner

Deployed in production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 30, 2012
  1. @antonrd

    Adding upcoming contests section to the home page.

    antonrd authored
    Signed-off-by: Anton Dimitrov <anton@takeofflabs.com>
  2. @antonrd

    Adding scope for upcoming contests to 'contest' model.

    antonrd authored
    Signed-off-by: Anton Dimitrov <anton@takeofflabs.com>
This page is out of date. Refresh to see the latest.
View
2  app/controllers/main_controller.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require 'ostruct'
class MainController < ApplicationController
@@ -6,6 +7,7 @@ class MainController < ApplicationController
def index
@contests = Contest.current.select {|contest| contest.visible or current_user.andand.admin?}
+ @upcoming_contests = Contest.upcoming.select {|contest| contest.visible or current_user.andand.admin?}
@practice_contests = Contest.practicable.select {|contest| contest.visible or current_user.andand.admin?}.reverse
@top_scores = User.rating_ordering(10)
end
View
2  app/models/contest.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require 'latinize'
class Contest < ActiveRecord::Base
@@ -12,6 +13,7 @@ class Contest < ActiveRecord::Base
has_many :contest_results
has_many :rating_changes, :through => :contest_results
+ scope :upcoming, lambda { {:conditions => ['? < start_time', Time.now.utc]} }
scope :current, lambda { {:conditions => ['? > start_time AND ? < end_time', Time.now.utc, Time.now.utc]} }
scope :finished, lambda { {:conditions => ['? > end_time', Time.now.utc]} }
scope :practicable, :conditions => { :practicable => true }
View
2  app/views/main/_current_contests.html.erb
@@ -33,5 +33,5 @@
Няма състезания, които текат в момента.
<br />
<br />
-Кога е следващото състезание? Вижте <%= link_to "календара", "http://cs.maycamp.com/?page_id=13" %>.
+Кога е следващото състезание? Вижте <%= link_to "календара", "http://cs.maycamp.com/?page_id=13" %> или секцията "Предстоящи състезания".
<% end %>
View
22 app/views/main/_upcoming_contests.html.erb
@@ -0,0 +1,22 @@
+<h2>Предстоящи състезания</h2>
+<br />
+<% if !@upcoming_contests.blank? %>
+<table>
+ <tr>
+ <th>Име на състезанието</th>
+ <th>Започва</th>
+ <th>Приключва</th>
+ <th>Продължителност</th>
+ </tr>
+<% for contest in @upcoming_contests do %>
+ <tr>
+ <td><%= contest.name %></td>
+ <td><%= contest.start_time.to_s :long %></td>
+ <td><%= contest.end_time.to_s :long %></td>
+ <td><%= duration_in_words contest.duration.minutes %></td>
+ </tr>
+<% end %>
+</table>
+<% else %>
+Няма предстоящи състезания.
+<% end %>
View
3  app/views/main/index.html.erb
@@ -17,6 +17,9 @@
<%= render :partial => "current_contests" %>
<br />
<br />
+ <%= render :partial => "upcoming_contests" %>
+ <br />
+ <br />
<%= render :partial => "practice_area" %>
<% end %>
<br />
Something went wrong with that request. Please try again.