Commit 9bcc6ad4 by nnnghia98

refatoring code

parent 7b646fb6
......@@ -27,7 +27,6 @@ gem 'config'
gem 'draper'
gem 'rsolr'
gem 'rsolr-ext'
gem 'pry'
gem 'nokogiri'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
......
......@@ -3,33 +3,22 @@ class Users::AdminsController < ApplicationController
def index
redirect_to root_path unless current_user.role?
params[:search_user] ||= ""
@applied_jobs = get_applied_jobs(params[:search_user])
params[:search_user]
@applied_jobs = get_applied_jobs
@user = User.find_by(email: params[:search_user])
@users = User.all
end
private
def user_params
params.require(:user).permit(:id, :email, :first_name, :last_name, :role)
end
def get_applied_jobs(email)
applied_jobs = []
if email != ""
user = User.find_by(email: email)
def get_applied_jobs
if params[:search_user]
user = User.find_by(email: params[:search_user])
return redirect_to users_admin_path, notice: "User/job not found!" if user.blank?
applied_jobs = user.jobs
elsif email = "" || nil
all_applied_jobs = UserJob.where.not(applied_at: nil).to_a
(0..all_applied_jobs.count - 1).each do |each_job|
applied_jobs << (all_applied_jobs[each_job].job)
end
applied_jobs
user.jobs
else
UserJob.where.not(applied_at: nil).collect { |uj| uj.job }
end
end
end
......@@ -4,7 +4,11 @@ module JobHelper
(params[:industry_id] ? "Industry: #{@jobs[0]["industry"]}" : params[:search])
end
def job_applied_at(job_id)
UserJob.where.not(applied_at: nil).find_by(job_id: job_id).applied_at
def job_applied_at(job)
job.user_jobs[0].applied_at
end
def get_all_user
User.all
end
end
......@@ -23,7 +23,7 @@
# Indexes
#
# 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
#
......
......@@ -2,11 +2,11 @@
<div class="job_data">
<dl class="job_data_row">
<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 class="job_data_row">
<dt>Salary</dt>
<dd><%= applied_jobs.salary %></dd>
<dd><%= applied_job.salary %></dd>
</dl>
<% if @user.present?%>
<dl class="job_data_row">
......@@ -15,7 +15,7 @@
</dl>
<dl class="job_data_row">
<dt>Applied at: </dt>
<dd><%= job_applied_at(applied_jobs.id) %></dd>
<dd><%= job_applied_at(applied_job) %></dd>
</dl>
<% end %>
</div>
......
<h4>Search user's applied jobs:</h4>
<%= 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" %>
<% 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