Merge branch 'master' into 'master'

Add widget and add signup infos in email.

See merge request spen/seminar!25
This commit is contained in:
chiu 2021-11-18 10:03:36 +00:00
commit e96da4244c
48 changed files with 593 additions and 45 deletions

View File

@ -502,7 +502,7 @@ class Admin::SeminarsController < OrbitAdminController
def edit
@seminar_items = SeminarItem.all
@seminar = SeminarMain.where(id: params[:id]).first
except_attributes = ["final_sessions","preferred_sessions","seminar_session_ids","preferred_session","final_session","sort_number","abstract_number","presentation_type"]
except_attributes = SeminarSignup::HiddenFields
@seminar.seminar_signup_field_sets.each do |signup_field_set|
if (!(SeminarSignup.attribute_names.include? signup_field_set.field_name) && signup_field_set.field_name != 'recaptcha') || except_attributes.include?(signup_field_set.field_name)
signup_field_set.delete
@ -752,34 +752,33 @@ class Admin::SeminarsController < OrbitAdminController
params.require(:seminar_main).permit!
end
def create_set (save_flag)
except_attributes = ["final_sessions","preferred_sessions","seminar_session_ids","preferred_session","final_session","sort_number","abstract_number","presentation_type"]
except_attributes = SeminarSignup::HiddenFields
@seminar.seminar_signup_field_sets.where(:field_name.in=>except_attributes).destroy
SeminarSignup.attribute_names.each do |attr_signup|
next if except_attributes.include?(attr_signup)
if !(['_id', 'created_at', 'updated_at','seminar_main_id','final_session','seminar_session_id'].include? attr_signup)
signup_set = @seminar.seminar_signup_field_sets.select{|v| v.field_name==attr_signup }
if signup_set.length==0
if ['status','name','tel','phone','email','password'].include? attr_signup
disabled = false
else
disabled = true
end
if ['status','name','tel'].include? attr_signup
hidden = false
else
hidden = true
end
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("seminar_signup.#{attr_signup}")
end
I18n.locale = now_locale
if save_flag
@seminar.seminar_signup_field_sets.create(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
else
@seminar.seminar_signup_field_sets.new(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
end
signup_set = @seminar.seminar_signup_field_sets.select{|v| v.field_name==attr_signup }
if signup_set.length==0
if SeminarSignup::DefaultEnableFields.include? attr_signup
disabled = false
else
disabled = true
end
if ['status','name','tel'].include? attr_signup
hidden = false
else
hidden = true
end
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("seminar_signup.#{attr_signup}")
end
I18n.locale = now_locale
if save_flag
@seminar.seminar_signup_field_sets.create(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
else
@seminar.seminar_signup_field_sets.new(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
end
end
end
@ -798,23 +797,22 @@ class Admin::SeminarsController < OrbitAdminController
@seminar.seminar_signup_field_sets.new(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true)
end
end
@seminar.seminar_submission_field_sets.where(:field_name.in=>except_attributes).destroy
SeminarSignupContribute.attribute_names.each do |attr_submission|
next if except_attributes.include?(attr_submission)
if !(['_id', 'created_at', 'updated_at','seminar_signup_id'].include? attr_submission)
signup_set = @seminar.seminar_submission_field_sets.select{|v| v.field_name==attr_submission }
if signup_set.length==0
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("seminar_signup.#{attr_submission}")
end
I18n.locale = now_locale
if save_flag
@seminar.seminar_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1)
else
@seminar.seminar_submission_field_sets.new(field_name:attr_submission,name:name1,placeholder:name1)
end
signup_set = @seminar.seminar_submission_field_sets.select{|v| v.field_name==attr_submission }
if signup_set.length==0
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("seminar_signup.#{attr_submission}")
end
I18n.locale = now_locale
if save_flag
@seminar.seminar_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1)
else
@seminar.seminar_submission_field_sets.new(field_name:attr_submission,name:name1,placeholder:name1)
end
end
end

View File

@ -17,6 +17,58 @@ class SeminarsController < ApplicationController
}
end
def widget
cats = OrbitHelper.widget_categories || []
widget_data_count = OrbitHelper.widget_data_count
seminars = SeminarMain.all.desc(:seminar_start_date).filter_by_categories(cats)
time_now = DateTime.now
session = OrbitHelper.request.session
seminars = seminars.map do |seminar|
link_url = OrbitHelper.url_to_show(seminar.to_param)
if !seminar.registration_status.blank? && (seminar.signup_start_date <= time_now rescue false) && ( seminar.signup_end_date.nil? || seminar.signup_end_date+1 >= time_now )
sign_up = ('<a href="'+ link_url + '" target="_blank">' + I18n.t('seminar.signup') + '</a>').html_safe
elsif seminar.registration_status.blank?
sign_up = I18n.t('seminar.sign_up_not_open')
elsif (seminar.signup_start_date > @time_now rescue false)
sign_up = I18n.t('seminar.sign_up_not_yet')
else
sign_up = I18n.t('seminar.sign_up_overdue')
end
if !seminar.registration_status.blank? && seminar.registration_status.include?('C') && (seminar.contribute_start_date <= time_now rescue false) && ( seminar.contribute_end_date.nil? || (seminar.contribute_end_date+1 >= time_now rescue false) )
sign_up += "<span style=\"margin-left: 1em;\">".html_safe
if !session[:seminar_signup_id].blank?
if session[:seminar_main_id] == seminar.id
sign_up += ('<a href="'+ link_url + '?method=con_upload">' + t('seminar_signup.uploads') + '</a>').html_safe
else
sign_up += ('<a href="'+ link_url + '?method=con_login">' + t('seminar_signup.con_login') + '</a>').html_safe
end
else
sign_up += ('<a href="'+ link_url + '?method=con_login">' + t('seminar_signup.con_login') + '</a>').html_safe
end
sign_up += "</span>".html_safe
end
files = seminar.seminar_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } } rescue []
files.delete(nil)
links = seminar.seminar_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
{"title" => seminar.title,
"subtitle" => sign_up,
"category" => (seminar.category.title rescue ""),
"link_to_show" => (link_url == "#" ? '' : link_url + "?method=show_data"),
"postdate" => seminar.seminar_start_date,
"statuses" => {},
"bulletin_links" => links,
"bulletin_files" => files
}
end
{
"seminars" => seminars,
"extras" => {
"date-head" => I18n.t("seminar.seminar_start_date"),
"category-head" => I18n.t(:category),
"title-head" => I18n.t("seminar.title")
}
}
end
def custom_frontend_data
params = OrbitHelper.params
seminar = SeminarMain.find_by(:uid=>params[:uid])
@ -185,6 +237,7 @@ class SeminarsController < ApplicationController
:params=>params,:session=>OrbitHelper.request.session},:layout=>false)
end
def render_other_method(render_method=nil,render_template=nil)
params = OrbitHelper.params
render_method = render_method || params[:method]
render_template = render_template || render_method
params = OrbitHelper.params
@ -367,6 +420,8 @@ class SeminarsController < ApplicationController
@seminar.save
end
extra_text = "<br>#{I18n.t('seminar_signup.serial_number')}: #{@seminar_signup.display_serial_number}"
extra_text += render_to_string("seminars/signup_email_contents",:locals=>{:seminar=>@seminar,
:seminar_signup=>@seminar_signup},:layout=>false)
if params['seminar_signup']['status']=='C'
status_param = '&status='
send_mail('submission',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id],extra_text)

