Commit 153f6cd86bff0f78abbee07feec6832b73535298
1 parent
2d577cae
Exists in
master
and in
4 other branches
refactoring + remove unnecessary feature
Showing
7 changed files
with
36 additions
and
50 deletions
Show diff stats
app/controllers/application_controller.rb
| @@ -42,15 +42,23 @@ class ApplicationController < ActionController::Base | @@ -42,15 +42,23 @@ class ApplicationController < ActionController::Base | ||
| 42 | end | 42 | end |
| 43 | end | 43 | end |
| 44 | 44 | ||
| 45 | - def refs_from_cookie | ||
| 46 | - if @project && session[:ui] && | ||
| 47 | - session[:ui][@project.id] | ||
| 48 | - project_session = session[:ui][@project.id] | ||
| 49 | - project_session[:branch] = nil if params[:tag] | ||
| 50 | - params[:branch] ||= project_session[:branch] | ||
| 51 | - params[:tag] ||= project_session[:tag] | ||
| 52 | - end | ||
| 53 | - rescue | ||
| 54 | - session[:ui] = nil | 45 | + def load_refs |
| 46 | + @branch = unless params[:branch].blank? | ||
| 47 | + params[:branch] | ||
| 48 | + else | ||
| 49 | + nil | ||
| 50 | + end | ||
| 51 | + | ||
| 52 | + @tag = unless params[:tag].blank? | ||
| 53 | + params[:tag] | ||
| 54 | + else | ||
| 55 | + nil | ||
| 56 | + end | ||
| 57 | + | ||
| 58 | + @ref = @branch || @tag || "master" | ||
| 59 | + end | ||
| 60 | + | ||
| 61 | + def render_404 | ||
| 62 | + render :file => File.join(Rails.root, "public", "404"), :layout => false, :status => "404" | ||
| 55 | end | 63 | end |
| 56 | end | 64 | end |
app/controllers/commits_controller.rb
| @@ -8,20 +8,14 @@ class CommitsController < ApplicationController | @@ -8,20 +8,14 @@ class CommitsController < ApplicationController | ||
| 8 | before_filter :authorize_read_project! | 8 | before_filter :authorize_read_project! |
| 9 | 9 | ||
| 10 | def index | 10 | def index |
| 11 | - refs_from_cookie | 11 | + load_refs # load @branch, @tag & @ref |
| 12 | + | ||
| 12 | @repo = project.repo | 13 | @repo = project.repo |
| 13 | - @branch = if !params[:branch].blank? | ||
| 14 | - params[:branch] | ||
| 15 | - elsif !params[:tag].blank? | ||
| 16 | - params[:tag] | ||
| 17 | - else | ||
| 18 | - "master" | ||
| 19 | - end | ||
| 20 | 14 | ||
| 21 | if params[:path] | 15 | if params[:path] |
| 22 | - @commits = @repo.log(@branch, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0) | 16 | + @commits = @repo.log(@ref, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0) |
| 23 | else | 17 | else |
| 24 | - @commits = @repo.commits(@branch, params[:limit] || 100, params[:offset] || 0) | 18 | + @commits = @repo.commits(@ref, params[:limit] || 100, params[:offset] || 0) |
| 25 | end | 19 | end |
| 26 | 20 | ||
| 27 | respond_to do |format| | 21 | respond_to do |format| |
app/controllers/projects_controller.rb
| @@ -16,7 +16,6 @@ class ProjectsController < ApplicationController | @@ -16,7 +16,6 @@ class ProjectsController < ApplicationController | ||
| 16 | end | 16 | end |
| 17 | 17 | ||
| 18 | def show | 18 | def show |
| 19 | - refs_from_cookie | ||
| 20 | @repo = project.repo | 19 | @repo = project.repo |
| 21 | @commit = @repo.commits.first | 20 | @commit = @repo.commits.first |
| 22 | @tree = @commit.tree | 21 | @tree = @commit.tree |
| @@ -33,34 +32,30 @@ class ProjectsController < ApplicationController | @@ -33,34 +32,30 @@ class ProjectsController < ApplicationController | ||
| 33 | end | 32 | end |
| 34 | 33 | ||
| 35 | def tree | 34 | def tree |
| 36 | - refs_from_cookie | 35 | + load_refs # load @branch, @tag & @ref |
| 36 | + | ||
| 37 | @repo = project.repo | 37 | @repo = project.repo |
| 38 | - @branch = if !params[:branch].blank? | ||
| 39 | - params[:branch] | ||
| 40 | - elsif !params[:tag].blank? | ||
| 41 | - params[:tag] | ||
| 42 | - else | ||
| 43 | - "master" | ||
| 44 | - end | ||
| 45 | 38 | ||
| 46 | if params[:commit_id] | 39 | if params[:commit_id] |
| 47 | @commit = @repo.commits(params[:commit_id]).first | 40 | @commit = @repo.commits(params[:commit_id]).first |
| 48 | else | 41 | else |
| 49 | - @commit = @repo.commits(@branch || "master").first | 42 | + @commit = @repo.commits(@ref || "master").first |
| 50 | end | 43 | end |
| 44 | + | ||
| 51 | @tree = @commit.tree | 45 | @tree = @commit.tree |
| 52 | @tree = @tree / params[:path] if params[:path] | 46 | @tree = @tree / params[:path] if params[:path] |
| 53 | 47 | ||
| 54 | respond_to do |format| | 48 | respond_to do |format| |
| 55 | format.html # show.html.erb | 49 | format.html # show.html.erb |
| 56 | format.js do | 50 | format.js do |
| 57 | - # temp solution | 51 | + # diasbale cache to allow back button works |
| 58 | response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" | 52 | response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" |
| 59 | response.headers["Pragma"] = "no-cache" | 53 | response.headers["Pragma"] = "no-cache" |
| 60 | response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" | 54 | response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" |
| 61 | end | 55 | end |
| 62 | - format.json { render json: project } | ||
| 63 | end | 56 | end |
| 57 | + rescue | ||
| 58 | + return render_404 | ||
| 64 | end | 59 | end |
| 65 | 60 | ||
| 66 | def blob | 61 | def blob |
| @@ -73,6 +68,8 @@ class ProjectsController < ApplicationController | @@ -73,6 +68,8 @@ class ProjectsController < ApplicationController | ||
| 73 | else | 68 | else |
| 74 | head(404) | 69 | head(404) |
| 75 | end | 70 | end |
| 71 | + rescue | ||
| 72 | + return render_404 | ||
| 76 | end | 73 | end |
| 77 | 74 | ||
| 78 | def new | 75 | def new |
app/helpers/projects_helper.rb
| @@ -3,12 +3,4 @@ module ProjectsHelper | @@ -3,12 +3,4 @@ module ProjectsHelper | ||
| 3 | cookies["project_view"] ||= "tile" | 3 | cookies["project_view"] ||= "tile" |
| 4 | cookies["project_view"] == type ? nil : "display:none" | 4 | cookies["project_view"] == type ? nil : "display:none" |
| 5 | end | 5 | end |
| 6 | - | ||
| 7 | - def remember_refs | ||
| 8 | - session[:ui] ||= {} | ||
| 9 | - session[:ui][@project.id] = { | ||
| 10 | - :branch => params[:branch], | ||
| 11 | - :tag => params[:tag] | ||
| 12 | - } | ||
| 13 | - end | ||
| 14 | end | 6 | end |
app/views/commits/index.html.haml
| @@ -6,12 +6,10 @@ | @@ -6,12 +6,10 @@ | ||
| 6 | | 6 | |
| 7 | .left.prepend-1 | 7 | .left.prepend-1 |
| 8 | = form_tag project_commits_path(@project), :method => :get do | 8 | = form_tag project_commits_path(@project), :method => :get do |
| 9 | - = select_tag "tag", options_for_select(@project.tags, @branch), :onchange => "this.form.submit();", :class => "", :prompt => "Tags" | 9 | + = select_tag "tag", options_for_select(@project.tags, @tag), :onchange => "this.form.submit();", :class => "", :prompt => "Tags" |
| 10 | = text_field_tag "ssh", @project.url_to_repo, :class => ["ssh_project_url", "one_click_select"] | 10 | = text_field_tag "ssh", @project.url_to_repo, :class => ["ssh_project_url", "one_click_select"] |
| 11 | .clear | 11 | .clear |
| 12 | - if params[:path] | 12 | - if params[:path] |
| 13 | %h3{:style => "color:#555"} /#{params[:path]} | 13 | %h3{:style => "color:#555"} /#{params[:path]} |
| 14 | %div{:id => dom_id(@project)} | 14 | %div{:id => dom_id(@project)} |
| 15 | = render "commits" | 15 | = render "commits" |
| 16 | - | ||
| 17 | -- remember_refs |
app/views/projects/_tree.html.haml
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | | 5 | |
| 6 | .left.prepend-1 | 6 | .left.prepend-1 |
| 7 | = form_tag tree_project_path(@project), :method => :get do | 7 | = form_tag tree_project_path(@project), :method => :get do |
| 8 | - = select_tag "tag", options_for_select(@project.tags, @branch), :onchange => "this.form.submit();", :class => "", :prompt => "Tags" | 8 | + = select_tag "tag", options_for_select(@project.tags, @tag), :onchange => "this.form.submit();", :class => "", :prompt => "Tags" |
| 9 | = text_field_tag "ssh", @project.url_to_repo, :class => ["ssh_project_url","one_click_select"] | 9 | = text_field_tag "ssh", @project.url_to_repo, :class => ["ssh_project_url","one_click_select"] |
| 10 | .clear | 10 | .clear |
| 11 | 11 | ||
| @@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
| 18 | - if part_path.empty? | 18 | - if part_path.empty? |
| 19 | - part_path = part | 19 | - part_path = part |
| 20 | \/ | 20 | \/ |
| 21 | - = link_to truncate(part, :length => 40), tree_file_project_path(@project, :path => part_path, :commit_id => @commit.try(:id)), :remote => :true | 21 | + = 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 |
| 22 | #tree-content-holder | 22 | #tree-content-holder |
| 23 | - if tree.is_a?(Grit::Blob) | 23 | - if tree.is_a?(Grit::Blob) |
| 24 | = render :partial => "projects/tree_file", :locals => { :name => tree.name, :content => tree.data, :file => tree } | 24 | = render :partial => "projects/tree_file", :locals => { :name => tree.name, :content => tree.data, :file => tree } |
| @@ -36,7 +36,7 @@ | @@ -36,7 +36,7 @@ | ||
| 36 | %tr{ :class => "tree-item", :url => tree_file_project_path(@project, @commit.id, file) } | 36 | %tr{ :class => "tree-item", :url => tree_file_project_path(@project, @commit.id, file) } |
| 37 | %td.tree-item-file-name | 37 | %td.tree-item-file-name |
| 38 | = image_tag "dir.png" | 38 | = image_tag "dir.png" |
| 39 | - = link_to "..", tree_file_project_path(@project, @commit.id, file), :remote => :true | 39 | + = link_to "..", tree_file_project_path(@project, @commit.id, file, :branch => @branch, :tag => @tag), :remote => :true |
| 40 | %td | 40 | %td |
| 41 | %td | 41 | %td |
| 42 | 42 | ||
| @@ -45,9 +45,6 @@ | @@ -45,9 +45,6 @@ | ||
| 45 | - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| | 45 | - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| |
| 46 | = render :partial => "projects/tree_item", :locals => { :content => content } | 46 | = render :partial => "projects/tree_item", :locals => { :content => content } |
| 47 | 47 | ||
| 48 | - | ||
| 49 | -- remember_refs | ||
| 50 | - | ||
| 51 | :javascript | 48 | :javascript |
| 52 | $(function(){ | 49 | $(function(){ |
| 53 | $('select#branch').selectmenu({style:'popup', width:200}); | 50 | $('select#branch').selectmenu({style:'popup', width:200}); |
app/views/projects/_tree_item.html.haml
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | = image_tag "txt.png" | 7 | = image_tag "txt.png" |
| 8 | - else | 8 | - else |
| 9 | = image_tag "dir.png" | 9 | = image_tag "dir.png" |
| 10 | - = link_to truncate(content.name, :length => 40), tree_file_project_path(@project, @commit.id, file), :remote => :true | 10 | + = link_to truncate(content.name, :length => 40), tree_file_project_path(@project, @commit.id, file, :branch => @branch, :tag => @tag), :remote => :true |
| 11 | %td | 11 | %td |
| 12 | = time_ago_in_words(content_commit.committed_date) | 12 | = time_ago_in_words(content_commit.committed_date) |
| 13 | ago | 13 | ago |