-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1677, add the "Any tag" for batch update form
- Loading branch information
1 parent
7afbe4c
commit cd014c3
Showing
7 changed files
with
122 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module BatchUpdateForm::RoutingTagMethods | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def form_data_foreign_key(attribute_name, options = {}) | ||
return super(attribute_name, options) unless attribute_name == :routing_tag_ids | ||
|
||
display_name = options.fetch(:display_name, :name) | ||
primary_key = options.fetch(:primary_key, :id) | ||
|
||
scope = Routing::RoutingTag.order(:name) | ||
scope = scope.pluck(display_name, primary_key) | ||
scope = add_any_tag_option(scope, options) | ||
scope | ||
end | ||
|
||
def add_any_tag_option(scope, options) | ||
if options[:any_tag] == true | ||
scope.prepend([[Routing::RoutingTag::ANY_TAG]]) | ||
elsif options[:any_tag] != false | ||
raise ArgumentError, 'options[:any_tag] must be a boolean' | ||
end | ||
scope | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters