Skip to content

Commit

Permalink
refactor tags templete -> use format_tags_json
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermeindl committed Nov 22, 2023
1 parent 958b207 commit 6dd633c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
9 changes: 9 additions & 0 deletions app/helpers/additional_tags_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
module AdditionalTagsHelper
include ActsAsTaggableOn::TagsHelper

def format_tags_json(tags)
tags.map do |tag|
{
'id' => tag.name,
'text' => tag.name
}
end
end

def manageable_tags
AdditionalTags::Tags.sort_tag_list ActsAsTaggableOn::Tag.where({})
end
Expand Down
1 change: 0 additions & 1 deletion app/views/auto_completes/_additional_tag_list.slim

This file was deleted.

24 changes: 13 additions & 11 deletions lib/additional_tags/patches/auto_completes_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,38 @@ module AutoCompletesControllerPatch
extend ActiveSupport::Concern

included do
include AdditionalTagsHelper
include InstanceMethods
end

module InstanceMethods
def issue_tags
suggestion_order = AdditionalTags.setting(:tags_suggestion_order) || 'name'
@tags = Issue.available_tags name_like: build_search_query_term(params),
sort_by: suggestion_order,
order: (suggestion_order == 'name' ? 'ASC' : 'DESC')
tags = Issue.available_tags name_like: build_search_query_term(params),
sort_by: suggestion_order,
order: (suggestion_order == 'name' ? 'ASC' : 'DESC')

@tags = AdditionalTags::Tags.sort_tag_list @tags if suggestion_order == 'name'
tags = AdditionalTags::Tags.sort_tag_list tags if suggestion_order == 'name'

render layout: false, partial: 'additional_tag_list', locals: { unsorted: true }
render json: format_tags_json(tags)
end

def wiki_tags
@tags = WikiPage.available_tags project: nil,
name_like: build_search_query_term(params)
render layout: false, partial: 'additional_tag_list', locals: { unsorted: true }
tags = WikiPage.available_tags project: nil,
name_like: build_search_query_term(params)

render json: format_tags_json(tags)
end

def all_tags
return render_403 unless User.current.admin?

q = build_search_query_term params
sql_for_where = "LOWER(#{ActiveRecord::Base.connection.quote_table_name ActsAsTaggableOn.tags_table}.name) LIKE ?"
@tags = ActsAsTaggableOn::Tag.where(sql_for_where, "%#{q.downcase}%")
.order(name: :asc)
tags = ActsAsTaggableOn::Tag.where(sql_for_where, "%#{q.downcase}%")
.order(name: :asc)

render layout: false, partial: 'additional_tag_list', locals: { unsorted: true }
render json: format_tags_json(tags)
end
end
end
Expand Down

0 comments on commit 6dd633c

Please sign in to comment.