mirror of
https://github.com/rickbarrette/subtask_field_copier.git
synced 2026-10-03 20:20:43 -04:00
Add support for registering custom fields in Subtask Field Copier
This commit is contained in:
1 parent
fbd394bbc9
commit
7772526c8d
3 files changed
+33
-11
No files matched your search
@@ -44,6 +44,27 @@ Once installed and the server is restarted, there is no configuration needed. Si
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### Developer API: Registering Custom Fields
|
||||||
|
|
||||||
|
If you have built your own Redmine plugins that add custom columns to the issues database table, you can register those fields to be automatically copied when a subtask is created.
|
||||||
|
In your custom plugin's init.rb, append your field names (as symbols) to the SubtaskFieldCopier.registered_fields array.
|
||||||
|
It is best practice to wrap this in a Rails.configuration.to_prepare block and check if the module is defined, ensuring your plugin won't crash if the Subtask Field Copier is uninstalled:
|
||||||
|
|
||||||
|
```Ruby
|
||||||
|
Rails.configuration.to_prepare do
|
||||||
|
if defined?(SubtaskFieldCopier)
|
||||||
|
# Register your custom issue fields here
|
||||||
|
SubtaskFieldCopier.registered_fields << :vehicle
|
||||||
|
SubtaskFieldCopier.registered_fields << :customer
|
||||||
|
|
||||||
|
# Ensure there are no duplicates (useful for development hot-reloading)
|
||||||
|
SubtaskFieldCopier.registered_fields.uniq!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
> The MIT License (MIT)
|
> The MIT License (MIT)
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
module SubtaskFieldCopier
|
module SubtaskFieldCopier
|
||||||
|
|
||||||
|
mattr_accessor :registered_fields
|
||||||
|
self.registered_fields = []
|
||||||
|
|
||||||
def self.setup
|
def self.setup
|
||||||
unless IssuesController.ancestors.include?(SubtaskFieldCopier::Patches::IssuesControllerPatch)
|
unless IssuesController.ancestors.include?(SubtaskFieldCopier::Patches::IssuesControllerPatch)
|
||||||
IssuesController.prepend SubtaskFieldCopier::Patches::IssuesControllerPatch
|
IssuesController.prepend SubtaskFieldCopier::Patches::IssuesControllerPatch
|
||||||
|
|||||||
@@ -28,17 +28,15 @@ module SubtaskFieldCopier
|
|||||||
end
|
end
|
||||||
@issue.custom_field_values = cf_values
|
@issue.custom_field_values = cf_values
|
||||||
|
|
||||||
# --- COPY CUSTOMER, VEHICLE & ESTIMATE---
|
# --- COPY REGISTERED FIELDS ---
|
||||||
if @issue.respond_to?(:customer=) && parent_issue.respond_to?(:customer)
|
# Iterate over any fields registered by other plugins
|
||||||
@issue.customer = parent_issue.customer
|
SubtaskFieldCopier.registered_fields.each do |field|
|
||||||
end
|
setter = "#{field}="
|
||||||
|
|
||||||
if @issue.respond_to?(:vehicle=) && parent_issue.respond_to?(:vehicle)
|
# Use metaprogramming to check if the setter/getter exists, then apply
|
||||||
@issue.vehicle = parent_issue.vehicle
|
if @issue.respond_to?(setter) && parent_issue.respond_to?(field)
|
||||||
end
|
@issue.send(setter, parent_issue.send(field))
|
||||||
|
end
|
||||||
if @issue.respond_to?(:estimate=) && parent_issue.respond_to?(:estimate)
|
|
||||||
@issue.estimate = parent_issue.estimate
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user