Commit aff6836e by Xuan Trung Le Committed by Xuan Trung Le

add history page

parent 82dfcdca
...@@ -7,7 +7,11 @@ class JobsController < ApplicationController ...@@ -7,7 +7,11 @@ class JobsController < ApplicationController
end end
def show def show
<<<<<<< 28f7fab9b8eeffd0552745bdf048484097ac3362
clear_session_candidate clear_session_candidate
=======
current_user.view(Job.find(params[:id])) if current_user
>>>>>>> add history page
end end
def city def city
......
...@@ -6,4 +6,8 @@ class MyPagesController < ApplicationController ...@@ -6,4 +6,8 @@ class MyPagesController < ApplicationController
def my_job def my_job
@jobs = current_user.applied_jobs.includes(:apply_jobs).includes(:company) @jobs = current_user.applied_jobs.includes(:apply_jobs).includes(:company)
end end
def history
@jobs = current_user.viewed_jobs.includes(:apply_jobs).includes(:company).limit(20)
end
end end
...@@ -9,6 +9,10 @@ class Job < ApplicationRecord ...@@ -9,6 +9,10 @@ class Job < ApplicationRecord
has_many :cities_jobs has_many :cities_jobs
has_many :cities, through: :cities_jobs has_many :cities, through: :cities_jobs
has_many :users_jobs
has_many :views, -> { where(action: :VIEW) }, class_name: 'UsersJob'
has_many :users_has_viewed, through: :views, class_name: 'User', source: :user
scope :top_list, -> { order(updated_date: :desc).limit(Settings.top.job_per_page) } scope :top_list, -> { order(updated_date: :desc).limit(Settings.top.job_per_page) }
def self.create_new_jobs(arr_jobs) def self.create_new_jobs(arr_jobs)
......
...@@ -6,6 +6,10 @@ class User < ApplicationRecord ...@@ -6,6 +6,10 @@ class User < ApplicationRecord
has_many :favorite_jobs has_many :favorite_jobs
has_many :liked_jobs, through: :favorite_jobs, class_name: 'Job', source: :job has_many :liked_jobs, through: :favorite_jobs, class_name: 'Job', source: :job
has_many :users_jobs
has_many :jobs_views, -> { where(action: :VIEW) }, class_name: 'UsersJob'
has_many :viewed_jobs, through: :jobs_views, class_name: 'Job', source: :job
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
...@@ -39,4 +43,16 @@ class User < ApplicationRecord ...@@ -39,4 +43,16 @@ class User < ApplicationRecord
return false if skip_validation return false if skip_validation
super super
end end
def view(job)
viewed_jobs << job unless viewed_jobs.include?(job)
end
def like(job)
liked_jobs << job unless liked_jobs.include?(job)
end
def unlike(job)
liked_jobs.delete(job.id)
end
end end
class UsersJob < ApplicationRecord
belongs_to :user
belongs_to :job
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<%- if current_user -%> my_pages <%- if current_user -%> my_pages
<li> <li>
<%= link_to my_pages_path do %> <%= link_to my_my_pages_path do %>
<i class="fa fa-user" aria-hidden="true"></i> My Page <i class="fa fa-user" aria-hidden="true"></i> My Page
<% end %> <% end %>
</li> </li>
...@@ -27,12 +27,21 @@ ...@@ -27,12 +27,21 @@
<% end %> <% end %>
</li> </li>
<%- end -%> <%- end -%>
<<<<<<< 2bb315a626e08b91ef63909403c9791c9db5b2b1
<li> <li>
<%= link_to favorites_path do %> Favorite <%= link_to favorites_path do %> Favorite
<i class="fa fa-star" aria-hidden="true"></i> <i class="fa fa-star" aria-hidden="true"></i>
<% end %> <% end %>
</li> </li>
<li><a href="#"><i class="fa fa-history" aria-hidden="true"></i></span> History</a></li> <li><a href="#"><i class="fa fa-history" aria-hidden="true"></i></span> History</a></li>
=======
<li><a href="#"><i class="fa fa-star" aria-hidden="true"></i></span> Favorite</a></li>
<li>
<%= link_to history_my_pages_path do %>
<i class="fa fa-history" aria-hidden="true"></i> History
<% end %>
</li>
>>>>>>> add history page
</ul> </ul>
</div> </div>
</nav> </nav>
<div class="row">
<div class="container">
<div class="jobs clearfix">
<div class="job col-md-12">
<h3>History</h3>
<table class="table">
<tbody>
<%- @jobs.each do |job|-%>
<tr>
<td class="col-md-1 position-relative">
<input type="radio" name="rbn-apply-job" class="mid-heigth">
</td>
<td class="col-md-9">
<h4 class="mr0"><%= link_to job.name, job_path(job) %></h4>
<p><strong>Description:</strong><%= strip_tags(job.description)[0...250] %>...</p>
<p>
<span><%= "<strong>Loacation</strong>: #{job.company.location}".html_safe %></span>
<span class="navbar-right"><%= "<strong>Salary</strong>: #{job.salary}".html_safe %></span>
</p>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<%= button_to "Apply", nil, class: "btn btn-primary btn-lg" %>
</div>
</div>
</div>
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<span><%= link_to @user.cv, "#"%></span> <span><%= link_to @user.cv, "#"%></span>
<br> <br>
<div class="col-md-6"> <div class="col-md-6">
<%= link_to "Update", "#", class: "btn btn-primary navbar-right" %> <%= link_to "Update", edit_user_registration_path, class: "btn btn-primary navbar-right" %>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<%= link_to "My jobs", jobs_my_pages_path, class: "btn btn-primary" %> <%= link_to "My jobs", jobs_my_pages_path, class: "btn btn-primary" %>
......
...@@ -21,14 +21,16 @@ Rails.application.routes.draw do ...@@ -21,14 +21,16 @@ Rails.application.routes.draw do
end end
resources :jobs do resources :jobs do
collection do collection do
get 'city/:city_id' => "jobs#city", as: :city get 'city/:city_id' => 'jobs#city', as: :city
get 'industry/:industry_id' => "jobs#industry", as: :industry get 'industry/:industry_id' => 'jobs#industry', as: :industry
get 'company/:company_id' => "jobs#company", as: :company get 'company/:company_id' => 'jobs#company', as: :company
end end
end end
resources :my_pages, only: [:index] do resources :my_pages, path: '', only: [:index] do
collection do collection do
get 'my' => 'my_pages#index'
get 'my/jobs' => 'my_pages#my_job', as: :jobs get 'my/jobs' => 'my_pages#my_job', as: :jobs
get 'history' => 'my_pages#history', as: :history
end end
end end
end end
class CreateUsersJobs < ActiveRecord::Migration[5.1]
def change
create_table :users_jobs do |t|
t.references :user, foreign_key: true
t.references :job, foreign_key: true
t.string :action
t.timestamps
end
end
end
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