Commit fc34fc86c6ac5bfd2312cdd404938cabf4c468d2

Authored by gitlabhq
1 parent 912a383d

branch/tag memorization

app/controllers/application_controller.rb
@@ -41,4 +41,13 @@ class ApplicationController < ActionController::Base @@ -41,4 +41,13 @@ class ApplicationController < ActionController::Base
41 super 41 super
42 end 42 end
43 end 43 end
  44 +
  45 + def refs_from_cookie
  46 + # branch is high priority so we should reset
  47 + # it if tag selected
  48 + cookies[:branch] = nil if params[:tag]
  49 +
  50 + params[:branch] ||= cookies[:branch]
  51 + params[:tag] ||= cookies[:tag]
  52 + end
44 end 53 end
app/controllers/commits_controller.rb
@@ -8,6 +8,7 @@ class CommitsController < ApplicationController @@ -8,6 +8,7 @@ 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 @repo = project.repo 12 @repo = project.repo
12 @branch = if !params[:branch].blank? 13 @branch = if !params[:branch].blank?
13 params[:branch] 14 params[:branch]
app/controllers/projects_controller.rb
@@ -16,6 +16,7 @@ class ProjectsController < ApplicationController @@ -16,6 +16,7 @@ class ProjectsController < ApplicationController
16 end 16 end
17 17
18 def show 18 def show
  19 + refs_from_cookie
19 @repo = project.repo 20 @repo = project.repo
20 @commit = @repo.commits.first 21 @commit = @repo.commits.first
21 @tree = @commit.tree 22 @tree = @commit.tree
@@ -32,6 +33,7 @@ class ProjectsController < ApplicationController @@ -32,6 +33,7 @@ class ProjectsController < ApplicationController
32 end 33 end
33 34
34 def tree 35 def tree
  36 + refs_from_cookie
35 @repo = project.repo 37 @repo = project.repo
36 @branch = if !params[:branch].blank? 38 @branch = if !params[:branch].blank?
37 params[:branch] 39 params[:branch]
app/views/commits/index.html.haml
@@ -13,3 +13,10 @@ @@ -13,3 +13,10 @@
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 +
  18 +:javascript
  19 + $(function(){
  20 + $.cookie('branch', '#{params[:branch]}', { expires: 1 });
  21 + $.cookie('tag', '#{params[:tag]}', { expires: 1 });
  22 + });
app/views/projects/_tree.html.haml
@@ -45,6 +45,13 @@ @@ -45,6 +45,13 @@
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 +:javascript
  50 + $(function(){
  51 + $.cookie('branch', '#{params[:branch]}', { expires: 1 });
  52 + $.cookie('tag', '#{params[:tag]}', { expires: 1 });
  53 + });
  54 +
48 :javascript 55 :javascript
49 $(function(){ 56 $(function(){
50 $('select#branch').selectmenu({style:'popup', width:200}); 57 $('select#branch').selectmenu({style:'popup', width:200});