diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index dcd46ac..e1e5269 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -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 diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index acd8aaf..2193d88 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -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 = ('' + I18n.t('seminar.signup') + '').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 += "".html_safe + if !session[:seminar_signup_id].blank? + if session[:seminar_main_id] == seminar.id + sign_up += ('' + t('seminar_signup.uploads') + '').html_safe + else + sign_up += ('' + t('seminar_signup.con_login') + '').html_safe + end + else + sign_up += ('' + t('seminar_signup.con_login') + '').html_safe + end + sign_up += "".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 = "
#{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) diff --git a/app/models/seminar_signup.rb b/app/models/seminar_signup.rb index 89ab028..ca62fa7 100644 --- a/app/models/seminar_signup.rb +++ b/app/models/seminar_signup.rb @@ -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 += "
" + 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 += "
" + 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 diff --git a/app/views/seminars/signup_email_contents.html.erb b/app/views/seminars/signup_email_contents.html.erb new file mode 100644 index 0000000..0d77369 --- /dev/null +++ b/app/views/seminars/signup_email_contents.html.erb @@ -0,0 +1,23 @@ + +

<%= seminar.title rescue nil %>

+ + + <% + fields_contents = seminar_signup.get_display_fields + %> + <% fields_contents.each_with_index do |h| %> + + + + + <% end %> + +
+ <%= h["title"] %>:  + + <%= h["value"].html_safe %> +
\ No newline at end of file diff --git a/app/views/seminars/signup_ok.html.erb b/app/views/seminars/signup_ok.html.erb index 3262582..0ddbf29 100644 --- a/app/views/seminars/signup_ok.html.erb +++ b/app/views/seminars/signup_ok.html.erb @@ -13,7 +13,12 @@ <%=t('seminar_signup.serial_number') %>: <%=data["serial_number"] rescue ""%> <% if !params['status'].nil? %>
- + <%= t('seminar.click_to_contribute') %> +<% else %> +
+ + <%= t('seminar.back') %> + <% end %> diff --git a/lib/seminar/engine.rb b/lib/seminar/engine.rb index 113e4e1..a84c45d 100644 --- a/lib/seminar/engine.rb +++ b/lib/seminar/engine.rb @@ -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" diff --git a/modules/seminar/_seminar_widget10.html.erb b/modules/seminar/_seminar_widget10.html.erb new file mode 100644 index 0000000..5584242 --- /dev/null +++ b/modules/seminar/_seminar_widget10.html.erb @@ -0,0 +1,22 @@ +
+

+ {{widget-title}} +

+ +
+ Read more +
+
diff --git a/modules/seminar/_seminar_widget11.html.erb b/modules/seminar/_seminar_widget11.html.erb new file mode 100644 index 0000000..2feb5be --- /dev/null +++ b/modules/seminar/_seminar_widget11.html.erb @@ -0,0 +1,22 @@ +
+

+ {{widget-title}} +

+ +
+ Read more +
+
diff --git a/modules/seminar/_seminar_widget12.html.erb b/modules/seminar/_seminar_widget12.html.erb new file mode 100644 index 0000000..2ab7ac2 --- /dev/null +++ b/modules/seminar/_seminar_widget12.html.erb @@ -0,0 +1,27 @@ +
+

+ {{widget-title}} +

+ + + + + + + + + + + + + +
{{title-head}}{{date-head}}
+ + {{status}} + + {{title}} +
+
+ Read more +
+
\ No newline at end of file diff --git a/modules/seminar/_seminar_widget13.html.erb b/modules/seminar/_seminar_widget13.html.erb new file mode 100644 index 0000000..0125094 --- /dev/null +++ b/modules/seminar/_seminar_widget13.html.erb @@ -0,0 +1,27 @@ +
+

+ {{widget-title}} +

