diff --git a/active.gemspec b/active.gemspec index 4a6e476..c65f810 100644 --- a/active.gemspec +++ b/active.gemspec @@ -2,7 +2,22 @@ $:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: require "active/version" - +bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install' +if bundle_update_flag + app_path = File.expand_path(__dir__) + template_path = ENV['PWD'] + '/app/templates' + all_template = Dir.glob(template_path+'/*/') + puts 'copying module' + all_template.each do |folder| + if folder.split('/')[-1] != 'mobile' + begin + system ('cp -r '+ app_path + '/modules/ ' + folder) + rescue + puts 'error copy' + end + end + end +end # Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "active" diff --git a/app/assets/stylesheets/active_front.css.scss b/app/assets/stylesheets/active_front.css.scss new file mode 100644 index 0000000..c570935 --- /dev/null +++ b/app/assets/stylesheets/active_front.css.scss @@ -0,0 +1,36 @@ +// Place all the styles related to the act controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +.active-index2 li.col-md-4{ + float: left; + .active-meta{ + padding-left: 1em; + padding-top: 0.5em; + } + .active-img-wrap { + overflow: hidden; + height: 12.5em; + img { + max-height: 100%; + max-width: 100%; + height: auto; + width: auto; + } + } + a:hover .active-title{ + color: #0032b2; + font-size: 1.3em; + } + @media (min-width: 992px){ + width: 33.3333%; + } + @media (min-width: 577px) and (max-width: 991px){ + width: 50%; + } + @media (max-width: 576px){ + width: 100%; + .active-img-wrap { + height: auto; + } + } +} \ No newline at end of file diff --git a/app/controllers/actives_controller.rb b/app/controllers/actives_controller.rb index 63e9705..ba2a138 100644 --- a/app/controllers/actives_controller.rb +++ b/app/controllers/actives_controller.rb @@ -3,41 +3,58 @@ class ActivesController < ApplicationController helper MemberHelper def index - + begin time_now = Time.now - + OrbitHelper.render_css_in_head(["active_front"]) actives = Act.filter_by_categories.desc(:sign_start_date).page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) acts = actives.collect do |a| - - title = ('' + a.title + '').html_safe - - if (!a.sign_up.blank? and a.sign_start_date <= time_now and ( a.sign_end_date >= time_now or a.sign_end_date.nil? ) rescue false) - sign_up = ('' + t('act.sign_up') + '').html_safe - elsif a.sign_up.blank? - sign_up = t('act.sign_up_not_open') - elsif (a.sign_start_date > time_now rescue false) - sign_up = t('act.sign_up_not_yet') - else - sign_up = t('act.sign_up_overdue') + link_to_show = OrbitHelper.url_to_show(a.to_param) + '?method=show_data' + title_text = a.title + title = "#{title_text}" + sign_up = a.signup_show + statuses = a.statuses_with_classname.collect do |status| + { + "status" => status["name"], + "status-class" => "status-#{status['classname']}" + } end + act_start_date = (a.act_start_date.blank? ? "" : a.act_start_date.strftime('%Y-%m-%d %H:%M') rescue "") + act_end_date = (a.act_end_date.blank? ? t(:no_deadline) : a.act_end_date.strftime('%Y-%m-%d %H:%M') rescue "") + act_duration_date = act_start_date.blank? ? act_end_date : "#{act_start_date} ~ #{act_end_date}" + + sign_start_date = (a.sign_start_date.blank? ? "" : a.sign_start_date.strftime('%Y-%m-%d %H:%M') rescue "") + sign_end_date = ((a.sign_end_date ? a.sign_end_date.strftime('%Y-%m-%d %H:%M') : t(:no_deadline)) rescue "") + sign_duration_date = sign_start_date.blank? ? sign_end_date : "#{sign_start_date} ~ #{sign_end_date}" + + desc = a.image_description + desc = (desc.blank? ? "active image" : desc) { + "link_to_show" => link_to_show, + "title_text" => title_text, + "statuses" => statuses, "title" => title, + "subtitle" => a.subtitle, + "img_src" => a.image.thumb.url || "/assets/announcement-default.jpg", + "img_description" => desc, "category" => a.category.title, - "sign_start_date" => (a.sign_start_date.strftime('%Y-%m-%d %H:%M') rescue ""), - "sign_end_date" => ((a.sign_end_date ? a.sign_end_date.strftime('%Y-%m-%d %H:%M') : t(:no_deadline)) rescue ""), - "act_start_date" => (a.act_start_date.strftime('%Y-%m-%d %H:%M') rescue ""), - "act_end_date" => (a.act_end_date ? a.act_end_date.strftime('%Y-%m-%d %H:%M') : t(:no_deadline) rescue ""), - 'sign_up_time_range' => (Act.time_range(a.sign_start_date, a.sign_end_date) rescue ""), - 'sign_up_time_range' => (Act.time_range(a.sign_start_date, a.sign_end_date) rescue ""), - 'act_time_range' => (Act.time_range(a.act_start_date, a.act_end_date) rescue ""), - 'sign_up' => sign_up + "sign_duration_date" => sign_duration_date, + "sign_start_date" => sign_start_date, + "sign_end_date" => sign_end_date, + "act_duration_date" => act_duration_date, + "act_start_date" => act_start_date, + "act_end_date" => act_end_date, + 'sign_up_time_range' => (Act.time_range(a.sign_start_date, a.sign_end_date) rescue ""), + 'act_time_range' => (Act.time_range(a.act_start_date, a.act_end_date) rescue ""), + 'sign_up' => sign_up } end + _display = acts.count == 0 ? "hide" : '' { "acts" => acts, "extras" => { + "display" => _display, "widget-title"=>t('act.active'), "th_title" => t('act.title'), "th_act_time_range" => t('act.act_time_range'), @@ -47,7 +64,9 @@ class ActivesController < ApplicationController }, "total_pages" => actives.total_pages } - + rescue => e + puts [e,e.backtrace] + end end def show_privacy @@ -73,19 +92,9 @@ class ActivesController < ApplicationController act = Act.find_by(uid: params[:uid]) - if (!act.sign_up.blank? and act.sign_start_date <= time_now and ( act.sign_end_date >= time_now or act.sign_end_date.nil? ) rescue false) - sign_up = ('' + t('act.sign_up') + '').html_safe - elsif act.sign_up.blank? - sign_up = t('act.sign_up_not_open') - elsif (act.sign_start_date > time_now rescue false) - sign_up = t('act.sign_up_not_yet') - else - sign_up = t('act.sign_up_overdue') - end - { 'act' => act, - 'sign_up' => sign_up, + 'sign_up' => act.signup_show, 'time_now' => time_now, 'sign_up_time_range' => (Act.time_range(act.sign_start_date, act.sign_end_date) rescue ""), 'act_time_range' => (Act.time_range(act.act_start_date, act.act_end_date) rescue "") @@ -102,7 +111,7 @@ class ActivesController < ApplicationController act = Act.find_by(uid: params[:uid]) - act_signup = ActSignup.new + act_signup = ActSignup.new(id: nil) time_now = Time.now diff --git a/app/controllers/admin/actives_controller.rb b/app/controllers/admin/actives_controller.rb index 6f55f7e..c397dd8 100644 --- a/app/controllers/admin/actives_controller.rb +++ b/app/controllers/admin/actives_controller.rb @@ -43,7 +43,7 @@ class Admin::ActivesController < OrbitAdminController def new @tags = @module_app.tags - @act = Act.new + @act = Act.new(id: nil) end def create diff --git a/app/models/act.rb b/app/models/act.rb index 51d0a11..0c41a70 100644 --- a/app/models/act.rb +++ b/app/models/act.rb @@ -8,11 +8,22 @@ class Act include OrbitCategory::Categorizable include Slug + include OrbitModel::Status + field :image_description, type: String, localize: true + field :top_end_date, :type => DateTime + mount_uploader :image, ImageUploader + field :is_external_link, type: Boolean, default: false + field :external_link, type: String, default: "" + field :title, as: :slug_title, type: String, localize: true + field :subtitle, type: String, localize: true + field :content, localize: true field :place, localize: true field :create_user_id field :update_user_id + field :postdate , :type => DateTime, :default => Time.now + field :end_date , :type => DateTime, :default => Time.now field :act_start_date , :type => DateTime, :default => Time.now field :act_end_date , :type => DateTime, :default => Time.now field :sign_start_date , :type => DateTime, :default => Time.now @@ -93,5 +104,50 @@ class Act end end + + def self.remove_expired_status + self.where(:is_top => true, :top_end_date.ne => nil, :top_end_date.lt => Time.now).each do |act| + act.is_top = false + act.top_end_date = nil + act.save + end + end + + def top_text + I18n.t("top") + end + def hot_text + I18n.t("hot") + end + def hidden_text + I18n.t("hidden") + end + + def statuses_with_classname + statuses = [] + statuses << {"name" => top_text, "classname" => "top"} if is_top? + statuses << {"name" => hot_text, "classname" => "hot"} if is_hot? + statuses << {"name" => hidden_text, "classname" => "hidden"} if is_hidden? + statuses + end + + def can_sign_up? + (self.sign_up && (self.sign_start_date.blank? || self.sign_start_date <= time_now) && ( self.sign_end_date.blank? || self.sign_end_date >= time_now )) rescue false + end + + def is_external_link? + self.is_external_link && !self.external_link.blank? + end + def signup_show + if self.can_sign_up? + sign_up = ('' + I18n.t('act.sign_up') + '').html_safe + elsif self.sign_up + sign_up = I18n.t('act.sign_up_not_open') + elsif (self.sign_start_date > time_now rescue false) + sign_up = I18n.t('act.sign_up_not_yet') + else + sign_up = I18n.t('act.sign_up_overdue') + end + end end diff --git a/app/views/actives/show_data.html.erb b/app/views/actives/show_data.html.erb index 6349988..b758ec1 100644 --- a/app/views/actives/show_data.html.erb +++ b/app/views/actives/show_data.html.erb @@ -8,70 +8,68 @@ @act_time_range = data["act_time_range"] %> - +

<%= @act.title %>

- + - + - - - + + + - <% if !@act.content.blank? %> - - - - - <% end %> - + <% if !@act.sign_start_date.blank? || !@act.sign_end_date.blank? %> + - <% if !@act.place.blank? %> - - - - <% end %> - <% if !@act.act_files.blank? %> - - - - - <% end %> - <% if !@act.act_links.blank? %> - - - - - <% end %> - <% if !@act.note.blank? %> - - - - - <% end %> - + <% if @act.sign_up %> + - + + <% end %>
<%= t(:category) %> <%= @act.category.title %>
<%= t('act.act_time_range') %> <%= @act_time_range %>
<%= t('act.title') %><%= @act.title %>
<%= t('act.place') %><%= @act.place %>
<%= t('act.content') %><%= nl2br(@act.content) %>
<%= t('act.place') %><%= @act.place %>
<%= t(:file_) %> - <% @act.act_files.map do |file| %> - <%= link_to (file.title.blank? ? File.basename(file.file.path) : file.title) , file.file.url, {:target => '_blank', :title => file.description} if file.file.file %> - <% end %> -
<%= t(:link) %> - <% @act.act_links.map do |link| %> - <%= link_to (link.title.blank? ? link.url : link.title), link.url, :target => '_blank' %> - <% end %> -
<%= t('act.note') %><%= @act.note %>
- -
- -<%= link_to t(:close), 'javascript:window.close();', :class => 'btn btn-primary' %> +
+<%= nl2br(@act.content.to_s).html_safe %> +
+ +<% if !@act.note.blank? %> +

<%= @act.note %>

+<% end %> +<%# link_to t(:close), 'javascript:window.close();', :class => 'btn btn-primary' %> diff --git a/app/views/admin/actives/_form.html.erb b/app/views/admin/actives/_form.html.erb index 4e3d76e..8eb496d 100644 --- a/app/views/admin/actives/_form.html.erb +++ b/app/views/admin/actives/_form.html.erb @@ -19,7 +19,10 @@ @@ -36,6 +39,22 @@ + +
+ +
+ <%= f.datetime_picker :postdate, :no_label => true, :new_record => @act.new_record? %> +
+
+ + +
+ +
+ <%= f.datetime_picker :end_date, :no_label => true, :new_record => @act.new_record? %> +
+
+
@@ -74,6 +93,22 @@
+ + + + +
@@ -82,7 +117,7 @@
@@ -318,6 +353,84 @@
+ + + +
+ +
+ +
+ + + +
+
+
" data-for="is_top"> + +
+ <%= f.datetime_picker :top_end_date, :no_label => true, :new_record => @act.new_record? %> +
+
+
+ + +
+
+ + <%= select_tags(f, @module_app) %> +
+
+ + +
+ + +
+ +
+
+
+ <% if @act.image.file %> + <%= image_tag @act.image %> + <% else %> + + <% end %> +
+
+ + <%= t(:select_image) %> + <%= t(:change) %> + <%= f.file_field :image %> + + <%= t(:cancel) %> +
+ +
+
+
+
+ <% @site_in_use_locales.each do |locale| %> + <%= f.fields_for :image_description_translations do |f| %> +
+ +
+ <%= f.text_field locale, value: (@act.image_description_translations[locale.to_s] rescue nil) %> +
+
+ <% end %> + <% end %> + +
+ @@ -342,7 +455,17 @@
<%= f.fields_for :title_translations do |f| %> - <%= f.text_field locale, class: "input-block-level", placeholder: t(:title), value: (@act.title_translations[locale] rescue nil) %> + <%= f.text_area locale, class: "ckeditor_reduce input-block-level", placeholder: t(:title), value: (@act.title_translations[locale] rescue nil) %> + <% end %> +
+ + + +
+ +
+ <%= f.fields_for :subtitle_translations do |f| %> + <%= f.text_area locale, class: "ckeditor input-block-level", placeholder: t(:subtitle), value: (@act.subtitle_translations[locale] rescue nil) %> <% end %>
@@ -457,6 +580,16 @@ <% content_for :page_specific_javascript do %> <% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 1c9be07..efd62e1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -11,6 +11,13 @@ en: verification_failed: Verification Failed act: + is_external_link: Enable External Link + external_link: External Link + external_link_hint: "Make sure URL starts with http://" + top_end_date: Top end date + postdate: Post date + end_date: End date + image: Cover Image active: Active title: Event Title content: Content diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index c343011..a84f711 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -11,6 +11,13 @@ zh_tw: verification_failed: 驗證碼錯誤 act: + is_external_link: 連結外部網址 + external_link: 外部連結 + external_link_hint: "確定連結開頭為http://" + top_end_date: 至頂結束時間 + postdate: 張貼日期 + end_date: 下架日期 + image: 封面圖片 active: 活動報名 title: 活動標題 content: 活動說明 @@ -34,7 +41,7 @@ zh_tw: sign_up_not_yet: 報名時間未開始 sign_up_not_open: 未開放報名 sign_up_overdue: 報名時間已過 - settings: Activity Settings + settings: 活動報名設定 has_idno: 報名是否需填寫身分證字號 has_birthday: 出生年月日 has_sex: 性別 diff --git a/module/active/active_index.html.erb b/module/active/active_index.html.erb new file mode 100644 index 0000000..3bb4e90 --- /dev/null +++ b/module/active/active_index.html.erb @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + +
+

{{page-title}}

+
{{th_category}}{{th_act_time_range}}{{th_title}}{{th_sign_up_time_range}}{{th_sign_up}}
{{category}}{{act_duration_date}} + + {{status}} + + {{title}} + {{sign_duration_date}}{{sign_up}}
+{{pagination_goes_here}} \ No newline at end of file diff --git a/module/active/active_index1.html.erb b/module/active/active_index1.html.erb new file mode 100644 index 0000000..49fe82a --- /dev/null +++ b/module/active/active_index1.html.erb @@ -0,0 +1,25 @@ +
+

{{page-title}}

+ + + + + + + + + + + + + + + +
{{th_act_time_range}}{{th_title}}{{th_sign_up}}
{{act_duration_date}} + + {{status}} + + {{title}} + {{sign_up}}
+
+{{pagination_goes_here}} diff --git a/module/active/active_index2.html.erb b/module/active/active_index2.html.erb new file mode 100644 index 0000000..99f9a19 --- /dev/null +++ b/module/active/active_index2.html.erb @@ -0,0 +1,32 @@ +
+

{{page-title}}

+ +
+{{pagination_goes_here}} \ No newline at end of file diff --git a/module/active/info.json b/module/active/info.json new file mode 100644 index 0000000..aa5f20c --- /dev/null +++ b/module/active/info.json @@ -0,0 +1,28 @@ +{ + "frontend": [ + { + "filename" : "active_index", + "name" : { + "zh_tw" : "1. 列表 (類別, 活動期間, 狀態, 活動標題, 報名期間, 線上報名)", + "en" : "1. List (Category, Event Period, status, Event Title, Registration Period, Register)" + }, + "thumbnail" : "thumb.png" + }, + { + "filename" : "active_index1", + "name" : { + "zh_tw" : "2. 精簡表格列表-2 ( 模組標題, 活動期間, 狀態, 標題, 線上報名)", + "en" : "2. Simple Table List (widget-title, Event Period, status, title, Register)" + }, + "thumbnail" : "active_index1_thumbs.png" + }, + { + "filename" : "active_index2", + "name" : { + "zh_tw" : "3. 三欄圖文 ( 模組標題, 圖片, 狀態, 活動期間, 類別, 標題, 副標題, 線上報名)", + "en" : "3. 3-Column Standard Image + Text (widget-title, image, status, postdate, category, title, subtitle, Register)" + }, + "thumbnail" : "active_index2_thumbs.png" + } + ] +} \ No newline at end of file diff --git a/module/active/thumbs/active_index1_thumbs.png b/module/active/thumbs/active_index1_thumbs.png new file mode 100644 index 0000000..0a58044 Binary files /dev/null and b/module/active/thumbs/active_index1_thumbs.png differ diff --git a/module/active/thumbs/active_index2_thumbs.png b/module/active/thumbs/active_index2_thumbs.png new file mode 100644 index 0000000..b69abd9 Binary files /dev/null and b/module/active/thumbs/active_index2_thumbs.png differ diff --git a/module/active/thumbs/thumb.png b/module/active/thumbs/thumb.png new file mode 100644 index 0000000..266af56 Binary files /dev/null and b/module/active/thumbs/thumb.png differ