first commit

This commit is contained in:
rulingcom 2023-05-26 22:17:05 +08:00
commit 0d5fb4f05c
94 changed files with 2571 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
.bundle/
log/*.log
pkg/
test/dummy/db/*.sqlite3
test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache

14
Gemfile Normal file
View File

@ -0,0 +1,14 @@
source "https://rubygems.org"
# Declare your gem's dependencies in personal_course.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
# To use debugger
# gem 'debugger'

20
MIT-LICENSE Normal file
View File

@ -0,0 +1,20 @@
Copyright 2022 YOURNAME
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3
README.rdoc Normal file
View File

@ -0,0 +1,3 @@
= PersonalAsiaDatabase
This project rocks and uses MIT-LICENSE.

34
Rakefile Normal file
View File

@ -0,0 +1,34 @@
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'PersonalAsiaDatabase'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
Bundler::GemHelper.install_tasks
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
task default: :test

View File

@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .

View File

@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/

View File

@ -0,0 +1,82 @@
class Admin::AsiaDatabasesController < OrbitAdminController
def index
@asia_academies = AsiaAcademy.all.page(params[:page]).per(10)
end
def render_404
render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found, :content_type => 'text/html'
end
def show
begin
uid = params[:id].split('-').last
@asia_academy = AsiaAcademy.find_by(:uid=>uid)
@asia_departs = @asia_academy.asia_departments.page(params[:page]).per(10)
rescue
render_404
end
end
def asia_teachers
begin
uid = params[:id].split('-').last
@asia_depart = AsiaDepartment.find_by(:uid=>uid)
@asia_academy = @asia_depart.asia_academy
@asia_teachers = @asia_depart.asia_teachers.page(params[:page]).per(10)
rescue
render_404
end
end
def asia_projects
begin
uid = params[:id].split('-').last
@asia_teacher = AsiaTeacher.find_by(:uid=>uid)
@asia_depart = @asia_teacher.asia_department
@asia_academy = @asia_teacher.asia_academy
@asia_projects = @asia_teacher.asia_projects.page(params[:page]).per(10)
rescue
render_404
end
end
def asia_papers
begin
uid = params[:id].split('-').last
@asia_teacher = AsiaTeacher.find_by(:uid=>uid)
@asia_depart = @asia_teacher.asia_department
@asia_academy = @asia_teacher.asia_academy
@asia_papers = @asia_teacher.asia_papers.page(params[:page]).per(10)
rescue
render_404
end
end
def asia_patents
begin
uid = params[:id].split('-').last
@asia_teacher = AsiaTeacher.find_by(:uid=>uid)
@asia_depart = @asia_teacher.asia_department
@asia_academy = @asia_teacher.asia_academy
@asia_patents = @asia_teacher.asia_patents.page(params[:page]).per(10)
rescue
render_404
end
end
def asia_tec_transfers
begin
uid = params[:id].split('-').last
@asia_teacher = AsiaTeacher.find_by(:uid=>uid)
@asia_depart = @asia_teacher.asia_department
@asia_academy = @asia_teacher.asia_academy
@asia_tec_transfers = @asia_teacher.asia_tec_transfers.page(params[:page]).per(10)
rescue
render_404
end
end
def asia_exhibitions
begin
uid = params[:id].split('-').last
@asia_teacher = AsiaTeacher.find_by(:uid=>uid)
@asia_depart = @asia_teacher.asia_department
@asia_academy = @asia_teacher.asia_academy
@asia_exhibitions = @asia_teacher.asia_exhibitions.page(params[:page]).per(10)
rescue
render_404
end
end
end

View File

@ -0,0 +1,406 @@
class AsiaDatabasesController < ApplicationController
include Admin::AsiaTeachersHelper
ExtraFields = {
'discipline_expertise'=> ['discipline_expertise'],
'project'=> ['project_name', 'start_date', 'sponsor'],
'paper'=> ['paper_name', 'issue_year', 'journal_name'],
'patent'=> ['patent_name', 'certification_date', 'patent_country'],
'tec_transfer'=> ['tech_transfer_name', 'start_date', 'receiving_unit'],
'exhibition'=> ['exhibition_name', 'exhibition_date', 'host']
}
def render_404
render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found, :content_type => 'text/html'
end
def get_data(params, for_frontend=false)
# choice unit
choice_unit = []
selected_unit = params[:unit]
selected_academy = nil
if selected_unit == 'all'
choice_unit << {"choice_value"=> 'all', "choice_show"=> 'All', 'choice_select'=> 'selected'}
AsiaAcademy.all.each do |academy|
choice_unit << {"choice_value"=> academy.uid, "choice_show"=> academy.academy_name, 'choice_select'=>''}
end
else
choice_unit << {"choice_value"=> 'all', "choice_show"=> 'All', 'choice_select'=> ''}
AsiaAcademy.all.each do |academy|
uid = academy.uid
if uid == selected_unit
selected_academy = academy
choice_select = 'selected'
else
choice_select = ''
end
choice_unit << {"choice_value"=> uid, "choice_show"=> academy.academy_name, 'choice_select'=> choice_select}
end
end
# choice field
choice_field = [{'choice_show'=> t('asia_database.extend_translate.select_field'), 'choice_value' => 'default', 'choice_select' => ''}]
fields_to_select = ["discipline_expertise", "project", "paper", "patent", "tec_transfer", "exhibition"]
fields_to_select.each do |fs|
choice_field << {'choice_show'=> t("asia_database.extend_translate.#{fs}"), 'choice_value' => fs, 'choice_select' => ''}
end
selected_field_int = 0
selected_field = fields_to_select[0]
choice_field.each_with_index do |h, i|
field_name = h['choice_value']
if field_name == params[:field]
h['choice_select'] = 'selected'
if field_name == 'default'
selected_field_int = 0
else
selected_field = field_name
selected_field_int = i - 1
end
break
end
end
fields_to_show = ['academy', 'department', 'teacher']
if selected_field_int == 0
fields_to_show += ExtraFields[selected_field]
table_headers = fields_to_show.map do |fs|
{
'head-title' => t("asia_database.#{fs}"),
'col' => (fs == 'teacher' ? 3 : 2)
}
end
else
table_headers = fields_to_show.map do |fs|
{
'head-title' => t("asia_database.#{fs}"),
'col' => (fs == 'teacher' ? 3 : 2)
}
end
fields_to_show = fields_to_show.map{|fs| "asia_teacher.#{fs}"}
extra_fields = ExtraFields[selected_field]
fields_to_show += extra_fields
table_headers += extra_fields.map do |fs|
{
'head-title' => t("asia_database.asia_#{selected_field}.#{fs}"),
'col' => 2
}
end
end
search_field = nil
if selected_field_int == 0 #Discipline Expertise
if selected_academy
asia_data = selected_academy.asia_teachers
else
asia_data = AsiaTeacher.all
end
search_field = 'discipline_expertise'
elsif selected_field_int == 1 #Project
if selected_academy
asia_data = AsiaProject.where(:asia_teacher_id.in=>selected_academy.asia_teacher_ids)
else
asia_data = AsiaProject.all
end
search_field = 'project_name'
elsif selected_field_int == 2 #Paper
if selected_academy
asia_data = AsiaPaper.where(:asia_teacher_id.in=>selected_academy.asia_teacher_ids)
else
asia_data = AsiaPaper.all
end
search_field = 'paper_name'
elsif selected_field_int == 3 #Patent
if selected_academy
asia_data = AsiaPatent.where(:asia_teacher_id.in=>selected_academy.asia_teacher_ids)
else
asia_data = AsiaPatent.all
end
search_field = 'patent_name'
elsif selected_field_int == 4 #Technology Transfer
if selected_academy
asia_data = AsiaTecTransfer.where(:asia_teacher_id.in=>selected_academy.asia_teacher_ids)
else
asia_data = AsiaTecTransfer.all
end
search_field = 'tech_transfer_name'
elsif selected_field_int == 5 #Exhibition
if selected_academy
asia_data = AsiaExhibition.where(:asia_teacher_id.in=>selected_academy.asia_teacher_ids)
else
asia_data = AsiaExhibition.all
end
search_field = 'exhibition_name'
end
asia_data = asia_data.sort_order
if params[:keywords].present?
asia_data = filter_keywords(asia_data,search_field,params[:keywords])
end
if for_frontend
asia_data = asia_data.page(params[:page_no]).per(OrbitHelper.page_data_count)
end
if for_frontend
asia_data_list = asia_data.collect do |asia_record|
{'jps' => fields_to_show.map{|field| {"value"=> get_display_field(asia_record,field)}}}
end
else
all_count = asia_data.count
store_record_id = @store_record.id
asia_data_list = asia_data.collect.with_index do |asia_record, i|
AsiaExportStore.where(:id=>store_record_id).update_all(:finish_percent=> ((i + 1) * 100.0 / all_count).round(1))
fields_to_show.map{|field| get_raw_field(asia_record, field)}
end
end
return asia_data_list, asia_data, table_headers, choice_unit, choice_field
end
def index
params = OrbitHelper.params
# page = OrbitHelper.page rescue Page.where(page_id: params[:page_id]).first
asia_data_list, asia_data, table_headers, choice_unit, choice_field = get_data(params, true)
download_excel_text = t('asia_database.extend_translate.download_excel')
select_field_text = t('asia_database.extend_translate.search_field')
select_text = t('asia_database.extend_translate.search_class')
search_text = t('asia_database.extend_translate.word_to_search')
@_request = OrbitHelper.request
csrf_value = form_authenticity_token
extras = {} #{"th-academy" => I18n.t("asia_database.academy"), "th-department" => I18n.t("asia_database.department"), "th-teacher" => I18n.t("asia_database.teacher"), "th-discipline_expertise" => I18n.t("asia_database.discipline_expertise"), "th-asia_project.project_name" => I18n.t("asia_database.asia_project.project_name"), "th-asia_project.start_date" => I18n.t("asia_database.asia_project.start_date"), "th-asia_project.sponsor" => I18n.t("asia_database.asia_project.sponsor"), "th-asia_paper.paper_name" => I18n.t("asia_database.asia_paper.paper_name"), "th-asia_paper.issue_year" => I18n.t("asia_database.asia_paper.issue_year"), "th-asia_paper.journal_name" => I18n.t("asia_database.asia_paper.journal_name"), "th-asia_patent.patent_name" => I18n.t("asia_database.asia_patent.patent_name"), "th-asia_patent.certification_date" => I18n.t("asia_database.asia_patent.certification_date"), "th-asia_patent.patent_country" => I18n.t("asia_database.asia_patent.patent_country"), "th-asia_tec_transfer.tech_transfer_name" => I18n.t("asia_database.asia_tec_transfer.tech_transfer_name"), "th-asia_tec_transfer.start_date" => I18n.t("asia_database.asia_tec_transfer.start_date"), "th-asia_tec_transfer.receiving_unit" => I18n.t("asia_database.asia_tec_transfer.receiving_unit"), "th-asia_exhibition.exhibition_name" => I18n.t("asia_database.asia_exhibition.exhibition_name"), "th-asia_exhibition.exhibition_date" => I18n.t("asia_database.asia_exhibition.exhibition_date"), "th-asia_exhibition.host" => I18n.t("asia_database.asia_exhibition.host")}
tmp_id = Time.now.to_i.to_s + '-' + csrf_value.gsub(/[\n\/]/, '')
extras = extras.merge({ 'url' => '/' + I18n.locale.to_s + params[:url],
'download_url' => "/xhr/asia_database/download_excel?tmp_id=#{tmp_id}",
'export_url' => '/xhr/asia_database/export_excel',
'check_url' => "/xhr/asia_database/get_store_status?tmp_id=#{tmp_id}",
'download_excel_text' => download_excel_text,
'select_field_text' => select_field_text,
'select_text' => select_text,
'search_text' => search_text,
'search_value' => params[:keywords].to_s.gsub(/\"/,''),
'search_trans' => t('asia_database.extend_translate.search'),
'unit_trans' => t('asia_database.extend_translate.unit'),
'csrf_value' => csrf_value,
'tmp_id' => tmp_id
})
extras["widget-title"] = I18n.t("module_name.asia_database")
{
"asia_databases" => asia_data_list,
"headers" => table_headers,
"extras" => extras,
"total_pages" => asia_data.total_pages,
'choice_unit' => choice_unit,
'choice_field' => choice_field
}
end
def export_excel
tmp_id = params['tmp_id']
if tmp_id.blank?
render(:nothing => true) and return
end
AsiaExportStore.where(:tmp_id.ne=>tmp_id, :updated_at.lte=> Time.now.to_i - 3600 * 24).destroy
filter_str = params.except('action', 'controller', 'tmp_id').to_query
@store_record = AsiaExportStore.any_of([{:tmp_id=>tmp_id}, {:filter_str=>filter_str}]).first
if @store_record.nil?
@store_record = AsiaExportStore.new(:tmp_id=>tmp_id)
else
if @store_record.filter_str == filter_str
render :json => {success: true} and return
end
@store_record.reinit
end
@store_record.filter_str = filter_str
@store_record.save
Thread.new do
begin
@asia_data_list, asia_data, @table_headers, choice_unit, choice_field = get_data(params)
store_record_id = @store_record.id
AsiaExportStore.where(:id=>store_record_id).update_all(:status=>1)
@excel_title = I18n.t("module_name.asia_database")
excel_contents = render_to_string( handlers: [:axlsx], formats: [:xlsx] ,partial: 'export_excel.xlsx',locals: {:@asia_data_list=> @asia_data_list, :@table_headers=> @table_headers, :@excel_title=> @excel_title} )
File.open(@store_record.file_path, 'w') do |f|
f.write excel_contents
end
AsiaExportStore.where(:id=>store_record_id).update_all(:status=>2)
rescue => e
puts [e.to_s, e.backtrace]
end
end
render :json => {success: true}
end
def download_excel
tmp_id = params['tmp_id']
@store_record = AsiaExportStore.where(:tmp_id=>tmp_id).first
if @store_record.nil? || @store_record.status != 2
render_404
else
send_file(@store_record.file_path,:filename=>'export_excel.xlsx')
end
end
def get_store_status
tmp_id = params['tmp_id']
@store_record = AsiaExportStore.where(:tmp_id=>tmp_id).first
if @store_record.nil?
render :json => {:finish_percent=> 0, :status=> 0}
else
render :json => {:finish_percent=> @store_record.finish_percent, :status=> @store_record.status}
end
end
def show
params = OrbitHelper.params
plugin = AsiaTeacher.where(:is_hidden=>false).find_by(uid: params[:uid].to_s)
fields_to_show = ["academy", "department", "teacher", "discipline_expertise", "asia_project.project_name", "asia_project.start_date", "asia_project.sponsor", "asia_paper.paper_name", "asia_paper.issue_year", "asia_paper.journal_name", "asia_patent.patent_name", "asia_patent.certification_date", "asia_patent.patent_country", "asia_tec_transfer.tech_transfer_name", "asia_tec_transfer.start_date", "asia_tec_transfer.receiving_unit", "asia_exhibition.exhibition_name", "asia_exhibition.exhibition_date", "asia_exhibition.host"]
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
end
def get_raw_field(asia_teacher, field)
text_only = false
value = asia_teacher.send(field) rescue ""
if field.include?(".")
value = asia_teacher
field.split(".").each{|f| value = value.send(f) rescue nil}
end
if value.class == Array
value = value.join("\n")
end
return value
end
def get_display_field(asia_teacher,field)
text_only = false
value = asia_teacher.send(field) rescue ""
if field.include?(".")
value = asia_teacher
field.split(".").each do |f|
if f == 'teacher'
tmp_value = value.teacher
value = "<a class=\"teacher_url\" target=\"_blank\" href=\"#{value.url}\" title=\"#{tmp_value}\">#{tmp_value}</a>"
else
value = value.send(f) rescue nil
end
end
elsif field == 'teacher'
value = "<a class=\"teacher_url\" target=\"_blank\" href=\"#{asia_teacher.url}\" title=\"#{value}\">#{value}</a>"
end
if value.class == Array
tmp = '<ul>'
value.each do |v|
tmp += "<li>#{v}</li>"
end
tmp += '</ul>'
value = tmp
end
# file_fields = []
# link_fields = []
# member_fields = []
# if file_fields.include?(field)
# files = asia_teacher.send(field.pluralize)
# value = files.map do |file|
# url = file.file.url
# title = (file.title.blank? ? File.basename(file.file.path) : file.title)
# "<li><a href='#{url}'' target='_blank'>#{title}</li>"
# end
# value = value.join("")
# elsif link_fields.include?(field)
# links = asia_teacher.send(field.pluralize)
# value = links.map do |link|
# url = link.url
# title = (link.title.blank? ? url : link.title)
# "<li><a href='#{url}'' target='_blank'>#{title}</li>"
# end
# value = value.join("")
# elsif member_fields.include?(field)
# members = asia_teacher.send(field.pluralize)
# value = members.map{|m|
# path = OrbitHelper.url_to_plugin_show(m.to_param, 'member') rescue '#'
# ((text_only rescue false) ? m.name : "<a href='#{path}'>#{m.name}</a>")
# }
# join_text = (text_only rescue false) ? "," : "<br>"
# value = value.join(join_text)
# elsif field == "authors"
# value = get_authors_show(asia_teacher)
# end
# strftime_hash = {}
# if strftime_hash.keys.include?(field)
# value = value.strftime(strftime_hash[field]) rescue value
# end
# if field == "teacher"
# link = OrbitHelper.url_to_plugin_show(asia_teacher.to_param,'asia_database')
# tmp_title = value
# url_to_plugin_show_blank = OrbitHelper.instance_variable_get(:@url_to_plugin_show_blank)
# value = url_to_plugin_show_blank ? tmp_title : "<a href='#{link}' target='_blank' title='#{tmp_title}'>#{tmp_title}</a>"
# end
return value
end
def get_fields_for_index
@page = Page.find(params[:page_id]) rescue nil
@fields_to_show = ["sid", "academy", "department", "teacher", "url", "discipline_expertise", "asia_project.project_name", "asia_project.start_date", "asia_project.sponsor", "asia_paper.paper_name", "asia_paper.issue_year", "asia_paper.journal_name", "asia_patent.patent_name", "asia_patent.certification_date", "asia_patent.patent_country", "asia_tec_transfer.tech_transfer_name", "asia_tec_transfer.start_date", "asia_tec_transfer.receiving_unit", "asia_exhibition.exhibition_name", "asia_exhibition.exhibition_date", "asia_exhibition.host"]
@fields_to_show = @fields_to_show.map { |fs| [t("asia_database.#{fs}"), fs] }
if @page.present? && @page.custom_string_field == 'table'
@default_fields_to_show = ["academy", "department", "teacher", "discipline_expertise", "asia_project.project_name", "asia_project.start_date", "asia_project.sponsor", "asia_paper.paper_name", "asia_paper.issue_year", "asia_paper.journal_name", "asia_patent.patent_name", "asia_patent.certification_date", "asia_patent.patent_country", "asia_tec_transfer.tech_transfer_name", "asia_tec_transfer.start_date", "asia_tec_transfer.receiving_unit", "asia_exhibition.exhibition_name", "asia_exhibition.exhibition_date", "asia_exhibition.host"]
else
@default_fields_to_show = ["year", "teacher"]
end
render layout: false
end
def save_index_fields
page = Page.find(params[:page_id]) rescue nil
page.custom_array_field = params[:keys]
page.save
render json: { 'success' => true }.to_json
end
def filter_keywords(asia_data,select_field,keywords)
member_fields = []
file_fields = []
link_fields = []
if select_field == "default"
asia_data = asia_data.where(:slug_title=>/#{gsub_invalid_character(keywords)}/)
elsif select_field == "member_profile"
ms = MemberProfile.all.select{|m| m.name.include?(keywords)}
asia_data = asia_data.where(:member_profile_id.in=>ms.map{|m| m.id})
elsif member_fields.include?(select_field)
ms = MemberProfile.all.select{|m| m.name.include?(keywords)}
m_ids = ms.map{|m| m.id.to_s }
tmp_asia_data = asia_data.select{|p| (p.send("#{select_field.singularize}_ids") & m_ids).count != 0}
asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
elsif select_field.split(".").count > 1
relate_name = select_field.split(".").first
field_name = select_field.split(".").last.gsub(/^\$+/, '')
relate = relate_name.camelize.constantize
relate_ids = relate.where(field_name=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
asia_data = asia_data.where("#{relate_name.singularize}_id"=>{'$in'=>relate_ids})
elsif (asia_data.klass.fields[select_field].options[:type] == Date rescue false)
keywords = keywords.split(/[\/\-]/)
if keywords.count > 1
Date.parse(keywords.join("/"))
else
start_date = Date.parse(keywords[0] + "/1/1")
end_date = Date.parse(keywords[0] + "/12/31")
asia_data = asia_data.where(select_field=>{'$gte'=>start_date,'$lte'=>end_date})
end
elsif (asia_data.klass.fields[select_field].options[:type] == DateTime rescue false)
keywords = keywords.split(/[\/\-]/)
if keywords.count > 1
DateTime.parse(keywords.join("/"))
elsif keywords[0].include?(":")
tmp_asia_data = asia_data.select{|p| (p.send(select_field).strftime('%Y/%m/%d %H:%M').include?(keywords[0]) rescue false)}
asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
else
start_date = DateTime.parse(keywords[0] + "/1/1 00:00")
end_date = DateTime.parse(keywords[0] + "/12/31 23:59")
asia_data = asia_data.where(select_field=>{'$gte'=>start_date,'$lte'=>end_date})
end
elsif (asia_data.klass.fields[select_field].options[:type] == Integer rescue false)
tmp_asia_data = asia_data.select{|p| p.send(select_field).to_s.include?(keywords)}
asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
elsif file_fields.include?(select_field)
file_field = select_field.camelize.constantize
ids1 = file_field.where(:file=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
ids2 = file_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
ids = ids1 + ids2
tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0}
asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
elsif link_fields.include?(select_field)
link_field = select_field.camelize.constantize
ids1 = link_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
ids2 = link_field.where(:url=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
ids = ids1 + ids2
tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0}
asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
else
asia_data = asia_data.where(select_field=>/#{gsub_invalid_character(keywords)}/)
end
return asia_data
end
def gsub_invalid_character(text)
::Regexp.escape(text.to_s)
end
end

View File

@ -0,0 +1,5 @@
module Admin::AsiaDatabasesHelper
def thead_t(label)
"<th>#{I18n.t(label)}</th>".html_safe
end
end

View File

@ -0,0 +1,8 @@
class AsiaAcademy
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :academy_name, :type => String, :default => "", :localize => true, :as => :slug_title
has_many :asia_departments
has_many :asia_teachers
end

View File

@ -0,0 +1,8 @@
class AsiaDepartment
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :department_name, :type => String, :default => "", :localize => true, :as => :slug_title
belongs_to :asia_academy
has_many :asia_teachers
end

View File

@ -0,0 +1,20 @@
class AsiaExhibition
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :exhibition_name, :type => String, :default => "", :localize => true, :as => :slug_title
field :exhibition_start_date, :type => Date
field :exhibition_end_date, :type => Date
field :host, :type => String, :default => "", :localize => true
field :rss2_id
belongs_to :asia_teacher, index: true
scope :sort_order, ->{order({exhibition_start_date: -1})}
index({exhibition_start_date: -1}, { unique: false, background: true })
def exhibition_date
if self.exhibition_start_date.nil? && self.exhibition_end_date.nil?
""
else
"#{self.exhibition_start_date} ~ #{self.exhibition_end_date}"
end
end
end

View File

@ -0,0 +1,31 @@
class AsiaExportStore
require "fileutils"
include Mongoid::Document
include Mongoid::Timestamps
field :tmp_id, :type => String # for syncing
field :filter_str, :type => String
field :status, :type => Integer, :default => 0 # 0 => preparing, 1 => generating, 2 => finish
field :finish_percent, :type => Float, :default => 0
StoreDir = "tmp/asia_db_export"
index({filter_str: 1}, { unique: false, background: true })
index({tmp_id: -1}, { unique: false, background: true })
before_create do
FileUtils.mkdir_p(StoreDir)
FileUtils.rm(self.file_path, :force => true)
end
before_destroy do
FileUtils.rm(self.file_path, :force => true)
end
def file_path
"#{StoreDir}/#{tmp_id}.xlsx"
end
def reinit
FileUtils.mkdir_p(StoreDir)
FileUtils.rm(self.file_path, :force => true)
self.status = 0
self.finish_percent = 0.0
self.save
end
end

12
app/models/asia_paper.rb Normal file
View File

@ -0,0 +1,12 @@
class AsiaPaper
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :paper_name, :type => String, :default => "", :localize => true, :as => :slug_title
field :issue_year, :type => String
field :journal_name, :type => String, :default => "", :localize => true
field :rss2_id
belongs_to :asia_teacher, index: true
scope :sort_order, ->{order({issue_year: -1})}
index({issue_year: -1}, { unique: false, background: true })
end

21
app/models/asia_patent.rb Normal file
View File

@ -0,0 +1,21 @@
class AsiaPatent
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :patent_name, :type => String, :default => "", :localize => true, :as => :slug_title
field :patent_no, :type => String, :default => ""
field :certification_date, :type => Date
field :end_date, :type => Date
field :patent_country, :type => String, :default => "", :localize => true
field :rss2_id
belongs_to :asia_teacher, index: true
scope :sort_order, ->{order({certification_date: -1})}
index({certification_date: -1}, { unique: false, background: true })
def term_of_patent
if self.certification_date.nil? && self.end_date.nil?
""
else
"#{self.certification_date} ~ #{self.end_date}"
end
end
end

View File

@ -0,0 +1,21 @@
class AsiaProject
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :project_name, :type => String, :default => "", :localize => true, :as => :slug_title
field :start_date, :type => Date
field :end_date, :type => Date
field :sponsor, :type => String, :default => "", :localize => true
field :sort_position, type: Integer, default: 0
field :rss2_id
belongs_to :asia_teacher, index: true
scope :sort_order, ->{order({start_date: -1})}
index({start_date: -1}, { unique: false, background: true })
def date
if self.start_date.nil? && self.end_date.nil?
""
else
"#{self.start_date} ~ #{self.end_date}"
end
end
end

152
app/models/asia_teacher.rb Normal file
View File

@ -0,0 +1,152 @@
class AsiaTeacher
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :email_id # for syncing
field :ukey, :type => String
field :academy, :type => String, :default => "", :localize => true
field :department, :type => String, :default => "", :localize => true
field :teacher, :type => String, :default => "", :localize => true, :as => :slug_title
field :discipline_expertise, :type => Array, :default => [], :localize => true
field :authors, :type => String, :default => "", :localize => true
belongs_to :asia_academy, index: true
belongs_to :asia_department, index: true
has_many :asia_projects
has_many :asia_papers
has_many :asia_patents
has_many :asia_tec_transfers
has_many :asia_exhibitions
scope :sort_order, ->{order({ukey: 1})}
index({ukey: 1}, { unique: false, background: true })
before_save do
if self.asia_academy_id_changed?
self.academy_translations = self.asia_academy.academy_name_translations rescue ""
end
if self.asia_department_id_changed?
self.department_translations = self.asia_department.department_name_translations rescue ""
end
AsiaExportStore.destroy_all
end
def url
"https://webap.asia.edu.tw/TchEportfolio/#{self.email_id}"
end
def parse_time(time_str)
DateTime.parse("0000-01-01 " + time_str)
end
def get_plugin_data(fields_to_show)
plugin_datas = []
fields_to_show.each do |field|
plugin_data = self.get_plugin_field_data(field) rescue nil
next if plugin_data.blank? or plugin_data['value'].blank?
plugin_datas << plugin_data
end
plugin_datas
end
def get_plugin_field_data(field)
asia_teacher = self
value = asia_teacher.send(field) rescue ""
if field.include?(".")
value = asia_teacher
field.split(".").each{|f| value = value.send(f) rescue nil }
end
file_fields = []
link_fields = []
member_fields = []
if file_fields.include?(field)
files = asia_teacher.send(field.pluralize)
value = files.map do |file|
url = file.file.url
title = (file.title.blank? ? File.basename(file.file.path) : file.title)
"<li><a href='#{url}'' target='_blank'>#{title}</li>"
end
value = value.join("")
elsif link_fields.include?(field)
links = asia_teacher.send(field.pluralize)
value = links.map do |link|
url = link.url
title = (link.title.blank? ? url : link.title)
"<li><a href='#{url}'' target='_blank'>#{title}</li>"
end
value = value.join("")
elsif member_fields.include?(field)
members = asia_teacher.send(field.pluralize)
value = members.map{|m|
path = OrbitHelper.url_to_plugin_show(m.to_param, 'member') rescue '#'
((text_only rescue false) ? m.name : "<a href='#{path}'>#{m.name}</a>")
}
join_text = (text_only rescue false) ? "," : "<br>"
value = value.join(join_text)
elsif field == "member_profile" || field == "authors"
value = get_authors_show(asia_teacher)
end
strftime_hash = {}
if strftime_hash.keys.include?(field)
value = value.strftime(strftime_hash[field]) rescue value
end
value
value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "<a href='#{value}' target='blank'>#{value}</a>" : value
{
"key"=>field,
"title_class"=>"asia_teacher-#{field.gsub('_','-')}-field",
"value_class"=>"asia_teacher-#{field.gsub('_','-')}-value",
"title"=>I18n.t('asia_database.'+field),
"value"=>value
}
end
def display_field(field,text_only=false,title_is_paper_format=false)
asia_teacher = self
value = asia_teacher.send(field) rescue ""
if field.include?(".")
value = asia_teacher
field.split(".").each{|f| value = value.send(f) rescue nil }
end
file_fields = []
link_fields = []
member_fields = []
if file_fields.include?(field)
files = asia_teacher.send(field.pluralize)
value = files.map do |file|
url = file.file.url
title = (file.title.blank? ? File.basename(file.file.path) : file.title)
"<li><a href='#{url}'' target='_blank'>#{title}</li>"
end
value = value.join("")
elsif link_fields.include?(field)
links = asia_teacher.send(field.pluralize)
value = links.map do |link|
url = link.url
title = (link.title.blank? ? url : link.title)
"<li><a href='#{url}'' target='_blank'>#{title}</li>"
end
value = value.join("")
elsif member_fields.include?(field)
members = asia_teacher.send(field.pluralize)
value = members.map{|m|
path = OrbitHelper.url_to_plugin_show(m.to_param, 'member') rescue '#'
((text_only rescue false) ? m.name : "<a href='#{path}'>#{m.name}</a>")
}
join_text = (text_only rescue false) ? "," : "<br>"
value = value.join(join_text)
elsif field == "member_profile" || field == "authors"
value = get_authors_show(asia_teacher)
end
strftime_hash = {}
if strftime_hash.keys.include?(field)
value = value.strftime(strftime_hash[field]) rescue value
end
if field == "teacher"
link = OrbitHelper.url_to_plugin_show(asia_teacher.to_param,'asia_database')
tmp_title = value
url_to_plugin_show_blank = OrbitHelper.instance_variable_get(:@url_to_plugin_show_blank)
value = url_to_plugin_show_blank ? tmp_title : "<a href='#{link}' target='_blank' title='#{tmp_title}'>#{tmp_title}</a>"
end
value
end
end

View File

@ -0,0 +1,20 @@
class AsiaTecTransfer
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :tech_transfer_name, :type => String, :default => "", :localize => true, :as => :slug_title
field :start_date, :type => Date
field :end_date, :type => Date
field :receiving_unit, :type => String, :default => "", :localize => true
field :rss2_id
belongs_to :asia_teacher, index: true
scope :sort_order, ->{order({start_date: -1})}
index({start_date: -1}, { unique: false, background: true })
def period
if self.start_date.nil? && self.end_date.nil?
""
else
"#{self.start_date} ~ #{self.end_date}"
end
end
end

View File

@ -0,0 +1,25 @@
<table class="table main-list tablet footable-loaded">
<caption><h3><%= @asia_academy.academy_name %><%= " - #{@asia_depart.department_name}" if @asia_depart.department_name.present? %> - <%=@asia_teacher.teacher %></h3></caption>
<thead>
<tr>
<%= thead_t('asia_database.asia_exhibition.exhibition_name') %>
<%= thead_t('asia_database.asia_exhibition.exhibition_date') %>
<%= thead_t('asia_database.asia_exhibition.host') %>
</tr>
</thead>
<tbody id="tbody_asia_academies" class="sort-holder">
<% @asia_exhibitions.each do |exhibition| %>
<tr>
<td><%= exhibition.exhibition_name %></td>
<td><%= exhibition.exhibition_date %></td>
<td><%= exhibition.host %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@asia_exhibitions), class: "pagination pagination-centered" %>
</div>
</div>

View File

@ -0,0 +1,25 @@
<table class="table main-list tablet footable-loaded">
<caption><h3><%= @asia_academy.academy_name %><%= " - #{@asia_depart.department_name}" if @asia_depart.department_name.present? %> - <%=@asia_teacher.teacher %></h3></caption>
<thead>
<tr>
<%= thead_t('asia_database.asia_paper.paper_name') %>
<%= thead_t('asia_database.asia_paper.issue_year') %>
<%= thead_t('asia_database.asia_paper.journal_name') %>
</tr>
</thead>
<tbody id="tbody_asia_academies" class="sort-holder">
<% @asia_papers.each do |paper| %>
<tr>
<td><%= paper.paper_name %></td>
<td><%= paper.issue_year %></td>
<td><%= paper.journal_name %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@asia_papers), class: "pagination pagination-centered" %>
</div>
</div>

View File

@ -0,0 +1,25 @@
<table class="table main-list tablet footable-loaded">
<caption><h3><%= @asia_academy.academy_name %><%= " - #{@asia_depart.department_name}" if @asia_depart.department_name.present? %> - <%=@asia_teacher.teacher %></h3></caption>
<thead>
<tr>
<%= thead_t('asia_database.asia_patent.patent_name') %>
<%= thead_t('asia_database.asia_patent.term_of_patent') %>
<%= thead_t('asia_database.asia_patent.patent_country') %>
</tr>
</thead>
<tbody id="tbody_asia_academies" class="sort-holder">
<% @asia_patents.each do |patent| %>
<tr>
<td><%= patent.patent_name %></td>
<td><%= patent.term_of_patent %></td>
<td><%= patent.patent_country %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@asia_patents), class: "pagination pagination-centered" %>
</div>
</div>

View File

@ -0,0 +1,25 @@
<table class="table main-list tablet footable-loaded">
<caption><h3><%= @asia_academy.academy_name %><%= " - #{@asia_depart.department_name}" if @asia_depart.department_name.present? %> - <%=@asia_teacher.teacher %></h3></caption>
<thead>
<tr>
<%= thead_t('asia_database.asia_project.project_name') %>
<%= thead_t('asia_database.asia_project.date') %>
<%= thead_t('asia_database.asia_project.sponsor') %>
</tr>
</thead>
<tbody id="tbody_asia_academies" class="sort-holder">
<% @asia_projects.each do |project| %>
<tr>
<td><%= project.project_name %></td>
<td><%= project.date %></td>
<td><%= project.sponsor %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@asia_projects), class: "pagination pagination-centered" %>
</div>
</div>

View File

@ -0,0 +1,33 @@
<table class="table main-list tablet footable-loaded">
<caption><h3><%= @asia_academy.academy_name %><%= " - #{@asia_depart.department_name}" if @asia_depart.department_name.present? %></h3></caption>
<thead>
<tr>
<%= thead_t('asia_database.teacher') %>
<%= thead_t('asia_database.extend_translate.discipline_expertise') %>
<%= thead_t('asia_database.extend_translate.project') %>
<%= thead_t('asia_database.extend_translate.paper') %>
<%= thead_t('asia_database.extend_translate.patent') %>
<%= thead_t('asia_database.extend_translate.tec_transfer') %>
<%= thead_t('asia_database.extend_translate.exhibition') %>
</tr>
</thead>
<tbody id="tbody_asia_academies" class="sort-holder">
<% @asia_teachers.each do |teacher| %>
<tr>
<td><h4><%= teacher.teacher %></h4></td>
<td><%= teacher.discipline_expertise %></td>
<td><a href="<%=asia_projects_admin_asia_database_path(teacher)%>"><%= teacher.asia_projects.count %></a></td>
<td><a href="<%=asia_papers_admin_asia_database_path(teacher)%>"><%= teacher.asia_papers.count %></a></td>
<td><a href="<%=asia_patents_admin_asia_database_path(teacher)%>"><%= teacher.asia_patents.count %></a></td>
<td><a href="<%=asia_tec_transfers_admin_asia_database_path(teacher)%>"><%= teacher.asia_tec_transfers.count %></a></td>
<td><a href="<%=asia_exhibitions_admin_asia_database_path(teacher)%>"><%= teacher.asia_exhibitions.count %></a></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@asia_teachers), class: "pagination pagination-centered" %>
</div>
</div>

View File

@ -0,0 +1,25 @@
<table class="table main-list tablet footable-loaded">
<caption><h3><%= @asia_academy.academy_name %><%= " - #{@asia_depart.department_name}" if @asia_depart.department_name.present? %> - <%=@asia_teacher.teacher %></h3></caption>
<thead>
<tr>
<%= thead_t('asia_database.asia_tec_transfer.tech_transfer_name') %>
<%= thead_t('asia_database.asia_tec_transfer.period') %>
<%= thead_t('asia_database.asia_tec_transfer.receiving_unit') %>
</tr>
</thead>
<tbody id="tbody_asia_academies" class="sort-holder">
<% @asia_tec_transfers.each do |tec_transfer| %>
<tr>
<td><%= tec_transfer.tech_transfer_name %></td>
<td><%= tec_transfer.period %></td>
<td><%= tec_transfer.receiving_unit %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@asia_tec_transfers), class: "pagination pagination-centered" %>
</div>
</div>

View File

@ -0,0 +1,20 @@
<table class="table main-list tablet footable-loaded">
<thead>
<tr>
<%= thead_t('asia_database.academy') %>
</tr>
</thead>
<tbody id="tbody_asia_academies" class="sort-holder">
<% @asia_academies.each do |academy| %>
<tr>
<td><h4><a href="<%=admin_asia_database_path(academy)%>"><%= academy.academy_name %></a></h4></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@asia_academies), class: "pagination pagination-centered" %>
</div>
</div>

View File

@ -0,0 +1,21 @@
<table class="table main-list tablet footable-loaded">
<caption><h3><%= @asia_academy.academy_name %></h3></caption>
<thead>
<tr>
<%= thead_t('asia_database.department') %>
</tr>
</thead>
<tbody id="tbody_asia_academies" class="sort-holder">
<% @asia_departs.each do |depart| %>
<tr>
<td><h4><a href="<%=asia_teachers_admin_asia_database_path(depart)%>"><%= "#{@asia_academy.academy_name}#{depart.department_name.present? ? (' - ' + depart.department_name) : ''}" %></a></h4></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@asia_departs), class: "pagination pagination-centered" %>
</div>
</div>

View File

@ -0,0 +1,42 @@
# encoding: utf-8
wb = xlsx_package.workbook
wb.add_worksheet(name: @excel_title) do |sheet|
row = []
@table_headers.each do |h|
row << h['head-title']
end
highlight_style = wb.styles.add_style(
:bg_color => 'ffeb3b',
:b => true,
:border => { :style => :thick, :color => "000000", :edges => [:top, :left, :bottom, :right] },
:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}
)
sheet.add_row row, :style => (0...row.count).collect{ highlight_style }
date_time_style = wb.styles.add_style({:format_code => 'yyyy/mm/dd hh:mm', :alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}})
wrap_text_style = wb.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}})
# types = [:time]
# styles = [date_time_style]
types = []
styles = []
@asia_data_list.each_with_index do |data, i|
row2 = []
data.each do |v|
row2 << v
end
if i == 0
(0...(row2.count)).each do |i|
types << :string
styles << wrap_text_style
end
end
sheet.add_row row2 , :types => types, :style => styles
end
end

View File

@ -0,0 +1,48 @@
<% if !@page.nil? %>
<form id="form_for_plugin_fields" action="">
<div class="form-inline">
<ul class="current-fields">
<% if @page.custom_array_field.blank? %>
<% @default_fields_to_show.each do |fs| %>
<li data-attrib-key="<%= fs %>" class="clearfix"><span class="field-value"><%= t("asia_database.#{fs}") %></span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>
<% end %>
<% else %>
<% @page.custom_array_field.each do |fs| %>
<li data-attrib-key="<%= fs %>" class="clearfix"><span class="field-value"><%= t("asia_database.#{fs}") %></span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>
<% end %>
<% end %>
</ul>
</div>
<div class="form-horizontal controls-row">
<div class="attr-type-wrap control-group">
<label class="attr control-label">Fields: </label>
<div class="attr controls">
<%= select_tag "fields_to_show_for_pp", options_for_select(@fields_to_show), prompt: "---Select something---" %>
</div>
</div>
<a href="#" class="add-pp-field btn btn-info">Add Field</a>
<input type="hidden" name="plugin_key" value="<%= @page.module %>">
<input type="hidden" name="plugin_page_frontend_id" value="<%= @page.id.to_s %>">
</div>
</form>
<script type="text/javascript">
$(".current-fields").sortable();
var select = $("select#fields_to_show_for_pp");
$(".add-pp-field").on("click",function(){
var val = select.val(),
text = select.find("option:selected").text(),
li = null;
if(val != ""){
li = '<li class="clearfix" data-attrib-key="' + val + '"><span class="field-value">' + text + '</span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>';
}
$("#modify_plugin_fields ul.current-fields").append(li);
})
$(document).on("click",".remove-field",function(){
$(this).parent().remove();
})
</script>
<% else %>
<h3>Page not found.</h3>
<% end %>

View File

@ -0,0 +1 @@
<%= render_view %>

View File

@ -0,0 +1 @@
<%= render_view %>

1
asia_academies.json Normal file
View File

@ -0,0 +1 @@
{"醫學暨健康學院":[["健康產業管理學系","ha.asia.edu.tw"],["食品營養與保健生技學系","als.asia.edu.tw"],["醫學檢驗暨生物技術學系","mlsb.asia.edu.tw"],["心理學系","psy.asia.edu.tw"],["視光學系","opt.asia.edu.tw"],["聽力暨語言治療學系","audslp.asia.edu.tw"],["職能治療學系","ot.asia.edu.tw"],["物理治療學系","pt.asia.edu.tw"],["學士後獸醫學系","dvm.asia.edu.tw"]],"資訊電機學院":[["生物資訊與醫學工程學系","bime.asia.edu.tw"],["資訊工程學系","csie.asia.edu.tw"],["行動商務與多媒體應用學系","mcma.asia.edu.tw"],["資訊傳播學系","infocom.asia.edu.tw"],["人工智慧博士學位學程","aip.asia.edu.tw"]],"管理學院":[["經營管理學系","dba.asia.edu.tw"],["休閒與遊憩管理學系","leisure.asia.edu.tw"],["會計與資訊學系","ai.asia.edu.tw"],["財務金融學系","fn.asia.edu.tw"],["財經法律學系","fel.asia.edu.tw"],["管理學院雙聯學制","dual.asia.edu.tw"]],"人文社會學院":[["外國語文學系","flts.asia.edu.tw"],["社會工作學系","sw.asia.edu.tw"],["幼兒教育學系","ece.asia.edu.tw"]],"創意設計學院":[["數位媒體設計系","dmd.asia.edu.tw"],["視覺傳達設計系","vcd.asia.edu.tw"],["創意商品設計系","cpd.asia.edu.tw"],["時尚設計系","dfd.asia.edu.tw"],["室內設計系","id.asia.edu.tw"],["創意設計暨發明中心","cdic.asia.edu.tw"]],"護理學院":[["護理學系","nur.asia.edu.tw"],["學士後護理學系","pbn.asia.edu.tw"]],"國際學院":[["國際學術交流中心","ciae.asia.edu.tw"],["華語文中心","jclc.asia.edu.tw"],["兩岸教育交流中心","ccae.asia.edu.tw"]],"人工智慧學院":[["人工智慧研究中心","aicenter.asia.edu.tw"]],"通識教育中心":[["","ged.asia.edu.tw"]],"體育室":[["","pe.asia.edu.tw"]]}

19
asia_database.gemspec Normal file
View File

@ -0,0 +1,19 @@
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "asia_database/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "asia_database"
s.version = AsiaDatabase::VERSION
s.authors = ["Bohung"]
s.email = ["bohung@rulingcom.com"]
s.homepage = "https://orbitek.co"
s.summary = "Asia Database Summary."
s.description = "Asia Database Description."
s.license = "MIT"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
end

File diff suppressed because one or more lines are too long

1
asia_teachers.json Normal file

File diff suppressed because one or more lines are too long

12
bin/rails Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/personal_course/engine', __FILE__)
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
require 'rails/all'
require 'rails/engine/commands'

7
combined_departs.rb Normal file
View File

@ -0,0 +1,7 @@
asia_teachers = JSON.parse(File.read('asia_teachers.json'))
asia_academies = JSON.parse(File.read('asia_academies.json'))
asia_depart_teachers = asia_academies.map do |academy, departs_info|
[academy, departs_info.map{|depart_name, url| [depart_name, asia_teachers[url].to_a] }.to_h ]
end.to_h
File.open('asia_depart_teachers.json', 'w+'){|f| f.write(asia_depart_teachers.to_json)}

73
config/locales/en.yml Normal file
View File

@ -0,0 +1,73 @@
en:
restful_actions:
asia_teachers: "Teacher"
asia_projects: "Project"
asia_papers: "Paper"
asia_patents: "Patent"
asia_tec_transfers: "Technology Transfer"
asia_exhibitions: "Exhibition"
module_name:
asia_database: Asia Talent Database
asia_database:
extend_translate:
download_excel: Download Excel
start_time: Start time
end_time: End time
start_date: Start date
end_date: End date
start_date_time: Start date & time
end_date_time: End date & time
start_year: Start year
end_year: End year
start_year_month: Start year/month
end_year_month: End year/month
total_number: Total number
select_class: "——select class——"
select_field: "——select field——"
search: "Search"
search_field: "Search Field:"
search_class: "Search Class:"
word_to_search: "Search Contents:"
discipline_expertise: "Discipline Expertise"
project: "Project"
paper: "Paper"
patent: "Patent"
tec_transfer: "Technology Transfer"
exhibition: "Exhibition"
unit: "Unit:"
graph_by: "Graph By"
sid: Staff ID
academy: Academy
department: Department
teacher: Teacher
url: URL
discipline_expertise: Discipline Expertise
asia_academy:
academy_name: "Academy Name"
asia_department:
department_name: "Department Name"
asia_project:
project_name: Project name
date: Date
start_date: Start Date
sponsor: Sponsor
asia_paper:
paper_name: Paper Name
issue_year: Issue Year
journal_name: Journal Name
asia_patent:
patent_name: Patent Name
term_of_patent: Term of Patent
certification_date: Certification Date
patent_country: Patent Country
asia_tec_transfer:
tech_transfer_name: Technology Transfer Name
period: Period
start_date: Start Date
receiving_unit: Receiving Unit
asia_exhibition:
exhibition_name: Exhibition Name
exhibition_date: Exhibition Date
host: Host
member_profile: Author

71
config/locales/zh_tw.yml Normal file
View File

@ -0,0 +1,71 @@
zh_tw:
restful_actions:
asia_teachers: "老師"
asia_projects: "計畫"
asia_papers: "論文(期刊+研討會)"
asia_patents: "專利"
asia_tec_transfers: "技轉"
asia_exhibitions: "展演"
module_name:
asia_database: 亞大人才資料庫
asia_database:
extend_translate:
download_excel: "下載Excel"
start_time: 開始時間
end_time: 結束時間
start_date: 開始日期
end_date: 結束日期
start_date_time: 開始日期時間
end_date_time: 結束日期時間
start_year: 開始年分
end_year: 結束年分
start_year_month: 開始年月
end_year_month: 結束年月
total_number: 總數量
select_class: "——選取分類——"
select_field: "——選取欄位——"
search: "搜尋"
search_field: "搜尋欄位:"
search_class: "搜尋類別:"
word_to_search: "關鍵字搜尋:"
discipline_expertise: "專長"
project: "計畫"
paper: "論文(期刊+研討會)"
patent: "專利"
tec_transfer: "技轉"
exhibition: "展演"
unit: "單位:"
graph_by: "Graph By"
sid: "員工編號"
academy: "學院"
department: "系所"
teacher: "老師"
url: URL
discipline_expertise: "專長"
asia_academy:
academy_name: "學院名稱"
asia_department:
department_name: "系所名稱"
asia_project:
project_name: "計畫名稱"
date: "時間"
start_date: "開始時間"
sponsor: "補助單位"
asia_paper:
paper_name: "論文名稱"
issue_year: "發表年份"
journal_name: "期刊名稱"
asia_patent:
patent_name: "專利名稱"
term_of_patent: "專利有效期"
certification_date: "獲證時間"
patent_country: "專利國家"
asia_tec_transfer:
tech_transfer_name: "技轉名稱"
period: "期間"
start_date: "開始時間"
receiving_unit: "技轉對象"
asia_exhibition:
exhibition_name: "展演名稱"
exhibition_date: "展演時間"
host: "展演單位"

51
config/routes.rb Normal file
View File

@ -0,0 +1,51 @@
Rails.application.routes.draw do
Thread.new do
AsiaTeacher.create_indexes
AsiaProject.create_indexes
AsiaPaper.create_indexes
AsiaPatent.create_indexes
AsiaTecTransfer.create_indexes
AsiaExhibition.create_indexes
AsiaExportStore.create_indexes
end
locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do
get 'asia_teacher_setting' => "asia_teachers#setting"
resources :asia_teachers do
collection do
get 'toggle_hide' => 'asia_teachers#toggle_hide'
get 'analysis'
get 'analysis_report'
get "download_excel"
end
end
resources :members do
collection do
scope '(:name-:uid)' do
resources :asia_teachers do
collection do
get 'frontend_setting' => 'asia_teachers#frontend_setting'
post 'update_frontend_setting' => 'asia_teachers#update_frontend_setting'
end
end
end
end
end
resources :asia_databases do
member do
get 'asia_teachers'
get 'asia_projects'
get 'asia_papers'
get 'asia_patents'
get 'asia_tec_transfers'
get 'asia_exhibitions'
end
end
end
post "/xhr/asia_database/export_excel" => "asia_databases#export_excel"
get "/xhr/asia_database/download_excel" => "asia_databases#download_excel"
post '/xhr/asia_database/get_store_status' => 'asia_databases#get_store_status'
end
end

4
lib/asia_database.rb Normal file
View File

@ -0,0 +1,4 @@
require "asia_database/engine"
module AsiaDatabase
end

View File

@ -0,0 +1,22 @@
module AsiaDatabase
class Engine < ::Rails::Engine
initializer "asia_database" do
OrbitApp.registration "AsiaDatabase",:type=> 'ModuleApp' do
module_label 'module_name.asia_database'
base_url File.expand_path File.dirname(__FILE__)
version "0.0.1"
desktop_enabled true
organization "Rulingcom"
author "RD dep"
frontend_enabled
data_count 1..10
side_bar do
head_label_i18n 'module_name.asia_database', icon_class: "fas fa-school-flag"
available_for "users"
active_for_controllers (['admin/asia_databases', 'admin/asia_teachers'])
head_link_path "admin_asia_databases_path"
end
end
end
end
end

View File

@ -0,0 +1,3 @@
module AsiaDatabase
VERSION = "0.0.1"
end

View File

@ -0,0 +1,245 @@
require 'net/http'
require "base64"
module AsiaDatabasePlugin
InUseLocales = Site.first.in_use_locales rescue [:en,:zh_tw]
class SafeHash < Hash
attr_accessor :duplicate_check_off
def []=(key, value)
if !duplicate_check_off && has_key?(key)
super(key,Array(self[key])+[value])
else
super
end
end
end
IV = [0x12, 0x34, 0x56, 0x84, 0x9b, 0xab, 0xcd, 0xef].pack('C*')
KEY = "Tch#^837".bytes.pack('C*')
def self.localize_data(data, locales=InUseLocales)
return locales.map{|locale| [locale, data.dup] }.to_h
end
# 研究計畫 Research Grants
def self.sync_projects(query_result, asia_teacher)
email_id = asia_teacher.email_id
return if email_id.blank?
puts "Projects(Research Grants) for user: #{email_id}"
projects = query_result["research"].to_a
if !query_result['emp'].blank?
AsiaProject.where(asia_teacher: asia_teacher,:rss2_id.ne=>nil).where(:rss2_id.nin=>projects.map{|v| v["ukey"]}).destroy
end
return if projects.count == 0
projects.each do |project|
pj = AsiaProject.where(:rss2_id=> project["ukey"]).first
pj = AsiaProject.new if pj.nil?
pj.rss2_id = project["ukey"]
pj.project_name_translations = localize_data(project["name"]) #計畫名稱
# pj.sponsor =
if project["period"].present?
period = project["period"].split('~').map{|date| DateTime.parse(date) rescue nil}
pj.start_date = period[0]
pj.end_date = period[1]
else
pj.start_date = nil
pj.end_date = nil
end
pj.asia_teacher = asia_teacher
puts "Project(Research Grants) #{pj.id} saved" if pj.save
end
end
def self.sync_papers(query_result, asia_teacher) # journal and conference papers
email_id = asia_teacher.email_id
return if email_id.blank?
puts "Paper for user: #{email_id}"
journal_papers = query_result["journal"].to_a
conference_papers = query_result["conference"].to_a
papers = journal_papers + conference_papers
if !query_result['emp'].blank?
AsiaPaper.where(asia_teacher: asia_teacher,:rss2_id.ne=>nil).where(:rss2_id.nin=>papers.map{|v| v["ukey"]}).destroy
end
return if papers.count == 0
journal_papers.each do |journal_paper|
jp = AsiaPaper.where(:rss2_id=> journal_paper["ukey"]).first
jp = AsiaPaper.new if jp.nil?
jp.rss2_id = journal_paper["ukey"]
jp.paper_name_translations = localize_data(journal_paper["Thesis_name"])
jp.journal_name_translations = localize_data(journal_paper["Journal_name"])
jp.issue_year = journal_paper["Thesis_year"]
jp.asia_teacher = asia_teacher
puts "Journal Paper #{jp.id} saved" if jp.save
end
conference_papers.each do |conference_paper|
wc = AsiaPaper.where(:rss2_id=> conference_paper["ukey"]).first
wc = AsiaPaper.new if wc.nil?
wc.rss2_id = conference_paper["ukey"]
titles = conference_paper["name"].split("-")
wc.paper_name_translations = localize_data(titles[0])
wc.journal_name_translations = localize_data(titles[1..-1].join("-"))
wc.issue_year = conference_paper["Thesis_year"]
wc.asia_teacher = asia_teacher
puts "conference paper #{wc.id} saved" if wc.save
end
end
def self.sync_patents(query_result, asia_teacher) # patents
email_id = asia_teacher.email_id
return if email_id.blank?
puts "Patent for user: #{email_id}"
patents = query_result["patent"].to_a
if !query_result['emp'].blank?
AsiaPatent.where(asia_teacher: asia_teacher,:rss2_id.ne=>nil).where(:rss2_id.nin=>patents.map{|v| v["ukey"]}).destroy
end
return if patents.count == 0
patents.each do |patent|
pt = AsiaPatent.where(:rss2_id=> patent["ukey"]).first
pt = AsiaPatent.new if pt.nil?
pt.rss2_id = patent["ukey"]
pt.patent_name_translations = localize_data(patent["Patent_name"])
pt.patent_country, pt.patent_no = patent["Patent_id"].split(":") #專利國家:專利編號, ex: 中華民國設計專利:D170464
if patent["sDate"].present?
period = patent["sDate"].split('~').map{|date| DateTime.parse(date) rescue nil}
pt.certification_date = period[0]
pt.end_date = period[1]
else
pt.certification_date = nil
pt.end_date = nil
end
pt.asia_teacher = asia_teacher
puts "Patent #{pt.id} saved" if pt.save
end
end
#技術轉移 Technology transfer
def self.sync_tec_transfers(query_result, asia_teacher)
email_id = asia_teacher.email_id
return if email_id.blank?
puts "Technology transfer for user: #{email_id}"
tec_transfers = query_result["tec_transfer"].to_a
if !query_result['emp'].blank?
AsiaTecTransfer.where(asia_teacher: asia_teacher,:rss2_id.ne=>nil).where(:rss2_id.nin=>tec_transfers.map{|v| v["ukey"]}).destroy
end
return if tec_transfers.count == 0
tec_transfers.each do |tec_transfer|
tt = AsiaTecTransfer.where(:rss2_id=> tec_transfer["ukey"]).first
tt = AsiaTecTransfer.new if tt.nil?
tt.rss2_id = tec_transfer["ukey"]
tt.tech_transfer_name_translations = localize_data(tec_transfer["Trans_Data_NAME"]) #技轉名稱
tt.receiving_unit_translations = localize_data(tec_transfer["Trans_Unit"]) #技轉對象
if tec_transfer["period"].present? #技轉期間
period = tec_transfer["period"].split('~').map{|date| Date.parse(date) rescue nil}
tt.start_date = period[0]
tt.end_date = period[1]
else
tt.start_date = nil
tt.end_date = nil
end
tt.asia_teacher = asia_teacher
puts "Technology transfer #{tt.id} saved" if tt.save
end
end
def self.sync_exhibitions(query_result, asia_teacher) # exhibitions
email_id = asia_teacher.email_id
return if email_id.blank?
puts "Exhibition(show) for user: #{email_id}"
exhibitions = query_result["show"].to_a
if !query_result['emp'].blank?
AsiaExhibition.where(asia_teacher: asia_teacher,:rss2_id.ne=>nil).where(:rss2_id.nin=>exhibitions.map{|v| v["ukey"]}).destroy
end
return if exhibitions.count == 0
exhibitions.each do |exhibition|
et = AsiaExhibition.where(:rss2_id=> exhibition["ukey"]).first
et = AsiaExhibition.new if et.nil?
et.rss2_id = exhibition["ukey"]
et.exhibition_name_translations = localize_data(exhibition["show_name"])
et.host_translations = localize_data(exhibition["show_author_local"])
if exhibition["period"].present? #展演期間
period = exhibition["period"].split('~').map{|date| DateTime.parse(date) rescue nil}
et.exhibition_start_date = period[0]
et.exhibition_end_date = period[1]
else
et.exhibition_start_date = nil
et.exhibition_end_date = nil
end
et.asia_teacher = asia_teacher
puts "Exhibition(show) #{et.id} saved" if et.save
end
end
end
namespace :asia_database do
desc "Sync asia database"
task :sync,[:user_names, :only_sync_data] => [:environment] do |task,args|
if args.user_names.present?
asia_teachers = AsiaTeacher.where(:email_id.in=>args.user_names).to_a
else
if args.only_sync_data.blank? || (args.only_sync_data != 'true' && args.only_sync_data != true)
asia_depart_teachers = JSON.parse(File.read(File.expand_path("../../../asia_depart_teachers.json", __FILE__)))
asia_depart_teachers.each do |academy_name, departs_info|
academy = AsiaAcademy.where("academy_name.zh_tw"=>academy_name).first
if academy.nil?
academy = AsiaAcademy.create({:academy_name_translations=>AsiaDatabasePlugin.localize_data(academy_name)})
end
departs_info.each do |depart_name, user_names|
depart = AsiaDepartment.where("department_name.zh_tw"=>depart_name, "asia_academy"=>academy).first
if depart.nil?
depart = AsiaDepartment.create({:department_name_translations=>AsiaDatabasePlugin.localize_data(depart_name), :asia_academy=>academy})
end
user_names.each do |email_id|
teacher_data = get_sync_data(email_id)
emp = teacher_data["emp"]
next if emp.blank?
emp = emp[0]
asia_teacher = AsiaTeacher.where(:email_id=>email_id).first
if asia_teacher.nil?
asia_teacher = AsiaTeacher.new(:email_id=>email_id, :asia_academy=>academy, :asia_department=>depart)
else
asia_teacher.asia_academy = academy
asia_teacher.asia_department = depart
end
asia_teacher.ukey = emp["ukey"]
asia_teacher.teacher_translations = {"zh_tw"=>emp["emp_nm"], "en"=>emp["emp_enm"]}
asia_teacher.save
end
end
end
end
asia_teachers = AsiaTeacher.all.to_a
end
asia_teachers.each do |asia_teacher|
query_result = get_sync_data(asia_teacher.email_id)
discipline_expertise_translations = AsiaDatabasePlugin.localize_data([], ['zh_tw', 'en'])
query_result['RshSkill'].to_a.each do |h|
tmp = h["RSkill"].to_s.strip
tmp2 = h["eRSkill"].to_s.strip
discipline_expertise_translations['zh_tw'] << [tmp, tmp2].select{|s| s.present?}.join('/')
discipline_expertise_translations['en'] << (tmp2.present? ? tmp2 : tmp)
end
asia_teacher.discipline_expertise_translations = discipline_expertise_translations
asia_teacher.save
AsiaDatabasePlugin.sync_projects(query_result, asia_teacher)
AsiaDatabasePlugin.sync_papers(query_result, asia_teacher)
AsiaDatabasePlugin.sync_patents(query_result, asia_teacher)
AsiaDatabasePlugin.sync_tec_transfers(query_result, asia_teacher)
AsiaDatabasePlugin.sync_exhibitions(query_result, asia_teacher)
end
end
def net_http_get_response(uri,headers={})
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https"
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
end
http.read_timeout = (@read_timeout.nil? ? 60 : @read_timeout)
res = http.get((uri.path.blank? ? "/" : uri.path)+(uri.query.blank? ? '' : "?#{uri.query}"))
res.uri = uri
res
end
def get_sync_data(email_id)
uri = URI.parse("https://webap.asia.edu.tw/TchEportfolio/API/Research/Load")
@read_timeout = 300
data = "id=#{email_id}"
cipher = OpenSSL::Cipher::Cipher.new("des-cbc").encrypt.tap do |obj|
obj.iv = AsiaDatabasePlugin::IV
obj.key = AsiaDatabasePlugin::KEY
end
encrypt = cipher.update(data) + cipher.final()
encrypt_base64 = Base64.encode64(encrypt).strip
res = net_http_get_response(uri + "?#{encrypt_base64}")
return JSON.parse(res.body,{object_class: AsiaDatabasePlugin::SafeHash})
end
end

View File

@ -0,0 +1,23 @@
<table class="table table-hover table-striped projects-index asia_teachers-index dt-responsive nowrap">
<caption><h3>{{widget-title}}</h3></caption>
<thead>
<tr data-level="0" data-list="headers">
<th class="col-md-{{col}}">{{head-title}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="asia_teachers">
<tr data-level="1" data-list="jps">
<td>{{value}}</td>
</tr>
</tbody>
</table>
{{pagination_goes_here}}
<script>
$('table.asia_teachers-index').DataTable({
searching: false,
paging: false,
ordering: false,
info: false
});
</script>

View File

@ -0,0 +1,54 @@
<script type="text/javascript">
$( ".selectbox" ).ready(function() {
var option_len = $(".search-widget option").length
for (var i=0;i<option_len;i++){
if($(".search-widget option").eq(i).data('selected')=="selected"){
$(".search-widget option").eq(i).attr('selected','selected')
}
}
});
</script>
<h3>{{widget-title}}</h3>
<div class="search-widget">
<form action="{{url}}" method="get">
<input type="hidden" name="authenticity_token" value="{{csrf_value}}">
{{unit_trans}}
<select class="selectbox" name="selectbox" data-level="0" data-list="choice_unit">
<option value={{choice_value}} data-selected='{{choice_select}}' >
{{choice_show}}</option>
</select>
{{select_field_text}}
<select class="selectbox" name="selectbox" data-level="0" data-list="choice_field">
<option value={{choice_value}} data-selected='{{choice_select}}' >
{{choice_show}}</option>
</select>
{{search_text}}
<input name="keywords" placeholder="Keywords" type="text" value="{{search_value}}">
<button>{{search_trans}}</button>
<a class="btn btn-danger" id="filter" style="" href="{{url}}">Clear</a>
</form>
</div>
<table class="table table-hover table-striped asia_teachers-index dt-responsive nowrap">
<caption style="display: none;"><h3>{{widget-title}}</h3></caption>
<thead>
<tr data-level="0" data-list="headers">
<th class="col-md-{{col}}">{{head-title}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="asia_teachers">
<tr data-level="1" data-list="jps">
<td>{{value}}</td>
</tr>
</tbody>
</table>
{{pagination_goes_here}}
<script>
$('table.asia_teachers-index').DataTable({
searching: false,
paging: false,
ordering: false,
info: false,
autoWidth: false
});
</script>

View File

@ -0,0 +1,126 @@
<div id="export-excel-modal" class="modal fade" tabindex="-1" role="dialog">
<style>
#export-excel-modal .modal-dialog{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 80%;
max-width: 37.5em;
}
</style>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Export</h4>
</div>
<div class="modal-body">
<div class="export-progress">
<span class="finish_percent">0</span>% (<span class="export-status">Preparing</span>)
</div>
<div class="export-link-block" style="display: none;">
<a title="Download" href="{{download_url}}" class="export-link btn btn-primary">Download</a>
</div>
</div>
</div>
</div>
</div>
<div id="asia-db-block">
<script type="text/javascript">
$( ".selectbox" ).ready(function() {
var option_len = $(".search-widget option").length
for (var i=0;i<option_len;i++){
if($(".search-widget option").eq(i).data('selected')=="selected"){
$(".search-widget option").eq(i).attr('selected','selected')
}
}
});
</script>
<h3>{{widget-title}}</h3>
<div class="search-widget">
<form action="{{url}}" method="get" id="asia-db-form">
<input type="hidden" name="authenticity_token" value="{{csrf_value}}">
{{unit_trans}}
<select class="selectbox" name="unit" data-level="0" data-list="choice_unit">
<option value={{choice_value}} data-selected='{{choice_select}}' >
{{choice_show}}</option>
</select>
{{select_field_text}}
<select class="selectbox" name="field" data-level="0" data-list="choice_field">
<option value={{choice_value}} data-selected='{{choice_select}}' >
{{choice_show}}</option>
</select>
{{search_text}}
<input name="keywords" placeholder="Keywords" type="text" value="{{search_value}}">
<button>{{search_trans}}</button>
<a class="btn btn-danger" id="clear-asia-db-form" style="" href="{{url}}">Clear</a>
<a class="btn btn-success" id="export-asia-db" style="" href="javascript:void(0)" data-href="{{export_url}}">Export</a>
</form>
</div>
<table class="table table-hover table-striped asia_databases-index dt-responsive nowrap">
<caption style="display: none;"><h3>{{widget-title}}</h3></caption>
<thead>
<tr data-level="0" data-list="headers">
<th class="col-md-{{col}}">{{head-title}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="asia_databases">
<tr data-level="1" data-list="jps">
<td>{{value}}</td>
</tr>
</tbody>
</table>
{{pagination_goes_here}}
<script>
var check_store_timeoutId = null;
var closed_export_modal = false;
function get_store_status(){
$.post('{{check_url}}').done(function(data){
$('#export-excel-modal .finish_percent').text(data.finish_percent);
var status_text = 'Preparing';
switch(data.status){
case 1:
status_text = 'Generating';
break;
case 2:
status_text = 'Finish';
break;
}
$('#export-excel-modal .export-status').text(status_text);
if(data.status != 2){
if(closed_export_modal){
return;
}
check_store_timeoutId = window.setTimeout(get_store_status, 1000);
}else{
$('#export-excel-modal .export-link-block').css('display', '');
}
})
}
$('table.asia_databases-index').DataTable({
searching: false,
paging: false,
ordering: false,
info: false,
autoWidth: false
});
$("#export-excel-modal").on('hidden.bs.modal', function (e) {
closed_export_modal = true;
if(check_store_timeoutId != null){
window.clearTimeout(check_store_timeoutId);
check_store_timeoutId = null;
}
});
$('#export-asia-db').click(function(){
closed_export_modal = false;
$.post($(this).data('href') + '?' + $('#asia-db-form').serialize() + '&tmp_id={{tmp_id}}').done(function(){
$('#export-excel-modal .export-link-block').css('display', 'none');
$('#export-excel-modal').modal();
get_store_status();
}).fail(function(){
alert("Something went wrong...");
})
})
</script>
</div>

View File

@ -0,0 +1,12 @@
{
"frontend": [
{
"filename" : "index_search1",
"name" : {
"zh_tw" : "1. 列表(含搜尋)",
"en" : "1. List which includes search"
},
"thumbnail" : "thumb.png"
}
]
}

View File

@ -0,0 +1,8 @@
<table class="table table-striped plugin-show-table">
<tbody data-list="plugin_datas" data-level="0">
<tr>
<th class="{{title_class}}">{{title}}</th>
<td class="{{value_class}}">{{value}}</td>
</tr>
</tbody>
</table>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

28
test/dummy/README.rdoc Normal file
View File

@ -0,0 +1,28 @@
== README
This README would normally document whatever steps are necessary to get the
application up and running.
Things you may want to cover:
* Ruby version
* System dependencies
* Configuration
* Database creation
* Database initialization
* How to run the test suite
* Services (job queues, cache servers, search engines, etc.)
* Deployment instructions
* ...
Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.

6
test/dummy/Rakefile Normal file
View File

@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks

View File

View File

@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .

View File

@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/

View File

@ -0,0 +1,5 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end

View File

@ -0,0 +1,2 @@
module ApplicationHelper
end

View File

View File

View File

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>

3
test/dummy/bin/bundle Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

4
test/dummy/bin/rails Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'

4
test/dummy/bin/rake Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run

4
test/dummy/config.ru Normal file
View File

@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application

View File

@ -0,0 +1,23 @@
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
require "personal_course"
module Dummy
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end

View File

@ -0,0 +1,5 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)

View File

@ -0,0 +1,25 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3

View File

@ -0,0 +1,5 @@
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!

View File

@ -0,0 +1,37 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

View File

@ -0,0 +1,78 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end

View File

@ -0,0 +1,39 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

View File

@ -0,0 +1,8 @@
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )

View File

@ -0,0 +1,7 @@
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!

View File

@ -0,0 +1,3 @@
# Be sure to restart your server when you modify this file.
Rails.application.config.action_dispatch.cookies_serializer = :json

View File

@ -0,0 +1,4 @@
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]

View File

@ -0,0 +1,16 @@
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end

View File

@ -0,0 +1,4 @@
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf

View File

@ -0,0 +1,3 @@
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_dummy_session'

View File

@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
end
# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
# self.include_root_in_json = true
# end

View File

@ -0,0 +1,23 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.
en:
hello: "Hello world"

View File

@ -0,0 +1,4 @@
Rails.application.routes.draw do
mount PersonalCourse::Engine => "/personal_course"
end

View File

@ -0,0 +1,22 @@
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.
# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.
development:
secret_key_base: 7c3d6006ba19a38b126337be5c954acc76ea069fc59ab3b64ddb42e42883655978b5162d26bdcfeb9f363e5626a2c34e2036a9b0a010c9adceabbcdc01daa3cd
test:
secret_key_base: f25e944e4db0a66681fe04d9a9f325978e481cabf76235247d86f881ab7c1616d542fb4a80306c539569becaeb9fee301d583845d11860df915e14e2224712b9
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

View File

0
test/dummy/log/.keep Normal file
View File

View File

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body>
<!-- This file lives in public/404.html -->
<div class="dialog">
<div>
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>

View File

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>The change you wanted was rejected (422)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body>
<!-- This file lives in public/422.html -->
<div class="dialog">
<div>
<h1>The change you wanted was rejected.</h1>
<p>Maybe you tried to change something you didn't have access to.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>

View File

@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>We're sorry, but something went wrong (500)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body>
<!-- This file lives in public/500.html -->
<div class="dialog">
<div>
<h1>We're sorry, but something went wrong.</h1>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>

View File

View File

@ -0,0 +1,10 @@
require 'test_helper'
class NavigationTest < ActionDispatch::IntegrationTest
fixtures :all
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class PersonalAsiaDatabaseTest < ActiveSupport::TestCase
test "truth" do
assert_kind_of Module, PersonalAsiaDatabase
end
end

19
test/test_helper.rb Normal file
View File

@ -0,0 +1,19 @@
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
require "rails/test_help"
# Filter out Minitest backtrace while allowing backtrace from other libraries
# to be shown.
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
# Load fixtures from the engine
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
end