diff --git a/app/controllers/asia_databases_controller.rb b/app/controllers/asia_databases_controller.rb index 9efbdf4..07a0038 100644 --- a/app/controllers/asia_databases_controller.rb +++ b/app/controllers/asia_databases_controller.rb @@ -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 = "#{tmp_value}" - 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 = "#{value}" end if value.class == Array tmp = '
{{head-title}} | +{{head-title}} |
---|