fix data_count error

This commit is contained in:
Chihyu 2020-04-06 16:36:42 +08:00
parent b845b3c835
commit 5a4b3088f9
5 changed files with 109 additions and 21 deletions

View File

@ -2,11 +2,12 @@ class Admin::ActivitiesController < OrbitMemberController
layout "member_plugin" layout "member_plugin"
include Admin::PersonalActivitiesHelper include Admin::PersonalActivitiesHelper
before_action :set_activity, only: [:edit, :update, :destroy] before_action :set_activity, only: [:show, :edit, :update, :destroy]
#before_action :set_plugin before_action :set_plugin
before_action :get_settings,:only => [:new, :edit, :setting]
#before_action :need_access_right before_action :need_access_right
#before_action :allow_admin_only, :only => [:index, :setting] before_action :allow_admin_only, :only => [:index, :setting]
def index def index
@activities = Activity.order_by(:year => 'desc').page(params[:page]).per(10) @activities = Activity.order_by(:year => 'desc').page(params[:page]).per(10)
@ -27,22 +28,56 @@ class Admin::ActivitiesController < OrbitMemberController
def create def create
if !activity_params['member_profile_id'].blank? if !activity_params['member_profile_id'].blank?
@member = MemberProfile.find(activity_params['member_profile_id']) rescue nil @member = MemberProfile.find(activity_params['member_profile_id']) rescue nil
@activity = Activity.new(activity_params)
@activity.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
else
redirect_to params['referer_url']
end
elsif !params[:author_members].blank? elsif !params[:author_members].blank?
activity_params['member_profile_id'] = params[:author_members]
params[:author_members].each do |author_member|
activity_params['member_profile_id'] = author_member
@activity = Activity.new(activity_params)
@activity.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
end
end
redirect_to params['referer_url']
else else
activity_params['member_profile_id'] = current_user.member_profile_id activity_params['member_profile_id'] = User.find(current_user.id).member_profile_id
@activity = Activity.new(activity_params)
@activity.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
end
redirect_to params['referer_url']
end end
@activity = Activity.new(activity_params)
@activity.save
redirect_to params['referer_url']
end end
def edit def edit
@member = @activity.member_profile rescue nil
if params[:desktop]
render :layout => false
end
end end
def update def update
@member = @activity.member_profile rescue nil
@activity.update_attributes(activity_params) @activity.update_attributes(activity_params)
redirect_to params['referer_url'] @activity.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
else
redirect_to params['referer_url']
end
end end
def destroy def destroy
@ -54,6 +89,7 @@ class Admin::ActivitiesController < OrbitMemberController
end end
end end
def analysis def analysis
end end
@ -105,6 +141,45 @@ class Admin::ActivitiesController < OrbitMemberController
end end
end end
def toggle_hide
if params[:ids]
@activities = Activity.any_in(_id: params[:ids])
@activities.each do |activity|
activity.is_hidden = params[:disable]
activity.save
end
end
render json: {"success"=>true}
end
def setting
end
def frontend_setting
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@intro = ActivityIntro.find_by(:member_profile_id=>@member.id) rescue nil
@intro = @intro.nil? ? ActivityIntro.new({:member_profile_id=>@member.id}) : @intro
end
def update_frontend_setting
@member = MemberProfile.find(intro_params['member_profile_id']) rescue nil
@intro = ActivityIntro.find_by(:member_profile_id=>@member.id) rescue nil
@intro = @intro.nil? ? ActivityIntro.new({:member_profile_id=>@member.id}) : @intro
@intro.update_attributes(intro_params)
@intro.save
redirect_to URI.encode('/admin/members/'+@member.to_param+'/activity')
end
def get_settings
end
def set_plugin
@plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'Activity'}.first
@module_app = ModuleApp.where(:key=>'personal_activity').first
@module_app = ModuleApp.create(:key=>'personal_activity',:title=>'PersonalActivity','frontend_enable'=>true) if @module_app.nil?
@categories = @module_app.categories
end
private private
def set_activity def set_activity
@ -122,4 +197,8 @@ class Admin::ActivitiesController < OrbitMemberController
def activity_params def activity_params
params.require(:activity).permit! rescue nil params.require(:activity).permit! rescue nil
end end
def intro_params
params.require(:activity_intro).permit! rescue nil
end
end end

