diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/application_controller.rb | 28 | ||||
-rw-r--r-- | app/controllers/commits_controller.rb | 14 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 21 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 8 | ||||
-rw-r--r-- | app/views/commits/index.html.haml | 4 | ||||
-rw-r--r-- | app/views/projects/_tree.html.haml | 9 | ||||
-rw-r--r-- | app/views/projects/_tree_item.html.haml | 2 |
7 files changed, 36 insertions, 50 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8d308767374..f8eb238b1d2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -42,15 +42,23 @@ class ApplicationController < ActionController::Base end end - def refs_from_cookie - if @project && session[:ui] && - session[:ui][@project.id] - project_session = session[:ui][@project.id] - project_session[:branch] = nil if params[:tag] - params[:branch] ||= project_session[:branch] - params[:tag] ||= project_session[:tag] - end - rescue - session[:ui] = nil + def load_refs + @branch = unless params[:branch].blank? + params[:branch] + else + nil + end + + @tag = unless params[:tag].blank? + params[:tag] + else + nil + end + + @ref = @branch || @tag || "master" + end + + def render_404 + render :file => File.join(Rails.root, "public", "404"), :layout => false, :status => "404" end end diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index 61a1a54f84d..fe46ddcefb7 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -8,20 +8,14 @@ class CommitsController < ApplicationController before_filter :authorize_read_project! def index - refs_from_cookie + load_refs # load @branch, @tag & @ref + @repo = project.repo - @branch = if !params[:branch].blank? - params[:branch] - elsif !params[:tag].blank? - params[:tag] - else - "master" - end if params[:path] - @commits = @repo.log(@branch, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0) + @commits = @repo.log(@ref, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0) else - @commits = @repo.commits(@branch, params[:limit] || 100, params[:offset] || 0) + @commits = @repo.commits(@ref, params[:limit] || 100, params[:offset] || 0) end respond_to do |format| diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f9f4226f6f0..09856803e78 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -16,7 +16,6 @@ class ProjectsController < ApplicationController end def show - refs_from_cookie @repo = project.repo @commit = @repo.commits.first @tree = @commit.tree @@ -33,34 +32,30 @@ class ProjectsController < ApplicationController end def tree - refs_from_cookie + load_refs # load @branch, @tag & @ref + @repo = project.repo - @branch = if !params[:branch].blank? - params[:branch] - elsif !params[:tag].blank? - params[:tag] - else - "master" - end if params[:commit_id] @commit = @repo.commits(params[:commit_id]).first else - @commit = @repo.commits(@branch || "master").first + @commit = @repo.commits(@ref || "master").first end + @tree = @commit.tree @tree = @tree / params[:path] if params[:path] respond_to do |format| format.html # show.html.erb format.js do - # temp solution + # 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 - format.json { render json: project } end + rescue + return render_404 end def blob @@ -73,6 +68,8 @@ class ProjectsController < ApplicationController else head(404) end + rescue + return render_404 end def new diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 5dae0c323b5..d570dff4639 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -3,12 +3,4 @@ module ProjectsHelper cookies["project_view"] ||= "tile" cookies["project_view"] == type ? nil : "display:none" end - - def remember_refs - session[:ui] ||= {} - session[:ui][@project.id] = { - :branch => params[:branch], - :tag => params[:tag] - } - end end diff --git a/app/views/commits/index.html.haml b/app/views/commits/index.html.haml index 2d184861e30..452e13f8bdb 100644 --- a/app/views/commits/index.html.haml +++ b/app/views/commits/index.html.haml @@ -6,12 +6,10 @@ .left.prepend-1 = form_tag project_commits_path(@project), :method => :get do - = select_tag "tag", options_for_select(@project.tags, @branch), :onchange => "this.form.submit();", :class => "", :prompt => "Tags" + = select_tag "tag", options_for_select(@project.tags, @tag), :onchange => "this.form.submit();", :class => "", :prompt => "Tags" = text_field_tag "ssh", @project.url_to_repo, :class => ["ssh_project_url", "one_click_select"] .clear - if params[:path] %h3{:style => "color:#555"} /#{params[:path]} %div{:id => dom_id(@project)} = render "commits" - -- remember_refs diff --git a/app/views/projects/_tree.html.haml b/app/views/projects/_tree.html.haml index 4d7e3d7ce70..d1903586400 100644 --- a/app/views/projects/_tree.html.haml +++ b/app/views/projects/_tree.html.haml @@ -5,7 +5,7 @@ .left.prepend-1 = form_tag tree_project_path(@project), :method => :get do - = select_tag "tag", options_for_select(@project.tags, @branch), :onchange => "this.form.submit();", :class => "", :prompt => "Tags" + = select_tag "tag", options_for_select(@project.tags, @tag), :onchange => "this.form.submit();", :class => "", :prompt => "Tags" = text_field_tag "ssh", @project.url_to_repo, :class => ["ssh_project_url","one_click_select"] .clear @@ -18,7 +18,7 @@ - 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)), :remote => :true + = 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 #tree-content-holder - if tree.is_a?(Grit::Blob) = render :partial => "projects/tree_file", :locals => { :name => tree.name, :content => tree.data, :file => tree } @@ -36,7 +36,7 @@ %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), :remote => :true + = link_to "..", tree_file_project_path(@project, @commit.id, file, :branch => @branch, :tag => @tag), :remote => :true %td %td @@ -45,9 +45,6 @@ - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| = render :partial => "projects/tree_item", :locals => { :content => content } - -- remember_refs - :javascript $(function(){ $('select#branch').selectmenu({style:'popup', width:200}); diff --git a/app/views/projects/_tree_item.html.haml b/app/views/projects/_tree_item.html.haml index 7179368a0c3..533c1484f7e 100644 --- a/app/views/projects/_tree_item.html.haml +++ b/app/views/projects/_tree_item.html.haml @@ -7,7 +7,7 @@ = image_tag "txt.png" - else = image_tag "dir.png" - = link_to truncate(content.name, :length => 40), tree_file_project_path(@project, @commit.id, file), :remote => :true + = 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 |