From e9e471cf9caeb54d28697ca6e3c6bd4439dc087d Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Thu, 13 Feb 2020 17:19:37 +0800 Subject: [PATCH] add field :uid by slug; add :get_plugin_data and :get_plugin_field_data --- app/models/activity.rb | 46 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/app/models/activity.rb b/app/models/activity.rb index 2a1421d..0f106c5 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -5,10 +5,10 @@ class Activity #include Admin::PersonalActivitiesHelper include OrbitModel::Status include MemberHelper - #include Slug + include Slug # Language - field :activity_name, type: String, localize: true + field :activity_name, as: :slug_title, type: String, localize: true field :activity_organizer, type: String, localize: true field :activity_area, type: String, localize: true @@ -19,4 +19,46 @@ class Activity field :note, type: String belongs_to :member_profile + + def get_plugin_data(fields_to_show) + plugin_datas = [] + fields_to_show.each do |field| + plugin_data = self.get_plugin_field_data(field) rescue nil + next if plugin_data.blank? or plugin_data['value'].blank? + plugin_datas << plugin_data + end + plugin_datas + end + + def get_plugin_field_data(field) + case field + when 'attendee' + path = OrbitHelper.url_to_plugin_show(self.member_profile.to_param, 'member') rescue '#' + value = "#{self.member_profile.name}" + when 'activity_name' + value = self.activity_name rescue '' + when 'activity_organizer' + value = self.activity_organizer rescue '' + when 'activity_area' + value = self.activity_area rescue '' + when 'activity_start_date' + value = self.activity_start_date rescue '' + when 'activity_end_date' + value = self.activity_end_date rescue '' + when 'year' + value = self.year rescue '' + when 'note' + value = self.note rescue '' + else + value = self.send(field) rescue '' + end + + { + 'key' => field, + 'title_class' => "activity-#{field.gsub('_','-')}-field", + 'value_class' => "activity-#{field.gsub('_','-')}-value", + 'title' => I18n.t('personal_activity.'+ field), + 'value' => value + } + end end