Commit c1a70c3f authored by azul's avatar azul

cleanup: unused controller url identifier helpers

parent 43238a2d
......@@ -13,9 +13,6 @@ module Common::Application::UrlIdentifiers
helper_method :action?
helper_method :controller?
helper_method :page_controller?
helper_method :id?
helper_method :active_url?
helper_method :url_active?
end
end
......@@ -65,80 +62,8 @@ module Common::Application::UrlIdentifiers
controller?('me/pages', 'groups/pages', 'people/pages', 'pages/') or controller.is_a?(Page::BaseController) or controller.is_a?(Page::CreateController)
end
# returns true if params[:id] matches the id passed in
# the arguments may include the id in the form of an integer,
# string, or active record object.
def id?(*ids)
for obj in ids
if obj.is_a?(ActiveRecord::Base)
return true if obj.id == params[:id].to_i
elsif obj.is_a?(Integer)
return true if obj == params[:id].to_i
elsif obj.is_a?(String)
return true if obj == params[:id].to_s
elsif obj.is_a?(Symbol)
return true if obj.to_s == params[:id].to_s
end
end
false
end
##
## ACTIVE URL IDENTIFICATION
##
# returns true if the current params matches url_hash
def url_active?(url_hash)
return false unless url_hash.is_a? Hash
url_hash[:action] ||= 'index'
selected = true
url_hash.each do |key, value|
selected = compare_param(params[key], value)
break unless selected
end
selected
end
# here is another method to do the same thing. it is a bad sign when we start
# to get duplicated efforts like this. I am not sure which one is better.
# i moved both of them to this file to make it clear they are similar. -elijah
def active_url?(url_path)
if url_path.is_a?(String) or url_path.is_a?(Hash)
url_for(url_path) =~ /^#{Regexp.escape(request.path)}$/i
elsif url_path.is_a?(Array)
!url_path.select do |path|
url_for(path) =~ /^#{Regexp.escape(request.path)}$/i ? true : false
end.empty?
else
false
end
end
private
def compare_param(a, b)
a = a.to_param
b = b.to_param
if b.empty?
true
elsif a.empty?
false
elsif a == b
true
elsif a.is_a?(Array) or b.is_a?(Array)
a = a.to_a.sort
b = b.to_a.sort
b == a
elsif a.sub(/^\//, '') == b.sub(/^\//, '')
true # a controller of '/groups' should match 'groups'
else
false
end
end
def controller_string
@controller_string ||= params[:controller].to_s.gsub(/^\//, '')
end
......
......@@ -32,10 +32,8 @@ module Common::Ui::LinkHelper
##
# just like link_to, but sets the <a> tag to have class 'active'
# if last argument is true or if the url is in the form of a hash
# and the current params match this hash.
# if active is true
def link_to_active(link_label, url_hash, active = nil, html_options = {})
active ||= url_active?(url_hash)
selected_class = active ? 'active' : ''
classes = [selected_class, html_options[:class]]
html_options[:class] = classes.join(' ')
......
......@@ -10,9 +10,9 @@
- f.tab do |t|
- t.label :survey_my_response_tab.t
- t.url response_path(my_response, page_id: @page)
- t.selected controller?(:survey_page_response) && action?(:show) && id?(my_response.id)
- t.selected controller?(:survey_page_response) && @response.user == current_user
- if may_view_survey_response?
- f.tab do |t|
- t.label :survey_list_all_tab.t
- t.url responses_path(page_id: @page)
- t.selected controller?(:survey_page_response) && action?(:index, :show) && !id?(my_response)
- t.selected controller?(:survey_page_response) && @response.try.user != current_user
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment