Commit 169f16fb32091701bcaa962872ea35b5772a1539
1 parent
5a5d214d
Exists in
master
and in
4 other branches
Remove Commits#compare, add CompareController
Showing
7 changed files
with
106 additions
and
74 deletions
Show diff stats
app/controllers/commits_controller.rb
| ... | ... | @@ -45,18 +45,6 @@ class CommitsController < ApplicationController |
| 45 | 45 | # end |
| 46 | 46 | # end |
| 47 | 47 | |
| 48 | - def compare | |
| 49 | - result = Commit.compare(project, params[:from], params[:to]) | |
| 50 | - | |
| 51 | - @commits = result[:commits] | |
| 52 | - @commit = result[:commit] | |
| 53 | - @diffs = result[:diffs] | |
| 54 | - @refs_are_same = result[:same] | |
| 55 | - @line_notes = [] | |
| 56 | - | |
| 57 | - @commits = CommitDecorator.decorate(@commits) | |
| 58 | - end | |
| 59 | - | |
| 60 | 48 | def patch |
| 61 | 49 | @commit = project.commit(params[:id]) |
| 62 | 50 | ... | ... |
| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | +class CompareController < ApplicationController | |
| 2 | + before_filter :project | |
| 3 | + layout "project" | |
| 4 | + | |
| 5 | + # Authorize | |
| 6 | + before_filter :add_project_abilities | |
| 7 | + before_filter :authorize_read_project! | |
| 8 | + before_filter :authorize_code_access! | |
| 9 | + before_filter :require_non_empty_project | |
| 10 | + | |
| 11 | + def show | |
| 12 | + result = Commit.compare(project, params[:from], params[:to]) | |
| 13 | + | |
| 14 | + @commits = result[:commits] | |
| 15 | + @commit = result[:commit] | |
| 16 | + @diffs = result[:diffs] | |
| 17 | + @refs_are_same = result[:same] | |
| 18 | + @line_notes = [] | |
| 19 | + | |
| 20 | + @commits = CommitDecorator.decorate(@commits) | |
| 21 | + end | |
| 22 | +end | ... | ... |
app/views/commits/compare.html.haml
| ... | ... | @@ -1,53 +0,0 @@ |
| 1 | -= render "head" | |
| 2 | - | |
| 3 | -%h3.page_title | |
| 4 | - Compare View | |
| 5 | -%hr | |
| 6 | - | |
| 7 | -%div | |
| 8 | - %p.slead | |
| 9 | - Fill input field with commit id like | |
| 10 | - %code.label_branch 4eedf23 | |
| 11 | - or branch/tag name like | |
| 12 | - %code.label_branch master | |
| 13 | - and press compare button for commits list, code diff. | |
| 14 | - | |
| 15 | - %br | |
| 16 | - | |
| 17 | - = form_tag compare_project_commits_path(@project), method: :get do | |
| 18 | - .clearfix | |
| 19 | - = text_field_tag :from, params[:from], placeholder: "master", class: "xlarge" | |
| 20 | - = "..." | |
| 21 | - = text_field_tag :to, params[:to], placeholder: "aa8b4ef", class: "xlarge" | |
| 22 | - - if @refs_are_same | |
| 23 | - .alert | |
| 24 | - %span Refs are the same | |
| 25 | - .actions | |
| 26 | - = submit_tag "Compare", class: "btn primary wide commits-compare-btn" | |
| 27 | - | |
| 28 | -- if @commits.present? | |
| 29 | - %div.ui-box | |
| 30 | - %h5.small Commits (#{@commits.count}) | |
| 31 | - %ul.unstyled= render @commits | |
| 32 | - | |
| 33 | - - unless @diffs.empty? | |
| 34 | - %h4 Diff | |
| 35 | - = render "commits/diffs", diffs: @diffs | |
| 36 | - | |
| 37 | -:javascript | |
| 38 | - $(function() { | |
| 39 | - var availableTags = #{@project.ref_names.to_json}; | |
| 40 | - | |
| 41 | - $("#from").autocomplete({ | |
| 42 | - source: availableTags, | |
| 43 | - minLength: 1 | |
| 44 | - }); | |
| 45 | - | |
| 46 | - $("#to").autocomplete({ | |
| 47 | - source: availableTags, | |
| 48 | - minLength: 1 | |
| 49 | - }); | |
| 50 | - | |
| 51 | - disableButtonIfEmptyField('#to', '.commits-compare-btn'); | |
| 52 | - }); | |
| 53 | - |
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +%ul.nav.nav-tabs | |
| 2 | + %li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'} | |
| 3 | + %li{class: "#{'active' if current_page?(project_commits_path(@project)) }"} | |
| 4 | + = link_to project_commits_path(@project) do | |
| 5 | + Commits | |
| 6 | + %li{class: "#{'active' if current_page?(compare_project_commits_path(@project)) }"} | |
| 7 | + = link_to compare_project_commits_path(@project) do | |
| 8 | + Compare | |
| 9 | + %li{class: "#{branches_tab_class}"} | |
| 10 | + = link_to project_repository_path(@project) do | |
| 11 | + Branches | |
| 12 | + %span.badge= @project.repo.branch_count | |
| 13 | + | |
| 14 | + %li{class: "#{'active' if current_page?(tags_project_repository_path(@project)) }"} | |
| 15 | + = link_to tags_project_repository_path(@project) do | |
| 16 | + Tags | |
| 17 | + %span.badge= @project.repo.tag_count | |
| 18 | + | |
| 19 | + - if current_page?(project_commits_path(@project)) && current_user.private_token | |
| 20 | + %li.right | |
| 21 | + %span.rss-icon | |
| 22 | + = link_to project_commits_path(@project, :atom, { private_token: current_user.private_token, ref: @ref }), title: "Feed" do | |
| 23 | + = image_tag "rss_ui.png", title: "feed" | ... | ... |
| ... | ... | @@ -0,0 +1,53 @@ |
| 1 | += render "head" | |
| 2 | + | |
| 3 | +%h3.page_title | |
| 4 | + Compare View | |
| 5 | +%hr | |
| 6 | + | |
| 7 | +%div | |
| 8 | + %p.slead | |
| 9 | + Fill input field with commit id like | |
| 10 | + %code.label_branch 4eedf23 | |
| 11 | + or branch/tag name like | |
| 12 | + %code.label_branch master | |
| 13 | + and press compare button for commits list, code diff. | |
| 14 | + | |
| 15 | + %br | |
| 16 | + | |
| 17 | + = form_tag compare_project_commits_path(@project), method: :get do | |
| 18 | + .clearfix | |
| 19 | + = text_field_tag :from, params[:from], placeholder: "master", class: "xlarge" | |
| 20 | + = "..." | |
| 21 | + = text_field_tag :to, params[:to], placeholder: "aa8b4ef", class: "xlarge" | |
| 22 | + - if @refs_are_same | |
| 23 | + .alert | |
| 24 | + %span Refs are the same | |
| 25 | + .actions | |
| 26 | + = submit_tag "Compare", class: "btn primary wide commits-compare-btn" | |
| 27 | + | |
| 28 | +- if @commits.present? | |
| 29 | + %div.ui-box | |
| 30 | + %h5.small Commits (#{@commits.count}) | |
| 31 | + %ul.unstyled= render @commits | |
| 32 | + | |
| 33 | + - unless @diffs.empty? | |
| 34 | + %h4 Diff | |
| 35 | + = render "commits/diffs", diffs: @diffs | |
| 36 | + | |
| 37 | +:javascript | |
| 38 | + $(function() { | |
| 39 | + var availableTags = #{@project.ref_names.to_json}; | |
| 40 | + | |
| 41 | + $("#from").autocomplete({ | |
| 42 | + source: availableTags, | |
| 43 | + minLength: 1 | |
| 44 | + }); | |
| 45 | + | |
| 46 | + $("#to").autocomplete({ | |
| 47 | + source: availableTags, | |
| 48 | + minLength: 1 | |
| 49 | + }); | |
| 50 | + | |
| 51 | + disableButtonIfEmptyField('#to', '.commits-compare-btn'); | |
| 52 | + }); | |
| 53 | + | ... | ... |
config/routes.rb
| ... | ... | @@ -162,10 +162,6 @@ Gitlab::Application.routes.draw do |
| 162 | 162 | resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/} |
| 163 | 163 | |
| 164 | 164 | resources :commits, only: [:index, :show] do |
| 165 | - collection do | |
| 166 | - get :compare | |
| 167 | - end | |
| 168 | - | |
| 169 | 165 | member do |
| 170 | 166 | get :patch |
| 171 | 167 | end |
| ... | ... | @@ -194,6 +190,7 @@ Gitlab::Application.routes.draw do |
| 194 | 190 | resources :blob, only: [:show], constraints: {id: /.+/} |
| 195 | 191 | # resources :raw, only: [:show], constraints: {id: /.+/} |
| 196 | 192 | resources :tree, only: [:show], constraints: {id: /.+/} |
| 193 | + match "/compare/:from...:to" => "compare#show", as: "compare", constraints: {from: /.+/, to: /.+/} | |
| 197 | 194 | end |
| 198 | 195 | |
| 199 | 196 | root to: "dashboard#index" | ... | ... |
spec/routing/project_routing_spec.rb
| ... | ... | @@ -289,16 +289,11 @@ describe CommitController, "routing" do |
| 289 | 289 | end |
| 290 | 290 | end |
| 291 | 291 | |
| 292 | -# compare_project_commits GET /:project_id/commits/compare(.:format) commits#compare | |
| 293 | 292 | # patch_project_commit GET /:project_id/commits/:id/patch(.:format) commits#patch |
| 294 | 293 | # project_commits GET /:project_id/commits(.:format) commits#index |
| 295 | 294 | # POST /:project_id/commits(.:format) commits#create |
| 296 | 295 | # project_commit GET /:project_id/commits/:id(.:format) commits#show |
| 297 | 296 | describe CommitsController, "routing" do |
| 298 | - it "to #compare" do | |
| 299 | - get("/gitlabhq/commits/compare").should route_to('commits#compare', project_id: 'gitlabhq') | |
| 300 | - end | |
| 301 | - | |
| 302 | 297 | it "to #patch" do |
| 303 | 298 | get("/gitlabhq/commits/1/patch").should route_to('commits#patch', project_id: 'gitlabhq', id: '1') |
| 304 | 299 | end |
| ... | ... | @@ -407,6 +402,13 @@ describe TreeController, "routing" do |
| 407 | 402 | end |
| 408 | 403 | end |
| 409 | 404 | |
| 405 | +describe CompareController, "routing" do | |
| 406 | + it "to #show" do | |
| 407 | + get("/gitlabhq/compare/master...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'master', to: 'stable') | |
| 408 | + get("/gitlabhq/compare/issue/1234...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable') | |
| 409 | + end | |
| 410 | +end | |
| 411 | + | |
| 410 | 412 | # TODO: Pending |
| 411 | 413 | # |
| 412 | 414 | # /:project_id/blame/*path | ... | ... |