From fc34fc86c6ac5bfd2312cdd404938cabf4c468d2 Mon Sep 17 00:00:00 2001 From: gitlabhq Date: Fri, 14 Oct 2011 18:08:25 +0300 Subject: [PATCH] branch/tag memorization --- app/controllers/application_controller.rb | 9 +++++++++ app/controllers/commits_controller.rb | 1 + app/controllers/projects_controller.rb | 2 ++ app/views/commits/index.html.haml | 7 +++++++ app/views/projects/_tree.html.haml | 7 +++++++ 5 files changed, 26 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 829126fe..783648f7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index d7daec13..61a1a54f 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -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] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 080a6ee6..f9f4226f 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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] diff --git a/app/views/commits/index.html.haml b/app/views/commits/index.html.haml index 0e231e4e..f7e8b087 100644 --- a/app/views/commits/index.html.haml +++ b/app/views/commits/index.html.haml @@ -13,3 +13,10 @@ %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 }); + }); diff --git a/app/views/projects/_tree.html.haml b/app/views/projects/_tree.html.haml index af3a209a..d84599ad 100644 --- a/app/views/projects/_tree.html.haml +++ b/app/views/projects/_tree.html.haml @@ -45,6 +45,13 @@ - 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});