fix error

This commit is contained in:
chiu 2021-06-16 12:34:39 +08:00
parent e4b1761651
commit cccf18ba4c
1 changed files with 8 additions and 4 deletions

View File

@ -16,18 +16,22 @@ class Admin::EventNewsController < OrbitAdminController
@tags = @module_app.tags @tags = @module_app.tags
@table_fields = [:status, :category, :title, "event_news.event_date", "event_news.start_date", "event_news.end_date", :last_modified] @table_fields = [:status, :category, :title, "event_news.event_date", "event_news.start_date", "event_news.end_date", :last_modified]
@current_user = current_user @current_user = current_user
if params[:sort].blank?
params[:sort] = 'event_date'
params[:order] = 'desc'
end
if EventNewsSetting.first.is_display_edit_only && !current_user.is_admin? && !current_user.is_manager?(@module_app) if EventNewsSetting.first.is_display_edit_only && !current_user.is_admin? && !current_user.is_manager?(@module_app)
current_user_is_sub_manager = !current_user.is_manager?(@module_app) && (current_user.is_sub_manager?(@module_app) || current_user.is_sub_manager_with_role?(@module_app)) rescue false current_user_is_sub_manager = !current_user.is_manager?(@module_app) && (current_user.is_sub_manager?(@module_app) || current_user.is_sub_manager_with_role?(@module_app)) rescue false
if current_user_is_sub_manager if current_user_is_sub_manager
@categories = current_user.approved_categories.select{|c| c.module_app_id == @module_app.id} rescue [] @categories = current_user.approved_categories.select{|c| c.module_app_id == @module_app.id} rescue []
@filter_fields = filter_fields(@categories, @tags) @filter_fields = filter_fields(@categories, @tags)
@event_news = EventNews.where(:category_id.ne=>nil, :create_user_id=>current_user.id,:is_preview.in=>[false,nil]) @event_news = EventNews.where(:category_id.ne=>nil, :create_user_id=>current_user.id,:is_preview.in=>[false,nil])
.order_by(sort || :event_date) .order_by(sort)
.with_categories(filters("category")) .with_categories(filters("category"))
.with_tags(filters("tag")) .with_tags(filters("tag"))
.with_status(filters("status")) .with_status(filters("status"))
else else
@event_news = EventNews.where(:category_id.ne=>nil, :uid=>nil).order_by(sort || :event_date) @event_news = EventNews.where(:category_id.ne=>nil, :uid=>nil).order_by(sort)
@categories = @module_app.categories.enabled @categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories, @tags) @filter_fields = filter_fields(@categories, @tags)
end end
@ -35,7 +39,7 @@ class Admin::EventNewsController < OrbitAdminController
@categories = @module_app.categories.enabled @categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories, @tags) @filter_fields = filter_fields(@categories, @tags)
@event_news = EventNews.where(:category_id.ne=>nil, :is_preview.in=>[false,nil]) @event_news = EventNews.where(:category_id.ne=>nil, :is_preview.in=>[false,nil])
.order_by(sort || :event_date) .order_by(sort)
.with_categories(filters("category")) .with_categories(filters("category"))
.with_tags(filters("tag")) .with_tags(filters("tag"))
.with_status(filters("status")) .with_status(filters("status"))
@ -325,7 +329,7 @@ class Admin::EventNewsController < OrbitAdminController
now_event_news_page = EventNews.where(:title.ne => "",:is_preview.in=>[false,nil]) now_event_news_page = EventNews.where(:title.ne => "",:is_preview.in=>[false,nil])
.order_by(sort).map(&:id).map.with_index.select{|v,i| v==event_news.id}[0][1] rescue nil .order_by(sort).map(&:id).map.with_index.select{|v,i| v==event_news.id}[0][1] rescue nil
now_event_news_page = now_event_news_page.nil? ? 0 : ((now_event_news_page+1).to_f/10).ceil now_event_news_page = now_event_news_page.nil? ? 0 : ((now_event_news_page+1).to_f/10).ceil
redirect_to "/zh_tw/admin/event_news?page=#{now_event_news_page}" redirect_to admin_event_news_index_path(:page=>now_bulletin_page)
end end
def destroy def destroy