View File

@ -4,8 +4,9 @@ class Activity
#include Mongoid::Attributes::Dynamic #include Mongoid::Attributes::Dynamic
#include Admin::PersonalActivitiesHelper #include Admin::PersonalActivitiesHelper
include OrbitModel::Status include OrbitModel::Status
include MemberHelper #include MemberHelper
include Slug include Slug
include OrbitCategory::Categorizable
belongs_to :member_profile belongs_to :member_profile
# Language # Language
@ -18,11 +19,12 @@ class Activity
field :activity_start_date, type: DateTime field :activity_start_date, type: DateTime
field :activity_end_date, type: DateTime field :activity_end_date, type: DateTime
field :note, type: String field :note, type: String
field :url
# paginates_per 10 # paginates_per 10
has_many :activity_files, :autosave => true, :dependent => :destroy has_many :activity_files, :autosave => true, :dependent => :destroy
belongs_to :activity_category #belongs_to :activity_category
accepts_nested_attributes_for :activity_files, :allow_destroy => true accepts_nested_attributes_for :activity_files, :allow_destroy => true
before_validation :add_http before_validation :add_http
@ -52,7 +54,7 @@ class Activity
pd_title = [] pd_title = []
fields_to_show.each do |t| fields_to_show.each do |t|
if (self.fields[t].type.to_s == "String" || self.fields[t].type.to_s == "Object" rescue false) if (self.fields[t].type.to_s == "String" rescue false)
fields_to_remove << t if (datas.where(t.to_sym.ne => nil, t.to_sym.ne => "").count == 0 rescue false) fields_to_remove << t if (datas.where(t.to_sym.ne => nil, t.to_sym.ne => "").count == 0 rescue false)
else else
fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false) fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false)
@ -64,25 +66,20 @@ class Activity
fields_to_show = fields_to_show - fields_to_remove fields_to_show = fields_to_show - fields_to_remove
plugin_datas = datas.sort_for_frontend.collect.with_index do |p, index| plugin_datas = datas.sort_for_frontend.collect do |p|
pd_data = [] pd_data = []
fields_to_show.collect do |t| fields_to_show.collect do |t|
if t == "activity_title" if t == "activity_title"
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_activity')}' title='#{p.send(t)}'>#{p.send(t)}" } pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_activity')}' title='#{p.send(t)}'>#{p.send(t)}" }
elsif t == "activity_category"
pd_data << {"data_title" => (p.activity_category.title rescue "")}
else else
pd_data << { "data_title" => p.send(t) } pd_data << { "data_title" => p.send(t) }
end end
end end
{ {
"pd_datas" => pd_data, "pd_datas" => pd_data
"type-sort" => (p.activity_category.sort_position.to_i rescue -1),
"sort-index" => index
} }
end end
plugin_datas = plugin_datas.sort_by{|pd| [pd["type-sort"], pd["sort-index"]]}
return [pd_title,plugin_datas] return [pd_title,plugin_datas]
end end

View File

@ -0,0 +1,10 @@
class ActivityFile
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, AssetUploader
field :description, localize: true
field :should_destroy, :type => Boolean
field :title, localize: true
belongs_to :activity
end

View File

@ -0,0 +1,2 @@
class ActivityIntro < PersonalPluginIntro
end

View File

@ -18,7 +18,7 @@ zh_tw:
description : "描述" description : "描述"
upload: "上傳" upload: "上傳"
frontend: frontend:
writings: "活動前台" activities: "活動前台"
create_success : "新增完成!!" create_success : "新增完成!!"
update_success : "更新完成!!" update_success : "更新完成!!"