Update published index and widget.
This commit is contained in:
parent
ad256f93c5
commit
1c118c4f12
|
@ -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) {
|
.ask-question .control-group.col-sm-6:nth-child(2n+1) {
|
||||||
clear: left;
|
clear: left;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,12 +55,134 @@ class AsksController < ApplicationController
|
||||||
'email_regex' => email_regex
|
'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("<br>").html_safe
|
||||||
|
else
|
||||||
|
case field_opt[:ext_type]
|
||||||
|
when 1 # file, image
|
||||||
|
fv = "<a href=\"#{fv[1]}\">#{fv[0]}</a>".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
|
else
|
||||||
data_count = OrbitHelper.widget_data_count.to_i
|
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
|
if data_count != 0
|
||||||
ask_questions = AskQuestion.where(situation: 'is_published').page(1).per(data_count)
|
ask_questions = ask_questions.page(1).per(data_count)
|
||||||
else
|
|
||||||
ask_questions = AskQuestion.where(situation: 'is_published')
|
|
||||||
end
|
end
|
||||||
ask_index_page = OrbitHelper.widget_more_url rescue nil
|
ask_index_page = OrbitHelper.widget_more_url rescue nil
|
||||||
ask_questions = ask_questions.collect do |v|
|
ask_questions = ask_questions.collect do |v|
|
||||||
|
@ -169,14 +291,66 @@ class AsksController < ApplicationController
|
||||||
page_number = OrbitHelper.page_number.to_i
|
page_number = OrbitHelper.page_number.to_i
|
||||||
page_number = 1 if page_number == 0
|
page_number = 1 if page_number == 0
|
||||||
page_data_count = OrbitHelper.page_data_count.to_i
|
page_data_count = OrbitHelper.page_data_count.to_i
|
||||||
if page_data_count != 0
|
category_ids = OrbitHelper.page_categories || []
|
||||||
ask_questions = AskQuestion.where(situation: 'is_published').page(page_number).per(page_data_count)
|
if category_ids.blank?
|
||||||
else
|
module_app = ModuleApp.where(:key => "ask").first
|
||||||
ask_questions = AskQuestion.where(situation: 'is_published')
|
category_ids = module_app.categories.enabled.pluck(:id)
|
||||||
end
|
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',
|
'layout_type' => 'published_index',
|
||||||
'ask_questions' => ask_questions,
|
'ask_questions' => ask_questions,
|
||||||
|
'ask_settings_info' => ask_settings_info,
|
||||||
'url' => @params['url']
|
'url' => @params['url']
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,18 +1,63 @@
|
||||||
<table class="table">
|
<%
|
||||||
<thead>
|
ask_questions = data['ask_questions']
|
||||||
<tr class="bg-primary">
|
ask_settings_info = data['ask_settings_info']
|
||||||
<th><%= t('categories') %></th>
|
%>
|
||||||
<th><%= t('title') %></th>
|
<%= stylesheet_link_tag "ask/ask" %>
|
||||||
</tr>
|
<div class="asks-3-column">
|
||||||
</thead>
|
<div class="ask-questions col-md-12 row">
|
||||||
<tbody>
|
<% ask_questions.each do |ask_question| %>
|
||||||
<% data['ask_questions'].each do |ask_question| %>
|
<%
|
||||||
<tr>
|
category_id = ask_question.category_id.to_s
|
||||||
<td><%= ask_question.category.title %></td>
|
extra_info = ask_settings_info[category_id]
|
||||||
<td><%= link_to ask_question.title,"#{data['url']}?item=#{ask_question.id}",title: ask_question.title %></td>
|
%>
|
||||||
</tr>
|
<div class="ask-question-wrap col-md-4 category-<%= category_id %>">
|
||||||
|
<div class="ask-question-basic">
|
||||||
|
<div class="ask-title"><%= link_to ask_question.title,"#{data['url']}?item=#{ask_question.id}",title: ask_question.title %></div>
|
||||||
|
<div class="ask-content"><%= ask_question.content %></div>
|
||||||
|
<div class="ask-sex-<%= ask_question.sex %>"></div>
|
||||||
|
<div class="asker"><%= ask_question.name %></div>
|
||||||
|
<div class="ask-identity"><%= ask_question[:identity] %></div>
|
||||||
|
</div>
|
||||||
|
<div class="ask-question-extras">
|
||||||
|
<div class="ask-question-extra ask-sex-<%= ask_question.sex %>"></div>
|
||||||
|
<% if extra_info.present? && extra_info[:custom_fields].present? %>
|
||||||
|
<%
|
||||||
|
extra_info[:custom_fields].each do |k, field_opt|
|
||||||
|
fk = "ask-q-#{k}"
|
||||||
|
fv = ask_question.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("<br>").html_safe
|
||||||
|
else
|
||||||
|
case field_opt[:ext_type]
|
||||||
|
when 1 # file, image
|
||||||
|
fv = "<a href=\"#{fv[1]}\">#{fv[0]}</a>".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
|
||||||
|
%>
|
||||||
|
<div class="ask-question-extra <%= fk %>">
|
||||||
|
<%= fv %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
</div>
|
||||||
<% total_pages = data['ask_questions'].total_pages %>
|
<% total_pages = data['ask_questions'].total_pages %>
|
||||||
<%= create_pagination(total_pages).html_safe if total_pages > 1 %>
|
<%= create_pagination(total_pages).html_safe if total_pages > 1 %>
|
|
@ -0,0 +1,21 @@
|
||||||
|
<div class="widget-asks asks-3-column widget3">
|
||||||
|
<h3 class="widget-title">
|
||||||
|
<span>{{widget-title}}</span>
|
||||||
|
</h3>
|
||||||
|
<div class="ask-questions col-md-12 row" data-level="0" data-list="ask_questions">
|
||||||
|
<div class="ask-question-wrap col-md-4 category-{{category_id}}">
|
||||||
|
<div class="ask-question-basic">
|
||||||
|
<div class="ask-title">{{link_url}}</div>
|
||||||
|
<div class="ask-content">{{content}}</div>
|
||||||
|
<div class="ask-sex-{{sex}}"></div>
|
||||||
|
<div class="asker">{{name}}</div>
|
||||||
|
<div class="ask-identity">{{identity}}</div>
|
||||||
|
</div>
|
||||||
|
<div class="ask-question-extras" data-level="1" data-list="ext_fields">
|
||||||
|
<div class="ask-question-extra {{fk}}">{{fv}}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
<div style="background: #337ab7; border: 1px solid rgb(204, 204, 204); padding: 5px 10px; text-align: right;"><span style="color:inherit;"><a href="{{more_href}}" title="{{more_title}}"><span style="color:#FFFFFF;">{{more_title}}</span></a></span></div>
|
||||||
|
</div>
|
|
@ -15,6 +15,14 @@
|
||||||
"en" : "2. widget-title, published list"
|
"en" : "2. widget-title, published list"
|
||||||
},
|
},
|
||||||
"thumbnail" : "thumb.png"
|
"thumbnail" : "thumb.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename" : "ask_widget_pub_3_column",
|
||||||
|
"name" : {
|
||||||
|
"zh_tw" : "3. 模組標題、 發佈回覆列表-3欄式",
|
||||||
|
"en" : "3. widget-title, published list - 3 Column"
|
||||||
|
},
|
||||||
|
"thumbnail" : "thumb.png"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue