Allowing time cutoff for Group.most_active and customizable time cutoff User.most_act...
[gitorious:yousource.git] / app / controllers / site_controller.rb
1 # encoding: utf-8
2 #--
3 #   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
4 #   Copyright (C) 2008 Johan Sørensen <johan@johansorensen.com>
5 #   Copyright (C) 2008 David A. Cuadrado <krawek@gmail.com>
6 #   Copyright (C) 2008 Tor Arne Vestbø <tavestbo@trolltech.com>
7 #   Copyright (C) 2009 Fabio Akita <fabio.akita@gmail.com>
8 #
9 #   This program is free software: you can redistribute it and/or modify
10 #   it under the terms of the GNU Affero General Public License as published by
11 #   the Free Software Foundation, either version 3 of the License, or
12 #   (at your option) any later version.
13 #
14 #   This program is distributed in the hope that it will be useful,
15 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #   GNU Affero General Public License for more details.
18 #
19 #   You should have received a copy of the GNU Affero General Public License
20 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #++
22
23 class SiteController < ApplicationController
24   skip_before_filter :public_and_logged_in, :only => [:index, :about, :faq]
25   before_filter :login_required, :only => [:dashboard]
26   renders_in_site_specific_context :except => [:about, :faq, :contact]
27   renders_in_global_context :only => [:about, :faq, :contact]
28   
29   def index
30     if !current_site.subdomain.blank?
31       render_site_index and return
32     else
33       render_global_index
34     end
35   end
36   
37   def dashboard
38     redirect_to current_user
39   end
40   
41   def about
42   end
43   
44   def faq    
45   end
46   
47   def contact    
48   end
49   
50   protected
51   
52     # Render a Site-specific index template
53     def render_site_index
54       @projects = current_site.projects.find(:all, :limit => 10, :order => "id desc")
55       @teams = Group.all_participating_in_projects(@projects)
56       @top_repository_clones = Repository.most_active_clones_in_projects(@projects)
57       @latest_events = Event.latest_in_projects(15, @projects.map{|p| p.id })
58       render "site/#{current_site.subdomain}/index"
59     end
60
61     # Render the global index template
62     def render_global_index
63       if GitoriousConfig["is_gitorious_dot_org"] && !logged_in?
64         @projects = Project.most_active_recently(10, 7.days.ago)
65         @teams = Group.most_active(10, 7.days.ago)
66         @users = User.most_active_pushers(10, 7.days.ago)
67         
68         render :layout => "second_generation/application", :inline => ""
69       else
70         @projects = Project.find(:all, :limit => 10, :order => "id desc")
71         @top_repository_clones = Repository.most_active_clones
72         @active_recently = Project.most_active_recently
73         @active_overall = Project.most_active_overall(@active_recently.size)
74         @active_users = User.most_active_pushers
75         @active_groups = Group.most_active
76         @latest_events = Event.latest(25)
77       end
78     end
79   
80 end