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 | 42 | end |
43 | 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 | 63 | end |
56 | 64 | end | ... | ... |
app/controllers/commits_controller.rb
... | ... | @@ -8,20 +8,14 @@ class CommitsController < ApplicationController |
8 | 8 | before_filter :authorize_read_project! |
9 | 9 | |
10 | 10 | def index |
11 | - refs_from_cookie | |
11 | + load_refs # load @branch, @tag & @ref | |
12 | + | |
12 | 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 | 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 | 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 | 19 | end |
26 | 20 | |
27 | 21 | respond_to do |format| | ... | ... |
app/controllers/projects_controller.rb
... | ... | @@ -16,7 +16,6 @@ class ProjectsController < ApplicationController |
16 | 16 | end |
17 | 17 | |
18 | 18 | def show |
19 | - refs_from_cookie | |
20 | 19 | @repo = project.repo |
21 | 20 | @commit = @repo.commits.first |
22 | 21 | @tree = @commit.tree |
... | ... | @@ -33,34 +32,30 @@ class ProjectsController < ApplicationController |
33 | 32 | end |
34 | 33 | |
35 | 34 | def tree |
36 | - refs_from_cookie | |
35 | + load_refs # load @branch, @tag & @ref | |
36 | + | |
37 | 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 | 39 | if params[:commit_id] |
47 | 40 | @commit = @repo.commits(params[:commit_id]).first |
48 | 41 | else |
49 | - @commit = @repo.commits(@branch || "master").first | |
42 | + @commit = @repo.commits(@ref || "master").first | |
50 | 43 | end |
44 | + | |
51 | 45 | @tree = @commit.tree |
52 | 46 | @tree = @tree / params[:path] if params[:path] |
53 | 47 | |
54 | 48 | respond_to do |format| |
55 | 49 | format.html # show.html.erb |
56 | 50 | format.js do |
57 | - # temp solution | |
51 | + # diasbale cache to allow back button works | |
58 | 52 | response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" |
59 | 53 | response.headers["Pragma"] = "no-cache" |
60 | 54 | response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" |
61 | 55 | end |
62 | - format.json { render json: project } | |
63 | 56 | end |
57 | + rescue | |
58 | + return render_404 | |
64 | 59 | end |
65 | 60 | |
66 | 61 | def blob |
... | ... | @@ -73,6 +68,8 @@ class ProjectsController < ApplicationController |
73 | 68 | else |
74 | 69 | head(404) |
75 | 70 | end |
71 | + rescue | |
72 | + return render_404 | |
76 | 73 | end |
77 | 74 | |
78 | 75 | def new | ... | ... |
app/helpers/projects_helper.rb
... | ... | @@ -3,12 +3,4 @@ module ProjectsHelper |
3 | 3 | cookies["project_view"] ||= "tile" |
4 | 4 | cookies["project_view"] == type ? nil : "display:none" |
5 | 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 | 6 | end | ... | ... |
app/views/commits/index.html.haml
... | ... | @@ -6,12 +6,10 @@ |
6 | 6 | |
7 | 7 | .left.prepend-1 |
8 | 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 | 10 | = text_field_tag "ssh", @project.url_to_repo, :class => ["ssh_project_url", "one_click_select"] |
11 | 11 | .clear |
12 | 12 | - if params[:path] |
13 | 13 | %h3{:style => "color:#555"} /#{params[:path]} |
14 | 14 | %div{:id => dom_id(@project)} |
15 | 15 | = render "commits" |
16 | - | |
17 | -- remember_refs | ... | ... |
app/views/projects/_tree.html.haml
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | |
6 | 6 | .left.prepend-1 |
7 | 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 | 9 | = text_field_tag "ssh", @project.url_to_repo, :class => ["ssh_project_url","one_click_select"] |
10 | 10 | .clear |
11 | 11 | |
... | ... | @@ -18,7 +18,7 @@ |
18 | 18 | - if part_path.empty? |
19 | 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 | 22 | #tree-content-holder |
23 | 23 | - if tree.is_a?(Grit::Blob) |
24 | 24 | = render :partial => "projects/tree_file", :locals => { :name => tree.name, :content => tree.data, :file => tree } |
... | ... | @@ -36,7 +36,7 @@ |
36 | 36 | %tr{ :class => "tree-item", :url => tree_file_project_path(@project, @commit.id, file) } |
37 | 37 | %td.tree-item-file-name |
38 | 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 | 40 | %td |
41 | 41 | %td |
42 | 42 | |
... | ... | @@ -45,9 +45,6 @@ |
45 | 45 | - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| |
46 | 46 | = render :partial => "projects/tree_item", :locals => { :content => content } |
47 | 47 | |
48 | - | |
49 | -- remember_refs | |
50 | - | |
51 | 48 | :javascript |
52 | 49 | $(function(){ |
53 | 50 | $('select#branch').selectmenu({style:'popup', width:200}); | ... | ... |
app/views/projects/_tree_item.html.haml
... | ... | @@ -7,7 +7,7 @@ |
7 | 7 | = image_tag "txt.png" |
8 | 8 | - else |
9 | 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 | 11 | %td |
12 | 12 | = time_ago_in_words(content_commit.committed_date) |
13 | 13 | ago | ... | ... |