[#98] create home controller; move activity, common issues/pull_requests & root pages here

This commit is contained in:
Alexander Machehin 2013-05-15 23:28:39 +06:00
parent 9ac1cdb2c0
commit f8f53b198b
24 changed files with 88 additions and 89 deletions

View File

@ -1,15 +0,0 @@
# -*- encoding : utf-8 -*-
class ActivityFeedsController < ApplicationController
before_filter :authenticate_user!
def index
@filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all
@activity_feeds = current_user.activity_feeds
@activity_feeds = @activity_feeds.where(:kind => "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all
@activity_feeds = @activity_feeds.paginate :page => params[:page]
respond_to do |format|
format.html { request.xhr? ? render('_list', :layout => false) : render('index') }
format.atom
end
end
end

View File

@ -0,0 +1,62 @@
# -*- encoding : utf-8 -*-
class HomeController < ApplicationController
before_filter :authenticate_user!, :only => [:activity, :issues, :pull_requests]
def root
render 'pages/tour/abf-tour-project-description-1', :layout => 'tour'
end
def activity
@filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all
@activity_feeds = current_user.activity_feeds
@activity_feeds = @activity_feeds.where(:kind => "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all
@activity_feeds = @activity_feeds.paginate :page => params[:page]
respond_to do |format|
format.html { request.xhr? ? render('_list', :layout => false) : render('activity') }
format.atom
end
end
def issues
@created_issues = current_user.issues
@assigned_issues = Issue.where(:assignee_id => current_user.id)
pr_ids = Project.accessible_by(current_ability, :membered).uniq.pluck(:id)
@all_issues = Issue.where(:project_id => pr_ids)
@created_issues, @assigned_issues, @all_issues =
if action_name == 'issues'
[@created_issues.without_pull_requests,
@assigned_issues.without_pull_requests,
@all_issues.without_pull_requests]
else
[@created_issues.joins(:pull_request),
@assigned_issues.joins(:pull_request),
@all_issues.joins(:pull_request)]
end
case params[:filter]
when 'created'
@issues = @created_issues
when 'assigned'
@issues = @assigned_issues
else
params[:filter] = 'all' # default
@issues = @all_issues
end
@filter = params[:filter]
@opened_issues, @closed_issues = @issues.not_closed_or_merged.count, @issues.closed_or_merged.count
@status = params[:status] == 'closed' ? :closed : :open
@issues = @issues.send( (@status == :closed) ? :closed_or_merged : :not_closed_or_merged )
@sort = params[:sort] == 'updated' ? :updated : :created
@direction = params[:direction] == 'asc' ? :asc : :desc
@issues = @issues.order("issues.#{@sort}_at #{@direction}")
.includes(:assignee, :user, :pull_request).uniq
.paginate :per_page => 20, :page => params[:page]
render 'issues', :layout => request.xhr? ? 'with_sidebar' : 'application'
end
def pull_requests
issues
end
end

View File

@ -1,11 +1,5 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
class PagesController < ApplicationController class PagesController < ApplicationController
# before_filter :authenticate_user!, :except => [:show, :main, :forbidden]
# load_and_authorize_resource
def root
render 'pages/tour/abf-tour-project-description-1', :layout => 'tour'
end
def tour_inside def tour_inside
@entries = case params[:id] @entries = case params[:id]

View File

@ -23,49 +23,6 @@ class Users::UsersController < Users::BaseController
render :json => {:name => @user.name}.to_json render :json => {:name => @user.name}.to_json
end end
def issues
@created_issues = current_user.issues
@assigned_issues = Issue.where(:assignee_id => current_user.id)
pr_ids = Project.accessible_by(current_ability, :membered).uniq.pluck(:id)
@all_issues = Issue.where(:project_id => pr_ids)
@created_issues, @assigned_issues, @all_issues =
if action_name == 'issues'
[@created_issues.without_pull_requests,
@assigned_issues.without_pull_requests,
@all_issues.without_pull_requests]
else
[@created_issues.joins(:pull_request),
@assigned_issues.joins(:pull_request),
@all_issues.joins(:pull_request)]
end
case params[:filter]
when 'created'
@issues = @created_issues
when 'assigned'
@issues = @assigned_issues
else
params[:filter] = 'all' # default
@issues = @all_issues
end
@filter = params[:filter]
@opened_issues, @closed_issues = @issues.not_closed_or_merged.count, @issues.closed_or_merged.count
@status = params[:status] == 'closed' ? :closed : :open
@issues = @issues.send( (@status == :closed) ? :closed_or_merged : :not_closed_or_merged )
@sort = params[:sort] == 'updated' ? :updated : :created
@direction = params[:direction] == 'asc' ? :asc : :desc
@issues = @issues.order("issues.#{@sort}_at #{@direction}")
.includes(:assignee, :user, :pull_request).uniq
.paginate :per_page => 20, :page => params[:page]
render 'issues_index', :layout => request.xhr? ? 'with_sidebar' : 'application'
end
def pull_requests
issues
end
protected protected
def find_user_by_key def find_user_by_key

View File

@ -15,7 +15,7 @@ class ActivityFeed < ActiveRecord::Base
self.per_page = 10 self.per_page = 10
def partial def partial
'activity_feeds/partials/' + self.kind 'home/partials/' + self.kind
end end
end end

View File

@ -2,4 +2,4 @@
%nav %nav
%ul %ul
- (collection = t 'feed_menu').each do |base, title| - (collection = t 'feed_menu').each do |base, title|
%li= link_to title, root_path(:filter => base), :class => controller_name == 'activity_feeds' && @filter == base ? 'active' : '' %li= link_to title, root_path(:filter => base), :class => @filter == base ? 'active' : ''

View File

@ -2,6 +2,6 @@
.sub-menu .sub-menu
%nav %nav
%ul %ul
%li= link_to t('activity_menu.activity_feed'), root_path, :class => controller_name == 'activity_feeds' ? 'active' : '' %li= link_to t('activity_menu.activity_feed'), root_path, :class => action_name == 'activity' ? 'active' : ''
%li= link_to t('activity_menu.tracker'), issues_path, :class => controller_name == 'users' && action_name == 'issues' ? 'active' : '' %li= link_to t('activity_menu.tracker'), issues_path, :class => action_name == 'issues' ? 'active' : ''
%li= link_to t('activity_menu.pull_requests'), pull_requests_path, :class => controller_name == 'users' && action_name == 'pull_requests' ? 'active' : '' %li= link_to t('activity_menu.pull_requests'), pull_requests_path, :class => action_name == 'pull_requests' ? 'active' : ''

View File

@ -2,7 +2,7 @@
%h3.fix %h3.fix
= t("layout.activity_feed.header") = t("layout.activity_feed.header")
= link_to image_tag("rss.ico", :width => '15px', :height => '15px', :class => 'atom_icon'), atom_activity_feeds_path(:format => 'atom', :token => current_user.authentication_token) = link_to image_tag("rss.ico", :width => '15px', :height => '15px', :class => 'atom_icon'), atom_activity_feeds_path(:format => 'atom', :token => current_user.authentication_token)
=render('feed_tabs') =render 'feed_tabs'
=render 'list' =render 'list'
- content_for :sidebar, render('sidebar') - content_for :sidebar, render('sidebar')

View File

@ -1,5 +1,5 @@
-set_meta_tags :title => t("users.users.#{action_name}_index.title") -set_meta_tags :title => t("users.users.#{action_name}_index.title")
-render('activity_feeds/top_menu') -render 'top_menu'
-content_for :sidebar do -content_for :sidebar do
=form_tag send("#{action_name}_path"), :id => 'filter_issues', :method => :get do =form_tag send("#{action_name}_path"), :id => 'filter_issues', :method => :get do
.bordered .bordered

View File

@ -6,11 +6,6 @@ en:
settings: settings:
profile: profile:
title: 'Your Profile' title: 'Your Profile'
users:
issues_index:
title: 'Your Issues'
pull_requests_index:
title: 'Your Pull Requests'
projects: projects:
build_lists: build_lists:
index: index:
@ -38,3 +33,8 @@ en:
product_build_lists: product_build_lists:
index: index:
title: 'Products Monitoring' title: 'Products Monitoring'
pages:
issues:
title: 'Your Issues'
pull_requests:
title: 'Your Pull Requests'

View File

@ -6,11 +6,6 @@ ru:
settings: settings:
profile: profile:
title: 'Ваш профиль' title: 'Ваш профиль'
users:
issues_index:
title: 'Ваши задачи'
pull_requests_index:
title: 'Ваши пул реквесты'
projects: projects:
build_lists: build_lists:
index: index:
@ -38,3 +33,8 @@ ru:
product_build_lists: product_build_lists:
index: index:
title: 'Мониторинг продуктов' title: 'Мониторинг продуктов'
pages:
issues:
title: 'Ваши задачи'
pull_requests:
title: 'Ваши пул реквесты'

View File

@ -94,16 +94,19 @@ Rosa::Application.routes.draw do
get '/forbidden' => 'pages#forbidden', :as => 'forbidden' get '/forbidden' => 'pages#forbidden', :as => 'forbidden'
get '/terms-of-service' => 'pages#tos', :as => 'tos' get '/terms-of-service' => 'pages#tos', :as => 'tos'
get '/tour/:id' => 'pages#tour_inside', :as => 'tour_inside', :id => /projects|sources|builds/ get '/tour/:id' => 'pages#tour_inside', :as => 'tour_inside', :id => /projects|sources|builds/
match '/invite.html' => redirect('/register_requests/new') #match '/invite.html' => redirect('/register_requests/new')
get '/activity_feeds.:format' => 'home#activity', :as => 'atom_activity_feeds', :format => /atom/
get '/issues' => 'home#issues'
get '/pull_requests' => 'home#pull_requests'
get '/activity_feeds.:format' => 'activity_feeds#index', :as => 'atom_activity_feeds', :format => /atom/
if APP_CONFIG['anonymous_access'] if APP_CONFIG['anonymous_access']
authenticated do authenticated do
root :to => 'activity_feeds#index' root :to => 'home#activity'
end end
root :to => 'pages#root' root :to => 'home#root'
else else
root :to => 'activity_feeds#index' root :to => 'home#activity'
end end
namespace :admin do namespace :admin do
@ -209,8 +212,6 @@ Rosa::Application.routes.draw do
get '/allowed' => 'users#allowed' get '/allowed' => 'users#allowed'
get '/check' => 'users#check' get '/check' => 'users#check'
get '/discover' => 'users#discover' get '/discover' => 'users#discover'
get '/issues' => 'users#issues'
get '/pull_requests' => 'users#pull_requests'
end end
scope :module => 'groups' do scope :module => 'groups' do