fix data_count error
This commit is contained in:
parent
b845b3c835
commit
5a4b3088f9
|
@ -2,11 +2,12 @@ class Admin::ActivitiesController < OrbitMemberController
|
|||
layout "member_plugin"
|
||||
include Admin::PersonalActivitiesHelper
|
||||
|
||||
before_action :set_activity, only: [:edit, :update, :destroy]
|
||||
#before_action :set_plugin
|
||||
before_action :set_activity, only: [:show, :edit, :update, :destroy]
|
||||
before_action :set_plugin
|
||||
before_action :get_settings,:only => [:new, :edit, :setting]
|
||||
|
||||
#before_action :need_access_right
|
||||
#before_action :allow_admin_only, :only => [:index, :setting]
|
||||
before_action :need_access_right
|
||||
before_action :allow_admin_only, :only => [:index, :setting]
|
||||
|
||||
def index
|
||||
@activities = Activity.order_by(:year => 'desc').page(params[:page]).per(10)
|
||||
|
@ -27,23 +28,57 @@ class Admin::ActivitiesController < OrbitMemberController
|
|||
def create
|
||||
if !activity_params['member_profile_id'].blank?
|
||||
@member = MemberProfile.find(activity_params['member_profile_id']) rescue nil
|
||||
elsif !params[:author_members].blank?
|
||||
activity_params['member_profile_id'] = params[:author_members]
|
||||
else
|
||||
activity_params['member_profile_id'] = current_user.member_profile_id
|
||||
end
|
||||
@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?
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
def edit
|
||||
@member = @activity.member_profile rescue nil
|
||||
if params[:desktop]
|
||||
render :layout => false
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@member = @activity.member_profile rescue nil
|
||||
@activity.update_attributes(activity_params)
|
||||
@activity.save
|
||||
if params[:desktop] == "true"
|
||||
render json: {"data" => get_paper_list}.to_json
|
||||
else
|
||||
redirect_to params['referer_url']
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@activity.destroy
|
||||
|
@ -54,6 +89,7 @@ class Admin::ActivitiesController < OrbitMemberController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def analysis
|
||||
end
|
||||
|
||||
|
@ -105,6 +141,45 @@ class Admin::ActivitiesController < OrbitMemberController
|
|||
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
|
||||
|
||||
def set_activity
|
||||
|
@ -122,4 +197,8 @@ class Admin::ActivitiesController < OrbitMemberController
|
|||
def activity_params
|
||||
params.require(:activity).permit! rescue nil
|
||||
end
|
||||
|
||||
def intro_params
|
||||
params.require(:activity_intro).permit! rescue nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,8 +4,9 @@ class Activity
|
|||
#include Mongoid::Attributes::Dynamic
|
||||
#include Admin::PersonalActivitiesHelper
|
||||
include OrbitModel::Status
|
||||
include MemberHelper
|
||||
#include MemberHelper
|
||||
include Slug
|
||||
include OrbitCategory::Categorizable
|
||||
belongs_to :member_profile
|
||||
|
||||
# Language
|
||||
|
@ -18,11 +19,12 @@ class Activity
|
|||
field :activity_start_date, type: DateTime
|
||||
field :activity_end_date, type: DateTime
|
||||
field :note, type: String
|
||||
field :url
|
||||
|
||||
# paginates_per 10
|
||||
|
||||
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
|
||||
before_validation :add_http
|
||||
|
@ -52,7 +54,7 @@ class Activity
|
|||
pd_title = []
|
||||
|
||||
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)
|
||||
else
|
||||
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
|
||||
|
||||
plugin_datas = datas.sort_for_frontend.collect.with_index do |p, index|
|
||||
plugin_datas = datas.sort_for_frontend.collect do |p|
|
||||
|
||||
pd_data = []
|
||||
fields_to_show.collect do |t|
|
||||
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)}" }
|
||||
elsif t == "activity_category"
|
||||
pd_data << {"data_title" => (p.activity_category.title rescue "")}
|
||||
else
|
||||
pd_data << { "data_title" => p.send(t) }
|
||||
end
|
||||
end
|
||||
{
|
||||
"pd_datas" => pd_data,
|
||||
"type-sort" => (p.activity_category.sort_position.to_i rescue -1),
|
||||
"sort-index" => index
|
||||
"pd_datas" => pd_data
|
||||
}
|
||||
end
|
||||
plugin_datas = plugin_datas.sort_by{|pd| [pd["type-sort"], pd["sort-index"]]}
|
||||
return [pd_title,plugin_datas]
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
|||
class ActivityIntro < PersonalPluginIntro
|
||||
end
|
|
@ -18,7 +18,7 @@ zh_tw:
|
|||
description : "描述"
|
||||
upload: "上傳"
|
||||
frontend:
|
||||
writings: "活動前台"
|
||||
activities: "活動前台"
|
||||
|
||||
create_success : "新增完成!!"
|
||||
update_success : "更新完成!!"
|
||||
|
|
Loading…
Reference in New Issue