Commit a1a78ac9 by Van Hau Le

Merge branch 'feature/admin_page' into 'master'

Feature/admin page

See merge request !22
parents 2f65fef8 71dc2fcf
...@@ -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'
......
class AdminsController < ApplicationController
before_action :authenticate_user!, only: :index
def index
redirect_to root_path unless current_user.role?
params[:search_user]
@applied_jobs = get_applied_jobs
@user = User.find_by(email: params[:search_user])
end
private
def get_applied_jobs
if params[:search_user]
user = User.find_by(email: params[:search_user])
return redirect_to admin_path, notice: "User/job not found!" if user.blank?
applied_jobs = user.jobs
applied_jobs.page(params[:page]).per(Settings.job.per_page)
else
applied_jobs = Job.joins(:user_jobs).where.not(user_jobs: { applied_at: nil}).distinct
applied_jobs.page(params[:page]).per(Settings.job.per_page)
end
end
end
...@@ -3,4 +3,8 @@ module JobHelper ...@@ -3,4 +3,8 @@ module JobHelper
params[:city_id] ? "City: #{@jobs[0]["city"]}" : params[:city_id] ? "City: #{@jobs[0]["city"]}" :
(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)
job.user_jobs.find_by(user_id: current_user.id).applied_at
end
end end
...@@ -35,4 +35,8 @@ class User < ApplicationRecord ...@@ -35,4 +35,8 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable :recoverable, :rememberable, :validatable
def self.list_emails
@emails ||= all.pluck(:email)
end
end end
<div class="box">
<div class="job_data">
<dl class="job_data_row">
<dt>Title</dt>
<dd><%= link_to applied_job.title, job_path(applied_job.id) %></dd>
</dl>
<dl class="job_data_row">
<dt>Salary</dt>
<dd><%= applied_job.salary %></dd>
</dl>
<% if @user.present?%>
<dl class="job_data_row">
<dt>User's email: </dt>
<dd><%= @user.email %></dd>
</dl>
<dl class="job_data_row">
<dt>Applied at: </dt>
<dd><%= job_applied_at(applied_job) %></dd>
</dl>
<% end %>
</div>
</div>
<h4>Search user's applied jobs:</h4>
<%= form_tag(admin_path, method: :get) do |f| %>
<%= select_tag :search_user, options_for_select(User.list_emails, params[:search_user]), include_blank: "Choose user's email" %>
<%= submit_tag "Search" %>
<% end %>
<%= render partial: "applied_job", collection: @applied_jobs %>
...@@ -20,4 +20,5 @@ Rails.application.routes.draw do ...@@ -20,4 +20,5 @@ Rails.application.routes.draw do
end end
end end
end end
get "admin", to: "admins#index", as: :admin
end end
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