rosa-build/app/controllers/home_controller.rb

113 lines
3.8 KiB
Ruby
Raw Normal View History

class HomeController < ApplicationController
2015-05-05 13:25:29 +01:00
before_action :authenticate_user!, except: [:root]
skip_after_action :verify_authorized
def root
respond_to do |format|
format.html { render 'pages/tour/abf-tour-project-description-1' }
end
end
2015-05-05 13:25:29 +01:00
def activity(is_my_activity = false)
@filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all
@activity_feeds = current_user.activity_feeds
2015-05-05 13:25:29 +01:00
.by_project_name(params[:project_name_filter])
.by_owner_uname(params[:owner_filter])
2014-01-21 04:51:49 +00:00
@activity_feeds = @activity_feeds.where(kind: "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all
2015-03-10 08:55:57 +00:00
@activity_feeds = @activity_feeds.where(user_id: current_user) if @own_filter == :created
@activity_feeds = @activity_feeds.where.not(user_id: current_user) if @own_filter == :not_created
2015-05-05 13:25:29 +01:00
@activity_feeds = if is_my_activity
@activity_feeds.where(creator_id: current_user)
else
@activity_feeds.where.not(creator_id: current_user)
end
2014-05-06 10:51:04 +01:00
@activity_feeds = @activity_feeds.paginate page: current_page
2014-04-11 09:57:00 +01:00
respond_to do |format|
2014-05-12 11:02:48 +01:00
format.html { render 'activity' }
2015-05-05 13:25:29 +01:00
format.json { render 'activity' }
format.atom
end
end
2015-05-05 13:25:29 +01:00
def own_activity
activity(true)
end
def issues
@created_issues = current_user.issues
2014-01-21 04:51:49 +00:00
@assigned_issues = Issue.where(assignee_id: current_user.id)
2015-03-26 00:26:24 +00:00
pr_ids = ProjectPolicy::Scope.new(current_user, Project).membered.uniq.pluck(:id)
2014-01-21 04:51:49 +00:00
@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]
2014-05-06 10:51:04 +01:00
@opened_issues, @closed_issues = @issues.not_closed_or_merged, @issues.closed_or_merged
@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
2014-05-06 10:51:04 +01:00
.paginate page: current_page
respond_to do |format|
2014-05-12 11:02:48 +01:00
format.html { render 'activity' }
format.json { render 'issues' }
end
end
def pull_requests
issues
end
2015-05-05 13:25:29 +01:00
def get_owners_list
if params[:term].present?
users = User.opened.search(params[:term]).pluck(:uname).first(5)
groups = Group.opened.search(params[:term]).pluck(:uname).first(5)
@owners = users | groups
end
respond_to do |format|
format.json {}
end
end
def get_project_names_list
if params[:term].present?
@projects = ProjectPolicy::Scope.new(current_user, Project).membered
@projects = @projects.where(owner_uname: params[:owner_uname]) if params[:owner_uname].present?
@projects = @projects.by_name("%#{params[:term]}%")
.distinct
.pluck(:name)
.first(10)
end
respond_to do |format|
format.json {}
end
end
2015-03-26 00:26:24 +00:00
end