diff --git a/Gemfile b/Gemfile index 0ccdafe..3f6ce83 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -# Declare your gem's dependencies in personal_honor.gemspec. +# Declare your gem's dependencies in academic_advising.gemspec. # Bundler will treat runtime dependencies like base dependencies, and # development dependencies will be added by default to the :development group. gemspec diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 0ecad5e..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,104 +0,0 @@ -PATH - remote: . - specs: - personal_honor (0.0.1) - mongoid (= 4.0.0.beta2) - rails (= 4.1.0.rc2) - -GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.1.0.rc2) - actionpack (= 4.1.0.rc2) - actionview (= 4.1.0.rc2) - mail (~> 2.5.4) - actionpack (4.1.0.rc2) - actionview (= 4.1.0.rc2) - activesupport (= 4.1.0.rc2) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - actionview (4.1.0.rc2) - activesupport (= 4.1.0.rc2) - builder (~> 3.1) - erubis (~> 2.7.0) - activemodel (4.1.0.rc2) - activesupport (= 4.1.0.rc2) - builder (~> 3.1) - activerecord (4.1.0.rc2) - activemodel (= 4.1.0.rc2) - activesupport (= 4.1.0.rc2) - arel (~> 5.0.0) - activesupport (4.1.0.rc2) - i18n (~> 0.6, >= 0.6.9) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.1) - tzinfo (~> 1.1) - arel (5.0.1.20140414130214) - bson (2.3.0) - builder (3.2.2) - connection_pool (2.0.0) - erubis (2.7.0) - hike (1.2.3) - i18n (0.6.9) - json (1.8.1) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.25.1) - minitest (5.3.4) - mongoid (4.0.0.beta2) - activemodel (>= 4.0.0) - moped (~> 2.0.beta6) - origin (~> 2.1) - tzinfo (>= 0.3.37) - moped (2.0.0.rc1) - bson (~> 2.2) - connection_pool (~> 2.0) - optionable (~> 0.2.0) - multi_json (1.10.1) - optionable (0.2.0) - origin (2.1.1) - polyglot (0.3.5) - rack (1.5.2) - rack-test (0.6.2) - rack (>= 1.0) - rails (4.1.0.rc2) - actionmailer (= 4.1.0.rc2) - actionpack (= 4.1.0.rc2) - actionview (= 4.1.0.rc2) - activemodel (= 4.1.0.rc2) - activerecord (= 4.1.0.rc2) - activesupport (= 4.1.0.rc2) - bundler (>= 1.3.0, < 2.0) - railties (= 4.1.0.rc2) - sprockets-rails (~> 2.0.0) - railties (4.1.0.rc2) - actionpack (= 4.1.0.rc2) - activesupport (= 4.1.0.rc2) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.3.2) - sprockets (2.12.1) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.0.1) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (~> 2.8) - thor (0.19.1) - thread_safe (0.3.4) - tilt (1.4.1) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - tzinfo (1.2.1) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - personal_honor! diff --git a/README.rdoc b/README.rdoc index 4feeb65..0c9108e 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,3 +1,3 @@ -= PersonalHonor += AcademicAdvising This project rocks and uses MIT-LICENSE. \ No newline at end of file diff --git a/Rakefile b/Rakefile index 4fbbc9c..3c113c3 100644 --- a/Rakefile +++ b/Rakefile @@ -8,7 +8,7 @@ require 'rdoc/task' RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'PersonalHonor' + rdoc.title = 'AcademicAdvising' rdoc.options << '--line-numbers' rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('lib/**/*.rb') diff --git a/personal_honor.gemspec b/academic_advising.gemspec similarity index 66% rename from personal_honor.gemspec rename to academic_advising.gemspec index 2898b81..0c36983 100644 --- a/personal_honor.gemspec +++ b/academic_advising.gemspec @@ -1,17 +1,17 @@ $:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: -require "personal_honor/version" +require "academic_advising/version" # Describe your gem and declare its dependencies: Gem::Specification.new do |s| - s.name = "personal_honor" - s.version = PersonalHonor::VERSION + s.name = "academic_advising" + s.version = AcademicAdvising::VERSION s.authors = ["Ruling Digital Inc."] s.email = ["orbit@rulingcom.com"] s.homepage = "http://www.rulingcom.com" - s.summary = "Summary of Personal Honor." - s.description = "Description of Personal Honor." + s.summary = "Summary of Academic Advising." + s.description = "Description of Academic Advising." s.license = "MIT" s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] diff --git a/app/assets/images/personal_conference/.keep b/app/assets/images/academic_advising/.keep similarity index 100% rename from app/assets/images/personal_conference/.keep rename to app/assets/images/academic_advising/.keep diff --git a/app/assets/images/desktop/personal_honor.svg b/app/assets/images/desktop/academic_advising.svg similarity index 100% rename from app/assets/images/desktop/personal_honor.svg rename to app/assets/images/desktop/academic_advising.svg diff --git a/app/assets/javascripts/personal_conference/.keep b/app/assets/javascripts/academic_advising/.keep similarity index 100% rename from app/assets/javascripts/personal_conference/.keep rename to app/assets/javascripts/academic_advising/.keep diff --git a/app/assets/stylesheets/personal_conference/.keep b/app/assets/stylesheets/academic_advising/.keep similarity index 100% rename from app/assets/stylesheets/personal_conference/.keep rename to app/assets/stylesheets/academic_advising/.keep diff --git a/app/controllers/academic_advisings_controller.rb b/app/controllers/academic_advisings_controller.rb new file mode 100644 index 0000000..fb98921 --- /dev/null +++ b/app/controllers/academic_advisings_controller.rb @@ -0,0 +1,124 @@ +class AcademicAdvisingsController < ApplicationController + def index + params = OrbitHelper.params + filter_value = params[:academic_advisings_filter_value] + academic_advisings = nil + + if filter_value.nil? || filter_value == t("academic_advising.academic_advising_types_all") || filter_value.empty? + academic_advisings = Advising.where(:award_name.ne => nil).or(:award_name.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + else + academic_advising_type_id = AdvisingType.or({ 'title.en' => filter_value }, { 'title.zh_tw' => filter_value }).first.id + academic_advisings = Advising.where(academic_advising_type_id: academic_advising_type_id).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + end + + fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue [] + + if fields_to_show.blank? + fields_to_show = [ + "academic_advising_type", + "year", + "award_name", + "authors", + "awarding_unit", + "advising_students" + ] + end + + academic_advising_list = [] + academic_advisings.each do |academic_advising| + t = [] + fields_to_show.each do |fs| + case fs + when "award_name" + t << {"value" => "" + (academic_advising.send(fs) rescue "") + ""} + when "academic_advising_type" + t << {"value" => (academic_advising.send("academic_advising_type").title rescue "")} + when "authors" + member_profile = academic_advising.send(:member_profile) + role_status_id = member_profile.role_status_ids.first.to_s + path = OrbitHelper.url_to_plugin_show(member_profile.to_param, 'member') rescue '#' + t << {"value" => "" + (member_profile.name rescue "") + "" } + when "award_date" + t << {"value" => (academic_advising.send(fs).strftime("%Y/%m") rescue "")} + when "advising_students" + t << {"value" => academic_advising.advising_students_front_data} + else + t << {"value" => (academic_advising.send(fs) rescue "")} + end + end + academic_advising_list << {"academic_advisings" => t} + end + + headers = [] + fields_to_show.each do |fs| + col = 2 + col = 3 if fs == "award_name" + header = fs == "authors" ? t("academic_advising.academic_advisingee") : t("academic_advising.#{fs}") + headers << { + "head-title" => header, + "col" => col + } + end + + current_locale = I18n.locale + academic_advising_types = AdvisingType.all.pluck(:title).map { |title| { 'academic_advising_type' => title.to_h[current_locale] } } + academic_advising_types.unshift({ 'academic_advising_type' => t("academic_advising.academic_advising_types_all") }) + + { + "advisings" => academic_advising_list, + "academic_advising_types" => academic_advising_types, + "extras" => { "widget-title" => t("module_name.academic_advising"), + "url" => '/' + current_locale.to_s + params[:url] }, + "headers" => headers, + "total_pages" => academic_advisings.total_pages + } + end + + def show + params = OrbitHelper.params + plugin = Advising.where(:is_hidden=>false).find_by(uid: params[:uid]) + fields_to_show = [ + "year", + "academic_advising_type", + "award_name", + "award_date", + "requirement", + "academic_advisingee", + "awarding_unit", + "advising_students" + ] + + {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} + end + + def get_fields_for_index + @page = Page.find(params[:page_id]) rescue nil + @fields_to_show = [ + "year", + "award_name", + "awarding_unit", + "academic_advising_type", + "award_date", + "requirement", + "authors", + "award_winner" + ] + @fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("academic_advising.#{fs}")), fs]} + @default_fields_to_show = [ + "academic_advising_type", + "year", + "award_name", + "authors", + "awarding_unit", + "advising_students" + ] + 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 +end diff --git a/app/controllers/admin/academic_advising_types_controller.rb b/app/controllers/admin/academic_advising_types_controller.rb new file mode 100644 index 0000000..64880ec --- /dev/null +++ b/app/controllers/admin/academic_advising_types_controller.rb @@ -0,0 +1,52 @@ +class Admin::AcademicAdvisingTypesController < OrbitMemberController + before_action :allow_admin_only + + def new + @academic_advising_type = AdvisingType.new + @url = admin_academic_advising_types_path(@academic_advising_type) + render :layout=>false + end + + def create + @academic_advising_type = AdvisingType.new(academic_advising_type_params) + @academic_advising_type.save + @academic_advising_types = AdvisingType.all + render :partial=>'list', :layout=>false + end + + def update_order + orders = params["order"] + AdvisingType.each do |ht| + ht.sort_position = orders["#{ht.id}"] + ht.save + end + render :json => {"success" => true}.to_json + end + + def edit + @academic_advising_type = AdvisingType.find(params[:id]) + @url = admin_academic_advising_type_path(@academic_advising_type) + render :layout=>false + end + + def update + @academic_advising_type = AdvisingType.find(params[:id]) + @academic_advising_type.update_attributes(academic_advising_type_params) + @academic_advising_type.save + @academic_advising_types = AdvisingType.all + render :partial=>'list', :layout=>false + end + + def destroy + academic_advising_type = AdvisingType.find(params[:id]) + academic_advising_type.destroy + @academic_advising_types = AdvisingType.all + render :partial=>'list', :layout=>false + end + + private + + def academic_advising_type_params + params.require(:advising_type).permit! rescue nil + end +end \ No newline at end of file diff --git a/app/controllers/admin/honors_controller.rb b/app/controllers/admin/academic_advisings_controller.rb similarity index 58% rename from app/controllers/admin/honors_controller.rb rename to app/controllers/admin/academic_advisings_controller.rb index 54322c1..7f52464 100644 --- a/app/controllers/admin/honors_controller.rb +++ b/app/controllers/admin/academic_advisings_controller.rb @@ -1,8 +1,8 @@ -class Admin::HonorsController < OrbitMemberController +class Admin::AcademicAdvisingsController < OrbitMemberController layout "member_plugin" - include Admin::PersonalHonorsHelper + include Admin::AcademicAdvisingsHelper - before_action :set_honor, only: [:show, :edit , :update, :destroy] + before_action :set_academic_advising, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] @@ -10,12 +10,12 @@ class Admin::HonorsController < OrbitMemberController before_action :allow_admin_only, :only => [:index, :setting] def index - @honors = Honor.order_by(:year=>'desc').page(params[:page]).per(10) + @academic_advisings = Advising.order_by(:year=>'desc').page(params[:page]).per(10) end def new @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @honor = Honor.new + @academic_advising = Advising.new if params[:desktop] render :layout => false @@ -39,18 +39,18 @@ class Admin::HonorsController < OrbitMemberController @data = get_data_for_excel(year_start,year_end) respond_to do |format| format.xlsx { - response.headers['Content-Disposition'] = 'attachment; filename="honors.xlsx"' + response.headers['Content-Disposition'] = 'attachment; filename="academic_advisings.xlsx"' } end end def create - if !honor_params['member_profile_id'].blank? + if !academic_advising_params['member_profile_id'].blank? - @member = MemberProfile.find(honor_params['member_profile_id']) rescue nil - @honor = Honor.new(honor_params) - @honor.save + @member = MemberProfile.find(academic_advising_params['member_profile_id']) rescue nil + @academic_advising = Advising.new(academic_advising_params) + @academic_advising.save if params[:desktop] == "true" render json: {"data" => get_paper_list}.to_json @@ -62,9 +62,9 @@ class Admin::HonorsController < OrbitMemberController params[:author_members].each do |author_member| - honor_params['member_profile_id'] = author_member - @honor = Honor.new(honor_params) - @honor.save + academic_advising_params['member_profile_id'] = author_member + @academic_advising = Advising.new(academic_advising_params) + @academic_advising.save if params[:desktop] == "true" render json: {"data" => get_paper_list}.to_json @@ -76,10 +76,10 @@ class Admin::HonorsController < OrbitMemberController else - honor_params['member_profile_id'] = User.find(current_user.id).member_profile_id + academic_advising_params['member_profile_id'] = User.find(current_user.id).member_profile_id - @honor = Honor.new(honor_params) - @honor.save + @academic_advising = Advising.new(academic_advising_params) + @academic_advising.save if params[:desktop] == "true" render json: {"data" => get_paper_list}.to_json @@ -92,16 +92,16 @@ class Admin::HonorsController < OrbitMemberController end def edit - @member = @honor.member_profile rescue nil + @member = @academic_advising.member_profile rescue nil if params[:desktop] render :layout => false end end def update - @member = @honor.member_profile rescue nil - @honor.update_attributes(honor_params) - @honor.save + @member = @academic_advising.member_profile rescue nil + @academic_advising.update_attributes(academic_advising_params) + @academic_advising.save if params[:desktop] == "true" render json: {"data" => get_paper_list}.to_json else @@ -110,9 +110,9 @@ class Admin::HonorsController < OrbitMemberController end def destroy - @honor.destroy + @academic_advising.destroy respond_to do |format| - format.html { redirect_to(admin_honor_url) } + format.html { redirect_to(admin_academic_advising_url) } # format.xml { head :ok } format.js format.json {render json: {"success" => true}} @@ -121,11 +121,11 @@ class Admin::HonorsController < OrbitMemberController def toggle_hide if params[:ids] - @honors = Honor.any_in(_id: params[:ids]) + @academic_advisings = Advising.any_in(_id: params[:ids]) - @honors.each do |honor| - honor.is_hidden = params[:disable] - honor.save + @academic_advisings.each do |academic_advising| + academic_advising.is_hidden = params[:disable] + academic_advising.save end end @@ -135,7 +135,7 @@ class Admin::HonorsController < OrbitMemberController def excel_format respond_to do |format| format.xlsx { - response.headers['Content-Disposition'] = 'attachment; filename="honor_format.xlsx"' + response.headers['Content-Disposition'] = 'attachment; filename="academic_advising_format.xlsx"' } end end @@ -149,12 +149,12 @@ class Admin::HonorsController < OrbitMemberController user = User.where(:user_name => row.cells[0].value).first rescue nil if !user.nil? mp = user.member_profile - import_this_honor(row,mp) + import_this_academic_advising(row,mp) end end - redirect_to admin_honors_url + redirect_to admin_academic_advisings_url else - redirect_to admin_honors_url(:error => "1") + redirect_to admin_academic_advisings_url(:error => "1") end end @@ -163,30 +163,30 @@ class Admin::HonorsController < OrbitMemberController def frontend_setting @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @intro = HonorIntro.find_by(:member_profile_id=>@member.id) rescue nil - @intro = @intro.nil? ? HonorIntro.new({:member_profile_id=>@member.id}) : @intro + @intro = AdvisingIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? AdvisingIntro.new({:member_profile_id=>@member.id}) : @intro end def update_frontend_setting @member = MemberProfile.find(intro_params['member_profile_id']) rescue nil - @intro = HonorIntro.find_by(:member_profile_id=>@member.id) rescue nil - @intro = @intro.nil? ? HonorIntro.new({:member_profile_id=>@member.id}) : @intro + @intro = AdvisingIntro.find_by(:member_profile_id=>@member.id) rescue nil + @intro = @intro.nil? ? AdvisingIntro.new({:member_profile_id=>@member.id}) : @intro @intro.update_attributes(intro_params) @intro.save - redirect_to URI.encode('/admin/members/'+@member.to_param+'/Honor') + redirect_to URI.encode('/admin/members/'+@member.to_param+'/AcademicAdvising') end def get_settings - @honor_types = HonorType.all + @academic_advising_types = AdvisingType.all end def set_plugin - @plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'Honor'}.first + @plugin = OrbitApp::Plugin::Registration.all.select{|plugin| plugin.app_name.eql? 'AcademicAdvising'}.first end private - def set_honor + def set_academic_advising path = request.path.split('/') if path.last.include? '-' uid = path[-1].split("-").last @@ -195,14 +195,14 @@ class Admin::HonorsController < OrbitMemberController uid = path[-2].split("-").last uid = uid.split("?").first end - @honor = Honor.find_by(:uid => uid) rescue Honor.find(params[:id]) + @academic_advising = Advising.find_by(:uid => uid) rescue Advising.find(params[:id]) end - def honor_params - params.require(:honor).permit! rescue nil + def academic_advising_params + params.require(:advising).permit! rescue nil end def intro_params - params.require(:honor_intro).permit! rescue nil + params.require(:advising_intro).permit! rescue nil end end \ No newline at end of file diff --git a/app/controllers/admin/honor_types_controller.rb b/app/controllers/admin/honor_types_controller.rb deleted file mode 100644 index 3126836..0000000 --- a/app/controllers/admin/honor_types_controller.rb +++ /dev/null @@ -1,52 +0,0 @@ -class Admin::HonorTypesController < OrbitMemberController - before_action :allow_admin_only - - def new - @honor_type = HonorType.new - @url = admin_honor_types_path(@honor_type) - render :layout=>false - end - - def create - @honor_type = HonorType.new(honor_type_params) - @honor_type.save - @honor_types = HonorType.all - render :partial=>'list', :layout=>false - end - - def update_order - orders = params["order"] - HonorType.each do |ht| - ht.sort_position = orders["#{ht.id}"] - ht.save - end - render :json => {"success" => true}.to_json - end - - def edit - @honor_type = HonorType.find(params[:id]) - @url = admin_honor_type_path(@honor_type) - render :layout=>false - end - - def update - @honor_type = HonorType.find(params[:id]) - @honor_type.update_attributes(honor_type_params) - @honor_type.save - @honor_types = HonorType.all - render :partial=>'list', :layout=>false - end - - def destroy - honor_type = HonorType.find(params[:id]) - honor_type.destroy - @honor_types = HonorType.all - render :partial=>'list', :layout=>false - end - - private - - def honor_type_params - params.require(:honor_type).permit! rescue nil - end -end \ No newline at end of file diff --git a/app/controllers/desktop/personal_honors_controller.bak b/app/controllers/desktop/personal_honors_controller.bak deleted file mode 100644 index 115cca8..0000000 --- a/app/controllers/desktop/personal_honors_controller.bak +++ /dev/null @@ -1,23 +0,0 @@ -class Desktop::PersonalHonorsController < DesktopAdminController - include Admin::PersonalHonorsHelper - - def menu - user = OrbitHelper.current_user - [ - { - "title" => "List", - "layout" => "list" - }, - { - "title" => "Add/Edit", - "layout" => "form", - "new_path" => "/admin/members/#{user.member_profile.to_param}/honors/new" - } - ] - end - - def list - get_paper_list - end - -end \ No newline at end of file diff --git a/app/controllers/personal_honors_controller.rb b/app/controllers/personal_honors_controller.rb deleted file mode 100644 index 23cbbe9..0000000 --- a/app/controllers/personal_honors_controller.rb +++ /dev/null @@ -1,125 +0,0 @@ -class PersonalHonorsController < ApplicationController - def index - params = OrbitHelper.params - filter_value = params[:honors_filter_value] - honors = nil - - if filter_value.nil? || filter_value == t("personal_honor.honor_types_all") || filter_value.empty? - honors = Honor.where(:award_name.ne => nil).or(:award_name.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) - else - honor_type_id = HonorType.or({ 'title.en' => filter_value }, { 'title.zh_tw' => filter_value }).first.id - honors = Honor.where(honor_type_id: honor_type_id).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) - end - - fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue [] - - if fields_to_show.blank? - fields_to_show = [ - "honor_type", - "year", - "award_name", - "authors", - "awarding_unit" - ] - end - - honor_list = [] - honors.each do |honor| - t = [] - fields_to_show.each do |fs| - case fs - when "award_name" - t << {"value" => "" + (honor.send(fs) rescue "") + ""} - when "honor_type" - t << {"value" => (honor.send("honor_type").title rescue "")} - when "authors" - member_profile = honor.send(:member_profile) - role_status_id = member_profile.role_status_ids.first.to_s - path = OrbitHelper.url_to_plugin_show(member_profile.to_param, 'member') rescue '#' - t << {"value" => "" + (member_profile.name rescue "") + "" } - when "award_date" - t << {"value" => (honor.send(fs).strftime("%Y/%m") rescue "")} - else - t << {"value" => (honor.send(fs) rescue "")} - end - end - honor_list << {"personal_honors" => t} - end - - headers = [] - fields_to_show.each do |fs| - col = 2 - col = 3 if fs == "award_name" - header = fs == "authors" ? t("users.name") : t("personal_honor.#{fs}") - headers << { - "head-title" => header, - "col" => col - } - end - - current_locale = I18n.locale - honor_types = HonorType.all.pluck(:title).map { |title| { 'honor_type' => title.to_h[current_locale] } } - honor_types.unshift({ 'honor_type' => t("personal_honor.honor_types_all") }) - - { - "honors" => honor_list, - "honor_types" => honor_types, - "extras" => { "widget-title" => t("module_name.personal_honor"), - "url" => '/' + current_locale.to_s + params[:url] }, - "headers" => headers, - "total_pages" => honors.total_pages - } - end - - def show - params = OrbitHelper.params - plugin = Honor.where(:is_hidden=>false).find_by(uid: params[:uid]) - fields_to_show = [ - "year", - "honor_type", - "award_name", - "award_date", - "country", - "honoree", - "awarding_unit", - "keywords", - "url", - "note" - ] - - {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} - end - - def get_fields_for_index - @page = Page.find(params[:page_id]) rescue nil - @fields_to_show = [ - "year", - "award_name", - "awarding_unit", - "honor_type", - "award_date", - "country", - "keywords", - "url", - "note", - "authors", - "award_winner" - ] - @fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_honor.#{fs}")), fs]} - @default_fields_to_show = [ - "honor_type", - "year", - "award_name", - "authors", - "awarding_unit" - ] - 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 -end diff --git a/app/helpers/admin/personal_honors_helper.rb b/app/helpers/admin/academic_advisings_helper.rb similarity index 62% rename from app/helpers/admin/personal_honors_helper.rb rename to app/helpers/admin/academic_advisings_helper.rb index c5ef370..98f0d8c 100644 --- a/app/helpers/admin/personal_honors_helper.rb +++ b/app/helpers/admin/academic_advisings_helper.rb @@ -1,25 +1,25 @@ -module Admin::PersonalHonorsHelper +module Admin::AcademicAdvisingsHelper def get_paper_list user = current_user.nil? ? OrbitHelper.current_user : current_user user_profile = user.member_profile - honors = Honor.where(:member_profile_id => user_profile.id) - honors = honors.collect do |h| + academic_advisings = Advising.where(:member_profile_id => user_profile.id) + academic_advisings = academic_advisings.collect do |h| { "id" => h.id.to_s, - "edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/honors/#{h.to_param}/edit", - "delete_url" => "/#{I18n.locale.to_s}/admin/honors/#{h.id.to_s}", + "edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/academic_advisings/#{h.to_param}/edit", + "delete_url" => "/#{I18n.locale.to_s}/admin/academic_advisings/#{h.id.to_s}", "paper_title" => h.award_name, "keywords" => h.keywords, "files" => [] } end - honors + academic_advisings end - def import_this_honor(row,mp) + def import_this_academic_advising(row,mp) value = nil - honor = Honor.new + academic_advising = Advising.new row.cells.each_with_index do |cell,index| next if index < 2 next if cell.nil? @@ -34,7 +34,7 @@ module Admin::PersonalHonorsHelper rescue value = {"zh_tw" => val} end - honor.award_name_translations = value + academic_advising.award_name_translations = value when 4 value = {"en" => val} when 5 @@ -43,24 +43,24 @@ module Admin::PersonalHonorsHelper rescue value = {"zh_tw" => val} end - honor.awarding_unit_translations = value + academic_advising.awarding_unit_translations = value when 6 - honor.year = val + academic_advising.year = val when 7 - honor.language = val + academic_advising.language = val when 8 - hts = HonorType.asc(:created_at).all.to_a - honor.honor_type = hts[val.to_i] if val.to_s.is_i? && val.to_i < hts.count + hts = AdvisingType.asc(:created_at).all.to_a + academic_advising.academic_advising_type = hts[val.to_i] if val.to_s.is_i? && val.to_i < hts.count when 9 - honor.url = val + academic_advising.url = val when 10 - honor.keywords = val + academic_advising.keywords = val when 11 - honor.note = val + academic_advising.note = val end end - honor.member_profile = mp - honor.save + academic_advising.member_profile = mp + academic_advising.save end def get_data_for_excel(year_start,year_end) @@ -72,7 +72,7 @@ module Admin::PersonalHonorsHelper mps = role.member_profile_ids # d1 = DateTime.new(year_start,1,1,0,0) # d2 = DateTime.new(year_end,12,31,23,59) - d["data"] = Honor.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue [] + d["data"] = Advising.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue [] data << d end return data @@ -81,7 +81,7 @@ module Admin::PersonalHonorsHelper def get_chart_data(year_start,year_end,role,type) case type when "category" - jls = HonorType.all + jls = AdvisingType.all end finaldata = [] @@ -97,7 +97,7 @@ module Admin::PersonalHonorsHelper (year_start..year_end).each do |year| # d1 = DateTime.new(year,1,1,0,0) # d2 = DateTime.new(year,12,31,23,59) - t = jl.honors.where(:year => year.to_s, :member_profile_id.in => mps).count rescue 0 + t = jl.academic_advisings.where(:year => year.to_s, :member_profile_id.in => mps).count rescue 0 data["data"][year.to_s] = t end finaldata << data @@ -108,7 +108,7 @@ module Admin::PersonalHonorsHelper # d2 = DateTime.new(year,12,31,23,59) case type when "category" - t = Honor.where(:year => year, :member_profile_id.in => mps, :honor_type_id => nil).count rescue 0 + t = Advising.where(:year => year, :member_profile_id.in => mps, :academic_advising_type_id => nil).count rescue 0 end data["data"][year.to_s] = t diff --git a/app/models/honor.rb b/app/models/advising.rb similarity index 63% rename from app/models/honor.rb rename to app/models/advising.rb index 536f1f7..48a1b3b 100644 --- a/app/models/honor.rb +++ b/app/models/advising.rb @@ -1,10 +1,10 @@ -class Honor +class Advising include Mongoid::Document include Mongoid::Timestamps include OrbitModel::Status include Slug - belongs_to :honor_type + belongs_to :academic_advising_type belongs_to :member_profile field :year, type: Integer @@ -16,10 +16,10 @@ class Honor field :url field :note field :rss2_id - field :country, localize: true + field :requirement, localize: true field :create_user_id, :type => BSON::ObjectId field :update_user_id, :type => BSON::ObjectId - + field :advising_student_ids, :type => Array, default: [] # paginates_per 10 before_validation :add_http @@ -29,7 +29,9 @@ class Honor def slug_title self.award_name+' '+self.awarding_unit rescue "" end - + def advising_students + MemberProfile.where(:id.in => self.advising_student_ids) + end def get_plugin_data(fields_to_show) plugin_datas = [] fields_to_show.each do |field| @@ -39,33 +41,38 @@ class Honor end plugin_datas end - + def advising_students_front_data + self.advising_students.collect{|member| "#{member.name}"}.join('、') + end def self.get_plugin_datas_to_member(datas) - page = Page.where(:module => "personal_honor").first rescue nil + page = Page.where(:module => "academic_advising").first rescue nil if !page.nil? && !page.custom_array_field.blank? fields_to_show = page.custom_array_field else fields_to_show = [ - "honor_type", + "academic_advising_type", "year", "award_name", - "awarding_unit" + "awarding_unit", + "advising_students" ] end fields_to_remove = [] pd_title = [] - + puts fields_to_show fields_to_show.each do |t| if (self.fields[t].type.to_s == "String" || self.fields[t].type.to_s == "Object" rescue false) fields_to_remove << t if (datas.where(t.to_sym.ne => nil, t.to_sym.ne => "").count == 0 rescue false) + elsif t=='advising_students' + fields_to_remove << t if (datas.where(:advising_student_ids.ne => []).count == 0 rescue false) else fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false) end pd_title << { - "plugin_data_title" => I18n.t("personal_honor.#{t}") + "plugin_data_title" => I18n.t("academic_advising.#{t}") } if !fields_to_remove.include?(t) end @@ -75,18 +82,20 @@ class Honor pd_data = [] fields_to_show.collect do |t| if t == "award_name" - pd_data << { "data_title" => "#{p.send(t)}" } - elsif t == "honor_type" - pd_data << {"data_title" => (p.honor_type.title rescue "")} + pd_data << { "data_title" => "#{p.send(t)}" } + elsif t == "academic_advising_type" + pd_data << {"data_title" => (p.academic_advising_type.title rescue "")} elsif t == "award_date" - pd_data << {"data_title" => (p.send(t).strftime("%Y/%m/%d") rescue "")} + pd_data << {"data_title" => (p.send(t).strftime("%Y/%m/%d") rescue "")} + elsif t == "advising_students" + pd_data << {"data_title" => p.advising_students_front_data} else pd_data << { "data_title" => p.send(t) } end end { "pd_datas" => pd_data, - "type-sort" => (p.honor_type.sort_position.to_i rescue 1000), + "type-sort" => (p.academic_advising_type.sort_position.to_i rescue 1000), "sort-index" => index } @@ -98,15 +107,17 @@ class Honor def get_plugin_field_data(field) case field - when "honoree" + when "academic_advisingee" path = OrbitHelper.url_to_plugin_show(self.member_profile.to_param, 'member') rescue '#' value = "" + self.member_profile.name + "" when "language" value = I18n.t(self.language) rescue "" - when "honor_type" - value = self.honor_type.title rescue "" + when "academic_advising_type" + value = self.academic_advising_type.title rescue "" when "award_date" value = self.award_date.strftime("%Y/%m/%d") rescue "" + when "advising_students" + value = self.advising_students_front_data else value = self.send(field) rescue "" end @@ -115,9 +126,9 @@ class Honor { "key"=>field, - "title_class"=>"honor-#{field.gsub('_','-')}-field", - "value_class"=>"honor-#{field.gsub('_','-')}-value", - "title"=>I18n.t('personal_honor.'+field), + "title_class"=>"academic_advising-#{field.gsub('_','-')}-field", + "value_class"=>"academic_advising-#{field.gsub('_','-')}-value", + "title"=>I18n.t('academic_advising.'+field), "value"=>value } end diff --git a/app/models/advising_intro.rb b/app/models/advising_intro.rb new file mode 100644 index 0000000..03949e1 --- /dev/null +++ b/app/models/advising_intro.rb @@ -0,0 +1,4 @@ +class AdvisingIntro < PersonalPluginIntro + + +end diff --git a/app/models/honor_type.rb b/app/models/advising_type.rb similarity index 74% rename from app/models/honor_type.rb rename to app/models/advising_type.rb index 4d7a51d..f391030 100644 --- a/app/models/honor_type.rb +++ b/app/models/advising_type.rb @@ -1,9 +1,9 @@ -class HonorType +class AdvisingType include Mongoid::Document include Mongoid::Timestamps field :title, localize: true field :sort_position, :type => Integer, :default => 0 - has_many :honors + has_many :academic_advisings end \ No newline at end of file diff --git a/app/models/honor_intro.rb b/app/models/honor_intro.rb deleted file mode 100644 index 0fcfdcc..0000000 --- a/app/models/honor_intro.rb +++ /dev/null @@ -1,4 +0,0 @@ -class HonorIntro < PersonalPluginIntro - - -end diff --git a/app/views/personal_honors/get_fields_for_index.html.erb b/app/views/academic_advisings/get_fields_for_index.html.erb similarity index 89% rename from app/views/personal_honors/get_fields_for_index.html.erb rename to app/views/academic_advisings/get_fields_for_index.html.erb index 1efddb3..047af58 100644 --- a/app/views/personal_honors/get_fields_for_index.html.erb +++ b/app/views/academic_advisings/get_fields_for_index.html.erb @@ -4,11 +4,11 @@ diff --git a/app/views/personal_honors/index.html.erb b/app/views/academic_advisings/index.html.erb similarity index 100% rename from app/views/personal_honors/index.html.erb rename to app/views/academic_advisings/index.html.erb diff --git a/app/views/personal_honors/show.html.erb b/app/views/academic_advisings/show.html.erb similarity index 100% rename from app/views/personal_honors/show.html.erb rename to app/views/academic_advisings/show.html.erb diff --git a/app/views/admin/honor_types/_form.html.erb b/app/views/admin/academic_advising_types/_form.html.erb similarity index 64% rename from app/views/admin/honor_types/_form.html.erb rename to app/views/admin/academic_advising_types/_form.html.erb index 9c31358..11fc75a 100644 --- a/app/views/admin/honor_types/_form.html.erb +++ b/app/views/admin/academic_advising_types/_form.html.erb @@ -1,7 +1,7 @@ -<%= form_for(@honor_type, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %> +<%= form_for(@academic_advising_type, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %> <% if params[:error] == "1" %> <% end %> \ No newline at end of file diff --git a/app/views/admin/academic_advisings/new.html.erb b/app/views/admin/academic_advisings/new.html.erb new file mode 100644 index 0000000..5c7cabe --- /dev/null +++ b/app/views/admin/academic_advisings/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @academic_advising, url: admin_academic_advisings_path, html: {class: "form-horizontal main-forms previewable"} do |f| %> +
+ <%= render partial: 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/honors/setting.html.erb b/app/views/admin/academic_advisings/setting.html.erb similarity index 59% rename from app/views/admin/honors/setting.html.erb rename to app/views/admin/academic_advisings/setting.html.erb index 4b6e5d2..29250b6 100644 --- a/app/views/admin/honors/setting.html.erb +++ b/app/views/admin/academic_advisings/setting.html.erb @@ -24,8 +24,8 @@

- <%= t('add')%> - <%= t("personal_honor.honor_category") %> + <%= t('add')%> + <%= t("academic_advising.academic_advising_category") %>

@@ -37,9 +37,9 @@
- +
- <%= render :partial => 'list_honor_type', :collection => @honor_types.asc(:sort_position) %> + <%= render :partial => 'list_academic_advising_type', :collection => @academic_advising_types.asc(:sort_position) %>
@@ -49,19 +49,19 @@
-
-