OSDN Git Service

branch/tag memorization
authorgitlabhq <m@gitlabhq.com>
Fri, 14 Oct 2011 15:08:25 +0000 (18:08 +0300)
committergitlabhq <m@gitlabhq.com>
Fri, 14 Oct 2011 15:08:25 +0000 (18:08 +0300)
app/controllers/application_controller.rb
app/controllers/commits_controller.rb
app/controllers/projects_controller.rb
app/views/commits/index.html.haml
app/views/projects/_tree.html.haml

index 829126f..783648f 100644 (file)
@@ -41,4 +41,13 @@ class ApplicationController < ActionController::Base
       super
     end
   end
+
+  def refs_from_cookie
+    # branch is high priority so we should reset
+    # it if tag selected
+    cookies[:branch] = nil if params[:tag]
+
+    params[:branch] ||= cookies[:branch]
+    params[:tag] ||= cookies[:tag]
+  end
 end
index d7daec1..61a1a54 100644 (file)
@@ -8,6 +8,7 @@ class CommitsController < ApplicationController
   before_filter :authorize_read_project!
 
   def index
+    refs_from_cookie
     @repo = project.repo
     @branch = if !params[:branch].blank?
                 params[:branch]
index 080a6ee..f9f4226 100644 (file)
@@ -16,6 +16,7 @@ class ProjectsController < ApplicationController
   end
 
   def show
+    refs_from_cookie
     @repo = project.repo
     @commit = @repo.commits.first
     @tree = @commit.tree
@@ -32,6 +33,7 @@ class ProjectsController < ApplicationController
   end
 
   def tree
+    refs_from_cookie
     @repo = project.repo
     @branch = if !params[:branch].blank?
                 params[:branch]
index 0e231e4..f7e8b08 100644 (file)
     %h3{:style => "color:#555"} /#{params[:path]}
   %div{:id => dom_id(@project)}
     = render "commits"
+
+
+:javascript
+  $(function(){
+    $.cookie('branch', '#{params[:branch]}', { expires: 1 });
+    $.cookie('tag', '#{params[:tag]}', { expires: 1 });
+  });
index af3a209..d84599a 100644 (file)
       - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content|
         = render :partial => "projects/tree_item", :locals => { :content => content }
 
+
+:javascript
+  $(function(){
+    $.cookie('branch', '#{params[:branch]}', { expires: 1 });
+    $.cookie('tag', '#{params[:tag]}', { expires: 1 });
+  });
+
 :javascript
   $(function(){
     $('select#branch').selectmenu({style:'popup', width:200});