View File

@ -3,7 +3,8 @@ class SeminarSignup
include Mongoid::Document
include Mongoid::Timestamps
HiddenFields = ['seminar_signup_id','_id', 'created_at', 'updated_at','seminar_main_id',"serial_number","final_session","final_sessions","preferred_sessions",'seminar_session_id',"seminar_session_ids","preferred_session","sort_number","abstract_number","presentation_type"]
DefaultEnableFields = ['status','name','tel','phone','email','password']
field :sort_number , type: Integer, default: 10000
field :status
@ -73,4 +74,88 @@ class SeminarSignup
self.preferred_sessions = self.seminar_signup_contributes.pluck(:preferred_session)
self.save
end
def get_display_fields
seminar = self.seminar_main
if seminar.nil?
return []
else
locale = I18n.locale.to_s
except_fields = ["password", "recaptcha"]
all_fields = []
if seminar.seminar_signup_field_sets.count != 0
all_fields = seminar.seminar_signup_field_sets.map do |set|
field_name = set.field_name
next if set.disabled || except_fields.include?(field_name)
value = self.send(field_name) rescue nil
next if value.nil?
if field_name == "status"
value = I18n.t("seminar.registration_status_#{value}")
elsif self.fields[field_name].options[:localize]
values = self.send("#{field_name}_translations").select{|k,v| v.present?}
value = ""
if values.count == 0
next
elsif values.count == 1
value = values.values.first
else
last_idx = values.count - 1
values.each_with_index do |(l, v), i|
value += (I18n.t(l) + ": " + v )
if i != last_idx
value += "<br>"
end
end
end
end
{
"field_name"=>field_name,
"title"=>set.name[locale],
"value"=> value
}
end.compact
else
field_names = self.class::DefaultEnableFields
all_fields = field_names.map do |field_name|
next if except_fields.include?(field_name)
value = self.send(field_name) rescue nil
next if value.nil?
field_name_trans = I18n.t("seminar_signup.#{field_name}")
if field_name == "status"
I18n.t("seminar.registration_status_#{value}")
elsif self.fields[field_name].options[:localize]
values = self.send("#{field_name}_translations").select{|k,v| v.present?}
value = ""
if values.count == 0
next
elsif values.count == 1
value = values.values.first
else
last_idx = values.count - 1
values.each_with_index do |(l, v), i|
value += (I18n.t(l) + ": " + v )
if i != last_idx
value += "<br>"
end
end
end
end
{
"field_name"=>field_name,
"title"=> field_name_trans,
"value"=> value
}
end.compact
end
seminar.seminar_signup_fields.asc(:_id).each do |rf|
seminar_signup_value = rf.seminar_signup_values.where(:seminar_signup_id=>self.id).last
if seminar_signup_value
value = seminar_signup_value.get_field_value rescue nil
if value
all_fields << value
end
end
end
return all_fields
end
end
end

