2014-12-05 07:03:30 +00:00
|
|
|
module Admin::PersonalLabsHelper
|
|
|
|
|
|
|
|
def get_paper_list
|
|
|
|
user = current_user.nil? ? OrbitHelper.current_user : current_user
|
|
|
|
user_profile = user.member_profile
|
|
|
|
labs = Lab.where(:member_profile_id => user_profile.id)
|
|
|
|
labs = labs.collect do |l|
|
|
|
|
files = l.lab_files.collect do |lf|
|
|
|
|
{
|
|
|
|
"title" => lf.title,
|
|
|
|
"description" => lf.description,
|
|
|
|
"link" => lf.file.url,
|
|
|
|
"extension" => (lf.file.url.split(".").last rescue "")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"id" => l.id.to_s,
|
|
|
|
"edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/labs/#{l.to_param}/edit",
|
|
|
|
"delete_url" => "/#{I18n.locale.to_s}/admin/labs/#{l.id.to_s}",
|
|
|
|
"paper_title" => l.lab_title,
|
|
|
|
"keywords" => l.keywords,
|
|
|
|
"files" => files
|
|
|
|
}
|
|
|
|
end
|
|
|
|
labs
|
|
|
|
end
|
2016-02-24 06:55:38 +00:00
|
|
|
|
|
|
|
def import_this_lab(row, mp)
|
|
|
|
value = nil
|
|
|
|
lab = Lab.new
|
|
|
|
row.cells.each_with_index do |cell,index|
|
|
|
|
next if index < 2
|
|
|
|
next if cell.nil?
|
|
|
|
val = cell.value
|
|
|
|
next if val.nil? || val == ""
|
|
|
|
case index
|
|
|
|
when 2
|
|
|
|
value = {"en" => val}
|
|
|
|
when 3
|
|
|
|
begin
|
|
|
|
value["zh_tw"] = val
|
|
|
|
rescue
|
|
|
|
value = {"zh_tw" => val}
|
|
|
|
end
|
|
|
|
lab.lab_title_translations = value
|
|
|
|
when 4
|
|
|
|
value = {"en" => val}
|
|
|
|
when 5
|
|
|
|
begin
|
|
|
|
value["zh_tw"] = val
|
|
|
|
rescue
|
|
|
|
value = {"zh_tw" => val}
|
|
|
|
end
|
|
|
|
lab.location_translations = value
|
|
|
|
when 6
|
|
|
|
value = {"en" => val}
|
|
|
|
when 7
|
|
|
|
begin
|
|
|
|
value["zh_tw"] = val
|
|
|
|
rescue
|
|
|
|
value = {"zh_tw" => val}
|
|
|
|
end
|
|
|
|
lab.participating_professor_translations = value
|
|
|
|
when 8
|
|
|
|
value = {"en" => val}
|
|
|
|
when 9
|
|
|
|
begin
|
|
|
|
value["zh_tw"] = val
|
|
|
|
rescue
|
|
|
|
value = {"zh_tw" => val}
|
|
|
|
end
|
|
|
|
lab.participating_student_translations = value
|
|
|
|
when 10
|
|
|
|
lab.year = val
|
|
|
|
when 11
|
|
|
|
lab.extension_no = val
|
|
|
|
when 12
|
|
|
|
lab.research_direction = val
|
|
|
|
when 13
|
|
|
|
lab.facility = val
|
|
|
|
when 14
|
|
|
|
lab.url = val
|
|
|
|
when 15
|
|
|
|
lab.keywords = val
|
|
|
|
when 16
|
|
|
|
lab.note = val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
lab.member_profile = mp
|
|
|
|
lab.save
|
|
|
|
end
|
2020-03-01 03:43:51 +00:00
|
|
|
def get_data_for_excel(year_start,year_end)
|
|
|
|
data = []
|
|
|
|
roles = Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key)
|
|
|
|
roles.each do |role|
|
|
|
|
d = {}
|
|
|
|
d["name"] = role.title
|
|
|
|
mps = role.member_profile_ids
|
|
|
|
# d1 = DateTime.new(year_start,1,1,0,0)
|
|
|
|
# d2 = DateTime.new(year_end,12,31,23,59)
|
|
|
|
d["data"] = Lab.where(:year.gte => year_start.to_s, :year.lte => year_end.to_s, :member_profile_id.in => mps) rescue []
|
|
|
|
data << d
|
|
|
|
end
|
|
|
|
return data
|
|
|
|
end
|
|
|
|
def get_chart_data(year_start,year_end,role,type)
|
|
|
|
case type
|
|
|
|
when "category"
|
|
|
|
jls = ResearchCategory.all
|
|
|
|
end
|
2016-02-24 06:55:38 +00:00
|
|
|
|
2020-03-01 03:43:51 +00:00
|
|
|
finaldata = []
|
|
|
|
role = Role.find(role) rescue nil
|
|
|
|
mps = []
|
|
|
|
if !role.nil?
|
|
|
|
mps = role.member_profile_ids
|
|
|
|
end
|
|
|
|
jls.each do |jl|
|
|
|
|
data = {}
|
|
|
|
data["name"] = jl.title
|
|
|
|
data["data"] = {}
|
|
|
|
(year_start..year_end).each do |year|
|
|
|
|
# d1 = DateTime.new(year,1,1,0,0)
|
|
|
|
# d2 = DateTime.new(year,12,31,23,59)
|
|
|
|
t = jl.researches.where(:year => year.to_s, :member_profile_id.in => mps).count rescue 0
|
|
|
|
data["data"][year.to_s] = t
|
|
|
|
end
|
|
|
|
finaldata << data
|
|
|
|
end
|
|
|
|
data = {"name" => "N/A", "data" => {}}
|
|
|
|
(year_start..year_end).each do |year|
|
|
|
|
# d1 = DateTime.new(year,1,1,0,0)
|
|
|
|
# d2 = DateTime.new(year,12,31,23,59)
|
|
|
|
case type
|
|
|
|
when "category"
|
|
|
|
t = Lab.where(:year => year, :member_profile_id.in => mps, :project_type_id => nil).count rescue 0
|
|
|
|
end
|
|
|
|
|
|
|
|
data["data"][year.to_s] = t
|
|
|
|
end
|
|
|
|
finaldata << data
|
|
|
|
finaldata
|
|
|
|
end
|
2014-12-05 07:03:30 +00:00
|
|
|
end
|