favorite-history funtion

parent f99a3f7b
Pipeline #1409 canceled with stages
in 0 seconds
...@@ -4,6 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ...@@ -4,6 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.0.1' ruby '3.0.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'jquery-rails', '~> 4.4'
gem 'rails', '~> 6.1.3', '>= 6.1.3.2' gem 'rails', '~> 6.1.3', '>= 6.1.3.2'
gem 'bootstrap', '~> 5.0.1' gem 'bootstrap', '~> 5.0.1'
gem 'nokogiri', '~> 1.11', '>= 1.11.7' gem 'nokogiri', '~> 1.11', '>= 1.11.7'
......
...@@ -106,6 +106,10 @@ GEM ...@@ -106,6 +106,10 @@ GEM
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
jbuilder (2.11.2) jbuilder (2.11.2)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
kaminari (1.2.1) kaminari (1.2.1)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1) kaminari-actionview (= 1.2.1)
...@@ -259,6 +263,7 @@ DEPENDENCIES ...@@ -259,6 +263,7 @@ DEPENDENCIES
devise devise
friendly_id (~> 5.4, >= 5.4.2) friendly_id (~> 5.4, >= 5.4.2)
jbuilder (~> 2.7) jbuilder (~> 2.7)
jquery-rails (~> 4.4)
kaminari (~> 1.2, >= 1.2.1) kaminari (~> 1.2, >= 1.2.1)
listen (~> 3.3) listen (~> 3.3)
mini_magick (>= 4.9.5) mini_magick (>= 4.9.5)
......
...@@ -60,6 +60,6 @@ class ApplyJobsController < ApplicationController ...@@ -60,6 +60,6 @@ class ApplyJobsController < ApplicationController
private private
def apply_params def apply_params
params.require(:apply_job).permit(:name, :email, :cv, :job_id, :id) params.require(:apply_job).permit(:name, :email, :cv, :job_id)
end end
end end
\ No newline at end of file
class FavoriteJobsController < ApplicationController
def show
@favorites = FavoriteJob.order('created_at DESC').page(params[:page])
end
def update
favorite = FavoriteJob.where(job: Job.find(params[:job_id]), user: current_user)
if favorite == []
FavoriteJob.create(job: Job.find(params[:job_id]), user: current_user)
@favorite_exists = true
else
FavoriteJob.where(job: Job.find(params[:job_id]), user: current_user).first.destroy
@favorite_exists = false
end
respond_to do |format|
format.html {}
format.js {}
end
end
def destroy
@favorite = FavoriteJob.where(job: Job.find(params[:job_id]), user: current_user).first.destroy
redirect_to favorite_url
flash[:success] = "#{@favorite.job.title} was completed and destroyed."
end
end
class HistoryJobsController < ApplicationController
def show
@histories = HistoryJob.order('created_at DESC')
end
end
class JobsController < ApplicationController class JobsController < ApplicationController
before_action :authenticate_user!, except: [:index]
after_action :history_action, only: [:show]
def index def index
if params[:city_slug].present? if params[:city_slug].present?
city = City.find_by(slug: params[:city_slug]) city = City.find_by(slug: params[:city_slug])
...@@ -11,9 +14,23 @@ class JobsController < ApplicationController ...@@ -11,9 +14,23 @@ class JobsController < ApplicationController
end end
@total = jobs.count @total = jobs.count
@jobs = jobs.latest_jobs.page(params[:page]) @jobs = jobs.latest_jobs.page(params[:page])
@favorite_exists = FavoriteJob.where(job: @job, user: current_user) == [] ? false : true
end end
def show def show
@job = Job.latest_jobs.find_by(slug: params[:job_slug]) @job = Job.latest_jobs.find_by(slug: params[:job_slug])
@favorite_exists = FavoriteJob.where(job: @job, user: current_user) == [] ? false : true
end
private
def history_action
history = HistoryJob.where(job_id: @job.id, user_id: current_user.id)
if history == []
HistoryJob.create(job_id: @job.id, user_id: current_user.id)
else
history.touch_all(:created_at)
end
HistoryJob.first.destroy if HistoryJob.count > 20
end end
end end
\ No newline at end of file
...@@ -24,4 +24,8 @@ module ApplicationHelper ...@@ -24,4 +24,8 @@ module ApplicationHelper
def render_404 def render_404
render file: "#{Rails.root}/public/404.html", status: :not_found render file: "#{Rails.root}/public/404.html", status: :not_found
end end
def favorite_text
return @favorite_exists ? 'Unfavorite' : 'Favorite'
end
end end
...@@ -17,7 +17,6 @@ h2.text-center ...@@ -17,7 +17,6 @@ h2.text-center
p.my-1 p.my-1
= f.label :cv, "Your CV" = f.label :cv, "Your CV"
br br
= f.hidden_field :id, value: @blob.id
= @apply_job.cv.filename = @apply_job.cv.filename
.span.p-3.text-center .span.p-3.text-center
= link_to "Back", apply_path(job_id: @apply_job.job_id), class: "btn btn-primary btn-space" = link_to "Back", apply_path(job_id: @apply_job.job_id), class: "btn btn-primary btn-space"
......
- provide :title, 'Favorite jobs'
h3.p-3.text-center
| Favorite Jobs
.col-6.offset-md-5.text-center
= paginate @favorites, window: 1
= form_with(url: apply_path, method: :get) do |f|
- @favorites.each do |favorite|
.row.bg-white
.col-1.p-3.border.card-body.text-dark.text-center
= f.radio_button :job_id, favorite.job.id, class: "form-check-input mt-0"
.col-9.p-3.border.card-body.text-dark
h5.mb-1
= favorite.job.title
p.mb-1
i.fas.fa-dollar-sign.m-1
| Lương:
= favorite.job.salary
p.mb-1
i.fas.fa-map-marker-alt.m-1
= favorite.job.cities.map(&:name).uniq.join(' | ')
p.mb-1
= truncate(favorite.job.overview, length: 250)
.col-sm-2.p-3.border.favourite
= link_to "Remove", unfavorite_path(job_id: favorite.job.id), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-outline-primary"
h6.offset-md-4.p-2
= page_entries_info @favorites
.col-6.offset-md-5.text-center
= paginate @favorites, window: 1
.span.p-3.text-center
= f.submit "Apply job", class: "btn btn-primary btn-lg"
| $('#favorite_link').text("
= favorite_text
| ");
\ No newline at end of file
- provide :title, 'History jobs'
h3.p-3.text-center
| History Jobs
= form_with(url: apply_path, method: :get) do |f|
- @histories.each do |history|
.row.bg-white
.col-1.p-3.border.card-body.text-dark.text-center
= f.radio_button :job_id, history.job.id, class: "form-check-input mt-0"
.col-11.p-3.border.card-body.text-dark
h5.mb-1
= history.job.title
p.mb-1
i.fas.fa-dollar-sign.m-1
| Lương:
= history.job.salary
p.mb-1
i.fas.fa-map-marker-alt.m-1
= history.job.cities.map(&:name).uniq.join(' | ')
p.mb-1
= truncate(history.job.overview, length: 250)
.span.p-3.text-center
= f.submit "Apply job", class: "btn btn-primary btn-lg"
\ No newline at end of file
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
p.mb-1 p.mb-1
= truncate(job.overview, length: 250) = truncate(job.overview, length: 250)
.col-sm-2.p-3.border.favourite .col-sm-2.p-3.border.favourite
= link_to "Farourite", "#", class: "btn btn-outline-primary" = link_to favorite_text, favorite_update_path(job_id: job.id), id: 'favorite_link', remote: true, class: "btn btn-outline-primary"
h6.offset-md-4.px-5 h6.offset-md-4.px-5
= page_entries_info @jobs = page_entries_info @jobs
h6.offset-md-4 h6.offset-md-4
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
.row.bg-white.p-4 .row.bg-white.p-4
.col.text-end .col.text-end
= link_to "Apply this Job", apply_path(job_id: @job.id), class: "btn btn-outline-primary btn-lg" = link_to "Apply this Job", apply_path(job_id: @job.id), class: "btn btn-outline-primary btn-lg"
.col .col.text-start
= link_to "Favourite", "#", class: "btn btn-outline-primary btn-lg" = link_to favorite_text, favorite_update_path(job_id: @job.id), id: 'favorite_link', remote: true, class: "btn btn-outline-primary btn-lg"
\ No newline at end of file
...@@ -8,9 +8,9 @@ header ...@@ -8,9 +8,9 @@ header
li li
= link_to "Profile", my_path = link_to "Profile", my_path
li li
= link_to "Favourite",'#' = link_to "Favorite", favorite_path
li li
= link_to "History", '#' = link_to "History", history_path
li li
= link_to('Logout', destroy_user_session_path, method: :delete) = link_to('Logout', destroy_user_session_path, method: :delete)
- else - else
......
...@@ -2,17 +2,17 @@ h2.p-3.text-center ...@@ -2,17 +2,17 @@ h2.p-3.text-center
| My Page | My Page
.row .row
.col-md-6.offset-md-3.form-apply .col-md-6.offset-md-3.form-apply
= form_with(scope: @user, local:true) do |f| = form_with(scope: :user, local:true) do |f|
.card .card
.card-body .card-body
.field .field
= f.label :email = f.label :email
br br
= f.email_field :email, disabled: true, class: 'form-control' = f.email_field :email, readonly: true, class: 'form-control'
.field .field
= f.label :name, "Full Name" = f.label :name, "Full Name"
br br
= f.text_field :name, disabled: true, class: 'form-control' = f.text_field :name, readonly: true, class: 'form-control'
.field .field
-if @user.cv.attached? -if @user.cv.attached?
= f.label :cv, "CV" = f.label :cv, "CV"
......
...@@ -8,6 +8,10 @@ Rails.application.routes.draw do ...@@ -8,6 +8,10 @@ Rails.application.routes.draw do
get 'apply', to: 'apply_jobs#new' get 'apply', to: 'apply_jobs#new'
post 'confirm', to: 'apply_jobs#confirm' post 'confirm', to: 'apply_jobs#confirm'
post 'done', to: 'apply_jobs#done' post 'done', to: 'apply_jobs#done'
get 'favorite', to: 'favorite_jobs#update', as: 'favorite_update'
get 'favorite2', to: 'favorite_jobs#show', as: 'favorite'
delete 'unfavorite', to: 'favorite_jobs#destroy'
get 'history', to: 'history_jobs#show', as: 'history'
devise_for :users, skip: %i[sessions registrations passwords], controllers: { confirmations: 'users/confirmations' } devise_for :users, skip: %i[sessions registrations passwords], controllers: { confirmations: 'users/confirmations' }
get '/my', to: 'users#show' get '/my', to: 'users#show'
devise_scope :user do devise_scope :user do
......
const { environment } = require('@rails/webpacker') const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery'
})
)
module.exports = environment module.exports = environment
{ {
"name": "ve-njob", "name": "ve-njob",
"license": "MIT",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@rails/actioncable": "^6.0.0", "@rails/actioncable": "^6.0.0",
...@@ -7,12 +8,14 @@ ...@@ -7,12 +8,14 @@
"@rails/ujs": "^6.0.0", "@rails/ujs": "^6.0.0",
"@rails/webpacker": "5.4.0", "@rails/webpacker": "5.4.0",
"bootstrap": "^5.0.2", "bootstrap": "^5.0.2",
"jquery": "^3.6.0",
"turbolinks": "^5.2.0", "turbolinks": "^5.2.0",
"webpack": "^4.46.0", "webpack": "^4.46.0",
"webpack-cli": "^3.3.12" "webpack-cli": "^3.3.12"
}, },
"version": "0.1.0", "version": "0.1.0",
"devDependencies": { "devDependencies": {
"webpack-dev-server": "^3.11.2" "@webpack-cli/serve": "^1.5.2",
"webpack-dev-server": "^4.0.0"
} }
} }
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