From 96e759bc859dfb9263312c61ca9ccda92e5a7915 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Fri, 29 Dec 2017 20:00:33 +0800 Subject: [PATCH] advanced search, job filtering, job show page done --- app/controllers/recruitments_controller.rb | 206 +++++++++++++++++- app/models/employer_profile.rb | 12 + app/models/recruitment_job.rb | 9 +- .../recruitments/_employer_form.html.erb | 2 +- app/views/recruitments/_job_form.html.erb | 2 +- app/views/recruitments/advancedform.html.erb | 43 ++++ app/views/recruitments/index.html.erb | 37 +++- app/views/recruitments/show.html.erb | 1 + config/locales/en.yml | 47 +++- config/locales/zh_tw.yml | 44 +++- config/routes.rb | 1 + 11 files changed, 389 insertions(+), 15 deletions(-) create mode 100644 app/views/recruitments/advancedform.html.erb create mode 100644 app/views/recruitments/show.html.erb diff --git a/app/controllers/recruitments_controller.rb b/app/controllers/recruitments_controller.rb index d9c0419..bfc5d3d 100644 --- a/app/controllers/recruitments_controller.rb +++ b/app/controllers/recruitments_controller.rb @@ -1,11 +1,135 @@ class RecruitmentsController < PseudoSessionController - - before_filter :set_key_for_this - before_filter :load_profile, :except => ["newprofile", "createprofile"] - before_filter :is_user_authorized? + 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"] layout :get_layout def index + jobs = [] + params = OrbitHelper.params + if params[:type].present? && params[:type] == "aq" + rjobs = advanced_filter_jobs(params) + criteria = "- " + elsif params[:q].present? + rjobs = filter_jobs(params) + criteria = "- " + params[:q] + " " + else + criteria = "" + rjobs = RecruitmentJob.not_filled + end + if !rjobs.nil? && !rjobs.is_a?(Array) + rjobs = rjobs.desc(:created_at).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) + total_pages = rjobs.total_pages + else + rjobs = [] + total_pages = 0 + end + rjobs.each do |rj| + if rj.work_experience_years == 0 && rj.work_experience_months == 0 + wey = t("recruitment.fresher") + wem = "" + else + wey = (rj.work_experience_years.to_s rescue "0") + " year(s)" + wem = (rj.work_experience_months.to_s rescue "0") + " month(s)" + end + jobs << { + "company_name" => rj.employer_profile.company_name, + "industry" => rj.employer_profile.get_industry, + "avatar" => rj.employer_profile.get_avatar, + "title" => rj.job_title, + "url_to_show" => OrbitHelper.url_to_show(rj.to_param), + "description" => simple_format(truncate(rj.job_description, :length => 50)), + "postdate" => rj.created_at, + "work_type" => rj.work_type, + "location" => rj.location_of_work, + "work_experience_years" => wey, + "work_experience_months" => wem, + "category" => rj.category, + "skills" => rj.skills.collect{|skill| {"skill-tag" => skill}} + } + end + { + "jobs" => jobs, + "extras" => { + "criteria" => criteria + }, + "total_pages" => total_pages + } + end + + def show + params = OrbitHelper.params + job = RecruitmentJob.where(:uid => params[:uid]).first + profile = job.employer_profile + infos = [] + if !profile.company_profile.nil? && profile.company_profile != "" + infos << { + "title" => t("recruitment.company_profile"), + "text" => simple_format(profile.company_profile) + } + end + ["job_description", "responsibility", "other_conditions"].each do |jj| + if !job.send(jj).nil? && job.send(jj) != "" + infos << { + "title" => t("recruitment.#{jj}"), + "text" => simple_format(job.send(jj)) + } + end + end + if !job.skills.empty? + skills = job.skills.collect{|skill| "#{skill}"} + else + skills = t("recruitment.not_available") + end + + if job.work_experience_years == 0 && job.work_experience_months == 0 + experience = t("recruitment.fresher") + else + experience = (job.work_experience_years.to_s rescue "0") + " year(s) " + (job.work_experience_months.to_s rescue "0") + " month(s)" + end + if !job.holiday_system.nil? || job.holiday_system != "" + if job.holiday_system == "type2" && !job.holiday_system_other.nil? && job.holiday_system_other != "" + holiday = job.holiday_system_other + else + holiday = t("recruitment.holiday_system.#{job.holiday_system}") + end + else + holiday = t("recruitment.not_available") + end + { + "infos" => infos, + "data" => { + "job-title" => job.job_title, + "job-category" => job.get_category, + "avatar" => profile.get_avatar, + "company-name" => profile.company_name, + "industry" => profile.get_industry, + "post-date" => job.created_at, + "location-title" => t("recruitment.location"), + "location" => (!job.location_of_work.nil? && job.location_of_work != "" ? job.location_of_work : t("recruitment.not_available")), + "skills-title" => t("recruitment.skills_title"), + "skills" => skills.join(" "), + "experience-title" => t("recruitment.experience_title"), + "experience" => experience, + "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")), + "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"), + "joining" => (!job.joining_time.nil? && job.joining_time != "" ? t("recruitment.joining_time.#{job.joining_time}") : t("recruitment.not_available")), + "worktype-title" => t("recruitment.worktype_title"), + "worktype" => (!job.work_type.nil? && job.work_type != "" ? t("recruitment.work_type.#{job.work_type}") : t("recruitment.not_available")), + "language-title" => t("recruitment.language"), + "language" => (!job.language_requirement.nil? && job.language_requirement != "" ? job.language_requirement : t("recruitment.not_available")), + "workingtime-title" => t("recruitment.workingtime_title"), + "workingtime" => (!job.working_time.nil? && job.working_time != "" ? t("recruitment.working_time.#{job.working_time}") : t("recruitment.not_available")), + "holiday-title" => t("recruitment.holiday_title"), + "holiday" => holiday, + } + } end def firstruncheck @@ -16,6 +140,13 @@ class RecruitmentsController < PseudoSessionController end end + def advancedform + @industries = RecruitmentIndustry.all.asc(:industry_title).collect{|ri| [ri.industry_title, ri.id]} + @categories = RecruitmentCategory.all.asc(:job_category).collect{|ri| [ri.job_category, ri.id]} + @locations = RecruitmentJob.all.asc(:location_of_work).pluck(:location_of_work).uniq + render :layout => false + end + def select_profile end @@ -34,7 +165,7 @@ class RecruitmentsController < PseudoSessionController end def recruitment_dashboard - @jobsposted = @profile.profile.recruitment_jobs + @jobsposted = @profile.profile.recruitment_jobs.desc(:created_at) @page = "/#{I18n.locale.to_s}" + Page.where(:module => "recruitment").first.url rescue "#" end @@ -91,6 +222,65 @@ class RecruitmentsController < PseudoSessionController private + def filter_jobs(params) + rjobs = [] + + keywords = params[:q].split(",").collect{|s| /#{s.strip}/i} + companies = EmployerProfile.where(:company_name.in => keywords).pluck(:id) + skills = RecruitmentJob.where(:skills.in => keywords) + designations = RecruitmentJob.where(:job_title.in => keywords) + query = [] + if companies.count > 0 + query << {:employer_profile_id.in => companies} + end + if skills.count > 0 + query << {:skills.in => keywords} + end + if designations.count > 0 + query << {:job_title.in => keywords} + end + if !query.empty? + rjobs = RecruitmentJob.any_of(query).not_filled + end + rjobs + end + + def advanced_filter_jobs(params) + if params[:q].present? + rjobs = filter_jobs(params) + else + rjobs = [] + end + query = [] + if params[:exp].present? + if params[:exp].to_i > 0 + query << {:work_experience_years.gte => params[:exp].to_i} + else + query << {:work_experience_years => params[:exp]} + end + end + if params[:industry].present? + companies = EmployerProfile.where(:industry => params[:industry]).pluck(:id) + if companies.count > 0 + query << {:employer_profile_id.in => companies} + end + end + if params[:category].present? + query << {:category => params[:category]} + end + if params[:location].present? + query << {:location_of_work => /#{params[:location]}/i} + end + if !query.empty? + if !rjobs.empty? + rjobs = rjobs.where(query.reduce({}, :merge)) + else + rjobs = RecruitmentJob.where(query.reduce({}, :merge)) + end + end + rjobs + end + def get_layout "recruit" end @@ -105,8 +295,10 @@ class RecruitmentsController < PseudoSessionController def recruitment_job_params par = params.require(:recruitment_job).permit! - par[:skills] = par[:skills].split(",") if par[:skills].present? - par[:skills].collect!{|sk| sk.strip} + if par[:skills].present? + par[:skills] = par[:skills].split(",") + par[:skills].collect!{|sk| sk.strip} + end par end diff --git a/app/models/employer_profile.rb b/app/models/employer_profile.rb index f346b61..3de333f 100644 --- a/app/models/employer_profile.rb +++ b/app/models/employer_profile.rb @@ -21,4 +21,16 @@ class EmployerProfile belongs_to :recruit_profile has_many :recruitment_jobs, :dependent => :destroy + def get_avatar + if self.avatar.url.nil? + return "/assets/person.png" + else + return self.avatar.url + end + end + + def get_industry + RecruitmentIndustry.find(self.industry).industry_title rescue "" + end + end \ No newline at end of file diff --git a/app/models/recruitment_job.rb b/app/models/recruitment_job.rb index bd72ccc..2969a1c 100644 --- a/app/models/recruitment_job.rb +++ b/app/models/recruitment_job.rb @@ -15,8 +15,8 @@ class RecruitmentJob field :holiday_system_other field :joining_time #type1 => Immediate, type2 => withing week, type3 => within a month, type4 => more than a month field :work_type #type1 => Office worker, type2 => graduate, type3 => foreigner, type4 => internship, type5 => SOHO - field :work_experience_years, type: Integer - field :work_experience_months, type: Integer + field :work_experience_years, type: Integer, :default => 0 + field :work_experience_months, type: Integer, :default => 0 field :academic_requirement field :language_requirement field :skills, type: Array, :default => [] @@ -29,5 +29,10 @@ class RecruitmentJob belongs_to :employer_profile + scope :not_filled, ->{where(:filled => false)} + + def get_category + RecruitmentCategory.find(self.category).job_category rescue "" + end end \ No newline at end of file diff --git a/app/views/recruitments/_employer_form.html.erb b/app/views/recruitments/_employer_form.html.erb index b8552fe..04c33f8 100644 --- a/app/views/recruitments/_employer_form.html.erb +++ b/app/views/recruitments/_employer_form.html.erb @@ -67,7 +67,7 @@
<%= fe.label :industry, "Industry", :class => "col-sm-2 control-label" %>
- <%= fe.select :industry, RecruitmentIndustry.all.collect{|ri| [ri.industry_title, ri.id.to_s]}, {:include_blank => "Select Industry"}, {:class => "form-control"} %> + <%= fe.select :industry, RecruitmentIndustry.all.asc(:industry_title).collect{|ri| [ri.industry_title, ri.id.to_s]}, {:include_blank => "Select Industry"}, {:class => "form-control"} %>
diff --git a/app/views/recruitments/_job_form.html.erb b/app/views/recruitments/_job_form.html.erb index 33db05a..afe2320 100644 --- a/app/views/recruitments/_job_form.html.erb +++ b/app/views/recruitments/_job_form.html.erb @@ -65,7 +65,7 @@
<%= f.label :category, "Category", :class => "col-sm-2 control-label" %>
- <%= f.select :category, RecruitmentCategory.all.collect{|rc| [rc.job_category,rc.id.to_s]}, {:include_blank => "Select Category"},{:class => "form-control"} %> + <%= f.select :category, RecruitmentCategory.all.asc(:job_category).collect{|rc| [rc.job_category,rc.id.to_s]}, {:include_blank => "Select Category"},{:class => "form-control"} %>
diff --git a/app/views/recruitments/advancedform.html.erb b/app/views/recruitments/advancedform.html.erb new file mode 100644 index 0000000..1fcbe14 --- /dev/null +++ b/app/views/recruitments/advancedform.html.erb @@ -0,0 +1,43 @@ + + + \ No newline at end of file diff --git a/app/views/recruitments/index.html.erb b/app/views/recruitments/index.html.erb index 2e16afc..66c2d94 100644 --- a/app/views/recruitments/index.html.erb +++ b/app/views/recruitments/index.html.erb @@ -1 +1,36 @@ -index frontend \ No newline at end of file +<%= render_view %> + + + + \ No newline at end of file diff --git a/app/views/recruitments/show.html.erb b/app/views/recruitments/show.html.erb new file mode 100644 index 0000000..648b75c --- /dev/null +++ b/app/views/recruitments/show.html.erb @@ -0,0 +1 @@ +<%= render_view %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 65cc22f..02b00a8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -8,6 +8,49 @@ en: employer: Employer members: Members industries: Industry Type - categories: Job Categories + categories: Job Category industry_title: Industry Title - job_category: Job Category \ No newline at end of file + job_category: Job Category + company_profile: Company Profile + job_description: Job Description + responsibility: Job Responsibilities + other_conditions: Job Conditions + location: Location + not_available: Not Available + skills_title: Required Skills + experience_title: Min Experience + qualification: Qualification + salary-title: Salary + travel: Travel + joining: Joining Time + worktype_title: Work Type + language: Language Requirements + workingtime_title: Working Time + holiday_title: Holiday + fresher: Fresher + advanced_search: Advanced Search + salary: + type1: Negotiable + type2: According to company rules + type3: Monthly Salary + travel_assignment: + type1: Need to travel + type2: Occasionally + type3: Travelling not required + working_time: + type1: Day Shift + type2: Night Shift + holiday_system: + type1: According to company rules + type2: Other + joining_time: + type1: Immediate + type2: Within a week + type3: Within a month + type4: More than a month + work_type: + type1: Office Worker + type2: Graduate + type3: Foreigner + type4: Internship + type5: SOHO \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 3a0e772..b9d6774 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -10,4 +10,46 @@ zh_tw: industries: Industry Type categories: Job Categories industry_title: Industry Title - job_category: Job Category \ No newline at end of file + job_category: Job Category + company_profile: Company Profile + job_description: Job Description + responsibility: Job Responsibilities + other_conditions: Job Conditions + location: Location + not_available: Not Available + skills_title: Required Skills + experience_title: Experience + qualification: Qualification + salary-title: Salary + travel: Travel + joining: Joining Time + worktype_title: Work Type + language: Language Requirements + workingtime_title: Working Time + holiday_title: Holiday + fresher: Fresher + salary: + type1: Negotiable + type2: According to company rules + type3: Monthly Salary + travel_assignment: + type1: Need to travel + type2: Occasionally + type3: Travelling not required + working_time: + type1: Day Shift + type2: Night Shift + holiday_system: + type1: According to company rules + type2: Other + joining_time: + type1: Immediate + type2: Within a week + type3: Within a month + type4: More than a month + work_type: + type1: Office Worker + type2: Graduate + type3: Foreigner + type4: Internship + type5: SOHO \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 82a3b1e..e1fd501 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,6 +39,7 @@ Rails.application.routes.draw do get "/:id/markfilled", to: "recruitments#markfilled" get "/:id/unmarkfilled", to: "recruitments#unmarkfilled" delete "/:id/deletejob", to: "recruitments#deletejob" + get "/advancedform", to: "recruitments#advancedform" end end end