Commit e080bec1 by Xuan Trung Le

update link to download cv my page

parent dd88deb0
...@@ -17,4 +17,7 @@ ...@@ -17,4 +17,7 @@
$(document).ready(function(){ $(document).ready(function(){
$('.message').delay(5000).fadeOut('slow'); $('.message').delay(5000).fadeOut('slow');
$(document).on('change', 'input[name=job_id]', function(event) {
$('#apply').removeAttr('disabled')
});
}); });
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
before_action :authenticate_user!
helper_method :clear_session_candidate helper_method :clear_session_candidate
def clear_session_candidate def clear_session_candidate
......
class AppliesController < ApplicationController class AppliesController < ApplicationController
before_action :authenticate_user!
def apply def apply
session[:job_id] = params[:job_id] if params[:job_id] session[:job_id] = params[:job_id] if params[:job_id]
if session[:candidate].present? if session[:candidate].present?
......
class CitiesController < ApplicationController class CitiesController < ApplicationController
skip_before_action :authenticate_user!
def index def index
@cities = City.city_list @cities = City.city_list
end end
......
class IndustriesController < ApplicationController class IndustriesController < ApplicationController
skip_before_action :authenticate_user!
def index def index
@industries = Industry.industry_list @industries = Industry.industry_list
end end
......
class JobsController < ApplicationController class JobsController < ApplicationController
before_action :set_job, only: [:show] before_action :set_job, only: [:show]
skip_before_action :authenticate_user!, only: [:index, :city, :industry, :company, :show]
def index def index
@jobs = Job.top_list.includes(:company) @jobs = Job.top_list.includes(:company)
@cities = City.top_cities.includes(:country) @cities = City.top_cities.includes(:country)
......
...@@ -10,4 +10,13 @@ class MyPagesController < ApplicationController ...@@ -10,4 +10,13 @@ class MyPagesController < ApplicationController
def history def history
@jobs = current_user.viewed_jobs.includes(:apply_jobs).includes(:company).limit(20) @jobs = current_user.viewed_jobs.includes(:apply_jobs).includes(:company).limit(20)
end end
def download_cv
if File.exist?(current_user.cv.path)
send_file current_user.cv.path
else
flash[:notice] = 'File not exist!'
redirect_back(fallback_location: root_path)
end
end
end end
module ApplicationHelper module ApplicationHelper
def user_has_applied?(job)
current_user && current_user.applied?(job) ? true : false
end
end end
...@@ -8,10 +8,8 @@ class Job < ApplicationRecord ...@@ -8,10 +8,8 @@ class Job < ApplicationRecord
has_many :industries, through: :industries_jobs has_many :industries, through: :industries_jobs
has_many :cities_jobs has_many :cities_jobs
has_many :cities, through: :cities_jobs has_many :cities, through: :cities_jobs
has_many :view_jobs
has_many :users_jobs has_many :users_has_viewed, through: :view_jobs, class_name: 'User', source: :user
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) }
...@@ -58,19 +56,18 @@ class Job < ApplicationRecord ...@@ -58,19 +56,18 @@ class Job < ApplicationRecord
puts "Saving #{item[:name]} ......................................" puts "Saving #{item[:name]} ......................................"
if job.save if job.save
puts "Job was successfully created" puts 'Job was successfully created'
else else
puts "Error..." puts 'Error...'
end end
end end
end end
def self.filter_link_exist(links) def self.filter_link_exist(links)
return links - Job.where(original_link: links).pluck(:original_link) links - Job.where(original_link: links).pluck(:original_link)
end end
def applied_at(user_id) def applied_at(user_id)
self.apply_jobs.select{|application| application.user_id = user_id}.first.created_at apply_jobs.select{ |application| application.user_id = user_id }.first.created_at
end end
end end
...@@ -5,10 +5,8 @@ class User < ApplicationRecord ...@@ -5,10 +5,8 @@ class User < ApplicationRecord
has_many :applied_jobs, through: :apply_jobs, class_name: 'Job', source: :job has_many :applied_jobs, through: :apply_jobs, class_name: 'Job', source: :job
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 :view_jobs
has_many :users_jobs has_many :viewed_jobs, through: :view_jobs, class_name: 'Job', source: :job
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
...@@ -38,7 +36,15 @@ class User < ApplicationRecord ...@@ -38,7 +36,15 @@ class User < ApplicationRecord
end end
def view(job) def view(job)
viewed_jobs << job unless viewed_jobs.include?(job) viewed_jobs << job unless viewed?(job)
end
def viewed?(job)
viewed_jobs.include?(job)
end
def applied?(job)
applied_jobs.include?(job)
end end
private private
......
class ViewJob < ApplicationRecord
belongs_to :user
belongs_to :job
end
...@@ -18,6 +18,11 @@ ...@@ -18,6 +18,11 @@
</ol> </ol>
</ol> </ol>
<div class="job"> <div class="job">
<% if user_has_applied?(@job) %>
<div class="alert alert-success" role="alert">
You have applied this job.
</div>
<% end %>
<div class="col-md-9"> <div class="col-md-9">
<h1>2.<%= @job.name %></h1> <h1>2.<%= @job.name %></h1>
<p>3.<%= link_to @job.company.name, company_jobs_path(@job.company) %></p> <p>3.<%= link_to @job.company.name, company_jobs_path(@job.company) %></p>
...@@ -33,13 +38,16 @@ ...@@ -33,13 +38,16 @@
</p> </p>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<%= link_to "Apply", apply_applies_path(job_id: @job.id), class: "btn btn-primary btn-lg" %> <%= link_to "Apply",
apply_applies_path(job_id: @job.id),
class: "btn btn-primary btn-lg #{user_has_applied?(@job) ? 'disabled' : ''} btn-block" %>
</div> </div>
<div class="action"> <div class="action">
<div class="col-md-6"> <div class="col-md-6">
<%= link_to "Apply", apply_applies_path(job_id: @job.id), class: "btn btn-primary btn-lg" %> <%= link_to "Apply",
apply_applies_path(job_id: @job.id),
class: "btn btn-primary btn-lg #{user_has_applied?(@job) ? 'disabled' : ''} btn-block" %>
</div> </div>
<div class="action">
<div class="col-md-6"> <div class="col-md-6">
<%= button_to "Favorite", <%= button_to "Favorite",
job_favorites_path(job_id: @job.id), job_favorites_path(job_id: @job.id),
...@@ -47,5 +55,4 @@ ...@@ -47,5 +55,4 @@
</div> </div>
</div> </div>
</div> </div>
</div>
</div> </div>
...@@ -14,7 +14,11 @@ ...@@ -14,7 +14,11 @@
<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>
<li><a href="#"><i class="fa fa-plus" aria-hidden="true"></i> Logout</a></li> <li>
<%= link_to destroy_user_session_path, method: :delete do %>
<i class="fa fa-sign-out" aria-hidden="true"></i>Logout
<% end %>
</li>
<%- else -%> <%- else -%>
<li> <li>
<%= link_to new_user_session_path do %> <%= link_to new_user_session_path do %>
...@@ -22,8 +26,13 @@ ...@@ -22,8 +26,13 @@
<% end %> <% end %>
</li> </li>
<li> <li>
<<<<<<< 28961f125c2471f7b2c147015938987727aa3193
<%= link_to new_user_session_path do %> <%= link_to new_user_session_path do %>
<i class="fa fa-sign-in" aria-hidden="true"></i> Login <i class="fa fa-sign-in" aria-hidden="true"></i> Login
=======
<%= link_to register_path(step: 1) do %>
<i class="fa fa-plus-circle" aria-hidden="true"></i> Register
>>>>>>> update link to download cv my page
<% end %> <% end %>
</li> </li>
<%- end -%> <%- end -%>
......
...@@ -4,14 +4,16 @@ ...@@ -4,14 +4,16 @@
<div class="job col-md-12"> <div class="job col-md-12">
<h3>History</h3> <h3>History</h3>
<table class="table"> <table class="table">
<%= form_tag apply_applies_path, method: :get do %>
<tbody> <tbody>
<%- @jobs.each do |job|-%> <%- @jobs.each do |job|-%>
<tr> <tr>
<td class="col-md-1 position-relative"> <td class="col-md-1 position-relative">
<input type="radio" name="rbn-apply-job" class="mid-heigth"> <%= radio_button_tag "job_id", job.id, false, class: "mid-heigth",
disabled: user_has_applied?(job) ? true : false %>
</td> </td>
<td class="col-md-9"> <td class="col-md-9">
<h4 class="mr0"><%= link_to job.name, job_path(job) %></h4> <h4 class="mr0"><%= link_to job.name + "#{user_has_applied?(job) ? ' (APPLIED)' : ''}", job_path(job) %></h4>
<p><strong>Description:</strong><%= strip_tags(job.description)[0...250] %>...</p> <p><strong>Description:</strong><%= strip_tags(job.description)[0...250] %>...</p>
<p> <p>
<span><%= "<strong>Loacation</strong>: #{job.company.location}".html_safe %></span> <span><%= "<strong>Loacation</strong>: #{job.company.location}".html_safe %></span>
...@@ -20,10 +22,17 @@ ...@@ -20,10 +22,17 @@
</td> </td>
</tr> </tr>
<% end %> <% end %>
<tr>
<td></td>
<td>
<%= submit_tag "Applys", class: "btn btn-primary btn-lg btn-block", id: "apply", disabled: true %>
</td>
<td></td>
</tr>
</tbody> </tbody>
<% end %>
</table> </table>
</div> </div>
<%= button_to "Apply", nil, class: "btn btn-primary btn-lg" %>
</div> </div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="container"> <div class="container">
<h2>MY PAGE</h2> <div class="col-sm-6 col-md-offset-3 toppad" >
<div class="input-group"> <div class="panel panel-info">
<span class="input-group-addon" id="basic-addon1">Mail</span> <div class="panel-heading">
<input type="text" <h3 class="panel-title">My Page</h3>
value="<%= @user.email %>" </div>
class="form-control" <div class="panel-body">
placeholder="Email" <div class="row">
aria-describedby="basic-addon1" <div class=" col-md-12">
disabled> <table class="table table-user-information">
</div> <tbody>
<br> <tr>
<div class="input-group"> <td>Name:</td>
<span class="input-group-addon" id="basic-addon1">Name</span> <td><%= @user.name %></td>
<input type="text" </tr>
value="<%= @user.name %>" <tr>
class="form-control" <td>email:</td>
placeholder="Name" <td><%= @user.email %></td>
aria-describedby="basic-addon1" </tr>
disabled> <tr>
</div> <td>CV:</td>
<br> <td>
<span>My Cv</span> <%= link_to @user.cv.file.filename, download_my_pages_path %>
<span><%= link_to @user.cv, "#"%></span> </td>
<br> </tr>
</tbody>
</table>
<div class="col-md-6"> <div class="col-md-6">
<%= link_to "Update", edit_user_registration_path, class: "btn btn-primary navbar-right" %> <%= link_to "Update", edit_user_registration_path, class: "btn btn-primary navbar-right" %>
</div> </div>
...@@ -31,4 +33,9 @@ ...@@ -31,4 +33,9 @@
<%= link_to "My jobs", jobs_my_pages_path, class: "btn btn-primary" %> <%= link_to "My jobs", jobs_my_pages_path, class: "btn btn-primary" %>
</div> </div>
</div> </div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
...@@ -6,7 +6,7 @@ Rails.application.routes.draw do ...@@ -6,7 +6,7 @@ Rails.application.routes.draw do
root 'applies#index' root 'applies#index'
end end
root 'jobs#index' root 'jobs#index'
devise_for :users, :controllers => {:registrations => "registrations"} devise_for :users, :controllers => {registrations: 'registrations'}
as :user do as :user do
get 'register/:step', to: 'registrations#new', as: :register get 'register/:step', to: 'registrations#new', as: :register
patch 'complete_registering' => 'registrations#complete_registering_user' patch 'complete_registering' => 'registrations#complete_registering_user'
...@@ -31,6 +31,14 @@ Rails.application.routes.draw do ...@@ -31,6 +31,14 @@ Rails.application.routes.draw do
get 'my' => 'my_pages#index' 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 get 'history' => 'my_pages#history', as: :history
get 'download' => 'my_pages#download_cv'
end
end
resources :applies do
collection do
get :apply
post :confirm
post :done
end end
end end
end end
class CreateViewJobs < ActiveRecord::Migration[5.1]
def change
create_table :view_jobs do |t|
t.references :user, index: true
t.references :job, index: true
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