Merge remote-tracking branch 'official/master' into saltation
[gitorious:taladars-gitorious-saltation.git] / app / controllers / site_controller.rb
1 # encoding: utf-8
2 #--
3 #   Copyright (C) 2010 Marko Peltola <marko@markopeltola.com>
4 #   Copyright (C) 2010 Tero Hänninen <tero.j.hanninen@jyu.fi>
5 #   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
6 #   Copyright (C) 2008 Johan Sørensen <johan@johansorensen.com>
7 #   Copyright (C) 2008 David A. Cuadrado <krawek@gmail.com>
8 #   Copyright (C) 2008 Tor Arne Vestbø <tavestbo@trolltech.com>
9 #   Copyright (C) 2009 Fabio Akita <fabio.akita@gmail.com>
10 #
11 #   This program is free software: you can redistribute it and/or modify
12 #   it under the terms of the GNU Affero General Public License as published by
13 #   the Free Software Foundation, either version 3 of the License, or
14 #   (at your option) any later version.
15 #
16 #   This program is distributed in the hope that it will be useful,
17 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
18 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 #   GNU Affero General Public License for more details.
20 #
21 #   You should have received a copy of the GNU Affero General Public License
22 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 #++
24
25 class SiteController < ApplicationController
26   skip_before_filter :public_and_logged_in, :only => [:index, :about, :faq, :contact]
27   before_filter :login_required, :only => [:dashboard]
28   renders_in_site_specific_context :except => [:about, :faq, :contact]
29   renders_in_global_context :only => [:about, :faq, :contact]
30
31   def index
32     if !current_site.subdomain.blank?
33       render_site_index and return
34     else
35       render_global_index
36     end
37   end
38
39   def public_timeline
40     render_public_timeline
41   end
42
43
44   def dashboard
45     redirect_to current_user
46   end
47
48   def about
49   end
50
51   def faq
52   end
53
54   def contact
55   end
56
57   protected
58
59     # Render a Site-specific index template
60     def render_site_index
61       @projects = current_site.projects.visibility_publics_or_all(logged_in?).find(:all, :order => "created_at asc")
62       @teams = Group.all_participating_in_projects(@projects)
63       @top_repository_clones = Repository.most_active_clones_in_projects(@projects)
64       @latest_events = Event.latest_in_projects(logged_in?, 25, @projects.map{|p| p.id })
65       render "site/#{current_site.subdomain}/index"
66     end
67
68     def render_public_timeline
69       @projects = Project.visibility_publics_or_all(logged_in?).find(:all, :limit => 10, :order => "id desc")
70       @top_repository_clones = Repository.most_active_clones
71       @active_projects = Project.most_active_recently(logged_in?, 15)
72       @active_users = User.most_active
73       @active_groups = Group.most_active
74       @latest_events = Event.latest(logged_in?, 25)
75       render :template => "site/index"
76     end
77
78     def render_dashboard
79       @user = current_user
80       @projects = @user.projects.find(:all,
81         :include => [:tags, { :repositories => :project }])
82       @repositories = current_user.commit_repositories 
83       @events = @user.paginated_events_in_watchlist(:page => params[:page])
84       @messages = @user.messages_in_inbox(3) if @user == current_user
85       @favorites = @user.watched_objects
86       @root = Breadcrumb::Dashboard.new(current_user)
87       @atom_auto_discovery_url = watchlist_user_path(current_user, :format => :atom)
88
89       render :template => "site/dashboard"
90     end
91
92     def render_gitorious_dot_org_in_public
93       @feed_items = Rails.cache.fetch("blog_feed:feed_items", :expires_in => 1.hour) do
94         BlogFeed.new("http://blog.gitorious.org/feed/").fetch
95       end
96       render :template => "site/public_index", :layout => "second_generation/application"
97     end
98
99     # Render the global index template
100     def render_global_index
101       if logged_in?
102         render_dashboard
103       elsif GitoriousConfig["is_gitorious_dot_org"]
104         render_gitorious_dot_org_in_public
105       else
106         render_public_timeline
107       end
108     end
109
110 end