Skip to content

Commit

Permalink
Refactor by_editor condition
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Dec 19, 2024
1 parent f480bf3 commit 4d7d470
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
15 changes: 1 addition & 14 deletions app/classes/query/location_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def initialize_flavor
add_ids_condition("locations")
add_owner_and_time_stamp_conditions("locations")
add_by_user_condition("locations")
add_by_editor_condition
add_by_editor_condition(:location)
end
add_bounding_box_conditions_for_locations
add_pattern_condition
Expand All @@ -39,19 +39,6 @@ def initialize_flavor
super
end

def add_by_editor_condition
return unless params[:by_editor]

user = find_cached_parameter_instance(User, :by_editor)
@title_tag = :query_title_by_editor.t(type: :location,
user: user.legal_name)
@title_args[:user] = user.legal_name
version_table = :location_versions
add_join(version_table)
where << "#{version_table}.user_id = '#{user.id}'"
where << "locations.user_id != '#{user.id}'"
end

def add_pattern_condition
return if params[:pattern].blank?

Expand Down
13 changes: 13 additions & 0 deletions app/classes/query/modules/conditions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ def add_by_user_condition(table)
where << "#{table}.user_id = '#{user.id}'"
end

def add_by_editor_condition(type)
return unless params[:by_editor]

user = find_cached_parameter_instance(User, :by_editor)
@title_tag = :query_title_by_editor
@title_args[:user] = user.legal_name
@title_args[:type] = type
version_table = :"#{type}_versions"
add_join(version_table)
where << "#{version_table}.user_id = '#{user.id}'"
where << "#{type}s.user_id != '#{user.id}'"
end

def add_pattern_condition
return if params[:pattern].blank?

Expand Down
15 changes: 1 addition & 14 deletions app/classes/query/name_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def initialize_flavor
add_ids_condition("names")
add_owner_and_time_stamp_conditions("names")
add_by_user_condition("names")
add_by_editor_condition
add_by_editor_condition(:name)
initialize_comments_and_notes_parameters
initialize_name_parameters_for_name_queries
add_pattern_condition
Expand All @@ -71,19 +71,6 @@ def initialize_flavor
super
end

def add_by_editor_condition
return unless params[:by_editor]

user = find_cached_parameter_instance(User, :by_editor)
@title_tag = :query_title_by_editor.t(type: :name,
user: user.legal_name)
@title_args[:user] = user.legal_name
version_table = :name_versions
add_join(version_table)
where << "#{version_table}.user_id = '#{user.id}'"
where << "names.user_id != '#{user.id}'"
end

def initialize_comments_and_notes_parameters
add_boolean_condition(
"LENGTH(COALESCE(names.notes,'')) > 0",
Expand Down

0 comments on commit 4d7d470

Please sign in to comment.