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 41 super
42 42 end
43 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 53 end
... ...
app/controllers/commits_controller.rb
... ... @@ -8,6 +8,7 @@ class CommitsController < ApplicationController
8 8 before_filter :authorize_read_project!
9 9  
10 10 def index
  11 + refs_from_cookie
11 12 @repo = project.repo
12 13 @branch = if !params[:branch].blank?
13 14 params[:branch]
... ...
app/controllers/projects_controller.rb
... ... @@ -16,6 +16,7 @@ class ProjectsController < ApplicationController
16 16 end
17 17  
18 18 def show
  19 + refs_from_cookie
19 20 @repo = project.repo
20 21 @commit = @repo.commits.first
21 22 @tree = @commit.tree
... ... @@ -32,6 +33,7 @@ class ProjectsController < ApplicationController
32 33 end
33 34  
34 35 def tree
  36 + refs_from_cookie
35 37 @repo = project.repo
36 38 @branch = if !params[:branch].blank?
37 39 params[:branch]
... ...
app/views/commits/index.html.haml
... ... @@ -13,3 +13,10 @@
13 13 %h3{:style => "color:#555"} /#{params[:path]}
14 14 %div{:id => dom_id(@project)}
15 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 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 +:javascript
  50 + $(function(){
  51 + $.cookie('branch', '#{params[:branch]}', { expires: 1 });
  52 + $.cookie('tag', '#{params[:tag]}', { expires: 1 });
  53 + });
  54 +
48 55 :javascript
49 56 $(function(){
50 57 $('select#branch').selectmenu({style:'popup', width:200});
... ...