Commit af08ed6b66530b8efc68bf45e1f11599e333b826
1 parent
f294b8d4
Exists in
master
and in
4 other branches
refactoring
Showing
19 changed files
with
180 additions
and
163 deletions
Show diff stats
app/assets/stylesheets/style.scss
| ... | ... | @@ -571,7 +571,7 @@ body.project-page .project-sidebar aside a:first-child{ |
| 571 | 571 | body.project-page .project-sidebar aside a:hover{background-color: #eee;} |
| 572 | 572 | body.project-page .project-sidebar aside a span.number{float: right; border-radius: 5px; text-shadow: none; background: rgba(0,0,0,.12); text-align: center; padding: 5px 8px; position: absolute; top: 10px; right: 10px} |
| 573 | 573 | body.project-page .project-sidebar aside a.current{background-color: #79c3e0; color: white; text-shadow: none; border-color: transparent} |
| 574 | -body.project-page .project-content{ padding: 20px; display: block; margin-left: 250px; min-height: 400px} | |
| 574 | +body.project-page .project-content{ padding: 20px; display: block; margin-left: 250px; min-height: 450px} | |
| 575 | 575 | body.project-page .project-content h2{ margin-top: 6px} |
| 576 | 576 | body.project-page .project-content .button.right{margin-left: 20px} |
| 577 | 577 | body.project-page table .commit a{color: #{$blue_link}} | ... | ... |
app/controllers/projects_controller.rb
| ... | ... | @@ -88,35 +88,6 @@ class ProjectsController < ApplicationController |
| 88 | 88 | end |
| 89 | 89 | end |
| 90 | 90 | |
| 91 | - # | |
| 92 | - # Repository preview | |
| 93 | - # | |
| 94 | - | |
| 95 | - def tree | |
| 96 | - @repo = project.repo | |
| 97 | - | |
| 98 | - @commit = if params[:commit_id] | |
| 99 | - @repo.commits(params[:commit_id]).first | |
| 100 | - else | |
| 101 | - @repo.commits(@ref).first | |
| 102 | - end | |
| 103 | - | |
| 104 | - @tree = @commit.tree | |
| 105 | - @tree = @tree / params[:path] if params[:path] | |
| 106 | - | |
| 107 | - respond_to do |format| | |
| 108 | - format.html # show.html.erb | |
| 109 | - format.js do | |
| 110 | - # diasbale cache to allow back button works | |
| 111 | - response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" | |
| 112 | - response.headers["Pragma"] = "no-cache" | |
| 113 | - response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" | |
| 114 | - end | |
| 115 | - end | |
| 116 | - rescue | |
| 117 | - return render_404 | |
| 118 | - end | |
| 119 | - | |
| 120 | 91 | def graph |
| 121 | 92 | @repo = project.repo |
| 122 | 93 | commits = Grit::Commit.find_all(@repo, nil, {:max_count => 650}) |
| ... | ... | @@ -145,20 +116,6 @@ class ProjectsController < ApplicationController |
| 145 | 116 | end.to_json |
| 146 | 117 | end |
| 147 | 118 | |
| 148 | - def blob | |
| 149 | - @repo = project.repo | |
| 150 | - @commit = project.commit(params[:commit_id]) | |
| 151 | - @tree = project.tree(@commit, params[:path]) | |
| 152 | - | |
| 153 | - if @tree.is_a?(Grit::Blob) | |
| 154 | - send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) | |
| 155 | - else | |
| 156 | - head(404) | |
| 157 | - end | |
| 158 | - rescue | |
| 159 | - return render_404 | |
| 160 | - end | |
| 161 | - | |
| 162 | 119 | def destroy |
| 163 | 120 | project.destroy |
| 164 | 121 | ... | ... |
| ... | ... | @@ -0,0 +1,53 @@ |
| 1 | +class RefsController < ApplicationController | |
| 2 | + before_filter :project | |
| 3 | + before_filter :ref | |
| 4 | + layout "project" | |
| 5 | + | |
| 6 | + # Authorize | |
| 7 | + before_filter :add_project_abilities | |
| 8 | + before_filter :authorize_read_project! | |
| 9 | + before_filter :require_non_empty_project | |
| 10 | + | |
| 11 | + # | |
| 12 | + # Repository preview | |
| 13 | + # | |
| 14 | + def tree | |
| 15 | + @repo = project.repo | |
| 16 | + | |
| 17 | + @commit = @repo.commits(@ref).first | |
| 18 | + @tree = @commit.tree | |
| 19 | + @tree = @tree / params[:path] if params[:path] | |
| 20 | + | |
| 21 | + respond_to do |format| | |
| 22 | + format.html # show.html.erb | |
| 23 | + format.js do | |
| 24 | + # diasbale cache to allow back button works | |
| 25 | + response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" | |
| 26 | + response.headers["Pragma"] = "no-cache" | |
| 27 | + response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" | |
| 28 | + end | |
| 29 | + end | |
| 30 | + rescue | |
| 31 | + return render_404 | |
| 32 | + end | |
| 33 | + | |
| 34 | + def blob | |
| 35 | + @repo = project.repo | |
| 36 | + @commit = project.commit(@ref) | |
| 37 | + @tree = project.tree(@commit, params[:path]) | |
| 38 | + | |
| 39 | + if @tree.is_a?(Grit::Blob) | |
| 40 | + send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) | |
| 41 | + else | |
| 42 | + head(404) | |
| 43 | + end | |
| 44 | + rescue | |
| 45 | + return render_404 | |
| 46 | + end | |
| 47 | + | |
| 48 | + protected | |
| 49 | + | |
| 50 | + def ref | |
| 51 | + @ref = params[:id] | |
| 52 | + end | |
| 53 | +end | ... | ... |
app/helpers/application_helper.rb
| ... | ... | @@ -73,7 +73,7 @@ module ApplicationHelper |
| 73 | 73 | project_nav = [ |
| 74 | 74 | { :label => "#{@project.code} / Issues", :url => project_issues_path(@project) }, |
| 75 | 75 | { :label => "#{@project.code} / Wall", :url => wall_project_path(@project) }, |
| 76 | - { :label => "#{@project.code} / Tree", :url => tree_project_path(@project) }, | |
| 76 | + { :label => "#{@project.code} / Tree", :url => tree_project_ref_path(@project, @project.root_ref) }, | |
| 77 | 77 | { :label => "#{@project.code} / Commits", :url => project_commits_path(@project) }, |
| 78 | 78 | { :label => "#{@project.code} / Team", :url => team_project_path(@project) } |
| 79 | 79 | ] | ... | ... |
app/models/project.rb
app/views/commits/_commits.html.haml
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | %data.commit-button |
| 10 | 10 | = truncate(commit.id.to_s, :length => 16) |
| 11 | 11 | %i |
| 12 | - %data.commit-browse{ :onclick => "location.href='#{tree_project_path(@project, :commit_id => commit.id)}';return false;"} | |
| 12 | + %data.commit-browse{ :onclick => "location.href='#{tree_project_ref_path(@project, commit.id)}';return false;"} | |
| 13 | 13 | Browse Code |
| 14 | 14 | - if commit.author_email |
| 15 | 15 | = image_tag gravatar_icon(commit.author_email), :class => "left", :width => 40, :style => "padding-right:5px;" | ... | ... |
app/views/commits/_diff.html.haml
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | - if diff.deleted_file |
| 10 | 10 | %strong{:id => "#{diff.b_path}"}= diff.a_path |
| 11 | 11 | - else |
| 12 | - = link_to tree_file_project_path(@project, @commit.id, diff.b_path) do | |
| 12 | + = link_to tree_file_project_ref_path(@project, @commit.id, diff.b_path) do | |
| 13 | 13 | %strong{:id => "#{diff.b_path}"}= diff.b_path |
| 14 | 14 | %br/ |
| 15 | 15 | .diff_file_content | ... | ... |
app/views/commits/show.html.haml
app/views/layouts/project.html.haml
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | GitLab #{" - #{@project.name}" if @project && !@project.new_record?} |
| 6 | 6 | = stylesheet_link_tag "application" |
| 7 | 7 | = javascript_include_tag "application" |
| 8 | - - if current_page?(tree_project_path(@project)) || current_page?(project_commits_path(@project)) | |
| 8 | + - if current_page?(tree_project_ref_path(@project, @project.root_ref)) || current_page?(project_commits_path(@project)) | |
| 9 | 9 | = auto_discovery_link_tag(:atom, project_commits_url(@project, :atom, :ref => @ref, :private_token => current_user.private_token), :title => "Recent commits to #{@project.name}:#{@ref}") |
| 10 | 10 | - if request.path == project_issues_path(@project) |
| 11 | 11 | = auto_discovery_link_tag(:atom, project_issues_url(@project, :atom, :private_token => current_user.private_token), :title => "#{@project.name} issues") |
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | %input.git-url.text{:id => "", :name => "", :readonly => "", :type => "text", :value => @project.url_to_repo, :class => "one_click_select"} |
| 25 | 25 | %aside |
| 26 | 26 | = link_to "Activities", project_path(@project), :class => current_page?(:controller => "projects", :action => "show", :id => @project) ? "current" : nil |
| 27 | - = link_to "Tree", tree_project_path(@project), :class => current_page?(:controller => "projects", :action => "tree", :id => @project) ? "current" : nil | |
| 27 | + = link_to "Tree", tree_project_ref_path(@project, @project.root_ref), :class => current_page?(:controller => "refs", :action => "tree", :project_id => @project, :id => @ref || @project.root_ref ) ? "current" : nil | |
| 28 | 28 | = link_to "Commits", project_commits_path(@project), :class => current_page?(:controller => "commits", :action => "index", :project_id => @project) ? "current" : nil |
| 29 | 29 | = link_to "Network graph", graph_project_path(@project), :class => current_page?(:controller => "projects", :action => "graph", :id => @project) ? "current" : nil |
| 30 | 30 | = link_to team_project_path(@project), :class => (current_page?(:controller => "projects", :action => "team", :id => @project) || controller.controller_name == "team_members") ? "current" : nil do | ... | ... |
app/views/projects/_tree.html.haml
| ... | ... | @@ -1,60 +0,0 @@ |
| 1 | --#%a.right.button{:href => "#"} Download | |
| 2 | --#-if can? current_user, :admin_project, @project | |
| 3 | - %a.right.button.blue{:href => "#"} EDIT | |
| 4 | -#tree-breadcrumbs | |
| 5 | - %h2.icon | |
| 6 | - %span | |
| 7 | - %d | |
| 8 | - = link_to tree_project_path(@project, :path => nil, :commit_id => @commit.try(:id)), :remote => true do | |
| 9 | - = @project.name | |
| 10 | - - if params[:path] | |
| 11 | - - part_path = "" | |
| 12 | - - params[:path].split("\/").each do |part| | |
| 13 | - - part_path = File.join(part_path, part) unless part_path.empty? | |
| 14 | - - if part_path.empty? | |
| 15 | - - part_path = part | |
| 16 | - \/ | |
| 17 | - = link_to truncate(part, :length => 40), tree_file_project_path(@project, :path => part_path, :commit_id => @commit.try(:id), :branch => @branch, :tag => @tag), :remote => :true | |
| 18 | - | |
| 19 | - .right= render :partial => "projects/refs", :locals => { :destination => tree_project_path(@project) } | |
| 20 | -.clear | |
| 21 | - | |
| 22 | -#tree-content-holder | |
| 23 | - - if tree.is_a?(Grit::Blob) | |
| 24 | - = render :partial => "projects/tree_file", :locals => { :name => tree.name, :content => tree.data, :file => tree } | |
| 25 | - - else | |
| 26 | - - contents = tree.contents | |
| 27 | - %table#tree-slider.round-borders | |
| 28 | - %thead | |
| 29 | - %th Name | |
| 30 | - %th Last Update | |
| 31 | - %th | |
| 32 | - Last commit | |
| 33 | - = link_to "history", project_commits_path(@project, :path => params[:path], :branch => params[:branch],:tag => params[:tag]), :class => "right" | |
| 34 | - - if params[:path] | |
| 35 | - - file = File.join(params[:path], "..") | |
| 36 | - %tr{ :class => "tree-item", :url => tree_file_project_path(@project, @commit.id, file) } | |
| 37 | - %td.tree-item-file-name | |
| 38 | - = image_tag "dir.png" | |
| 39 | - = link_to "..", tree_file_project_path(@project, @commit.id, file, :branch => @branch, :tag => @tag), :remote => :true | |
| 40 | - %td | |
| 41 | - %td | |
| 42 | - | |
| 43 | - - contents.select{ |i| i.is_a?(Grit::Tree)}.each do |content| | |
| 44 | - = render :partial => "projects/tree_item", :locals => { :content => content } | |
| 45 | - - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| | |
| 46 | - = render :partial => "projects/tree_item", :locals => { :content => content } | |
| 47 | - | |
| 48 | -:javascript | |
| 49 | - $(function(){ | |
| 50 | - $('select#branch').selectmenu({style:'popup', width:200}); | |
| 51 | - $('select#tag').selectmenu({style:'popup', width:200}); | |
| 52 | - }); | |
| 53 | - | |
| 54 | -- if params[:path] && request.xhr? | |
| 55 | - :javascript | |
| 56 | - $(window).unbind('popstate'); | |
| 57 | - $(window).bind('popstate', function() { | |
| 58 | - if(location.pathname.search("tree") != -1) { | |
| 59 | - $.ajax({type: "GET", url: location.pathname, dataType: "script"})} | |
| 60 | - else { location.href = location.pathname;}}); |
app/views/projects/_tree_file.html.haml
| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | -:css | |
| 2 | -.view_file | |
| 3 | - .view_file_header | |
| 4 | - %strong | |
| 5 | - = name | |
| 6 | - = link_to "raw", blob_project_path(@project, :commit_id => @commit.id, :path => params[:path] ), :class => "right", :target => "_blank" | |
| 7 | - = link_to "history", project_commits_path(@project, :path => params[:path], :branch => params[:branch], :tag => params[:tag] ), :class => "right", :style => "margin-right:10px;" | |
| 8 | - %br/ | |
| 9 | - - if file.text? | |
| 10 | - .view_file_content | |
| 11 | - :erb | |
| 12 | - <%= raw file.colorize %> | |
| 13 | - - elsif file.image? | |
| 14 | - .view_file_content_image | |
| 15 | - %img{ :src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} | |
| 16 | - - else | |
| 17 | - %p | |
| 18 | - %center No preview for this file type | |
| 19 | - |
app/views/projects/_tree_item.html.haml
| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | -- file = params[:path] ? File.join(params[:path], content.name) : content.name | |
| 2 | -- content_commit = @project.repo.log(@commit.id, file, :max_count => 1).last | |
| 3 | -- return unless content_commit | |
| 4 | -%tr{ :class => "tree-item", :url => tree_file_project_path(@project, @commit.id, file) } | |
| 5 | - %td.tree-item-file-name | |
| 6 | - - if content.is_a?(Grit::Blob) | |
| 7 | - = image_tag "txt.png" | |
| 8 | - - else | |
| 9 | - = image_tag "dir.png" | |
| 10 | - = link_to truncate(content.name, :length => 40), tree_file_project_path(@project, @commit.id, file, :branch => @branch, :tag => @tag), :remote => :true | |
| 11 | - %td | |
| 12 | - = time_ago_in_words(content_commit.committed_date) | |
| 13 | - ago | |
| 14 | - %td.commit | |
| 15 | - = link_to truncate(content_commit.safe_message, :length => 40), project_commit_path(@project, content_commit), :class => "tree-commit-link" | |
| 16 | - - tm = @project.team_member_by_name_or_email(content_commit.author_email, content_commit.author_name) | |
| 17 | - - if tm | |
| 18 | - = link_to "[#{tm.user_name}]", project_team_member_path(@project, tm) |
app/views/projects/tree.html.erb
| ... | ... | @@ -0,0 +1,60 @@ |
| 1 | +-#%a.right.button{:href => "#"} Download | |
| 2 | +-#-if can? current_user, :admin_project, @project | |
| 3 | + %a.right.button.blue{:href => "#"} EDIT | |
| 4 | +#tree-breadcrumbs | |
| 5 | + %h2.icon | |
| 6 | + %span | |
| 7 | + %d | |
| 8 | + = link_to tree_project_ref_path(@project, @ref, :path => nil), :remote => true do | |
| 9 | + = @project.name | |
| 10 | + - if params[:path] | |
| 11 | + - part_path = "" | |
| 12 | + - params[:path].split("\/").each do |part| | |
| 13 | + - part_path = File.join(part_path, part) unless part_path.empty? | |
| 14 | + - if part_path.empty? | |
| 15 | + - part_path = part | |
| 16 | + \/ | |
| 17 | + = link_to truncate(part, :length => 40), tree_file_project_ref_path(@project, @ref, :path => part_path), :remote => :true | |
| 18 | + | |
| 19 | + .right= render :partial => "projects/refs", :locals => { :destination => tree_project_ref_path(@project, @ref) } | |
| 20 | +.clear | |
| 21 | + | |
| 22 | +#tree-content-holder | |
| 23 | + - if tree.is_a?(Grit::Blob) | |
| 24 | + = render :partial => "refs/tree_file", :locals => { :name => tree.name, :content => tree.data, :file => tree } | |
| 25 | + - else | |
| 26 | + - contents = tree.contents | |
| 27 | + %table#tree-slider.round-borders | |
| 28 | + %thead | |
| 29 | + %th Name | |
| 30 | + %th Last Update | |
| 31 | + %th | |
| 32 | + Last commit | |
| 33 | + = link_to "history", project_commits_path(@project, :path => params[:path], :ref => @ref), :class => "right" | |
| 34 | + - if params[:path] | |
| 35 | + - file = File.join(params[:path], "..") | |
| 36 | + %tr{ :class => "tree-item", :url => tree_file_project_ref_path(@project, @ref, file) } | |
| 37 | + %td.tree-item-file-name | |
| 38 | + = image_tag "dir.png" | |
| 39 | + = link_to "..", tree_file_project_ref_path(@project, @ref, file), :remote => :true | |
| 40 | + %td | |
| 41 | + %td | |
| 42 | + | |
| 43 | + - contents.select{ |i| i.is_a?(Grit::Tree)}.each do |content| | |
| 44 | + = render :partial => "refs/tree_item", :locals => { :content => content } | |
| 45 | + - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| | |
| 46 | + = render :partial => "refs/tree_item", :locals => { :content => content } | |
| 47 | + | |
| 48 | +:javascript | |
| 49 | + $(function(){ | |
| 50 | + $('select#branch').selectmenu({style:'popup', width:200}); | |
| 51 | + $('select#tag').selectmenu({style:'popup', width:200}); | |
| 52 | + }); | |
| 53 | + | |
| 54 | +- if params[:path] && request.xhr? | |
| 55 | + :javascript | |
| 56 | + $(window).unbind('popstate'); | |
| 57 | + $(window).bind('popstate', function() { | |
| 58 | + if(location.pathname.search("tree") != -1) { | |
| 59 | + $.ajax({type: "GET", url: location.pathname, dataType: "script"})} | |
| 60 | + else { location.href = location.pathname;}}); | ... | ... |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +:css | |
| 2 | +.view_file | |
| 3 | + .view_file_header | |
| 4 | + %strong | |
| 5 | + = name | |
| 6 | + = link_to "raw", blob_project_ref_path(@project, @ref, :path => params[:path] ), :class => "right", :target => "_blank" | |
| 7 | + = link_to "history", project_commits_path(@project, :path => params[:path], :ref => @ref ), :class => "right", :style => "margin-right:10px;" | |
| 8 | + %br/ | |
| 9 | + - if file.text? | |
| 10 | + .view_file_content | |
| 11 | + :erb | |
| 12 | + <%= raw file.colorize %> | |
| 13 | + - elsif file.image? | |
| 14 | + .view_file_content_image | |
| 15 | + %img{ :src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} | |
| 16 | + - else | |
| 17 | + %p | |
| 18 | + %center No preview for this file type | |
| 19 | + | ... | ... |
| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | +- file = params[:path] ? File.join(params[:path], content.name) : content.name | |
| 2 | +- content_commit = @project.repo.log(@commit.id, file, :max_count => 1).last | |
| 3 | +- return unless content_commit | |
| 4 | +%tr{ :class => "tree-item", :url => tree_file_project_ref_path(@project, @ref, file) } | |
| 5 | + %td.tree-item-file-name | |
| 6 | + - if content.is_a?(Grit::Blob) | |
| 7 | + = image_tag "txt.png" | |
| 8 | + - else | |
| 9 | + = image_tag "dir.png" | |
| 10 | + = link_to truncate(content.name, :length => 40), tree_file_project_ref_path(@project, @ref || @commit.id, file), :remote => :true | |
| 11 | + %td | |
| 12 | + = time_ago_in_words(content_commit.committed_date) | |
| 13 | + ago | |
| 14 | + %td.commit | |
| 15 | + = link_to truncate(content_commit.safe_message, :length => 40), project_commit_path(@project, content_commit), :class => "tree-commit-link" | |
| 16 | + - tm = @project.team_member_by_name_or_email(content_commit.author_email, content_commit.author_name) | |
| 17 | + - if tm | |
| 18 | + = link_to "[#{tm.user_name}]", project_team_member_path(@project, tm) | ... | ... |
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +#tree-holder= render :partial => "tree", :locals => {:repo => @repo, :commit => @commit, :tree => @tree} | ... | ... |
| ... | ... | @@ -0,0 +1,5 @@ |
| 1 | +:plain | |
| 2 | + $("#tree-holder table").hide("slide", { direction: "left" }, 150, function(){ | |
| 3 | + $("#tree-holder").html("#{escape_javascript(render(:partial => "tree", :locals => {:repo => @repo, :commit => @commit, :tree => @tree}))}"); | |
| 4 | + $("#tree-holder table").show("slide", { direction: "right" }, 150); | |
| 5 | + }); | ... | ... |
config/routes.rb
| ... | ... | @@ -30,22 +30,24 @@ Gitlab::Application.routes.draw do |
| 30 | 30 | |
| 31 | 31 | resources :projects, :except => [:new, :create, :index], :path => "/" do |
| 32 | 32 | member do |
| 33 | - get "tree" | |
| 34 | - get "blob" | |
| 35 | 33 | get "team" |
| 36 | 34 | get "wall" |
| 37 | 35 | get "graph" |
| 36 | + end | |
| 38 | 37 | |
| 39 | - # tree viewer | |
| 40 | - get "tree/:commit_id" => "projects#tree" | |
| 41 | - get "tree/:commit_id/:path" => "projects#tree", | |
| 42 | - :as => :tree_file, | |
| 43 | - :constraints => { | |
| 44 | - :id => /[a-zA-Z0-9_\-]+/, | |
| 45 | - :commit_id => /[a-zA-Z0-9]+/, | |
| 46 | - :path => /.*/ | |
| 47 | - } | |
| 38 | + resources :refs, :only => [], :path => "/" do | |
| 39 | + member do | |
| 40 | + get "tree" | |
| 41 | + get "blob" | |
| 48 | 42 | |
| 43 | + # tree viewer | |
| 44 | + get "tree/:path" => "refs#tree", | |
| 45 | + :as => :tree_file, | |
| 46 | + :constraints => { | |
| 47 | + :id => /[a-zA-Z0-9_\-]+/, | |
| 48 | + :path => /.*/ | |
| 49 | + } | |
| 50 | + end | |
| 49 | 51 | end |
| 50 | 52 | |
| 51 | 53 | resources :snippets | ... | ... |