BaseContext
Controllers refactoring with contexts Move commit compare logic to model
This commit is contained in:
parent
3c6daec4b1
commit
3063af5adc
11 changed files with 130 additions and 62 deletions
|
@ -26,43 +26,31 @@ class CommitsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@commit = project.commit(params[:id])
|
||||
result = CommitLoad.new(project, current_user, params).execute
|
||||
|
||||
git_not_found! and return unless @commit
|
||||
@commit = result[:commit]
|
||||
|
||||
@commit = CommitDecorator.decorate(@commit)
|
||||
|
||||
@note = @project.build_commit_note(@commit)
|
||||
@comments_allowed = true
|
||||
@line_notes = project.commit_line_notes(@commit)
|
||||
|
||||
@notes_count = @line_notes.count + project.commit_notes(@commit).count
|
||||
|
||||
if @commit.diffs.size > 200 && !params[:force_show_diff]
|
||||
@suppress_diff = true
|
||||
if @commit
|
||||
@suppress_diff = result[:suppress_diff]
|
||||
@note = result[:note]
|
||||
@line_notes = result[:line_notes]
|
||||
@notes_count = result[:notes_count]
|
||||
@comments_allowed = true
|
||||
else
|
||||
return git_not_found!
|
||||
end
|
||||
|
||||
rescue Grit::Git::GitTimeout
|
||||
render "huge_commit"
|
||||
end
|
||||
|
||||
def compare
|
||||
first = project.commit(params[:to].try(:strip))
|
||||
last = project.commit(params[:from].try(:strip))
|
||||
result = Commit.compare(project, params[:from], params[:to])
|
||||
|
||||
@diffs = []
|
||||
@commits = []
|
||||
@commits = result[:commits]
|
||||
@commit = result[:commit]
|
||||
@diffs = result[:diffs]
|
||||
@line_notes = []
|
||||
|
||||
if first && last
|
||||
commits = [first, last].sort_by(&:created_at)
|
||||
younger = commits.first
|
||||
older = commits.last
|
||||
|
||||
|
||||
@commits = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)}
|
||||
@diffs = project.repo.diff(younger.id, older.id) rescue []
|
||||
@commit = Commit.new(older)
|
||||
end
|
||||
end
|
||||
|
||||
def patch
|
||||
|
|
|
@ -2,11 +2,8 @@ class DashboardController < ApplicationController
|
|||
respond_to :html
|
||||
|
||||
def index
|
||||
@projects = current_user.projects.includes(:events).order("events.created_at DESC")
|
||||
@projects = @projects.page(params[:page]).per(40)
|
||||
|
||||
@events = Event.where(:project_id => current_user.projects.map(&:id)).recent.limit(20)
|
||||
|
||||
@projects = current_user.projects_with_events.page(params[:page]).per(40)
|
||||
@events = Event.recent_for_user(current_user).limit(20)
|
||||
@last_push = current_user.recent_push
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
@ -24,16 +24,7 @@ class MergeRequestsController < ApplicationController
|
|||
|
||||
|
||||
def index
|
||||
@merge_requests = @project.merge_requests
|
||||
|
||||
@merge_requests = case params[:f].to_i
|
||||
when 1 then @merge_requests
|
||||
when 2 then @merge_requests.closed
|
||||
when 3 then @merge_requests.opened.assigned(current_user)
|
||||
else @merge_requests.opened
|
||||
end.page(params[:page]).per(20)
|
||||
|
||||
@merge_requests = @merge_requests.includes(:author, :project).order("closed, created_at desc")
|
||||
@merge_requests = MergeRequestsLoad.new(project, current_user, params).execute
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -40,25 +40,6 @@ class NotesController < ApplicationController
|
|||
protected
|
||||
|
||||
def notes
|
||||
@notes = case params[:target_type]
|
||||
when "commit"
|
||||
then project.commit_notes(project.commit((params[:target_id]))).fresh.limit(20)
|
||||
when "snippet"
|
||||
then project.snippets.find(params[:target_id]).notes
|
||||
when "wall"
|
||||
then project.common_notes.order("created_at DESC").fresh.limit(50)
|
||||
when "issue"
|
||||
then project.issues.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20)
|
||||
when "merge_request"
|
||||
then project.merge_requests.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20)
|
||||
end
|
||||
|
||||
@notes = if params[:last_id]
|
||||
@notes.where("id > ?", params[:last_id])
|
||||
elsif params[:first_id]
|
||||
@notes.where("id < ?", params[:first_id])
|
||||
else
|
||||
@notes
|
||||
end
|
||||
@notes = NotesLoad.new(project, current_user, params).execute
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue