Skip to content
Permalink
Browse files

update to handle preloading category custom fields

  • Loading branch information...
angusmcleod committed Mar 19, 2019
1 parent df8e1fd commit 5017187c4d8e2af406e05e8457e65c8a928a111a
Showing with 23 additions and 7 deletions.
  1. +23 −7 plugin.rb
@@ -22,6 +22,8 @@
Discourse.filters.push(:calendar)
Discourse.anonymous_filters.push(:calendar)

register_svg_icon "rss" if respond_to?(:register_svg_icon)

load File.expand_path('../models/events_timezone_default_site_setting.rb', __FILE__)
load File.expand_path('../models/events_timezone_display_site_setting.rb', __FILE__)

@@ -49,12 +51,18 @@
Category.register_custom_field_type('events_calendar_enabled', :boolean)
Category.register_custom_field_type('events_min_trust_to_create', :integer)
Category.register_custom_field_type('events_required', :boolean)
add_to_serializer(:basic_category, :events_enabled) { object.events_enabled }
add_to_serializer(:basic_category, :events_event_label_no_text) { object.custom_fields['events_event_label_no_text'] }
add_to_serializer(:basic_category, :events_agenda_enabled) { object.events_agenda_enabled }
add_to_serializer(:basic_category, :events_calendar_enabled) { object.events_calendar_enabled }
add_to_serializer(:basic_category, :events_min_trust_to_create) { object.events_min_trust_to_create }
add_to_serializer(:basic_category, :events_required) { object.events_required }

[
"events_enabled",
"events_event_label_no_text",
"events_agenda_enabled",
"events_calendar_enabled",
"events_min_trust_to_create",
"events_required"
].each do |key|
Site.preloaded_category_custom_fields << key if Site.respond_to? :preloaded_category_custom_fields
add_to_serializer(:basic_category, key.to_sym) { object.send(key) }
end

class ::Category
def events_min_trust_to_create
@@ -96,6 +104,14 @@ def events_required
false
end
end

def events_event_label_no_text
if self.custom_fields['events_event_label_no_text'] != nil
self.custom_fields['events_event_label_no_text']
else
false
end
end
end

module EventsSiteSettingExtension
@@ -496,7 +512,7 @@ def event_ics(opts = {})
end
e.summary = t.title
e.description = t.excerpt
e.url = calendar_url
e.url = t.url
end
end
end

0 comments on commit 5017187

Please sign in to comment.
You can’t perform that action at this time.