fix calendar error

This commit is contained in:
chiu 2020-08-12 21:28:57 +08:00
parent ed06f3e891
commit 6c63cae62c
3 changed files with 38 additions and 27 deletions

View File

@ -5,7 +5,10 @@ class Admin::AnnouncementsController < OrbitAdminController
before_action ->(module_app = @app_title) { set_variables module_app } before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_bulletin, only: [:edit, :destroy, :comment] before_action :set_bulletin, only: [:edit, :destroy, :comment]
before_action :load_access_level, :load_settings before_action :load_access_level, :load_settings
before_action :set_module_pages, only: [:edit,:new]
def set_module_pages
@module_pages = Page.where(:module => 'announcement').collect{|p| [p.name,p.id] }
end
def initialize def initialize
super super
@app_title = "announcement" @app_title = "announcement"
@ -224,18 +227,7 @@ class Admin::AnnouncementsController < OrbitAdminController
end end
if !defined?(Calendar).nil? if !defined?(Calendar).nil?
if bps[:add_to_calendar] == '0' && !bps[:event_id].blank? bps = update_calendar(bps,bulletin)
Event.find(bps[:event_id]).destroy rescue nil
bps[:event_id] = nil
elsif bps[:add_to_calendar] == '1'
event = Event.find(bps[:event_id]) rescue Event.new(create_user_id: current_user.id)
e_start = bps[:calendar_start_date].blank? ? bps[:postdate] : bps[:calendar_start_date]
e_start = Time.now.to_datetime if e_start.blank?
e_end = bps[:calendar_end_date].blank? ? bps[:deadline] : bps[:calendar_end_date]
e_end = Time.now.to_datetime + 1.year if e_end.blank?
event.update_attributes(bulletin_id: bulletin.id,start: e_start,end: e_end,update_user_id: current_user.id,all_day: bps[:calendar_all_day],calendar_type_id: bps[:calendar_type_id],title: bps[:title_translations][I18n.locale],note: bps[:subtitle_translations][I18n.locale])
bps[:event_id] = event.id
end
end end
bulletin.create_user_id = current_user.id bulletin.create_user_id = current_user.id
bulletin.update_user_id = current_user.id bulletin.update_user_id = current_user.id
@ -316,18 +308,7 @@ class Admin::AnnouncementsController < OrbitAdminController
bps[:is_hidden] = bulletin.is_hidden bps[:is_hidden] = bulletin.is_hidden
end end
if !defined?(Calendar).nil? if !defined?(Calendar).nil?
if bps[:add_to_calendar] == '0' && !bps[:event_id].blank? bps = update_calendar(bps,bulletin)
Event.find(bps[:event_id]).destroy rescue nil
bps[:event_id] = nil
elsif bps[:add_to_calendar] == '1'
event = Event.find(bps[:event_id]) rescue Event.new(create_user_id: current_user.id)
e_start = bps[:calendar_start_date].blank? ? bps[:postdate] : bps[:calendar_start_date]
e_start = Time.now.to_datetime if e_start.blank?
e_end = bps[:calendar_end_date].blank? ? bps[:deadline] : bps[:calendar_end_date]
e_end = Time.now.to_datetime + 1.year if e_end.blank?
event.update_attributes(bulletin_id: bulletin.id,start: e_start,end: e_end,update_user_id: current_user.id,all_day: bps[:calendar_all_day],calendar_type_id: bps[:calendar_type_id],title: bps[:title_translations][I18n.locale],note: bps[:subtitle_translations][I18n.locale])
bps[:event_id] = event.id
end
end end
bulletin.update_attributes(bps) bulletin.update_attributes(bps)
bulletin.update_user_id = current_user.id bulletin.update_user_id = current_user.id
@ -495,7 +476,31 @@ class Admin::AnnouncementsController < OrbitAdminController
def settings_params def settings_params
params.require(:announcement_setting).permit! params.require(:announcement_setting).permit!
end end
def update_calendar(bps,bulletin)
if bps[:add_to_calendar] == '0' && !bps[:event_id].blank?
Event.find(bps[:event_id]).destroy rescue nil
bps[:event_id] = nil
elsif bps[:add_to_calendar] == '1'
event = Event.find(bps[:event_id]) rescue Event.new(create_user_id: current_user.id)
e_start = bps[:calendar_start_date].blank? ? bps[:postdate] : bps[:calendar_start_date]
e_start = Time.now.to_datetime if e_start.blank?
e_end = bps[:calendar_end_date].blank? ? bps[:deadline] : bps[:calendar_end_date]
#e_end = Time.now.to_datetime + 1.year if e_end.blank?
event.update_attributes(model_class: 'Bulletin',
module_key: 'announcement',
model_cat: bps[:category_id],
model_tags: bps[:tags],
model_page_id: bps[:page_id],
model_id: bulletin.id,start: e_start,
end: e_end,update_user_id: current_user.id,
all_day: bps[:calendar_all_day],
calendar_type_id: bps[:calendar_type_id],
title_translations: bps[:title_translations],
note_translations: bps[:subtitle_translations])
bps[:event_id] = event.id
end
bps
end
def create_feed_cache(bulletin=nil,bulletin_feed=nil) def create_feed_cache(bulletin=nil,bulletin_feed=nil)
if !bulletin.nil? if !bulletin.nil?
BulletinFeed.where(:tag_ids.in => Array(bulletin.tag_ids).collect{|v| v.to_s}).each do |bulletin_feed| BulletinFeed.where(:tag_ids.in => Array(bulletin.tag_ids).collect{|v| v.to_s}).each do |bulletin_feed|

View File

@ -21,7 +21,7 @@ class Bulletin
field :calendar_all_day,type: Boolean,default: false field :calendar_all_day,type: Boolean,default: false
field :calendar_type_id field :calendar_type_id
field :event_id field :event_id
field :page_id
field :title, type: String, localize: true field :title, type: String, localize: true
field :subtitle, localize: true field :subtitle, localize: true
field :text, localize: true field :text, localize: true

View File

@ -149,6 +149,12 @@
<%= f.check_box :calendar_all_day %> <%= f.check_box :calendar_all_day %>
</div> </div>
</div> </div>
<div class="control-group">
<label class="control-label muted">Select Read More Page :</label>
<div class="controls">
<%= f.select :page_id,[["----- Select a page -----",nil]]+@module_pages %>
</div>
</div>
</div> </div>
<%= f.hidden_field :event_id %> <%= f.hidden_field :event_id %>
</div> </div>