|
10 | 10 |
|
11 | 11 | module ::CommunityCustomFields |
12 | 12 | PLUGIN_NAME = "community-custom-fields" |
13 | | - CUSTOM_FIELD_NAMES = %i[ |
14 | | - assignee_id |
15 | | - first_assigned_to_id |
16 | | - first_assigned_at |
17 | | - last_assigned_at |
18 | | - last_action_by_assignee_at |
19 | | - priority |
20 | | - product_area |
21 | | - status |
22 | | - snoozed_until |
23 | | - ] |
24 | | - CUSTOM_FIELD_TYPES = %i[ |
25 | | - integer |
26 | | - integer |
27 | | - datetime |
28 | | - datetime |
29 | | - datetime |
30 | | - string |
31 | | - string |
32 | | - string |
33 | | - datetime |
34 | | - ] |
| 13 | + CUSTOM_FIELDS = { |
| 14 | + assignee_id: :integer, |
| 15 | + first_assigned_to_id: :integer, |
| 16 | + first_assigned_at: :datetime, |
| 17 | + last_assigned_at: :datetime, |
| 18 | + last_action_by_assignee_at: :datetime, |
| 19 | + priority: :string, |
| 20 | + product_area: :string, |
| 21 | + status: :string, |
| 22 | + snoozed_until: :datetime |
| 23 | + } |
35 | 24 | end |
36 | 25 |
|
37 | 26 | require_relative 'lib/community_custom_fields/engine.rb' |
38 | 27 |
|
39 | 28 | after_initialize do |
40 | | - CommunityCustomFields::CUSTOM_FIELD_NAMES.each_with_index do |field, i| |
41 | | - Topic.register_custom_field_type(field, CommunityCustomFields::CUSTOM_FIELD_TYPES[i]) |
| 29 | + CommunityCustomFields::CUSTOM_FIELDS.each do |name, type| |
| 30 | + Topic.register_custom_field_type(name, type) |
42 | 31 | end |
43 | 32 |
|
44 | | - TopicList.preloaded_custom_fields.merge(CommunityCustomFields::CUSTOM_FIELD_NAMES) |
| 33 | + TopicList.preloaded_custom_fields.merge(CommunityCustomFields::CUSTOM_FIELDS.keys) |
45 | 34 |
|
46 | 35 | add_to_serializer(:topic_view, :custom_fields) do |
47 | | - object.topic.custom_fields.slice(*CommunityCustomFields::CUSTOM_FIELD_NAMES) |
| 36 | + object.topic.custom_fields.slice(*CommunityCustomFields::CUSTOM_FIELDS.keys) |
48 | 37 | end |
49 | 38 |
|
50 | 39 | on(:topic_created) do |topic, params, user| |
51 | 40 | topic.custom_fields[:status] = "new" |
| 41 | + topic.custom_fields[:assignee_id] = 0 |
52 | 42 | topic.save_custom_fields |
53 | 43 | end |
54 | 44 | end |
0 commit comments