Commit 1f8ea292 by Ngô Trung Hưng

create func favorite

parent dbcda2ab
Pipeline #962 failed with stages
in 0 seconds
...@@ -17,6 +17,5 @@ ...@@ -17,6 +17,5 @@
//= require_tree . //= require_tree .
toastr.options = { toastr.options = {
'closeButton': true, 'closeButton': true,
'progressBar': true, 'timeOut': 8000
'timeOut': 10000
} }
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
...@@ -15,12 +15,16 @@ ...@@ -15,12 +15,16 @@
display: none; display: none;
} }
.link_favorite { .link_favorite {
color: #999; color:#e62958;
z-index: 100000; z-index: 100000;
margin-right: 15px;
&:hover { &:hover {
text-decoration: none; text-decoration: none;
} }
} }
.link_favorite.active {
color: #e62958 !important;
}
.block_click_favorite { .block_click_favorite {
color: #999; color: #999;
cursor: pointer; cursor: pointer;
...@@ -101,6 +105,10 @@ ...@@ -101,6 +105,10 @@
font-weight: 600; font-weight: 600;
font-family: 'Raleway', sans-serif; font-family: 'Raleway', sans-serif;
} }
@media only screen and (max-width: 992px) {
}
@media only screen and (max-width: 768px) { @media only screen and (max-width: 768px) {
.block_link_favorite.lg { .block_link_favorite.lg {
display: none; display: none;
......
// Place all the styles related to the favorite controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
# frozen_string_literal: true
class FavoriteController < ApplicationController
before_action :authenticate_user!
def discard_flash
flash.discard
end
def index
@list_favorited = current_user.favorites.all
end
def check_user_signin
flash[:error] = t('devise.failure.unauthenticated')
redirect_to new_user_session_path unless user_signed_in?
end
def create
return redirect_to root_path if Job.find(params[:job_id]).blank?
@favorite = current_user.favorites.new(job_id: params[:job_id])
respond_to :js if @favorite.save
end
def destroy
@favorite = current_user.favorites.find_by(id: params[:favorite_id])
return redirect_to root_path if @favorite.blank?
respond_to :js if @favorite.destroy
end
end
...@@ -13,6 +13,7 @@ module ApplicationHelper ...@@ -13,6 +13,7 @@ module ApplicationHelper
next if message.blank? next if message.blank?
type = 'success' if type == 'notice' type = 'success' if type == 'notice'
type = 'error' if type == 'alert' type = 'error' if type == 'alert'
type = 'warning' if type == 'alert'
text = "<script>toastr.#{type}('#{message}');</script>" text = "<script>toastr.#{type}('#{message}');</script>"
flash_messages << text.html_safe if message flash_messages << text.html_safe if message
end end
......
module FavoriteHelper
end
$('.block_link_favorite').bind('ajax:success', function() {
$(this).html("<%= j render 'job/link_destroy',favorite_id: @favorite.id %>")
});
\ No newline at end of file
$('.block_link_favorite').bind('ajax:success', function() {
$(this).html("<%= j render 'job/link_create',job_id: @favorite.job_id %>")
});
\ No newline at end of file
weklhjdfqwl;edjwjhqgbedklqwheuiqw
<%= render 'job/block_job_mini' %>
\ No newline at end of file
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
<div class="box_text_five_jobs"> <div class="box_text_five_jobs">
<span><%= t('pages.index.lasted_job') %></span> <span><%= t('pages.index.lasted_job') %></span>
</div> </div>
<%= render 'job/modal_login' %>
<%= render partial: 'job/block_info_job', collection: @lasted_jobs, as: :data %> <%= render partial: 'job/block_info_job', collection: @lasted_jobs, as: :data %>
<%= render 'box_nine_city' %> <%= render 'box_nine_city' %>
<%= render 'box_nine_industries' %> <%= render 'box_nine_industries' %>
......
...@@ -3,16 +3,19 @@ ...@@ -3,16 +3,19 @@
<div class="col-sm-12"> <div class="col-sm-12">
<div class="box_jobs"> <div class="box_jobs">
<div class="col-sm-12 d-block d-sm-none"> <div class="col-sm-12 d-block d-sm-none">
<% if user_signed_in? %>
<div class="link_favorite_top block_link_favorite md"> <div class="link_favorite_top block_link_favorite md">
<span><%= link_to '<i class="far fa-heart"></i>'.html_safe, '#', class: 'link_favorite' %><span> <% if user_signed_in? %>
</div> <% favorite_id = current_user.favorites.find_by(job_id: data.id) %>
<% if favorite_id.present? %>
<%= render 'job/link_destroy', favorite_id: favorite_id %>
<% else %> <% else %>
<div class="block_click_favorite link_favorite_top "> <%= render 'job/link_create', job_id: data.id %>
<span><i class="far fa-heart"></i><span> <% end %>
</div> <% else %>
<%= render 'job/link_create', job_id: data.id %>
<% end %> <% end %>
</div> </div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-10 col-md-9 col-lg-10"> <div class="col-sm-10 col-md-9 col-lg-10">
<div class="box_info"> <div class="box_info">
...@@ -34,28 +37,21 @@ ...@@ -34,28 +37,21 @@
</div> </div>
</div> </div>
<div class="col-sm-2 col-md-3 d-none d-sm-block col-lg-2"> <div class="col-sm-2 col-md-3 d-none d-sm-block col-lg-2">
<div class="link_favorite_top block_link_favorite">
<% if user_signed_in? %> <% if user_signed_in? %>
<div class="box_link_favotite"> <% @favorite_id = current_user.favorites.find_by(job_id: data.id) %>
<div class="block_link_favorite lg"> <% if favorite_id.present? %>
<span><i class="far fa-heart"></i> <%= link_to t('pages.index.btn_text_favorite'), '#', class: 'link_favorite' %><span> <%= render 'job/link_destroy', favorite_id: @favorite_id %>
</div>
<div class="block_link_favorite md">
<span><%= link_to '<i class="far fa-heart"></i>'.html_safe, '#', class: 'link_favorite' %><span>
</div>
</div>
<% else %> <% else %>
<div class="box_link_favotite"> <%= render 'job/link_create', job_id: data.id %>
<div class="block_click_favorite lg"> <% end %>
<span><i class="far fa-heart"></i> <%= t('pages.index.btn_text_favorite') %><span> <% else %>
</div> <%= render 'job/link_create', job_id: data.id %>
<div class="block_click_favorite md">
<span><i class="far fa-heart"></i><span>
</div>
</div>
<% end %> <% end %>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div>
</div> </div>
wrewerwerwetet
\ No newline at end of file
<%= link_to '<i class="far fa-heart"></i>'.html_safe, favorite_path(job_id: job_id), method: :post, remote: true, class: 'link_favorite' %>
\ No newline at end of file
<%= link_to '<i class="fas fa-heart"></i>'.html_safe, destroy_favorite_path(favorite_id: favorite_id), method: :delete, remote: true, class: 'link_favorite' %>
\ No newline at end of file
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<div class="header_top_menu_right"> <div class="header_top_menu_right">
<ul class="list_menu_header_right"> <ul class="list_menu_header_right">
<li class="list_item_menu_header_right"> <li class="list_item_menu_header_right">
<%= link_to t('pages.index.favorite'), '#', class: 'link_item_menu_header_right' %> <%= link_to t('pages.index.favorite'), favorite_index_path, class: 'link_item_menu_header_right' %>
</li> </li>
<li class="list_item_menu_header_right"> <li class="list_item_menu_header_right">
<%= link_to t('pages.index.history'), '#', class: 'link_item_menu_header_right' %> <%= link_to t('pages.index.history'), '#', class: 'link_item_menu_header_right' %>
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<div class = "menu_mobile_vertical"> <div class = "menu_mobile_vertical">
<ul class = "list_menu_mobile_vertical"> <ul class = "list_menu_mobile_vertical">
<li class = "item_menu_mobile_vertical"> <li class = "item_menu_mobile_vertical">
<%= link_to t('pages.index.favorite'), '#', class: 'link_item_menu_mobile' %> <%= link_to t('pages.index.favorite'), favorite_index_path, class: 'link_item_menu_mobile' %>
</li> </li>
<li class = "item_menu_mobile_vertical"> <li class = "item_menu_mobile_vertical">
<%= link_to t('pages.index.history'), '#', class: 'link_item_menu_mobile' %> <%= link_to t('pages.index.history'), '#', class: 'link_item_menu_mobile' %>
......
alert('You will be redirected to log in.');
window.location = '/users/sign_in';
\ No newline at end of file
...@@ -82,8 +82,7 @@ Devise.setup do |config| ...@@ -82,8 +82,7 @@ Devise.setup do |config|
# config.http_authenticatable = false # config.http_authenticatable = false
# If 401 status code should be returned for AJAX requests. True by default. # If 401 status code should be returned for AJAX requests. True by default.
# config.http_authenticatable_on_xhr = true config.http_authenticatable_on_xhr = false
# The realm used in Http Basic Authentication. 'Application' by default. # The realm used in Http Basic Authentication. 'Application' by default.
# config.http_authentication_realm = 'Application' # config.http_authentication_realm = 'Application'
......
...@@ -14,6 +14,10 @@ Rails.application.routes.draw do ...@@ -14,6 +14,10 @@ Rails.application.routes.draw do
post 'confirm', to: 'apply_job#confirm', as: :confirm post 'confirm', to: 'apply_job#confirm', as: :confirm
post 'done', to: 'apply_job#done', as: :done post 'done', to: 'apply_job#done', as: :done
get 'my/jobs', to: 'apply_job#index', as: :list_applied_jobs get 'my/jobs', to: 'apply_job#index', as: :list_applied_jobs
# Fovorite
post 'favorite', to: 'favorite#create', as: :favorite
delete 'favorite', to: 'favorite#destroy', as: :destroy_favorite
get 'favorite', to: 'favorite#index', as: :favorite_index
# Details job # Details job
get 'detail/:id', to: 'job#detail', as: :detail_job get 'detail/:id', to: 'job#detail', as: :detail_job
# Search # Search
......
alert('You will be redirected to log in.');
window.location = '/users/sign_in';
\ No newline at end of file
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