Commit 9267cb04b0b3fdf127899c4b7e636dc27fac06d3
Exists in
master
and in
4 other branches
Merge branch 'refactoring_controllers' of dev.gitlabhq.com:gitlabhq
Showing
11 changed files
with
132 additions
and
64 deletions
Show diff stats
... | ... | @@ -0,0 +1,26 @@ |
1 | +class CommitLoad < BaseContext | |
2 | + def execute | |
3 | + result = { | |
4 | + :commit => nil, | |
5 | + :suppress_diff => false, | |
6 | + :line_notes => [], | |
7 | + :notes_count => 0, | |
8 | + :note => nil | |
9 | + } | |
10 | + | |
11 | + commit = project.commit(params[:id]) | |
12 | + | |
13 | + if commit | |
14 | + commit = CommitDecorator.decorate(commit) | |
15 | + line_notes = project.commit_line_notes(commit) | |
16 | + | |
17 | + result[:suppress_diff] = true if commit.diffs.size > 200 && !params[:force_show_diff] | |
18 | + result[:commit] = commit | |
19 | + result[:note] = project.build_commit_note(commit) | |
20 | + result[:line_notes] = line_notes | |
21 | + result[:notes_count] = line_notes.count + project.commit_notes(commit).count | |
22 | + end | |
23 | + | |
24 | + result | |
25 | + end | |
26 | +end | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +class MergeRequestsLoad < BaseContext | |
2 | + def execute | |
3 | + type = params[:f].to_i | |
4 | + | |
5 | + merge_requests = project.merge_requests | |
6 | + | |
7 | + merge_requests = case type | |
8 | + when 1 then merge_requests | |
9 | + when 2 then merge_requests.closed | |
10 | + when 3 then merge_requests.opened.assigned(current_user) | |
11 | + else merge_requests.opened | |
12 | + end.page(params[:page]).per(20) | |
13 | + | |
14 | + merge_requests.includes(:author, :project).order("closed, created_at desc") | |
15 | + end | |
16 | +end | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +class NotesLoad < BaseContext | |
2 | + def execute | |
3 | + target_type = params[:target_type] | |
4 | + target_id = params[:target_id] | |
5 | + first_id = params[:first_id] | |
6 | + last_id = params[:last_id] | |
7 | + | |
8 | + | |
9 | + @notes = case target_type | |
10 | + when "commit" | |
11 | + then project.commit_notes(project.commit(target_id)).fresh.limit(20) | |
12 | + when "snippet" | |
13 | + then project.snippets.find(target_id).notes | |
14 | + when "wall" | |
15 | + then project.common_notes.order("created_at DESC").fresh.limit(50) | |
16 | + when "issue" | |
17 | + then project.issues.find(target_id).notes.inc_author.order("created_at DESC").limit(20) | |
18 | + when "merge_request" | |
19 | + then project.merge_requests.find(target_id).notes.inc_author.order("created_at DESC").limit(20) | |
20 | + end | |
21 | + | |
22 | + @notes = if last_id | |
23 | + @notes.where("id > ?", last_id) | |
24 | + elsif first_id | |
25 | + @notes.where("id < ?", first_id) | |
26 | + else | |
27 | + @notes | |
28 | + end | |
29 | + end | |
30 | +end | ... | ... |
app/controllers/commits_controller.rb
... | ... | @@ -26,43 +26,31 @@ class CommitsController < ApplicationController |
26 | 26 | end |
27 | 27 | |
28 | 28 | def show |
29 | - @commit = project.commit(params[:id]) | |
30 | - | |
31 | - git_not_found! and return unless @commit | |
32 | - | |
33 | - @commit = CommitDecorator.decorate(@commit) | |
34 | - | |
35 | - @note = @project.build_commit_note(@commit) | |
36 | - @comments_allowed = true | |
37 | - @line_notes = project.commit_line_notes(@commit) | |
38 | - | |
39 | - @notes_count = @line_notes.count + project.commit_notes(@commit).count | |
40 | - | |
41 | - if @commit.diffs.size > 200 && !params[:force_show_diff] | |
42 | - @suppress_diff = true | |
29 | + result = CommitLoad.new(project, current_user, params).execute | |
30 | + | |
31 | + @commit = result[:commit] | |
32 | + | |
33 | + if @commit | |
34 | + @suppress_diff = result[:suppress_diff] | |
35 | + @note = result[:note] | |
36 | + @line_notes = result[:line_notes] | |
37 | + @notes_count = result[:notes_count] | |
38 | + @comments_allowed = true | |
39 | + else | |
40 | + return git_not_found! | |
43 | 41 | end |
42 | + | |
44 | 43 | rescue Grit::Git::GitTimeout |
45 | 44 | render "huge_commit" |
46 | 45 | end |
47 | 46 | |
48 | 47 | def compare |
49 | - first = project.commit(params[:to].try(:strip)) | |
50 | - last = project.commit(params[:from].try(:strip)) | |
48 | + result = Commit.compare(project, params[:from], params[:to]) | |
51 | 49 | |
52 | - @diffs = [] | |
53 | - @commits = [] | |
50 | + @commits = result[:commits] | |
51 | + @commit = result[:commit] | |
52 | + @diffs = result[:diffs] | |
54 | 53 | @line_notes = [] |
55 | - | |
56 | - if first && last | |
57 | - commits = [first, last].sort_by(&:created_at) | |
58 | - younger = commits.first | |
59 | - older = commits.last | |
60 | - | |
61 | - | |
62 | - @commits = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)} | |
63 | - @diffs = project.repo.diff(younger.id, older.id) rescue [] | |
64 | - @commit = Commit.new(older) | |
65 | - end | |
66 | 54 | end |
67 | 55 | |
68 | 56 | def patch | ... | ... |
app/controllers/dashboard_controller.rb
... | ... | @@ -2,11 +2,8 @@ class DashboardController < ApplicationController |
2 | 2 | respond_to :html |
3 | 3 | |
4 | 4 | def index |
5 | - @projects = current_user.projects.includes(:events).order("events.created_at DESC") | |
6 | - @projects = @projects.page(params[:page]).per(40) | |
7 | - | |
8 | - @events = Event.where(:project_id => current_user.projects.map(&:id)).recent.limit(20) | |
9 | - | |
5 | + @projects = current_user.projects_with_events.page(params[:page]).per(40) | |
6 | + @events = Event.recent_for_user(current_user).limit(20) | |
10 | 7 | @last_push = current_user.recent_push |
11 | 8 | |
12 | 9 | respond_to do |format| | ... | ... |
app/controllers/merge_requests_controller.rb
... | ... | @@ -24,16 +24,7 @@ class MergeRequestsController < ApplicationController |
24 | 24 | |
25 | 25 | |
26 | 26 | def index |
27 | - @merge_requests = @project.merge_requests | |
28 | - | |
29 | - @merge_requests = case params[:f].to_i | |
30 | - when 1 then @merge_requests | |
31 | - when 2 then @merge_requests.closed | |
32 | - when 3 then @merge_requests.opened.assigned(current_user) | |
33 | - else @merge_requests.opened | |
34 | - end.page(params[:page]).per(20) | |
35 | - | |
36 | - @merge_requests = @merge_requests.includes(:author, :project).order("closed, created_at desc") | |
27 | + @merge_requests = MergeRequestsLoad.new(project, current_user, params).execute | |
37 | 28 | end |
38 | 29 | |
39 | 30 | def show | ... | ... |
app/controllers/notes_controller.rb
... | ... | @@ -40,25 +40,6 @@ class NotesController < ApplicationController |
40 | 40 | protected |
41 | 41 | |
42 | 42 | def notes |
43 | - @notes = case params[:target_type] | |
44 | - when "commit" | |
45 | - then project.commit_notes(project.commit((params[:target_id]))).fresh.limit(20) | |
46 | - when "snippet" | |
47 | - then project.snippets.find(params[:target_id]).notes | |
48 | - when "wall" | |
49 | - then project.common_notes.order("created_at DESC").fresh.limit(50) | |
50 | - when "issue" | |
51 | - then project.issues.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20) | |
52 | - when "merge_request" | |
53 | - then project.merge_requests.find(params[:target_id]).notes.inc_author.order("created_at DESC").limit(20) | |
54 | - end | |
55 | - | |
56 | - @notes = if params[:last_id] | |
57 | - @notes.where("id > ?", params[:last_id]) | |
58 | - elsif params[:first_id] | |
59 | - @notes.where("id < ?", params[:first_id]) | |
60 | - else | |
61 | - @notes | |
62 | - end | |
43 | + @notes = NotesLoad.new(project, current_user, params).execute | |
63 | 44 | end |
64 | 45 | end | ... | ... |
app/models/commit.rb
... | ... | @@ -80,6 +80,29 @@ class Commit |
80 | 80 | def commits_between(repo, from, to) |
81 | 81 | repo.commits_between(from, to).map { |c| Commit.new(c) } |
82 | 82 | end |
83 | + | |
84 | + def compare(project, from, to) | |
85 | + first = project.commit(to.try(:strip)) | |
86 | + last = project.commit(from.try(:strip)) | |
87 | + | |
88 | + result = { | |
89 | + :commits => [], | |
90 | + :diffs => [], | |
91 | + :commit => nil | |
92 | + } | |
93 | + | |
94 | + if first && last | |
95 | + commits = [first, last].sort_by(&:created_at) | |
96 | + younger = commits.first | |
97 | + older = commits.last | |
98 | + | |
99 | + result[:commits] = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)} | |
100 | + result[:diffs] = project.repo.diff(younger.id, older.id) rescue [] | |
101 | + result[:commit] = Commit.new(older) | |
102 | + end | |
103 | + | |
104 | + result | |
105 | + end | |
83 | 106 | end |
84 | 107 | |
85 | 108 | def persisted? | ... | ... |
app/models/event.rb
app/roles/account.rb