diff --git a/app/assets/stylesheets/style.scss b/app/assets/stylesheets/style.scss index 833a681..1f3fa1b 100644 --- a/app/assets/stylesheets/style.scss +++ b/app/assets/stylesheets/style.scss @@ -571,7 +571,7 @@ body.project-page .project-sidebar aside a:first-child{ body.project-page .project-sidebar aside a:hover{background-color: #eee;} 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} body.project-page .project-sidebar aside a.current{background-color: #79c3e0; color: white; text-shadow: none; border-color: transparent} -body.project-page .project-content{ padding: 20px; display: block; margin-left: 250px; min-height: 400px} +body.project-page .project-content{ padding: 20px; display: block; margin-left: 250px; min-height: 450px} body.project-page .project-content h2{ margin-top: 6px} body.project-page .project-content .button.right{margin-left: 20px} body.project-page table .commit a{color: #{$blue_link}} diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e778ae8..b700dc8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -88,35 +88,6 @@ class ProjectsController < ApplicationController end end - # - # Repository preview - # - - def tree - @repo = project.repo - - @commit = if params[:commit_id] - @repo.commits(params[:commit_id]).first - else - @repo.commits(@ref).first - end - - @tree = @commit.tree - @tree = @tree / params[:path] if params[:path] - - respond_to do |format| - format.html # show.html.erb - format.js do - # diasbale cache to allow back button works - response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" - response.headers["Pragma"] = "no-cache" - response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" - end - end - rescue - return render_404 - end - def graph @repo = project.repo commits = Grit::Commit.find_all(@repo, nil, {:max_count => 650}) @@ -145,20 +116,6 @@ class ProjectsController < ApplicationController end.to_json end - def blob - @repo = project.repo - @commit = project.commit(params[:commit_id]) - @tree = project.tree(@commit, params[:path]) - - if @tree.is_a?(Grit::Blob) - send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) - else - head(404) - end - rescue - return render_404 - end - def destroy project.destroy diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb new file mode 100644 index 0000000..cbe8751 --- /dev/null +++ b/app/controllers/refs_controller.rb @@ -0,0 +1,53 @@ +class RefsController < ApplicationController + before_filter :project + before_filter :ref + layout "project" + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_read_project! + before_filter :require_non_empty_project + + # + # Repository preview + # + def tree + @repo = project.repo + + @commit = @repo.commits(@ref).first + @tree = @commit.tree + @tree = @tree / params[:path] if params[:path] + + respond_to do |format| + format.html # show.html.erb + format.js do + # diasbale cache to allow back button works + response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" + response.headers["Pragma"] = "no-cache" + response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" + end + end + rescue + return render_404 + end + + def blob + @repo = project.repo + @commit = project.commit(@ref) + @tree = project.tree(@commit, params[:path]) + + if @tree.is_a?(Grit::Blob) + send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) + else + head(404) + end + rescue + return render_404 + end + + protected + + def ref + @ref = params[:id] + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4768ea8..530709e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -73,7 +73,7 @@ module ApplicationHelper project_nav = [ { :label => "#{@project.code} / Issues", :url => project_issues_path(@project) }, { :label => "#{@project.code} / Wall", :url => wall_project_path(@project) }, - { :label => "#{@project.code} / Tree", :url => tree_project_path(@project) }, + { :label => "#{@project.code} / Tree", :url => tree_project_ref_path(@project, @project.root_ref) }, { :label => "#{@project.code} / Commits", :url => project_commits_path(@project) }, { :label => "#{@project.code} / Team", :url => team_project_path(@project) } ] diff --git a/app/models/project.rb b/app/models/project.rb index c6a07f8..09c91fb 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -121,6 +121,10 @@ class Project < ActiveRecord::Base @admins ||=users_projects.includes(:user).where(:admin => true).map(&:user) end + def root_ref + "master" + end + def public? !private_flag end diff --git a/app/views/commits/_commits.html.haml b/app/views/commits/_commits.html.haml index f47252a..e6c0f22 100644 --- a/app/views/commits/_commits.html.haml +++ b/app/views/commits/_commits.html.haml @@ -9,7 +9,7 @@ %data.commit-button = truncate(commit.id.to_s, :length => 16) %i - %data.commit-browse{ :onclick => "location.href='#{tree_project_path(@project, :commit_id => commit.id)}';return false;"} + %data.commit-browse{ :onclick => "location.href='#{tree_project_ref_path(@project, commit.id)}';return false;"} Browse Code - if commit.author_email = image_tag gravatar_icon(commit.author_email), :class => "left", :width => 40, :style => "padding-right:5px;" diff --git a/app/views/commits/_diff.html.haml b/app/views/commits/_diff.html.haml index e385d9d..4bf0e06 100644 --- a/app/views/commits/_diff.html.haml +++ b/app/views/commits/_diff.html.haml @@ -9,7 +9,7 @@ - if diff.deleted_file %strong{:id => "#{diff.b_path}"}= diff.a_path - else - = link_to tree_file_project_path(@project, @commit.id, diff.b_path) do + = link_to tree_file_project_ref_path(@project, @commit.id, diff.b_path) do %strong{:id => "#{diff.b_path}"}= diff.b_path %br/ .diff_file_content diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index b42b23d..93a8283 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -18,7 +18,7 @@ = preserve @commit.safe_message %tr %td Tree - %td= link_to 'Browse Code', tree_project_path(@project, :commit_id => @commit.id) + %td= link_to 'Browse Code', tree_project_ref_path(@project, @commit.id) .clear %br diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index 7c5a162..6407da1 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -5,7 +5,7 @@ GitLab #{" - #{@project.name}" if @project && !@project.new_record?} = stylesheet_link_tag "application" = javascript_include_tag "application" - - if current_page?(tree_project_path(@project)) || current_page?(project_commits_path(@project)) + - if current_page?(tree_project_ref_path(@project, @project.root_ref)) || current_page?(project_commits_path(@project)) = 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}") - if request.path == project_issues_path(@project) = auto_discovery_link_tag(:atom, project_issues_url(@project, :atom, :private_token => current_user.private_token), :title => "#{@project.name} issues") @@ -24,7 +24,7 @@ %input.git-url.text{:id => "", :name => "", :readonly => "", :type => "text", :value => @project.url_to_repo, :class => "one_click_select"} %aside = link_to "Activities", project_path(@project), :class => current_page?(:controller => "projects", :action => "show", :id => @project) ? "current" : nil - = link_to "Tree", tree_project_path(@project), :class => current_page?(:controller => "projects", :action => "tree", :id => @project) ? "current" : nil + = 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 = link_to "Commits", project_commits_path(@project), :class => current_page?(:controller => "commits", :action => "index", :project_id => @project) ? "current" : nil = link_to "Network graph", graph_project_path(@project), :class => current_page?(:controller => "projects", :action => "graph", :id => @project) ? "current" : nil = link_to team_project_path(@project), :class => (current_page?(:controller => "projects", :action => "team", :id => @project) || controller.controller_name == "team_members") ? "current" : nil do diff --git a/app/views/projects/_tree.html.haml b/app/views/projects/_tree.html.haml deleted file mode 100644 index b7d4b32..0000000 --- a/app/views/projects/_tree.html.haml +++ /dev/null @@ -1,60 +0,0 @@ --#%a.right.button{:href => "#"} Download --#-if can? current_user, :admin_project, @project - %a.right.button.blue{:href => "#"} EDIT -#tree-breadcrumbs - %h2.icon - %span - %d - = link_to tree_project_path(@project, :path => nil, :commit_id => @commit.try(:id)), :remote => true do - = @project.name - - if params[:path] - - part_path = "" - - params[:path].split("\/").each do |part| - - part_path = File.join(part_path, part) unless part_path.empty? - - if part_path.empty? - - part_path = part - \/ - = 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 - - .right= render :partial => "projects/refs", :locals => { :destination => tree_project_path(@project) } -.clear - -#tree-content-holder - - if tree.is_a?(Grit::Blob) - = render :partial => "projects/tree_file", :locals => { :name => tree.name, :content => tree.data, :file => tree } - - else - - contents = tree.contents - %table#tree-slider.round-borders - %thead - %th Name - %th Last Update - %th - Last commit - = link_to "history", project_commits_path(@project, :path => params[:path], :branch => params[:branch],:tag => params[:tag]), :class => "right" - - if params[:path] - - file = File.join(params[:path], "..") - %tr{ :class => "tree-item", :url => tree_file_project_path(@project, @commit.id, file) } - %td.tree-item-file-name - = image_tag "dir.png" - = link_to "..", tree_file_project_path(@project, @commit.id, file, :branch => @branch, :tag => @tag), :remote => :true - %td - %td - - - contents.select{ |i| i.is_a?(Grit::Tree)}.each do |content| - = render :partial => "projects/tree_item", :locals => { :content => content } - - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| - = render :partial => "projects/tree_item", :locals => { :content => content } - -:javascript - $(function(){ - $('select#branch').selectmenu({style:'popup', width:200}); - $('select#tag').selectmenu({style:'popup', width:200}); - }); - -- if params[:path] && request.xhr? - :javascript - $(window).unbind('popstate'); - $(window).bind('popstate', function() { - if(location.pathname.search("tree") != -1) { - $.ajax({type: "GET", url: location.pathname, dataType: "script"})} - else { location.href = location.pathname;}}); diff --git a/app/views/projects/_tree_file.html.haml b/app/views/projects/_tree_file.html.haml deleted file mode 100644 index b5b1821..0000000 --- a/app/views/projects/_tree_file.html.haml +++ /dev/null @@ -1,19 +0,0 @@ -:css -.view_file - .view_file_header - %strong - = name - = link_to "raw", blob_project_path(@project, :commit_id => @commit.id, :path => params[:path] ), :class => "right", :target => "_blank" - = link_to "history", project_commits_path(@project, :path => params[:path], :branch => params[:branch], :tag => params[:tag] ), :class => "right", :style => "margin-right:10px;" - %br/ - - if file.text? - .view_file_content - :erb - <%= raw file.colorize %> - - elsif file.image? - .view_file_content_image - %img{ :src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} - - else - %p - %center No preview for this file type - diff --git a/app/views/projects/_tree_item.html.haml b/app/views/projects/_tree_item.html.haml deleted file mode 100644 index 1637202..0000000 --- a/app/views/projects/_tree_item.html.haml +++ /dev/null @@ -1,18 +0,0 @@ -- file = params[:path] ? File.join(params[:path], content.name) : content.name -- content_commit = @project.repo.log(@commit.id, file, :max_count => 1).last -- return unless content_commit -%tr{ :class => "tree-item", :url => tree_file_project_path(@project, @commit.id, file) } - %td.tree-item-file-name - - if content.is_a?(Grit::Blob) - = image_tag "txt.png" - - else - = image_tag "dir.png" - = link_to truncate(content.name, :length => 40), tree_file_project_path(@project, @commit.id, file, :branch => @branch, :tag => @tag), :remote => :true - %td - = time_ago_in_words(content_commit.committed_date) - ago - %td.commit - = link_to truncate(content_commit.safe_message, :length => 40), project_commit_path(@project, content_commit), :class => "tree-commit-link" - - tm = @project.team_member_by_name_or_email(content_commit.author_email, content_commit.author_name) - - if tm - = link_to "[#{tm.user_name}]", project_team_member_path(@project, tm) diff --git a/app/views/projects/tree.html.erb b/app/views/projects/tree.html.erb deleted file mode 100644 index c29ed2f..0000000 --- a/app/views/projects/tree.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -