Commit 9bcc6ad4 by nnnghia98

refatoring code

parent 7b646fb6
...@@ -27,7 +27,6 @@ gem 'config' ...@@ -27,7 +27,6 @@ gem 'config'
gem 'draper' gem 'draper'
gem 'rsolr' gem 'rsolr'
gem 'rsolr-ext' gem 'rsolr-ext'
gem 'pry'
gem 'nokogiri' gem 'nokogiri'
# Use Redis adapter to run Action Cable in production # Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0' # gem 'redis', '~> 4.0'
......
...@@ -3,33 +3,22 @@ class Users::AdminsController < ApplicationController ...@@ -3,33 +3,22 @@ class Users::AdminsController < ApplicationController
def index def index
redirect_to root_path unless current_user.role? redirect_to root_path unless current_user.role?
params[:search_user] ||= "" params[:search_user]
@applied_jobs = get_applied_jobs(params[:search_user]) @applied_jobs = get_applied_jobs
@user = User.find_by(email: params[:search_user]) @user = User.find_by(email: params[:search_user])
@users = User.all
end end
private private
def user_params def get_applied_jobs
params.require(:user).permit(:id, :email, :first_name, :last_name, :role) if params[:search_user]
end user = User.find_by(email: params[:search_user])
def get_applied_jobs(email)
applied_jobs = []
if email != ""
user = User.find_by(email: email)
return redirect_to users_admin_path, notice: "User/job not found!" if user.blank? return redirect_to users_admin_path, notice: "User/job not found!" if user.blank?
applied_jobs = user.jobs user.jobs
elsif email = "" || nil else
all_applied_jobs = UserJob.where.not(applied_at: nil).to_a UserJob.where.not(applied_at: nil).collect { |uj| uj.job }
(0..all_applied_jobs.count - 1).each do |each_job|
applied_jobs << (all_applied_jobs[each_job].job)
end
applied_jobs
end end
end end
end end
...@@ -4,7 +4,11 @@ module JobHelper ...@@ -4,7 +4,11 @@ module JobHelper
(params[:industry_id] ? "Industry: #{@jobs[0]["industry"]}" : params[:search]) (params[:industry_id] ? "Industry: #{@jobs[0]["industry"]}" : params[:search])
end end
def job_applied_at(job_id) def job_applied_at(job)
UserJob.where.not(applied_at: nil).find_by(job_id: job_id).applied_at job.user_jobs[0].applied_at
end
def get_all_user
User.all
end end
end end
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
# Indexes # Indexes
# #
# index_users_on_email (email) UNIQUE # index_users_on_email (email) UNIQUE
# index_users_on_reset_password_token (reset_password_token) UNIQUE # index_users_on_reset_password_token (reset_passsword_token) UNIQUE
# index_users_on_username (username) UNIQUE # index_users_on_username (username) UNIQUE
# #
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
<div class="job_data"> <div class="job_data">
<dl class="job_data_row"> <dl class="job_data_row">
<dt>Title</dt> <dt>Title</dt>
<dd><%= link_to applied_jobs.title, job_path(applied_jobs.id) %></dd> <dd><%= link_to applied_job.title, job_path(applied_job.id) %></dd>
</dl> </dl>
<dl class="job_data_row"> <dl class="job_data_row">
<dt>Salary</dt> <dt>Salary</dt>
<dd><%= applied_jobs.salary %></dd> <dd><%= applied_job.salary %></dd>
</dl> </dl>
<% if @user.present?%> <% if @user.present?%>
<dl class="job_data_row"> <dl class="job_data_row">
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</dl> </dl>
<dl class="job_data_row"> <dl class="job_data_row">
<dt>Applied at: </dt> <dt>Applied at: </dt>
<dd><%= job_applied_at(applied_jobs.id) %></dd> <dd><%= job_applied_at(applied_job) %></dd>
</dl> </dl>
<% end %> <% end %>
</div> </div>
......
<h4>Search user's applied jobs:</h4> <h4>Search user's applied jobs:</h4>
<%= form_tag(users_admin_path, method: :get) do |f| %> <%= form_tag(users_admin_path, method: :get) do |f| %>
<%= select_tag :search_user, options_from_collection_for_select(@users, "email", "email", params[:search_user]), include_blank: "Choose user's email" %> <%= select_tag :search_user, options_from_collection_for_select(get_all_user, "email", "email", params[:search_user]), include_blank: "Choose user's email" %>
<%= submit_tag "Search" %> <%= submit_tag "Search" %>
<% end %> <% end %>
<%= render partial: "applied_jobs", collection: @applied_jobs %> <%= render partial: "applied_job", collection: @applied_jobs %>
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment