Change logic code and fix mentor's comments

parent d91084a9
Pipeline #1066 canceled with stages
in 0 seconds
class FavoriteJobsController < ApplicationController
before_action :sign_in_favorite_validation, only: %i[create destroy]
before_action :sign_in_validation, only: [:index]
before_action :sign_in_validation, only: %i[create destroy index]
def index
if params[:page].present? || params[:page] == ""
return redirect_to favorite_jobs_path, flash: {warning: Settings.user.favorite_job.validate_page } if params[:page].to_i <= 0 || params[:page].scan(/\D+/).present?
end
@count = current_user.favorite_jobs.count
@favorited_jobs = current_user.favorite_jobs.order_favorite.page(params[:page]).per(Job::LIMIT_PAGE)
end
def create
@job = Job.find_by_id(params[:job_id])
return if current_user.favorite_jobs.exists?(job_id: params[:job_id])
@follow = current_user.favorite!(params[:job_id])
respond_to { |format| format.js }
end
def destroy
@job = Job.find_by_id(params[:job_id])
@unfollow = current_user.unfavorite!(params[:job_id])
respond_to { |format| format.js }
if request.referer.include?("favorite")
@count = current_user.favorite_jobs.count
......@@ -31,17 +29,12 @@ class FavoriteJobsController < ApplicationController
return redirect_to request.referer if count_on_page == Job::DIVISIBLE
end
respond_to { |format| format.js }
end
private
def sign_in_favorite_validation
return if signed_in?
session[:return_to] = request.referer
flash[:warning] = Settings.user.warning_signin
redirect_to login_path
end
def sign_in_validation
return if signed_in?
store_location
......
class HistoryJobsController < ApplicationController
before_action :sign_in_favorite_validation, only: [:destroy]
before_action :sign_in_validation, only: [:index]
def index
......@@ -9,13 +8,6 @@ class HistoryJobsController < ApplicationController
private
def sign_in_favorite_validation
return if signed_in?
session[:return_to] = request.referer
flash[:warning] = Settings.user.warning_signin
redirect_to login_path
end
def sign_in_validation
return if signed_in?
store_location
......
......@@ -30,15 +30,15 @@ class JobsController < ApplicationController
session.delete(:job_applied)
return redirect_to jobs_path unless @job
if signed_in?
@user = JobApplied.where(user_id: current_user.id, job_id: params[:id])
history_jobs = current_user.histories.order_history
history_jobs.last.destroy if history_jobs.count >= Job::LIMIT_HISTORY
@is_job_applied = current_user.job_applieds.pluck(:job_id).include?@job.id
founded_history = current_user.histories.find_by(job_id: params[:id])
return founded_history.update(updated_at: Time.current.utc) if founded_history.present?
history = current_user.histories.create!(job_id: params[:id])
history_jobs = current_user.histories.order_history
history_jobs.last.destroy if history_jobs.count >= Job::LIMIT_HISTORY
end
end
......
......@@ -33,6 +33,7 @@ module SessionsHelper
end
def store_location
return session[:return_to] = request.referer if request.url.include?("favorite_job")
session[:return_to] = request.url if request.get?
end
end
......@@ -27,6 +27,10 @@ class Job < ApplicationRecord
company&.name
end
def converted_company_name
company&.converted_name
end
def format_desc
description.truncate_words(250)
end
......
......@@ -29,11 +29,11 @@ class User < ApplicationRecord
end
def unfavorite!(job_id)
favorite_jobs.find_by(job_id: job_id).destroy
favorite_jobs.find_by(job_id: job_id)&.destroy
end
def remove_history!(job_id)
histories.find_by(job_id: job_id).destroy
histories.find_by(job_id: job_id)&.destroy
end
def self.new_remember_token
......
$("#favorite-form-<%= @job.id %>").html("<%=escape_javascript render 'users/unfavorite', job_id: @job.id %>");
$("#favorite-form-<%= @follow.job_id %>").html("<%=escape_javascript render 'users/unfavorite', job_id: @follow.job_id %>");
$("#favorite-form-<%= @job.id %>").html("<%= j render 'users/favorite', job_id: @job.id %>");
$(".job-id-<%= @job.id %>").remove();
$("#favorite-form-<%= @unfollow.job_id %>").html("<%= j render 'users/favorite', job_id: @unfollow.job_id %>");
$(".job-id-<%= @unfollow.job_id %>").remove();
$(".count-favorite-jobs").html("<%= @count %>");
<div class="container">
<%= render 'layouts/flash' %>
<% if @favorited_jobs.count > 0 %>
<h1 class="text-center my-job-label">Favorite Job (<span class="count-favorite-jobs"><%= @count %></span> jobs)</h1>
<%= paginate @favorited_jobs, outer_window: 2, window: 1 %>
......
......@@ -4,7 +4,7 @@
<div class="job-info">
<div><strong><%= @job.title %></strong></div>
<div>
<%= link_to @job.company_name, company_jobs_path(converted_name: @job.company.converted_name), class: 'company' %>
<%= link_to @job.company_name, company_jobs_path(converted_name: @job.converted_company_name), class: 'company' %>
</div>
<div class="breadcrumb">
<%= link_to "TOP", root_path %>&ensp;/&ensp;
......@@ -18,7 +18,7 @@
<% end %>/&ensp;
<%= @job.title.truncate_words(5) %>
</div>
<% if signed_in? && @user.present? %>
<% if @is_job_applied %>
<div class="apply-job">
<strong>Applied</strong>
</div>
......
<%= form_for(:job_unfavorite, url: unfavorite_job_path(job_id: job_id), method: :delete, remote: true) do |f| %>
<%= form_for(:job_unfavorite, url: unfavorite_job_path(job_id: job_id), method: :delete, remote: true, data: { disable_with: false }) do |f| %>
<%= f.submit "Unfavorite", class: "btn btn-outline-danger", id: "button-unfavorite" %>
<% end %>
......@@ -21,6 +21,9 @@ user:
applied_job:
applied: 'You applied for this job'
favorite_job:
validate_page: 'Params Page format failed'
email:
confirmation: 'Welcome To VeNJOB! Confirm Your Email'
reset_password: 'VeNJOB Password Assistance'
......
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