memberlog/app/controllers/admin/memberlogs_controller.rb

82 lines
1.8 KiB
Ruby
Raw Normal View History

2017-02-13 17:27:57 +00:00
class Admin::MemberlogsController < OrbitMemberController
before_action :set_memberlog, only: [:show, :edit , :update, :destroy]
before_action :set_plugin
layout "member_plugin"
include Admin::MemberlogsHelper
def index
@dayoffs = Dayoff.all
@now = Time.now.to_date
2017-03-27 02:44:36 +00:00
# @ch = ["一","二","三","四","五","六","日"]
2017-02-13 17:27:57 +00:00
@memberlogs = MemberLog.all.order_by(:created_at=>'desc').page(params[:page]).per(10)
end
def new
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@memberlog = MemberLog.new
end
def create
# render :text =>"#{params[:member_log]}"
memberlog = MemberLog.create(memberlog_params)
redirect_to params[:referer_url]
end
def show
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
render :layout => false
end
def edit
end
def update
@memberlog.update_attributes(memberlog_params)
@memberlog.save
redirect_to params[:referer_url]
end
def destroy
@memberlog.destroy
redirect_to admin_memberlogs_path(:page => params[:page])
end
def toggle_hide
if params[:ids]
@projects = Member.any_in(_id: params[:ids])
@projects.each do |project|
project.is_hidden = params[:disable]
project.save
end
end
render json: {"success"=>true}
end
private
def memberlog_params
p = params.require(:member_log).permit!
p[:checkout] = Time.now if p[:finish].present?
p
end
def set_memberlog
path = request.path.split('/')
if path.last.include? '-'
uid = path[-1].split("-").last
uid = uid.split("?").first
else
uid = path[-2].split("-").last
uid = uid.split("?").first
end
@memberlog = MemberLog.find_by(:uid => uid) rescue MemberLog.find(params[:id])
end
def set_plugin
@plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'MemberLog'}.first
end
end