personal-thesis-guidance/app/controllers/admin/thesis_guidance_papers_cont...

260 lines
7.6 KiB
Ruby

require 'rubyXL'
class Admin::ThesisGuidancePapersController < OrbitMemberController
include Admin::ThesisGuidancePapersHelper
layout "member_plugin"
before_action :set_thesis_guidance_paper, 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]
def merge_process
params['journal_id'].each do |journal_id|
journal_ids = journal_id.split('/')
journals = ThesisGuidancePaper.find(journal_ids)
member_ids = journals.collect(&:member_profile_id).uniq
journals.each_with_index do |journal,index1|
if index1== 0
journal.member_profile_id = member_ids
journal.save!
else
journal.delete
end
end
end
redirect_to :action=> 'index'
end
def merge
@journals=ThesisGuidancePaper.sort_year_date.map{|value| value}.group_by{|v| [v[:paper_title],v[:journal_title]]}
@journals.each do |key,value|
if value.length<=1
@journals.delete key
end
end
if params['mode']!='simple'
@journals.each do |key,value|
@journals[key] = value.group_by{|v| [get_level_type(v),get_author_type(v),get_paper_type(v),get_publication_date(v)]}
@journals[key].each do |key1,value1|
if value1.length<=1
@journals[key].delete key1
end
end
if @journals[key].length==0
@journals.delete key
end
end
end
end
def index
@writing_thesis_guidances = ThesisGuidancePaper.sort_year_date
if params[:keywords]
@writing_thesis_guidances = search_data(@writing_thesis_guidances,[:slug_title])
end
@writing_thesis_guidances = @writing_thesis_guidances.page(params[:page]).per(10)
if request.xhr?
render "index_js", :layout => false
end
end
def new
@member = Array(MemberProfile.find_by(:uid=>params['uid'].to_s)) rescue nil
@thesis_guidance_paper = ThesisGuidancePaper.new
if params[:desktop]
render :layout => false
end
end
def analysis
end
def analysis_report
role = params[:role_id]
year_start = params[:year_start].to_i
year_end = params[:year_end].to_i
graph_by = params[:graph_by]
@data = get_chart_data(year_start,year_end,role,params[:graph_by])
render :layout => false
end
def download_excel
year_start = params[:year_start].to_i
year_end = params[:year_end].to_i
@data = get_data_for_excel(year_start,year_end)
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="thesis_guidance_papers.xlsx"'
}
end
end
def create
if !thesis_guidance_paper_params['member_profile_id'].blank?
@member = MemberProfile.find(thesis_guidance_paper_params['member_profile_id']) rescue nil
@thesis_guidance_paper = ThesisGuidancePaper.new(thesis_guidance_paper_params)
@thesis_guidance_paper.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|
thesis_guidance_paper_params['member_profile_id'] = params[:author_members]
@thesis_guidance_paper = ThesisGuidancePaper.new(thesis_guidance_paper_params)
@thesis_guidance_paper.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
end
#end
redirect_to params['referer_url']
else
thesis_guidance_paper_params['member_profile_id'] = User.find(current_user.id).member_profile_id
@thesis_guidance_paper = ThesisGuidancePaper.new(thesis_guidance_paper_params)
@thesis_guidance_paper.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
end
redirect_to params['referer_url']
end
end
def edit
@member = get_member(@thesis_guidance_paper)
if params[:desktop]
render :layout => false
end
end
def update
@member = get_member(@thesis_guidance_paper)
thesis_guidance_paper_params['member_profile_id'] = params[:author_members]
@thesis_guidance_paper.update_attributes(thesis_guidance_paper_params)
@thesis_guidance_paper.save
if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
else
redirect_to params['referer_url']
end
end
def destroy
@thesis_guidance_paper.destroy
respond_to do |format|
format.html { redirect_to(admin_thesis_guidance_papers_url) }
# format.xml { head :ok }
format.js
format.json {render json: {"success" => true}}
end
end
def excel_format
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="thesis_guidance_paper_format.xlsx"'
}
end
end
def import_from_excel
workbook = RubyXL::Parser.parse(params["import_file"].tempfile)
sheet = workbook[0]
if sheet.count <= 503
sheet.each_with_index do |row, i|
next if i < 3
user = User.where(:user_name => row.cells[0].value).first rescue nil
if !user.nil?
mp = user.member_profile
import_this_thesis_guidance_paper(row,mp)
end
end
redirect_to admin_thesis_guidance_papers_url
else
redirect_to admin_thesis_guidance_papers_url(:error => "1")
end
end
def toggle_hide
if params[:ids]
@thesis_guidance_papers = ThesisGuidancePaper.any_in(_id: params[:ids])
@thesis_guidance_papers.each do |thesis_guidance_paper|
thesis_guidance_paper.is_hidden = params[:disable]
thesis_guidance_paper.save
end
end
render json: {"success"=>true}
end
def setting
end
def frontend_setting
@member = MemberProfile.find_by(:uid=>params['uid'].to_s) rescue nil
@intro = ThesisGuidancePaperIntro.find_by(:member_profile_id=>@member.id) rescue nil
@intro = @intro.nil? ? ThesisGuidancePaperIntro.new({:member_profile_id=>@member.id}) : @intro
end
def update_frontend_setting
@member = MemberProfile.find(intro_params['member_profile_id']) rescue nil
@intro = ThesisGuidancePaperIntro.find_by(:member_profile_id=>@member.id) rescue nil
@intro = @intro.nil? ? ThesisGuidancePaperIntro.new({:member_profile_id=>@member.id}) : @intro
@intro.update_attributes(intro_params)
@intro.save
redirect_to URI.encode('/admin/members/'+@member.to_param+'/ThesisGuidancePaper')
end
def get_settings
@thesis_guidance_levels = ThesisGuidanceLevel.all
@author_types = ThesisGuidancePaperAuthorType.all
@paper_types = ThesisGuidancePaperType.all
@thesis_guidance_types = ThesisGuidanceType.all
end
def set_plugin
@plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'ThesisGuidancePaper'}.first
end
private
def set_thesis_guidance_paper
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
@thesis_guidance_paper = ThesisGuidancePaper.find_by(:uid => uid) rescue ThesisGuidancePaper.find(params[:id])
end
def thesis_guidance_paper_params
params.require(:thesis_guidance_paper).permit! rescue nil
end
def intro_params
params.require(:thesis_guidance_paper_intro).permit! rescue nil
end
end