diff --git a/app/assets/stylesheets/ask/ask.css b/app/assets/stylesheets/ask/ask.css
index f0adc19..a5ce17c 100644
--- a/app/assets/stylesheets/ask/ask.css
+++ b/app/assets/stylesheets/ask/ask.css
@@ -1,3 +1,7 @@
+.asks-3-column .ask-questions {
+ display: flex;
+ flex-wrap: wrap;
+}
.ask-question .control-group.col-sm-6:nth-child(2n+1) {
clear: left;
}
diff --git a/app/controllers/asks_controller.rb b/app/controllers/asks_controller.rb
index 692c8a7..2ea9edd 100644
--- a/app/controllers/asks_controller.rb
+++ b/app/controllers/asks_controller.rb
@@ -55,12 +55,134 @@ class AsksController < ApplicationController
'email_regex' => email_regex
}
}
+ when /.*_pub.*/
+ data_count = OrbitHelper.widget_data_count.to_i
+ category_ids = OrbitHelper.widget_categories || []
+ if category_ids.blank?
+ module_app = ModuleApp.where(:key => "ask").first
+ category_ids = module_app.categories.enabled.pluck(:id)
+ end
+ default_ask_setting = AskSetting.first
+ ask_settings_info = category_ids.map do |category_id|
+ ask_setting = AskCategorySetting.enabled.where(category_id: category_id.to_s).first
+ ask_setting = default_ask_setting if ask_setting.nil?
+ custom_fields = ask_setting.custom_fields.map do |k,field_info|
+ options = nil
+ multiple = false
+ ext_type = 0
+ case field_info["type"]
+ when "select", "radio_button", "checkbox"
+ multiple = (field_info["type"] == "checkbox")
+ options = field_info[:options].map do |i, opt_vals|
+ opt_val = opt_vals[I18n.locale]
+ if opt_val.blank?
+ opt_val = opt_vals.values.select{|s| s.present?}
+ end
+ [i, opt_val]
+ end.to_h
+ when "file", "image"
+ ext_type = 1
+ when "date"
+ ext_type = 2
+ end
+ [k, {
+ options: options,
+ multiple: multiple,
+ ext_type: ext_type
+ }]
+ end
+ if custom_fields.present?
+ sort_number = ask_setting.get_cache_sort_number
+ custom_fields = custom_fields.sort_by do |k, v|
+ if k.start_with?('default@')
+ sort_number[k]
+ else
+ sort_number["custom@#{ask_setting.id}@#{k}"]
+ end
+ end
+ end
+ [category_id,
+ {
+ setting: ask_setting,
+ custom_fields: custom_fields.to_h
+ }
+ ]
+ end.to_h
+ ask_questions = AskQuestion.where(:situation => 'is_published', :category_id.in => category_ids)
+ if data_count != 0
+ ask_questions = ask_questions.page(1).per(data_count)
+ end
+ ask_index_page = OrbitHelper.widget_more_url rescue nil
+ ask_questions = ask_questions.collect do |v|
+ url = ((ask_index_page+"?item=#{v.id}") rescue "javascript:alert('#{t('ask.no_index_page')}')")
+ category_id = v.category_id.to_s
+ extra_info = ask_settings_info[category_id]
+ d = {
+ "category_id" => category_id,
+ "link_url" => link_to(v.title,"#{url}",title: v.title),
+ "identity" => v[:identity],
+ "title" => v.title,
+ "name" => v.name,
+ "sex" => v.sex,
+ "content" => v.content,
+ "category" => v.category.title
+ }
+ ext_fields = [
+ {
+ "fk" => "ask-sex-#{v.sex}",
+ "fv" => ""
+ }
+ ]
+ if extra_info.present? && extra_info[:custom_fields].present?
+ ext_fields += extra_info[:custom_fields].map do |k, field_opt|
+ fv = v.custom_values[k]
+ if fv.present?
+ options = field_opt[:options]
+ if options
+ if field_opt[:multiple]
+ fv = fv.values rescue []
+ else
+ fv = Array(fv)
+ end
+ fv = fv.map{|vv| options[vv]}.join("
").html_safe
+ else
+ case field_opt[:ext_type]
+ when 1 # file, image
+ fv = "#{fv[0]}".html_safe
+ when 2 # date
+ fv = fv["datetime"].values[0].values rescue []
+ if fv.count == 2
+ fv = fv[0].to_s.gsub('-', '/') + " ~ " + fv[1].to_s.gsub('-', '/')
+ else
+ fv = fv[0].to_s.gsub('-', '/')
+ end
+ end
+ end
+ end
+ {
+ "fk"=> "ask-q-#{k}",
+ "fv"=> fv
+ }
+ end
+ end
+ d["ext_fields"] = ext_fields
+ d
+ end
+ {
+ 'ask_questions' => ask_questions,
+ 'extras' => {'more_title'=>I18n.t('ask.more_title'),
+ 'more_href'=>ask_index_page}
+ }
else
data_count = OrbitHelper.widget_data_count.to_i
+ category_ids = OrbitHelper.widget_categories || []
+ if category_ids.blank?
+ module_app = ModuleApp.where(:key => "ask").first
+ category_ids = module_app.categories.enabled.pluck(:id)
+ end
+ ask_questions = AskQuestion.where(:situation => 'is_published', :category_id.in => category_ids)
if data_count != 0
- ask_questions = AskQuestion.where(situation: 'is_published').page(1).per(data_count)
- else
- ask_questions = AskQuestion.where(situation: 'is_published')
+ ask_questions = ask_questions.page(1).per(data_count)
end
ask_index_page = OrbitHelper.widget_more_url rescue nil
ask_questions = ask_questions.collect do |v|
@@ -169,14 +291,66 @@ class AsksController < ApplicationController
page_number = OrbitHelper.page_number.to_i
page_number = 1 if page_number == 0
page_data_count = OrbitHelper.page_data_count.to_i
- if page_data_count != 0
- ask_questions = AskQuestion.where(situation: 'is_published').page(page_number).per(page_data_count)
- else
- ask_questions = AskQuestion.where(situation: 'is_published')
+ category_ids = OrbitHelper.page_categories || []
+ if category_ids.blank?
+ module_app = ModuleApp.where(:key => "ask").first
+ category_ids = module_app.categories.enabled.pluck(:id)
end
+ default_ask_setting = AskSetting.first
+ ask_settings_info = category_ids.map do |category_id|
+ ask_setting = AskCategorySetting.enabled.where(category_id: category_id.to_s).first
+ ask_setting = default_ask_setting if ask_setting.nil?
+ custom_fields = ask_setting.custom_fields.map do |k,field_info|
+ options = nil
+ multiple = false
+ ext_type = 0
+ case field_info["type"]
+ when "select", "radio_button", "checkbox"
+ multiple = (field_info["type"] == "checkbox")
+ options = field_info[:options].map do |i, opt_vals|
+ opt_val = opt_vals[I18n.locale]
+ if opt_val.blank?
+ opt_val = opt_vals.values.select{|s| s.present?}
+ end
+ [i, opt_val]
+ end.to_h
+ when "file", "image"
+ ext_type = 1
+ when "date"
+ ext_type = 2
+ end
+ [k, {
+ options: options,
+ multiple: multiple,
+ ext_type: ext_type
+ }]
+ end
+ if custom_fields.present?
+ sort_number = ask_setting.get_cache_sort_number
+ custom_fields = custom_fields.sort_by do |k, v|
+ if k.start_with?('default@')
+ sort_number[k]
+ else
+ sort_number["custom@#{ask_setting.id}@#{k}"]
+ end
+ end
+ end
+ [category_id,
+ {
+ setting: ask_setting,
+ custom_fields: custom_fields.to_h
+ }
+ ]
+ end.to_h
+ ask_questions = AskQuestion.where(:situation => 'is_published', :category_id.in => category_ids)
+ if page_data_count != 0
+ ask_questions = ask_questions.page(1).per(page_data_count)
+ end
+
{
'layout_type' => 'published_index',
'ask_questions' => ask_questions,
+ 'ask_settings_info' => ask_settings_info,
'url' => @params['url']
}
else
diff --git a/app/views/asks/published_index.erb b/app/views/asks/published_index.erb
index c840abb..34ee025 100644
--- a/app/views/asks/published_index.erb
+++ b/app/views/asks/published_index.erb
@@ -1,18 +1,63 @@
-
<%= t('categories') %> | -<%= t('title') %> | -
---|---|
<%= ask_question.category.title %> | -<%= link_to ask_question.title,"#{data['url']}?item=#{ask_question.id}",title: ask_question.title %> | -