View File

@ -0,0 +1,23 @@
<style>
.signup_infos td:first-child {
white-space: nowrap;
}
</style>
<h3><%= seminar.title rescue nil %></h3>
<table id="signup_infos">
<tbody>
<%
fields_contents = seminar_signup.get_display_fields
%>
<% fields_contents.each_with_index do |h| %>
<tr>
<td>
<%= h["title"] %>:&nbsp;
</td>
<td>
<%= h["value"].html_safe %>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@ -13,7 +13,12 @@
<%=t('seminar_signup.serial_number') %>: <%=data["serial_number"] rescue ""%>
<% if !params['status'].nil? %>
<br>
<a href="<%= prefix_url %>?method=con_login">
<a href="<%= prefix_url %>?method=con_login" class="btn btn-primary">
<%= t('seminar.click_to_contribute') %>
</a>
<% else %>
<br>
<a href="<%= prefix_url %>?method=show_data" class="btn btn-primary">
<%= t('seminar.back') %>
</a>
<% end %>

View File

@ -8,7 +8,8 @@ module Seminar
categorizable
frontend_enabled
data_count 1..20
widget_methods ["widget"]
widget_settings [{"data_count"=>30}]
side_bar do
head_label_i18n 'seminar.seminar', icon_class: "icon-globe"
available_for "users"

View File

@ -0,0 +1,22 @@
<div class="w-annc widget-announcement-10">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<ul class="w-annc__list" data-level="0" data-list="seminars">
<li class="w-annc__item row">
<h4 class="w-annc__entry-title col-sm-9">
<span class="w-annc__status-wrap" data-list="statuses" data-level="1">
<span class="w-annc__status label status {{status-class}}">{{status}}</span>
</span>
<a class="w-annc__title" href="{{link_to_show}}">{{title}}</a>
</h4>
<span class="w-annc__postdate-wrap col-sm-3" date-format="%Y-%m-%d">
<i class="fa fa-calendar-o"></i>
<span class="w-annc__postdate">{{postdate}}</span>
</span>
</li>
</ul>
<div class="w-annc__more-wrap clearfix">
<a class="w-annc__more btn btn-primary pull-right" href="{{more_url}}">Read more</a>
</div>
</div>

View File

@ -0,0 +1,22 @@
<div class="w-annc widget-announcement-11">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<ul class="w-annc__list" data-level="0" data-list="seminars">
<li class="w-annc__item row">
<span class="w-annc__postdate-wrap col-sm-3" date-format="%Y-%m-%d">
<i class="fa fa-calendar-o"></i>
<span class="w-annc__postdate">{{postdate}}</span>
</span>
<h4 class="w-annc__entry-title col-sm-9">
<span class="w-annc__status-wrap" data-list="statuses" data-level="1">
<span class="w-annc__status label status {{status-class}}">{{status}}</span>
</span>
<a class="w-annc__title" href="{{link_to_show}}">{{title}}</a>
</h4>
</li>
</ul>
<div class="w-annc__more-wrap clearfix">
<a class="w-annc__more btn btn-primary pull-right" href="{{more_url}}">Read more</a>
</div>
</div>

