Commit e080bec1 by Xuan Trung Le

update link to download cv my page

parent dd88deb0
......@@ -17,4 +17,7 @@
$(document).ready(function(){
$('.message').delay(5000).fadeOut('slow');
$(document).on('change', 'input[name=job_id]', function(event) {
$('#apply').removeAttr('disabled')
});
});
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
helper_method :clear_session_candidate
def clear_session_candidate
......
class AppliesController < ApplicationController
before_action :authenticate_user!
def apply
session[:job_id] = params[:job_id] if params[:job_id]
if session[:candidate].present?
......
class CitiesController < ApplicationController
skip_before_action :authenticate_user!
def index
@cities = City.city_list
end
......
class IndustriesController < ApplicationController
skip_before_action :authenticate_user!
def index
@industries = Industry.industry_list
end
......
class JobsController < ApplicationController
before_action :set_job, only: [:show]
skip_before_action :authenticate_user!, only: [:index, :city, :industry, :company, :show]
def index
@jobs = Job.top_list.includes(:company)
@cities = City.top_cities.includes(:country)
......
......@@ -10,4 +10,13 @@ class MyPagesController < ApplicationController
def history
@jobs = current_user.viewed_jobs.includes(:apply_jobs).includes(:company).limit(20)
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
module ApplicationHelper
def user_has_applied?(job)
current_user && current_user.applied?(job) ? true : false
end
end
......@@ -8,10 +8,8 @@ class Job < ApplicationRecord
has_many :industries, through: :industries_jobs
has_many :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
has_many :view_jobs
has_many :users_has_viewed, through: :view_jobs, class_name: 'User', source: :user
scope :top_list, -> { order(updated_date: :desc).limit(Settings.top.job_per_page) }
......@@ -58,19 +56,18 @@ class Job < ApplicationRecord
puts "Saving #{item[:name]} ......................................"
if job.save
puts "Job was successfully created"
puts 'Job was successfully created'
else
puts "Error..."
puts 'Error...'
end
end
end
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
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
......@@ -5,10 +5,8 @@ class User < ApplicationRecord
has_many :applied_jobs, through: :apply_jobs, class_name: 'Job', source: :job
has_many :favorite_jobs
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
has_many :view_jobs
has_many :viewed_jobs, through: :view_jobs, class_name: 'Job', source: :job
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
......@@ -38,7 +36,15 @@ class User < ApplicationRecord
end
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
private
......
class ViewJob < ApplicationRecord
belongs_to :user
belongs_to :job
end
......@@ -18,6 +18,11 @@
</ol>
</ol>
<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">
<h1>2.<%= @job.name %></h1>
<p>3.<%= link_to @job.company.name, company_jobs_path(@job.company) %></p>
......@@ -33,18 +38,20 @@
</p>
</div>
<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 class="action">
<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 class="action">
<div class="col-md-6">
<%= button_to "Favorite",
job_favorites_path(job_id: @job.id),
class: "btn btn-primary btn-lg" %>
</div>
<div class="col-md-6">
<%= button_to "Favorite",
job_favorites_path(job_id: @job.id),
class: "btn btn-primary btn-lg" %>
</div>
</div>
</div>
......
......@@ -14,7 +14,11 @@
<i class="fa fa-user" aria-hidden="true"></i> My Page
<% end %>
</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 -%>
<li>
<%= link_to new_user_session_path do %>
......@@ -22,8 +26,13 @@
<% end %>
</li>
<li>
<<<<<<< 28961f125c2471f7b2c147015938987727aa3193
<%= link_to new_user_session_path do %>
<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 %>
</li>
<%- end -%>
......
......@@ -4,26 +4,35 @@
<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>
<%= form_tag apply_applies_path, method: :get do %>
<tbody>
<%- @jobs.each do |job|-%>
<tr>
<td class="col-md-1 position-relative">
<%= radio_button_tag "job_id", job.id, false, class: "mid-heigth",
disabled: user_has_applied?(job) ? true : false %>
</td>
<td class="col-md-9">
<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>
<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 %>
<tr>
<td></td>
<td>
<%= submit_tag "Applys", class: "btn btn-primary btn-lg btn-block", id: "apply", disabled: true %>
</td>
<td></td>
</tr>
</tbody>
<% end %>
</table>
</div>
<%= button_to "Apply", nil, class: "btn btn-primary btn-lg" %>
</div>
</div>
</div>
<div class="row">
<div class="container">
<h2>MY PAGE</h2>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Mail</span>
<input type="text"
value="<%= @user.email %>"
class="form-control"
placeholder="Email"
aria-describedby="basic-addon1"
disabled>
</div>
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Name</span>
<input type="text"
value="<%= @user.name %>"
class="form-control"
placeholder="Name"
aria-describedby="basic-addon1"
disabled>
</div>
<br>
<span>My Cv</span>
<span><%= link_to @user.cv, "#"%></span>
<br>
<div class="col-md-6">
<%= link_to "Update", edit_user_registration_path, class: "btn btn-primary navbar-right" %>
</div>
<div class="col-md-6">
<%= link_to "My jobs", jobs_my_pages_path, class: "btn btn-primary" %>
<div class="col-sm-6 col-md-offset-3 toppad" >
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">My Page</h3>
</div>
<div class="panel-body">
<div class="row">
<div class=" col-md-12">
<table class="table table-user-information">
<tbody>
<tr>
<td>Name:</td>
<td><%= @user.name %></td>
</tr>
<tr>
<td>email:</td>
<td><%= @user.email %></td>
</tr>
<tr>
<td>CV:</td>
<td>
<%= link_to @user.cv.file.filename, download_my_pages_path %>
</td>
</tr>
</tbody>
</table>
<div class="col-md-6">
<%= link_to "Update", edit_user_registration_path, class: "btn btn-primary navbar-right" %>
</div>
<div class="col-md-6">
<%= link_to "My jobs", jobs_my_pages_path, class: "btn btn-primary" %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
......@@ -6,7 +6,7 @@ Rails.application.routes.draw do
root 'applies#index'
end
root 'jobs#index'
devise_for :users, :controllers => {:registrations => "registrations"}
devise_for :users, :controllers => {registrations: 'registrations'}
as :user do
get 'register/:step', to: 'registrations#new', as: :register
patch 'complete_registering' => 'registrations#complete_registering_user'
......@@ -31,6 +31,14 @@ Rails.application.routes.draw do
get 'my' => 'my_pages#index'
get 'my/jobs' => 'my_pages#my_job', as: :jobs
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
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