Commit b94adaf7 by Ba Toi Dang

Merge branch 'features/create_my_page' into 'master'

create my page

See merge request !7
parents 8d0f1d38 75d6f614
......@@ -20,3 +20,6 @@
# Ignore application configuration
/config/application.yml
# Ignore public
/public
......@@ -82,12 +82,13 @@ GEM
loofah (2.1.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.6.6)
mime-types (>= 1.16, < 4)
mail (2.7.0)
mini_mime (>= 0.1.1)
method_source (0.9.0)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_mime (0.1.4)
mini_portile2 (2.3.0)
minitest (5.10.3)
multipart-post (2.0.0)
......
......@@ -17,4 +17,8 @@
$(document).ready(function(){
$('.message').delay(5000).fadeOut('slow');
$(document).on('change', 'input[name=job_id]', function(event) {
event.preventDefault();
$('#apply').removeAttr('disabled')
});
});
......@@ -37,6 +37,10 @@ body{
width: 80% !important;
}
.mrTop5{
margin-top: 5px;
}
// key-visual
.key-visual{
width: 100%;
......
......@@ -15,13 +15,14 @@ class AppliesController < ApplicationController
@application = ApplyJob.new(application_params)
@application.user = current_user
@application.job_id = session[:job_id]
session[:candidate] = {name: application_params[:name],
email: application_params[:email],
cv: application_params[:cv]}
@application.cv = current_user.cv if application_params[:cv].blank?
session[:candidate] = { name: application_params[:name],
email: application_params[:email],
cv: (application_params[:cv] || current_user.cv) }
unless @application.valid?
flash[:error] = @application.errors.full_messages.to_sentence
redirect_to apply_path(job_id: session[:job_id])
redirect_to apply_applies_path(job_id: session[:job_id])
return
end
end
......@@ -30,6 +31,7 @@ class AppliesController < ApplicationController
@application = ApplyJob.new(user: current_user,
job_id: session[:job_id])
@application.attributes = session[:candidate]
@application.cv = current_user.cv if @application.cv.file.nil?
if @application.save
flash[:notice] = 'Congratulation! Job was successfully applied'
......
......@@ -8,6 +8,7 @@ class JobsController < ApplicationController
def show
clear_session_candidate
current_user.view(Job.find(params[:id])) if current_user
end
def city
......
class MyPagesController < ApplicationController
before_action :authenticate_user!
def index
@user = current_user
end
def my_job
@jobs = current_user.my_jobs
end
def history
@jobs = current_user.viewed_jobs.includes(:apply_jobs, :company).limit(Settings.top.job_per_history_page)
end
def download_cv
if current_user.cv.file.exists?
send_file current_user.cv.path
else
flash[:notice] = 'File not exist!'
redirect_back(fallback_location: root_path)
end
end
end
class PasswordsController < Devise::PasswordsController
def edit
self.resource = User.with_reset_password_token(params[:reset_password_token])
if self.resource
set_minimum_password_length
resource.reset_password_token = params[:reset_password_token]
else
flash[:notice] = 'was already confirmed, please try signing in'
redirect_to root_path
end
end
end
module ApplicationHelper
def user_has_applied?(job)
current_user && current_user.applied?(job)
end
end
class ApplyJob < ApplicationRecord
belongs_to :job
belongs_to :user
validates :cv, presence: true
validates_size_of :cv, maximum: 5.megabytes, message: 'size should be less than 5MB'
validates :email, presence: true
validates :name, presence: true
# CarrierWave
mount_uploader :cv, CvUploader
end
......@@ -8,6 +8,8 @@ class Job < ApplicationRecord
has_many :industries, through: :industries_jobs
has_many :cities_jobs
has_many :cities, through: :cities_jobs
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) }
......@@ -54,15 +56,14 @@ 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
end
......@@ -5,6 +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 :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
......@@ -33,6 +35,25 @@ class User < ApplicationRecord
liked_jobs.include?(job)
end
def view(job)
viewed_jobs << job unless viewed?(job)
end
def viewed?(job)
viewed_jobs.include?(job)
end
def applied?(job)
applied_jobs.include?(job)
end
def my_jobs
Job.select(:'jobs.id', :'jobs.name', :'jobs.salary', :'jobs.description',
:'companies.location', :'apply_jobs.created_at')
.joins(:company, :apply_jobs)
.where(apply_jobs: { user_id: id })
end
private
def password_required?
......
class ViewJob < ApplicationRecord
belongs_to :user
belongs_to :job
end
......@@ -5,7 +5,7 @@
<p class="text-info">1. Apply form</p>
</div>
<div class="form-horizontal">
<%= form_for @application, url: confirm_applies_path do |f| %>
<%= form_for(@application, url: confirm_applies_path, html: { multipart: true }) do |f| %>
<div class="form-group">
<%= f.label :Email, 'Email:', class: "control-label col-md-2" %>
<div class="col-sm-10">
......@@ -22,8 +22,9 @@
<div class="form-group">
<%= f.label :cv, 'Cv:',class: "control-label col-md-2" %>
<div class="col-sm-10">
<%= f.text_field :cv, class: "form-control" %>
<div class="col-sm-10 mrTop5">
<label for="apply_job_cv"><%= @application.cv.filename %></label>
</label>
</div>
</div>
......
......@@ -7,7 +7,7 @@
<div class="col-md-offset-2 col-md-10">
<p>Fullname: <%= @application.name %></p>
<p>Email: <%= @application.email %></p>
<p>Cv: <%= @application.cv %></p>
<p>Cv: <%= @application.cv.filename %></p>
<div class="col-md-10">
<%= button_to "Edit",
apply_applies_path(job_id: session[:job_id]),
......
......@@ -28,7 +28,9 @@
</p>
<p>
<span>CV Link: </span>
<span> <%= @application.cv %></span>
<span>
<%= link_to @application.cv.filename, download_my_pages_url %>
</span>
</p>
</div>
......
......@@ -3,29 +3,42 @@
<div class="jobs clearfix">
<div class="job col-md-12">
<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><%= "Loacation: #{job.company.location}" %></p>
<p><%= "Salary: #{job.salary}" %></p>
</td>
<td class="col-md-2 position-relative">
<%= button_to "Remove",
unlike_job_favorites_path(job_id: job.id),
data: {confirm: "Are you sure you want to remove this job?"},
class: "btn btn-danger btn-lg mid-heigth" %>
</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>
<td class="col-md-2 position-relative">
<%= link_to "Remove",
unlike_job_favorites_path(job_id: job.id),
method: :post,
data: {confirm: "Are you sure you want to remove this job?"},
class: "btn btn-danger btn-lg mid-heigth" %>
</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" %>
</div>
</div>
</div>
<div class="job-intro well mr0 mrBot20">
<h4 class="mr0"><%= link_to job.name, job_path(job) %></h4>
<p><%= "Loacation: #{job.company.location}" %></p>
<p><%= strip_tags(job.description)[0...250] %>...</p>
<p><%= "Salary: #{job.salary}" %></p>
</div>
......@@ -5,8 +5,8 @@
</p>
<div class="job-list">
<p>
<span><%= "1. Total: #{@jobs.count}" %></span>
<span><%= "Result for: #{@result}" %></span>
<span>1. Total: <%= "#{@jobs.count}" %></span>
<span>Result for: <%= "#{@result}" %></span>
</p>
<div class="top-page">
<div class="top-page-info">
......@@ -28,7 +28,9 @@
</div>
<div class="col-md-2 favorite">
<%= link_to "FAVORITE", "#", class: "btn btn-default" %>
<%= button_to "Favorite",
job_favorites_path(job_id: job.id),
class: "btn btn-primary btn-lg btn-block" %>
</div>
</div>
<%- 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 btn-block" %>
</div>
</div>
</div>
......
......@@ -9,7 +9,11 @@
<!-- check an user is logged in or not -->
<ul class="nav navbar-nav navbar-right">
<%- if current_user -%>
<li><a href="#"><i class="fa fa-user" aria-hidden="true"></i> My Page</a></li>
<li>
<%= link_to my_my_pages_path do %>
<i class="fa fa-user" aria-hidden="true"></i> My Page
<% end %>
</li>
<li>
<%= link_to destroy_user_session_path, method: :delete do %>
<i class="fa fa-sign-out" aria-hidden="true"></i>Logout
......@@ -17,13 +21,13 @@
</li>
<%- else -%>
<li>
<%= link_to register_path(step: 1) do %>
<i class="fa fa-plus-circle" aria-hidden="true"></i> Register
<%= link_to new_user_session_path do %>
<i class="fa fa-sign-in" aria-hidden="true"></i> Login
<% end %>
</li>
<li>
<%= 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
<% end %>
</li>
<%- end -%>
......@@ -32,7 +36,11 @@
<i class="fa fa-star" aria-hidden="true"></i>
<% end %>
</li>
<li><a href="#"><i class="fa fa-history" aria-hidden="true"></i></span> History</a></li>
<li>
<%= link_to history_my_pages_path do %>
<i class="fa fa-history" aria-hidden="true"></i> History
<% end %>
</li>
</ul>
</div>
</nav>
<div class="row">
<div class="container">
<div class="jobs clearfix">
<div class="job col-md-12">
<h3>History</h3>
<table class="table">
<%= 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>
</div>
</div>
</div>
<div class="row">
<div class="container">
<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>
<div class="row">
<div class="container">
<h2>Applied jobs</h2>
<div class="jobs clearfix">
<%- @jobs.each do |job|-%>
<div class="job">
<div class="col-md-10 job-detail well">
<p><h4 class="mr0"><%= link_to job.name, job_path(job) %></h4></p>
<p><%= strip_tags(job.description)[0...250] %>...</p>
<p>
<span><strong>Location:</strong> <%= "#{job.location}" %></span>
<span><strong>Salary:</strong> <%= job.salary %></span>
<span class="navbar-right"><strong>Applied at:</strong> <%= I18n.localize(job.created_at, format: :long) %></span>
</p>
</div>
</div>
<%- end -%>
</div>
</div>
</div>
<p>Dear <%= @resource.name %>!</p>
<p>You have a new password!</p>
<p>Your password for signing in to VenJOB was recently changed. If you made this change, then we're all set.</p>
<p>If you did not make this change, please reset your password to secure your account. Then reply to this email to notify us.</p>
<p>Either way, feel free to reach out with any questions you might have. We're here to help.</p>
<p>Best,</p>
<p>Hello <%= @resource.email %>!</p>
<p>We received a request to reset the password associated with this e-mail address. If you made this request, please follow the instructions below.</p>
<p>Click the link below to reset your password using our secure server:.</p>
<p><%= link_to 'Reset your password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you did not request to have your password reset you can safely ignore this email. Rest assured your account is safe.</p>
<p>Please also be noted that the above link is valid for 24 hours.</p>
<p>Best,</p>
<div class="row">
<div class="container">
<h2>Change your password</h2>
<%=form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="form-inputs form-group">
<%= f.hidden_field :reset_password_token %>
</div>
<div class="form-inputs form-group">
<%= f.label :email, "Email" %><br />
<%= f.email_field :email, required: true, class: "form-control", disabled: true %>
</div>
<div class="form-inputs form-group">
<%= f.label :password, "New password" %><br />
<%= f.password_field :password,
class: 'form-control',
required: true,
autofocus: true,
hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
</div>
<div class="form-inputs form-group">
<%= f.label :password, "Confirm password" %><br />
<%= f.password_field :password_confirmation, required: true, class: "form-control" %>
</div>
<div class="form-actions">
<%= submit_tag "Submit", class: "btn btn-danger form-control" %>
</div>
<% end %>
</div>
</div>
<div class="row">
<div class="container">
<h2>Forgot your password?</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<div class="form-inputs form-group">
<%= f.text_field :email, required: true, autofocus: true, class: "form-control" %>
</div>
<div class="form-actions form-group">
<%= submit_tag "Confirm", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
......@@ -12,11 +12,14 @@
</div>
<% if devise_mapping.rememberable? -%>
<div class="field form-group">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end -%>
<div class="field form-group">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
<%= link_to "Forgot password?", forgot_password_path %>
</div>
<% end -%>
<div class="actions form-group">
<%= f.submit "Log in", class: "btn btn-default" %>
......
......@@ -47,7 +47,7 @@ Rails.application.configure do
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { protocol: 'http', host: 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: 'localhost',
port: 1025 }
......
......@@ -12,7 +12,7 @@ Devise.setup do |config|
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
config.mailer_sender = 'notify@venjob.com'
# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'
......@@ -114,7 +114,7 @@ Devise.setup do |config|
# config.send_email_changed_notification = false
# Send a notification email when the user's password is changed.
# config.send_password_change_notification = false
config.send_password_change_notification = true
# ==> Configuration for :confirmable
# A period that the user is allowed to access the website even without
......
......@@ -20,13 +20,13 @@ en:
confirmation_instructions:
subject: "Confirmation instructions"
reset_password_instructions:
subject: "Reset password instructions"
subject: "VeNJOB Password Assistance"
unlock_instructions:
subject: "Unlock instructions"
email_changed:
subject: "Email Changed"
password_change:
subject: "Password Changed"
subject: "VeNJOB Password Assistance: Your password has been reset"
omniauth_callbacks:
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
success: "Successfully authenticated from %{kind} account."
......
......@@ -6,10 +6,12 @@ Rails.application.routes.draw do
root 'applies#index'
end
root 'jobs#index'
devise_for :users, :controllers => {:registrations => "registrations"}
devise_for :users, controllers: { registrations: 'registrations', passwords: 'passwords' }
as :user do
get 'register/:step', to: 'registrations#new', as: :register
patch 'complete_registering' => 'registrations#complete_registering_user'
get 'forgot_password' => 'passwords#new'
get 'reset_password' => 'password#edit'
end
resources :cities, only: [:index, :show]
resources :industries, only: [:index, :show]
......@@ -21,12 +23,20 @@ Rails.application.routes.draw do
end
resources :jobs do
collection do
get 'city/:city_id' => "jobs#city", as: :city
get 'industry/:industry_id' => "jobs#industry", as: :industry
get 'company/:company_id' => "jobs#company", as: :company
get 'city/:city_id' => 'jobs#city', as: :city
get 'industry/:industry_id' => 'jobs#industry', as: :industry
get 'company/:company_id' => 'jobs#company', as: :company
end
end
resources :applies do
resources :my_pages, path: '', only: [:index] do
collection 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, path: '', only: [] do
collection do
get :apply
post :confirm
......
......@@ -3,6 +3,7 @@ defaults: &defaults
job_per_page: 5
industry_per_page: 9
city_per_page: 9
job_per_history_page: 20
development:
<<: *defaults
......
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
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