View File

@ -0,0 +1,27 @@
<div class="w-annc widget-announcement-12">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<table class="w-annc__table table">
<thead>
<tr>
<th class="w-annc__th w-annc__th--title">{{title-head}}</th>
<th class="w-annc__th w-annc__th--date">{{date-head}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="seminars">
<tr>
<td class="w-annc_content">
<span class="w-annc__status-wrap" data-list="statuses" data-level="1">
<span class="w-annc__status label status {{status-class}}">{{status}}</span>
</span>
<a class="w-annc__title" href="{{link_to_show}}">{{title}}</a>
</td>
<td class="w-annc__postdate" date-format="%Y-%m-%d">{{postdate}}</td>
</tr>
</tbody>
</table>
<div class="w-annc__more-wrap clearfix">
<a class="w-annc__more btn btn-primary pull-right" href="{{more_url}}">Read more</a>
</div>
</div>

View File

@ -0,0 +1,27 @@
<div class="w-annc widget-announcement-13">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<table class="w-annc__table table">
<thead>
<tr>
<th class="w-annc__th w-annc__th--date">{{date-head}}</th>
<th class="w-annc__th w-annc__th--title">{{title-head}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="seminars">
<tr>
<td class="w-annc__postdate" date-format="%Y-%m-%d">{{postdate}}</td>
<td class="w-annc_content">
<span class="w-annc__status-wrap" data-list="statuses" data-level="1">
<span class="w-annc__status label status {{status-class}}">{{status}}</span>
</span>
<a class="w-annc__title" href="{{link_to_show}}">{{title}}</a>
</td>
</tr>
</tbody>
</table>
<div class="w-annc__more-wrap clearfix">
<a class="w-annc__more btn btn-primary pull-right" href="{{more_url}}">Read more</a>
</div>
</div>

View File

@ -0,0 +1,31 @@
<div class="w-annc widget-announcement-5">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<ul class="w-annc__list row" data-level="0" data-list="seminars">
<li class="w-annc__item">
<div class="w-annc__content-wrap">
<div class="w-annc__meta">
<span class="w-annc__postdate-wrap" date-format="%Y-%m-%d">
<i class="fa fa-calendar-o"></i>
<span class="w-annc__postdate">{{postdate}}</span>
</span>
<span class="w-annc__category-wrap">
<i class="fa fa-tasks"></i>
<span class="w-annc__category">{{category}}</span>
</span>
<span class="w-annc__status-wrap" data-list="statuses" data-level="1">
<span class="w-annc__status label status {{status-class}}">{{status}}</span>
</span>
</div>
<h4 class="w-annc__entry-title">
<a class="w-annc__title" href="{{link_to_show}}">{{title}}</a>
</h4>
<p class="w-annc__subtitle">{{subtitle}}</p>
</div>
</li>
</ul>
<div class="w-annc__more-wrap clearfix">
<a class="w-annc__more btn btn-primary pull-right" href="{{more_url}}">Read more</a>
</div>
</div>

View File

@ -0,0 +1,26 @@
<div class="w-annc widget-announcement-6">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<ul class="w-annc__list" data-level="0" data-list="seminars">
<li class="w-annc__item row">
<span class="w-annc__category-wrap col-sm-2">
<i class="fa fa-tasks"></i>
<span class="w-annc__category">{{category}}</span>
</span>
<h4 class="w-annc__entry-title col-sm-8">
<span class="w-annc__status-wrap" data-list="statuses" data-level="1">
<span class="w-annc__status label status {{status-class}}">{{status}}</span>
</span>
<a class="w-annc__title" href="{{link_to_show}}">{{title}}</a>
</h4>
<span class="w-annc__postdate-wrap col-sm-2" date-format="%Y-%m-%d">
<i class="fa fa-calendar-o"></i>
<span class="w-annc__postdate">{{postdate}}</span>
</span>
</li>
</ul>
<div class="w-annc__more-wrap clearfix">
<a class="w-annc__more btn btn-primary pull-right" href="{{more_url}}">Read more</a>
</div>
</div>

View File

@ -0,0 +1,26 @@
<div class="w-annc widget-announcement-7">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<ul class="w-annc__list" data-level="0" data-list="seminars">
<li class="w-annc__item row">
<span class="w-annc__postdate-wrap col-sm-2" date-format="%Y-%m-%d">
<i class="fa fa-calendar-o"></i>
<span class="w-annc__postdate">{{postdate}}</span>
</span>
<h4 class="w-annc__entry-title col-sm-8">
<span class="w-annc__status-wrap" data-list="statuses" data-level="1">
<span class="w-annc__status label status {{status-class}}">{{status}}</span>
</span>
<a class="w-annc__title" href="{{link_to_show}}">{{title}}</a>
</h4>
<span class="w-annc__category-wrap col-sm-2">
<i class="fa fa-tasks"></i>
<span class="w-annc__category">{{category}}</span>
</span>
</li>
</ul>
<div class="w-annc__more-wrap clearfix">
<a class="w-annc__more btn btn-primary pull-right" href="{{more_url}}">Read more</a>
</div>
</div>

View File

@ -0,0 +1,29 @@
<div class="w-annc widget-announcement-8">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<table class="w-annc__table table">
<thead>
<tr>
<th class="w-annc__th w-annc__th--category">{{category-head}}</th>
<th class="w-annc__th w-annc__th--title">{{title-head}}</th>
<th class="w-annc__th w-annc__th--date">{{date-head}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="seminars">
<tr>
<td class="w-annc__category">{{category}}</td>
<td class="w-annc_content">
<span class="w-annc__status-wrap" data-list="statuses" data-level="1">
<span class="w-annc__status label status {{status-class}}">{{status}}</span>
</span>
<a class="w-annc__title" href="{{link_to_show}}">{{title}}</a>
</td>
<td class="w-annc__postdate" date-format="%Y-%m-%d">{{postdate}}</td>
</tr>
</tbody>
</table>
<div class="w-annc__more-wrap clearfix">
<a class="w-annc__more btn btn-primary pull-right" href="{{more_url}}">Read more</a>
</div>
</div>

View File

@ -0,0 +1,29 @@
<div class="w-annc widget-announcement-9">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<table class="w-annc__table table">
<thead>
<tr>
<th class="w-annc__th w-annc__th--date">{{date-head}}</th>
<th class="w-annc__th w-annc__th--title">{{title-head}}</th>
<th class="w-annc__th w-annc__th--category">{{category-head}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="seminars">
<tr>
<td class="w-annc__postdate" date-format="%Y-%m-%d">{{postdate}}</td>
<td class="w-annc_content">
<span class="w-annc__status-wrap" data-list="statuses" data-level="1">
<span class="w-annc__status label status {{status-class}}">{{status}}</span>
</span>
<a class="w-annc__title" href="{{link_to_show}}">{{title}}</a>
</td>
<td class="w-annc__category">{{category}}</td>
</tr>
</tbody>
</table>
<div class="w-annc__more-wrap clearfix">
<a class="w-annc__more btn btn-primary pull-right" href="{{more_url}}">Read more</a>
</div>
</div>

76
modules/seminar/info.json Normal file
View File

@ -0,0 +1,76 @@
{
"widgets": [
{
"filename": "seminar_widget5",
"name": {
"zh_tw": "5. 標準文字列表 ( 模組標題, 日期, 類別, 狀態, 標題, 副標題 )",
"en": "5. Standard Text List (widget-title, postdate, category, status, title, subtitle)"
},
"thumbnail": "seminar_widget5_thumbs.png"
},
{
"filename": "seminar_widget6",
"name": {
"zh_tw": "6. 標準標題列表-1 ( 模組標題, 類別, 狀態, 標題, 日期 )",
"en": "6. Standard Title List-1 (widget-title, category, status, title, postdate)"
},
"thumbnail": "seminar_widget6_thumbs.png"
},
{
"filename": "seminar_widget7",
"name": {
"zh_tw": "7. 標準標題列表-2 ( 模組標題, 日期, 狀態, 標題, 類別 )",
"en": "7. Standard Title List-2 (widget-title, postdate, status, title, category)"
},
"thumbnail": "seminar_widget7_thumbs.png"
},
{
"filename": "seminar_widget8",
"name": {
"zh_tw": "8. 標準表格列表-1 ( 模組標題, 類別, 狀態, 標題, 日期 )",
"en": "8. Standard Table List-1 (widget-title, category, status, title, postdate)"
},
"thumbnail": "seminar_widget8_thumbs.png"
},
{
"filename": "seminar_widget9",
"name": {
"zh_tw": "9. 標準表格列表-2 ( 模組標題, 日期, 狀態, 標題, 類別 )",
"en": "9. Standard Table List-2 (widget-title, postdate, status, title, category)"
},
"thumbnail": "seminar_widget9_thumbs.png"
},
{
"filename": "seminar_widget10",
"name": {
"zh_tw": "10. 精簡標題列表-1 ( 模組標題, 狀態, 標題, 日期 )",
"en": "10. Simple Title List-1 (widget-title, status, title, postdate)"
},
"thumbnail": "seminar_widget10_thumbs.png"
},
{
"filename": "seminar_widget11",
"name": {
"zh_tw": "11. 精簡標題列表-2 ( 模組標題, 日期, 狀態, 標題 )",
"en": "11. Simple Title List-2 (widget-title, postdate, status, title)"
},
"thumbnail": "seminar_widget11_thumbs.png"
},
{
"filename": "seminar_widget12",
"name": {
"zh_tw": "12. 精簡表格列表-1 ( 模組標題, 狀態, 標題, 日期 )",
"en": "12. Simple Table List (widget-title, status, title, postdate)"
},
"thumbnail": "seminar_widget12_thumbs.png"
},
{
"filename": "seminar_widget13",
"name": {
"zh_tw": "13. 精簡表格列表-2 ( 模組標題, 日期, 狀態, 標題 )",
"en": "13. Simple Table List (widget-title, postdate, status, title)"
},
"thumbnail": "seminar_widget13_thumbs.png"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -8,6 +8,72 @@ begin
rescue => e
puts [e.to_s,e.backtrace]
end
require "json"
env_pwd = ENV['PWD']
app_path = File.expand_path(__dir__)
template_path = env_pwd + '/app/templates'
all_template = Dir.glob(template_path+'/*/')
default_seminar_widget_info = JSON.parse(File.read("#{app_path}/modules/seminar/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue []
all_template.each do |folder|
if !folder.include?('mobile')
info_json_file = "#{folder}modules/seminar/info.json"
if File.exist?(info_json_file)
Bundler.with_clean_env{system ('cp -f '+ app_path + '/modules/seminar/show.html.erb ' + "#{folder}modules/seminar/.")}
update_seminar_template(folder)
begin
file_text = File.read(info_json_file) rescue ""
encode_file_text = file_text.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???")
next if (encode_file_text.include?("???") rescue true)
info = JSON.parse(encode_file_text) rescue {}
flag = (info.count != 0 rescue false)
if flag
puts "Checking seminar widgets"
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
update_flag = false
last_index = widget_info[-1]["filename"].match(/\d+/)[0].to_i rescue nil
if !last_index.nil?
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
default_seminar_widget_info.each do |h|
name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'')
widget_info_index = (widget_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1)
if widget_info_index == -1
update_flag = true
copy_h = h.dup
h.delete("force_cover")
last_index = last_index + 1
copy_h["filename"] = copy_h["filename"].sub(/\d+/){|ff| last_index.to_s}
copy_h["name"].keys.each do |locale|
copy_h["name"][locale] = copy_h["name"][locale].sub(/\d+/){|ff| last_index.to_s}
end
widget_info << copy_h
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/seminar/_#{h["filename"]}.html.erb #{folder}modules/seminar/_#{copy_h["filename"]}.html.erb]}
elsif h["force_cover"] == "true"
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/seminar/_#{h["filename"]}.html.erb #{folder}modules/seminar/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
end
end
if update_flag
info["widgets"] = widget_info
puts "Writing json #{info["widgets"].count} in #{info_json_file}"
begin
info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n")
rescue
info_json = info.to_s.gsub("=>",": \n")
end
File.open(info_json_file,"w+"){|f| f.write(info_json)}
end
end
end
rescue => e
puts e
puts "There has some error when checking seminar widgets"
end
else
if !Dir.exist?(File.dirname(info_json_file)) && Dir.exist?(File.dirname(File.dirname(info_json_file)))
Bundler.with_clean_env{system ('cp -r '+ app_path + '/modules/ ' + folder)}
end
end
end
end
Gem::Specification.new do |s|
s.name = "seminar"
s.version = "0.0.1"