From 280fb5407ef4b29c6d0efe0cd4120e2b88a85f6d Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 11 Jan 2018 20:21:16 +0800 Subject: [PATCH] recommendations added and minor changes done asked by nthu --- app/controllers/recruitments_controller.rb | 68 +++++++++- app/models/employee_profile.rb | 4 +- app/models/employee_recommendation.rb | 11 ++ app/models/recruitment_job.rb | 9 +- .../recruitments/_dashboard_header.html.erb | 1 + app/views/recruitments/_job_form.html.erb | 42 ++++-- app/views/recruitments/addjob.html.erb | 9 +- .../create_recommendation.html.erb | 6 + app/views/recruitments/editjob.html.erb | 9 +- .../recruitments/employee_portfolio.html.erb | 4 +- .../employee_recommendation.html.erb | 126 ++++++++++++++++++ .../recommendation_email.html.erb | 9 ++ .../write_recommendation.html.erb | 61 +++++++++ config/locales/en.yml | 27 +++- config/locales/zh_tw.yml | 21 +++ config/routes.rb | 5 + 16 files changed, 385 insertions(+), 27 deletions(-) create mode 100644 app/models/employee_recommendation.rb create mode 100644 app/views/recruitments/create_recommendation.html.erb create mode 100644 app/views/recruitments/employee_recommendation.html.erb create mode 100644 app/views/recruitments/recommendation_email.html.erb create mode 100644 app/views/recruitments/write_recommendation.html.erb diff --git a/app/controllers/recruitments_controller.rb b/app/controllers/recruitments_controller.rb index 59c2242..5bc76d8 100644 --- a/app/controllers/recruitments_controller.rb +++ b/app/controllers/recruitments_controller.rb @@ -2,7 +2,7 @@ class RecruitmentsController < PseudoSessionController include ActionView::Helpers::TextHelper before_filter :set_key_for_this, :except => ["index", "show"] before_filter :load_profile, :except => ["newprofile", "createprofile", "index", "show", "advancedform"] - before_filter :is_user_authorized?, :except => ["index", "show", "advancedform"] + before_filter :is_user_authorized?, :except => ["index", "show", "advancedform", "write_recommendation", "create_recommendation"] layout :get_layout def index @@ -147,7 +147,7 @@ class RecruitmentsController < PseudoSessionController end skills = profile.skills.collect{|skill| {"skill-name" => skill}} if !profile.skills.empty? infos = [] - ["autobiography", "resume_content", "recommendation1_info", "recommendation2_info"].each do |t| + ["autobiography", "resume_content"].each do |t| if !profile.send(t).nil? && profile.send(t) != "" infos << { "title" => t("recruitment.#{t}"), @@ -155,6 +155,16 @@ class RecruitmentsController < PseudoSessionController } end end + + recommendations = [] + profile.employee_recommendations.desc(:creted_at).each do |rec| + recommendations << { + "name" => rec.name, + "email" => rec.email, + "rec-letter" => rec.info + } + end + if profile.experience_years == 0 && profile.experience_months == 0 experience = t("recruitment.fresher") else @@ -163,6 +173,7 @@ class RecruitmentsController < PseudoSessionController { "skills" => skills, "infos" => infos, + "recommendations" => recommendations, "data" => { "name" => rp.name, "job-title" => profile.desired_job_title, @@ -185,6 +196,7 @@ class RecruitmentsController < PseudoSessionController "language" => profile.languages, "workingtime-title" => t("recruitment.workingtime_title"), "workingtime" => (!profile.working_time.nil? && profile.working_time != "" ? t("recruitment.working_time.#{profile.working_time}") : t("recruitment.not_available")), + "recommendation-title" => t("recruitment.recommendation") } } end @@ -241,6 +253,13 @@ class RecruitmentsController < PseudoSessionController end end end + if job.max_salary > job.min_salary + range = (job.min_salary * 1000).to_s + " ~ " + (job.max_salary * 1000).to_s + " / Month " + elsif job.max_salary == job.min_salary + range = t("recruitment.not_available") + elsif job.max_salary < job.min_salary + range = (job.min_salary * 1000).to_s + " ~ #{t('recruitment.salary.type1')} / Month" + end { "infos" => infos, "data" => { @@ -256,10 +275,14 @@ class RecruitmentsController < PseudoSessionController "skills" => skills, "experience-title" => t("recruitment.experience_title"), "experience" => experience, + "min-qualification-title" => t("recruitment.min_qualification"), + "min-qualification" => (!job.academic_type.nil? && job.academic_type != "" ? t("recruitment.academic_type.#{job.academic_type}") : t("recruitment.not_available")), "qualification-title" => t("recruitment.qualification"), "qualification" => (!job.academic_requirement.nil? && job.academic_requirement != "" ? simple_format(job.academic_requirement) : t("recruitment.not_available")), "salary-title" => t("recruitment.salary-title"), "salary" => (!job.salary.nil? && job.salary != "" ? t("recruitment.salary.#{job.salary}") : t("recruitment.not_available")), + "salary-range" => t("recruitment.salary_range"), + "range" => range, "travel-title" => t("recruitment.travel"), "travel" => (!job.travel_assignment.nil? && job.travel_assignment != "" ? t("recruitment.travel_assignment.#{job.travel_assignment}") : t("recruitment.not_available")), "joining-title" => t("recruitment.joining"), @@ -423,6 +446,41 @@ class RecruitmentsController < PseudoSessionController end end + def employee_recommendation + @recommendations = @profile.profile.employee_recommendations.desc(:created_at) + if request.request_method == "POST" + token = rand(10**8).to_s + eprofile = @profile.profile + eprofile.recommendation_tokens << token + eprofile.save + url = "http://#{request.host_with_port}/recruit/#{@profile.uid}/write_recommendation?token=#{token}" + data = {"url" => url, "letter" => params[:request_letter], "referral_name" => params[:referral_name], "name" => @profile.name, "respected" => t("recruitment.respected"), "recommendation_link" => t("recruitment.recommendation_link"), "yours_sincerely" => t("recruitment.yours_sincerely")} + email = Email.new + email.mail_to = params[:referral_email] + email.mail_subject = t("recruitment.recommendation_subject") + email.template = "recruitments/recommendation_email.html.erb" + email.template_data = data + email.deliver + redirect_to employee_recommendation_path + end + end + + def write_recommendation + @profile = RecruitProfile.where(:uid => params[:id]).first + @is_written = @profile.profile.employee_recommendations.where(:employee_recommendation_token => params[:token]).count > 0 + @recommendation = EmployeeRecommendation.new + end + + def create_recommendation + rec = EmployeeRecommendation.create(recommendation_params) + end + + def delete_employee_recommendation + rec = EmployeeRecommendation.find(params[:id]) + rec.destroy + redirect_to employee_recommendation_path + end + def edit_employee_experience @experience = EmployeeExperience.find(params[:id]) end @@ -435,10 +493,12 @@ class RecruitmentsController < PseudoSessionController def addjob @job = RecruitmentJob.new + @academic_types = ["type1","type2","type3"].collect{|t| [t("recruitment.academic_type.#{t}"), t]} end def editjob @job = RecruitmentJob.find(params[:id]) + @academic_types = ["type1","type2","type3"].collect{|t| [t("recruitment.academic_type.#{t}"), t]} end def createjob @@ -577,4 +637,8 @@ class RecruitmentsController < PseudoSessionController par end + def recommendation_params + params.require(:employee_recommendation).permit! + end + end \ No newline at end of file diff --git a/app/models/employee_profile.rb b/app/models/employee_profile.rb index fd0570a..b8620db 100644 --- a/app/models/employee_profile.rb +++ b/app/models/employee_profile.rb @@ -24,11 +24,10 @@ class EmployeeProfile field :working_time #type1 -> day shift type2 -> night shift field :skills, type: Array, :default => [] field :languages - field :recommendation1_info - field :recommendation2_info field :experience_years, type: Integer, :default => 0 field :experience_months, type: Integer, :default => 0 field :introduction, localize: true + field :recommendation_tokens, type: Array, :default => [] mount_uploader :resume, AssetUploader @@ -39,6 +38,7 @@ class EmployeeProfile has_many :employee_academics has_many :employee_experiences has_many :employee_job_applications + has_many :employee_recommendations scope :job_seekers, ->{where(:active => true)} diff --git a/app/models/employee_recommendation.rb b/app/models/employee_recommendation.rb new file mode 100644 index 0000000..efa2db3 --- /dev/null +++ b/app/models/employee_recommendation.rb @@ -0,0 +1,11 @@ +class EmployeeRecommendation + include Mongoid::Document + include Mongoid::Timestamps + + field :name + field :email + field :info + field :employee_recommendation_token + + belongs_to :employee_profile +end \ No newline at end of file diff --git a/app/models/recruitment_job.rb b/app/models/recruitment_job.rb index 8a09c9a..6b68424 100644 --- a/app/models/recruitment_job.rb +++ b/app/models/recruitment_job.rb @@ -3,12 +3,13 @@ class RecruitmentJob include Mongoid::Timestamps include Slug - + field :post_type #type1 => Job, type2 => Internship, type3 => Exchange + field :job_title, as: :slug_title, localize: true field :job_description, localize: true field :responsibility, localize: true field :other_conditions, localize: true - field :salary #type1 => negotiable type2 => according to company rules type3 => monthly salary + field :salary #type1 => negotiable type2 => according to company rules field :travel_assignment #type1 => Need to travel, type2 => occasionally, type3 => travelling not required field :working_time #type1 => Day Shift, type2 => Night Shift field :holiday_system #type1 => According to Company Rules, type2 => other @@ -23,6 +24,10 @@ class RecruitmentJob field :category field :location_of_work field :industrial_area + field :academic_type #type1 -> bachelors, type2 -> masters, type3 -> phd, type4 -> course + field :min_salary, type: Integer, :default => 0 + field :max_salary, type: Integer, :default => 0 + field :filled, type: Boolean, :default => false diff --git a/app/views/recruitments/_dashboard_header.html.erb b/app/views/recruitments/_dashboard_header.html.erb index c8b4f5c..ae07605 100644 --- a/app/views/recruitments/_dashboard_header.html.erb +++ b/app/views/recruitments/_dashboard_header.html.erb @@ -12,6 +12,7 @@ + <% end %> <% if params[:action] == "recruitment_dashboard" && @profile.is_employer? %> diff --git a/app/views/recruitments/_job_form.html.erb b/app/views/recruitments/_job_form.html.erb index 7360377..29ca1df 100644 --- a/app/views/recruitments/_job_form.html.erb +++ b/app/views/recruitments/_job_form.html.erb @@ -69,8 +69,18 @@ -