修復需求2.0

This commit is contained in:
邱博亞 2023-05-27 17:54:38 +08:00
parent 0d5fb4f05c
commit bd9bab2b3e
6 changed files with 137 additions and 69 deletions

View File

@ -35,8 +35,8 @@ class AsiaDatabasesController < ApplicationController
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"]
choice_field = []
fields_to_select = ["patent", "project", "paper", "discipline_expertise", "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
@ -46,29 +46,23 @@ class AsiaDatabasesController < ApplicationController
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
selected_field = field_name
selected_field_int = i
break
end
end
fields_to_show = ['academy', 'department', 'teacher']
if selected_field_int == 0
if selected_field == "discipline_expertise"
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)
'head-title' => t("asia_database.#{fs}")
}
end
else
table_headers = fields_to_show.map do |fs|
{
'head-title' => t("asia_database.#{fs}"),
'col' => (fs == 'teacher' ? 3 : 2)
'head-title' => t("asia_database.#{fs}")
}
end
fields_to_show = fields_to_show.map{|fs| "asia_teacher.#{fs}"}
@ -76,13 +70,12 @@ class AsiaDatabasesController < ApplicationController
fields_to_show += extra_fields
table_headers += extra_fields.map do |fs|
{
'head-title' => t("asia_database.asia_#{selected_field}.#{fs}"),
'col' => 2
'head-title' => t("asia_database.asia_#{selected_field}.#{fs}")
}
end
end
search_field = nil
if selected_field_int == 0 #Discipline Expertise
if selected_field_int == 3 #Discipline Expertise
if selected_academy
asia_data = selected_academy.asia_teachers
else
@ -103,7 +96,7 @@ class AsiaDatabasesController < ApplicationController
asia_data = AsiaPaper.all
end
search_field = 'paper_name'
elsif selected_field_int == 3 #Patent
elsif selected_field_int == 0 #Patent
if selected_academy
asia_data = AsiaPatent.where(:asia_teacher_id.in=>selected_academy.asia_teacher_ids)
else
@ -132,16 +125,19 @@ class AsiaDatabasesController < ApplicationController
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)}
asia_data_list = []
if !params['keywords'].nil?
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
end
return asia_data_list, asia_data, table_headers, choice_unit, choice_field
@ -253,21 +249,25 @@ class AsiaDatabasesController < ApplicationController
end
return value
end
def get_display_field(asia_teacher,field)
def get_display_field(model,field)
text_only = false
value = asia_teacher.send(field) rescue ""
value = ""
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
field_level = field.split(".")
field_level[0...-1].each do |f|
model = model.send(f) rescue model
end
if field_level[-1] == 'teacher'
value = teacher_frontend_text(model)
else
value = model.send(field_level[-1])
end
else
if field == 'teacher'
value = teacher_frontend_text(model)
else
value = model.send(field)
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>'
@ -341,7 +341,7 @@ class AsiaDatabasesController < ApplicationController
member_fields = []
file_fields = []
link_fields = []
if select_field == "default"
if select_field == nil
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)}
@ -403,4 +403,8 @@ class AsiaDatabasesController < ApplicationController
def gsub_invalid_character(text)
::Regexp.escape(text.to_s)
end
def teacher_frontend_text(value)
tmp_value = value.teacher
"<a class=\"teacher_url link-primary\" target=\"_blank\" href=\"#{value.url}\" title=\"#{tmp_value}\">#{tmp_value}</a>"
end
end

View File

@ -4,5 +4,5 @@ class AsiaAcademy
include Slug
field :academy_name, :type => String, :default => "", :localize => true, :as => :slug_title
has_many :asia_departments
has_many :asia_teachers
has_many :asia_teachers, :order => 'ukey DESC'
end

View File

@ -18,8 +18,8 @@ class AsiaTeacher
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 })
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 ""

View File

