Compare commits

..

2 Commits

Author SHA1 Message Date
邱博亞 a55848b554 Add event_start_date and event_end_date seperated template.(index 20 and widget 19)
Add category custom translations.
2024-01-28 20:23:35 +08:00
邱博亞 dfdefa3032 Fix bug.
Fix bug.
2024-01-28 20:22:07 +08:00
8 changed files with 54 additions and 8 deletions

View File

@ -468,7 +468,7 @@ class Admin::EventNewsController < OrbitAdminController
content = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s USR2 $UNICORN_PID ; n=20; while (kill -0 $UNICORN_PID > /dev/null 2>&1) && test $n -ge 0; do printf '.' && sleep 1 && n=$(( $n - 1 )); done ; if test $n -lt 0; then kill -s TERM $UNICORN_PID; sleep 3; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{Rails.env}; else kill -s QUIT $UNICORN_PID; fi"
system(content)
end
redirect_to action: :index
redirect_to admin_event_news_index_path
end
private

View File

@ -79,6 +79,8 @@ class EventNewsModsController < ApplicationController
"notes-head" => EventNewsCustomTitle.get_trans('notes'),
"event_date-head" => EventNewsCustomTitle.get_trans('event_date'),
"date-head" => EventNewsCustomTitle.get_trans('event_date'),
"event_start_date-head" => EventNewsCustomTitle.get_trans('start_date'),
"event_end_date-head" => EventNewsCustomTitle.get_trans('end_date'),
"status-head" => t('event_news.table.status'),
"author-head" => t('event_news.table.author'),
"subtitle-head" => t('event_news.table.sub_title'),
@ -386,6 +388,8 @@ class EventNewsModsController < ApplicationController
"notes-head" => EventNewsCustomTitle.get_trans('notes'),
"event_date-head" => EventNewsCustomTitle.get_trans('event_date'),
"date-head" => EventNewsCustomTitle.get_trans('event_date'),
"event_start_date-head" => EventNewsCustomTitle.get_trans('start_date'),
"event_end_date-head" => EventNewsCustomTitle.get_trans('end_date'),
"author-head" => t('event_news.table.author'),
"status-head" => t('event_news.table.status'),
"subtitle-head" => t('event_news.table.sub_title'),

View File

@ -65,6 +65,8 @@ module EventNewsHelper
"category" => (a.category.title rescue ""),
"tag_ids" => (set_tag_ids.nil? ? (a.tag_ids.map{|id| id.to_s}.to_s.gsub('"',"'") rescue '[]') : set_tag_ids),
"postdate" => event_time_formated,
"event_start_date" => a.event_date_frontend,
"event_end_date" => a.event_end_date_frontend,
"event_date" => event_time_formated,
"author" => author,
"link_to_show" => link_to_show,

View File

@ -3,6 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "event_news_mod/version"
require "json"
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
if bundle_update_flag
require File.expand_path("../update_event_news", __FILE__)
@ -24,7 +25,9 @@ if bundle_update_flag
app_path = File.expand_path(__dir__)
template_path = env_pwd + '/app/templates'
all_template = Dir.glob(template_path+'/*/')
default_event_news_widget_info = JSON.parse(File.read("#{app_path}/modules/event_news_mod/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue []
default_info_contents = JSON.parse(File.read("#{app_path}/modules/event_news_mod/info.json")) rescue {}
default_event_news_index_info = default_info_contents["frontend"].sort_by{|h| h["filename"].to_f} rescue []
default_event_news_widget_info = default_info_contents["widgets"].sort_by{|h| h["filename"].to_f} rescue []
all_template.each do |folder|
if !folder.include?('mobile')
if Dir.exist?("#{folder}modules/event_news")
@ -44,6 +47,41 @@ if bundle_update_flag
info = JSON.parse(encode_file_text) rescue {}
flag = (info.count != 0 rescue false)
if flag
puts "Checking event_news index"
index_info = info["frontend"].sort_by{|h| h["filename"].to_i} rescue []
update_flag = false
last_index = index_info.collect{|v| v["filename"].to_s.scan(/\d+/).collect{|v1| v1.to_i}}.flatten.sort[-1] rescue nil
if !last_index.nil?
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
default_event_news_index_info.each do |h|
name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'')
index_info_index = (index_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1)
if index_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
index_info << copy_h
bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/#{h["filename"]}.html.erb #{folder}modules/event_news_mod/#{copy_h["filename"]}.html.erb]}
elsif h["force_cover"] == "true"
bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/#{h["filename"]}.html.erb #{folder}modules/event_news_mod/#{index_info[index_info_index]["filename"]}.html.erb]}
end
end
if update_flag
info["frontend"] = index_info
puts "Writing json #{info["frontend"].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
puts "Checking event_news widgets"
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
update_flag = false

View File

@ -1,5 +1,7 @@
<div class="i-annc index-announcement-12s {{display}}">
<h1 class="i-annc__page-title">{{page-title}}</h1>
<div class="i-annc index-announcement-12s w-annc widget-announcement-19">
<h3 class="w-annc__widget-title">
<span>{{widget-title}}</span>
</h3>
<table class="i-annc__table table table-striped">
<thead>
<tr>

View File

@ -1,4 +1,4 @@
<div class="i-annc index-announcement-12s {{display}}">
<div class="i-annc index-announcement-12s index-announcement-19 {{display}}">
<h1 class="i-annc__page-title">{{page-title}}</h1>
<table class="i-annc__table table table-striped">
<thead>

View File

@ -1,4 +1,4 @@
<div class="i-annc index-announcement-12s {{display}}">
<div class="i-annc index-announcement-12s index-announcement-20 {{display}}">
<h1 class="i-annc__page-title">{{page-title}}</h1>
<table class="i-annc__table table table-striped">
<thead>

View File

@ -155,8 +155,8 @@
{
"filename" : "event_news_index20",
"name" : {
"zh_tw" : "20. 標準標題列表-3 ( 類別, 演講者, 事件日期, 狀態, 標題, 截止日期, 瀏覽人次 )",
"en" : "20. Standard Title List-3 ( category, EventDate, speaker, EventDate, status, title, EndDate, view-count)"
"zh_tw" : "20. 標準標題列表-4 ( 類別, 演講者, 事件日期, 狀態, 標題, 截止日期, 瀏覽人次 )",
"en" : "20. Standard Title List-4 ( category, EventDate, speaker, EventDate, status, title, EndDate, view-count)"
},
"thumbnail" : "event_news_index1_thumbs.png"
}