+ + + + + + + + + + + + + +
{{date-head}}{{title-head}}
+ + {{status}} + + {{title}} +
+
+ Read more +
+
\ No newline at end of file diff --git a/modules/seminar/_seminar_widget5.html.erb b/modules/seminar/_seminar_widget5.html.erb new file mode 100644 index 0000000..698132f --- /dev/null +++ b/modules/seminar/_seminar_widget5.html.erb @@ -0,0 +1,31 @@ +
+

+ {{widget-title}} +

+ +
+ Read more +
+
diff --git a/modules/seminar/_seminar_widget6.html.erb b/modules/seminar/_seminar_widget6.html.erb new file mode 100644 index 0000000..6d16b24 --- /dev/null +++ b/modules/seminar/_seminar_widget6.html.erb @@ -0,0 +1,26 @@ +
+

+ {{widget-title}} +

+ +
+ Read more +
+
diff --git a/modules/seminar/_seminar_widget7.html.erb b/modules/seminar/_seminar_widget7.html.erb new file mode 100644 index 0000000..66e76a5 --- /dev/null +++ b/modules/seminar/_seminar_widget7.html.erb @@ -0,0 +1,26 @@ +
+

+ {{widget-title}} +

+ +
+ Read more +
+
diff --git a/modules/seminar/_seminar_widget8.html.erb b/modules/seminar/_seminar_widget8.html.erb new file mode 100644 index 0000000..a69abb3 --- /dev/null +++ b/modules/seminar/_seminar_widget8.html.erb @@ -0,0 +1,29 @@ +
+

+ {{widget-title}} +

+ + + + + + + + + + + + + + + +
{{category-head}}{{title-head}}{{date-head}}
{{category}} + + {{status}} + + {{title}} +
+
+ Read more +
+
\ No newline at end of file diff --git a/modules/seminar/_seminar_widget9.html.erb b/modules/seminar/_seminar_widget9.html.erb new file mode 100644 index 0000000..43d637b --- /dev/null +++ b/modules/seminar/_seminar_widget9.html.erb @@ -0,0 +1,29 @@ +
+

+ {{widget-title}} +