@ -2,7 +2,22 @@ $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "asia_database/version"
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
if bundle_update_flag
app_path = File.expand_path(__dir__)
template_path = ENV['PWD'] + '/app/templates'
all_template = Dir.glob(template_path+'/*/')
puts 'copying module'
all_template.each do |folder|
if folder.split('/')[-1] != 'mobile'
begin
system ('cp -r '+ app_path + '/modules/ ' + folder)
rescue
puts 'error copy'
end
end
end
end
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "asia_database"

View File

@ -1,3 +1,9 @@
<div id="asia-db-block" style="font-family: Microsoft JhengHei;">
<style type="text/css">
.clear-btn{
margin-right: 3em;
}
</style>
<script type="text/javascript">
$( ".selectbox" ).ready(function() {
var option_len = $(".search-widget option").length
@ -24,11 +30,11 @@ $( ".selectbox" ).ready(function() {
</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>
<button class="btn btn-light">{{search_trans}}</button>
<a aria-pressed="true" class="btn btn-default clear-btn" href="{{url}}">Clear</a>
</form>
</div>
<table class="table table-hover table-striped asia_teachers-index dt-responsive nowrap">
<table class="asia_teachers-index table table-hover table-striped dt-responsive dataTable no-footer dtr-inline">
<caption style="display: none;"><h3>{{widget-title}}</h3></caption>
<thead>
<tr data-level="0" data-list="headers">
@ -49,6 +55,8 @@ $('table.asia_teachers-index').DataTable({
paging: false,
ordering: false,
info: false,
autoWidth: false
autoWidth: false,
responsive: true
});
</script>
</script>
</div>

View File

@ -8,6 +8,28 @@
width: 80%;
max-width: 37.5em;
}
.clear-btn{
margin-right: 3em;
}
#asia-db-form > span{
display: inline-block;
}
@media (max-width: 576px) {
#asia-db-form > span{
width: 100%;
}
}
.link-primary.teacher_url{
color: #337ab7;
text-decoration-line: underline;
font-weight: 700;
}
.asia_databases-index{
table-layout: fixed;
}
.asia_databases-index ul{
padding: 0;
}
</style>
<div class="modal-dialog">
<div class="modal-content">
@ -26,7 +48,7 @@
</div>
</div>
</div>
<div id="asia-db-block">
<div id="asia-db-block" style="font-family: Microsoft JhengHei;">
<script type="text/javascript">
$( ".selectbox" ).ready(function() {
var option_len = $(".search-widget option").length
@ -39,30 +61,39 @@
</script>
<h3>{{widget-title}}</h3>
<div class="search-widget">
<form action="{{url}}" method="get" id="asia-db-form">
<form action="{{url}}" method="get" id="asia-db-form" class="form-horizontal" role="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>
<span>
{{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>
</span>
<span>
{{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>
</span>
<span>
{{search_text}}
<input name="keywords" placeholder="Keywords" type="text" value="{{search_value}}">
<button class="btn btn-default">{{search_trans}}</button>
</span>
<span>
<a aria-pressed="true" class="btn btn-default clear-btn" href="{{url}}">Clear</a>
<button type="button" class="btn btn-default" id="export-asia-db" data-href="{{export_url}}">Export</a>
</button>
</span>
</form>
</div>
<table class="table table-hover table-striped asia_databases-index dt-responsive nowrap">
<table class="asia_databases-index table table-hover table-striped">
<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>
<th>{{head-title}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="asia_databases">
@ -98,12 +129,22 @@
}
})
}
var columnDefs = [
{ "width": "7em", targets: 0 },
{ "width": "7em", targets: 1 },
{ "width": "4em", targets: 2 }
]
if ($('table.asia_databases-index th').length > 4){
columnDefs.push({ "width": "40%", targets: 3 });
}
$('table.asia_databases-index').DataTable({
searching: false,
paging: false,
ordering: false,
info: false,
autoWidth: false
autoWidth: false,
responsive: true,
columnDefs: columnDefs
});
$("#export-excel-modal").on('hidden.bs.modal', function (e) {
closed_export_modal = true;