90 lines
2.2 KiB
Ruby
90 lines
2.2 KiB
Ruby
module Admin::PersonalPatentsHelper
|
|
|
|
def get_paper_list
|
|
user = current_user.nil? ? OrbitHelper.current_user : current_user
|
|
user_profile = user.member_profile
|
|
patents = Patent.where(:member_profile_id => user_profile.id)
|
|
patents = patents.collect do |p|
|
|
files = p.patent_files.collect do |pf|
|
|
{
|
|
"title" => pf.title,
|
|
"description" => pf.description,
|
|
"link" => pf.file.url,
|
|
"extension" => (pf.file.url.split(".").last rescue "")
|
|
}
|
|
end
|
|
{
|
|
"id" => p.id.to_s,
|
|
"edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/patents/#{p.to_param}/edit",
|
|
"delete_url" => "/#{I18n.locale.to_s}/admin/patents/#{p.id.to_s}",
|
|
"paper_title" => p.patent_title,
|
|
"keywords" => p.keywords,
|
|
"abstract" => [],
|
|
"files" => files
|
|
}
|
|
end
|
|
patents
|
|
end
|
|
|
|
def import_this_patent(row,mp)
|
|
value = nil
|
|
patent = Patent.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
|
|
patent.patent_title_translations = value
|
|
when 4
|
|
value = {"en" => val}
|
|
when 5
|
|
begin
|
|
value["zh_tw"] = val
|
|
rescue
|
|
value = {"zh_tw" => val}
|
|
end
|
|
patent.patent_country_translations = value
|
|
when 6
|
|
value = {"en" => val}
|
|
when 7
|
|
begin
|
|
value["zh_tw"] = val
|
|
rescue
|
|
value = {"zh_tw" => val}
|
|
end
|
|
patent.authors_translations = value
|
|
when 8
|
|
patent.year = val
|
|
when 9
|
|
patent.language = val
|
|
when 10
|
|
pts = PatentType.asc(:created_at).all.to_a
|
|
ts = val.to_s.split(",")
|
|
ts.each do |t|
|
|
patent.patent_type_ids << pts[t.to_i].id if t.to_s.is_i? && t.to_i < pts.count
|
|
end
|
|
when 11
|
|
patent.patent_no = val
|
|
when 12
|
|
patent.publish_date = val
|
|
when 13
|
|
patent.url = val
|
|
when 14
|
|
patent.keywords = val
|
|
when 15
|
|
patent.note = val
|
|
end
|
|
end
|
|
patent.member_profile = mp
|
|
patent.save
|
|
end
|
|
end |