+ + + + + + + + + + + + + + + +
{{date-head}}{{title-head}}{{category-head}}
+ + {{status}} + + {{title}} + {{category}}
+
+ Read more +
+
\ No newline at end of file diff --git a/modules/seminar/info.json b/modules/seminar/info.json new file mode 100644 index 0000000..3f21e9c --- /dev/null +++ b/modules/seminar/info.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/modules/seminar/thumbs/seminar_index10_thumbs.png b/modules/seminar/thumbs/seminar_index10_thumbs.png new file mode 100644 index 0000000..0745dc6 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index10_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index11_thumbs.png b/modules/seminar/thumbs/seminar_index11_thumbs.png new file mode 100644 index 0000000..8dc2261 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index11_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index12_thumbs.png b/modules/seminar/thumbs/seminar_index12_thumbs.png new file mode 100644 index 0000000..2e00654 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index12_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index13_thumbs.png b/modules/seminar/thumbs/seminar_index13_thumbs.png new file mode 100644 index 0000000..82eee2c Binary files /dev/null and b/modules/seminar/thumbs/seminar_index13_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index14_thumbs.png b/modules/seminar/thumbs/seminar_index14_thumbs.png new file mode 100644 index 0000000..0a58044 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index14_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index15_thumbs.png b/modules/seminar/thumbs/seminar_index15_thumbs.png new file mode 100644 index 0000000..cb9ed5e Binary files /dev/null and b/modules/seminar/thumbs/seminar_index15_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index16_thumbs.png b/modules/seminar/thumbs/seminar_index16_thumbs.png new file mode 100644 index 0000000..6ecaa4e Binary files /dev/null and b/modules/seminar/thumbs/seminar_index16_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index19_thumbs.png b/modules/seminar/thumbs/seminar_index19_thumbs.png new file mode 100644 index 0000000..21bb4c9 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index19_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index1_thumbs.png b/modules/seminar/thumbs/seminar_index1_thumbs.png new file mode 100644 index 0000000..0ad29c4 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index1_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index2_thumbs.png b/modules/seminar/thumbs/seminar_index2_thumbs.png new file mode 100644 index 0000000..d7baca7 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index2_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index3_thumbs.png b/modules/seminar/thumbs/seminar_index3_thumbs.png new file mode 100644 index 0000000..0193f81 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index3_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index4_thumbs.png b/modules/seminar/thumbs/seminar_index4_thumbs.png new file mode 100644 index 0000000..7c0a551 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index4_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index5_thumbs.png b/modules/seminar/thumbs/seminar_index5_thumbs.png new file mode 100644 index 0000000..832fe35 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index5_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index6_thumbs.png b/modules/seminar/thumbs/seminar_index6_thumbs.png new file mode 100644 index 0000000..eac8619 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index6_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index7_thumbs.png b/modules/seminar/thumbs/seminar_index7_thumbs.png new file mode 100644 index 0000000..b69abd9 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index7_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index8_thumbs.png b/modules/seminar/thumbs/seminar_index8_thumbs.png new file mode 100644 index 0000000..cf6eb30 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index8_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_index9_thumbs.png b/modules/seminar/thumbs/seminar_index9_thumbs.png new file mode 100644 index 0000000..9fc7c23 Binary files /dev/null and b/modules/seminar/thumbs/seminar_index9_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget10_thumbs.png b/modules/seminar/thumbs/seminar_widget10_thumbs.png new file mode 100644 index 0000000..8dc2261 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget10_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget11_thumbs.png b/modules/seminar/thumbs/seminar_widget11_thumbs.png new file mode 100644 index 0000000..2e00654 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget11_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget12_thumbs.png b/modules/seminar/thumbs/seminar_widget12_thumbs.png new file mode 100644 index 0000000..82eee2c Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget12_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget13_thumbs.png b/modules/seminar/thumbs/seminar_widget13_thumbs.png new file mode 100644 index 0000000..0a58044 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget13_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget14_thumbs.png b/modules/seminar/thumbs/seminar_widget14_thumbs.png new file mode 100644 index 0000000..d1cab18 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget14_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget1_thumbs.png b/modules/seminar/thumbs/seminar_widget1_thumbs.png new file mode 100644 index 0000000..77ba0a8 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget1_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget2_thumbs.png b/modules/seminar/thumbs/seminar_widget2_thumbs.png new file mode 100644 index 0000000..832fe35 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget2_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget3_thumbs.png b/modules/seminar/thumbs/seminar_widget3_thumbs.png new file mode 100644 index 0000000..eac8619 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget3_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget4_thumbs.png b/modules/seminar/thumbs/seminar_widget4_thumbs.png new file mode 100644 index 0000000..b69abd9 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget4_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget5_thumbs.png b/modules/seminar/thumbs/seminar_widget5_thumbs.png new file mode 100644 index 0000000..cf6eb30 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget5_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget6_thumbs.png b/modules/seminar/thumbs/seminar_widget6_thumbs.png new file mode 100644 index 0000000..9fc7c23 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget6_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget7_thumbs.png b/modules/seminar/thumbs/seminar_widget7_thumbs.png new file mode 100644 index 0000000..0745dc6 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget7_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget8_thumbs.png b/modules/seminar/thumbs/seminar_widget8_thumbs.png new file mode 100644 index 0000000..7cfddf7 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget8_thumbs.png differ diff --git a/modules/seminar/thumbs/seminar_widget9_thumbs.png b/modules/seminar/thumbs/seminar_widget9_thumbs.png new file mode 100644 index 0000000..b0a2bb4 Binary files /dev/null and b/modules/seminar/thumbs/seminar_widget9_thumbs.png differ diff --git a/seminar.gemspec b/seminar.gemspec index ce46ac5..2beacfa 100644 --- a/seminar.gemspec +++ b/seminar.gemspec @@ -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"