Commit 4e70cfdf by Tô Ngọc Ánh

Merge branch 'id1-top-page' into 'master'

show latest jobs, top industries, top cities

See merge request !7
parents 3a9ba394 c1dd47eb
Pipeline #756 failed with stages
in 0 seconds
...@@ -13,3 +13,16 @@ ...@@ -13,3 +13,16 @@
*= require_tree . *= require_tree .
*= require_self *= require_self
*/ */
$main-color: #1da173;
.navbar {
background-color: $main-color;
}
.footer {
width: 100%;
height: 50px;
background-color: $main-color;
}
\ No newline at end of file
// Place all the styles related to the home controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// .container-fluid {
// background-position: center bottom;
// background-repeat: no-repeat;
// background-size: cover;
// height: 600px;
// }
body {
padding: 0;
margin: 0;
}
.banner_top {
position: relative;
width: 100%;
height: 600px;
}
.banner_img {
width: 100%;
height: 100%;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba($color: #333, $alpha: 0.2);
}
.box_seach {
position: absolute;
width: 430px;
height: 300px;
top: 10%;
right: 5%;
background-color: rgb(233, 241, 232);
border-radius: 8px;
box-shadow: 6px 5px 5px 2px rgb(164, 190, 157);
padding: 20px;
}
class HomeController < ApplicationController
def index
@total_jobs = Job.count
@locations = Location.all
@industries = Industry.all
@jobs = Job.order(created_at: :desc).limit(Job::NUMBER_LATEST_JOB)
@top_cities = Location.top_locations(9)
@top_industries = Industry.top_industries(9)
end
end
module HomeHelper
end
class Industry < ApplicationRecord class Industry < ApplicationRecord
scope :top_industries, ->(number) { joins(:jobs)
.group(:industry_id)
.order(Arel.sql('count(jobs.id) DESC'))
.take(number) }
has_and_belongs_to_many :jobs has_and_belongs_to_many :jobs
end end
class Job < ApplicationRecord class Job < ApplicationRecord
NUMBER_LATEST_JOB = 6
belongs_to :company belongs_to :company
has_many :applied_jobs has_many :applied_jobs
has_many :histories has_many :histories
......
class Location < ApplicationRecord class Location < ApplicationRecord
CITY_VIETNAM_NUMBER = 70.freeze scope :top_locations, ->(number) { joins(:jobs)
.group(:location_id)
.order(Arel.sql('count(jobs.id) DESC'))
.take(number) }
CITY_VIETNAM_NUMBER = 70
has_many :locations_jobs has_many :locations_jobs
has_many :jobs, through: :locations_jobs has_many :jobs, through: :locations_jobs
......
<div class='col-4 my-2'>
<div class='card'>
<%= link_to '#', class: 'card-body text-decoration-none' do %>
<h5 class='card-title font-weight-bold'><%= location.city %></h5>
<p class='card-text'><%= location.jobs.size %> Jobs</p>
<% end %>
</div>
</div>
<div class='col-4 my-2'>
<div class='card'>
<%= link_to '#', class: 'card-body text-decoration-none' do %>
<h5 class='card-title font-weight-bold'><%= industry.name %></h5>
<p class='card-text'><%= industry.jobs.size %> Jobs</p>
<% end %>
</div>
</div>
<div class='col-md-6 col-sm-12 my-2'>
<div class='card'>
<div class='card-body'>
<%= link_to job.title, '#', class: 'card-title font-weight-bold text-decoration-none' %>
<p class='card-text'><%= job.company.name %></p>
<p class='mb-0'>
<strong>Work place:</strong>
<% job.locations.each do |location| %>
<%= location.city %>
<% end %>
<strong>Salary: </strong><%= job.salary %>
</p>
</div>
</div>
</div>
<div class='banner_top'>
<%= image_tag 'venjob-banner',class: 'banner_img'%>
<div class='overlay'></div>
<div class='box_seach text-center'>
<h3>We have <%= @total_jobs %> jobs for you</h3>
<%= render 'shared/searchbar' %>
</div>
</div>
<div id='latest-jobs' class='my-4 text-center'>
<h1>Latest Jobs</h1>
<div class='row'>
<%= render partial: 'home/job', collection: @jobs %>
</div>
<a href='#'>All Jobs</a>
</div>
<div id='top-cities' class='my-4 text-center'>
<h1>Top Cities</h1>
<div class='row'>
<%= render partial: 'home/city', collection: @top_cities, as: :location %>
</div>
<a href='#'>All Cities</a>
</div>
<div id='top-industries' class='my-4 text-center'>
<h1>Top Industries</h1>
<div class='row'>
<%= render partial: 'home/industry', collection: @top_industries, as: :industry %>
</div>
<a href='#'>All Industries</a>
</div>
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head> </head>
<body> <body class='container'>
<%= render 'shared/header' %>
<%= yield %> <%= yield %>
<%= render 'shared/footer' %>
</body> </body>
</html> </html>
<div class='footer text-center'>
<span>Copyright &#169; 2020 ZIGExN VeNtura</span>
</div>
<nav class='navbar navbar-expand-lg navbar-light sticky-top'>
<a class='navbar-brand' href='#'>
<%= image_tag 'venjob-logo.png', alt: 'VeNJob', size: '120x50' %>
</a>
<button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarSupportedContent' aria-controls='navbarSupportedContent' aria-expanded='false' aria-label='Toggle navigation'>
<span class='navbar-toggler-icon'></span>
</button>
<div class='collapse navbar-collapse' id='navbarSupportedContent'>
<ul class='navbar-nav ml-auto'>
<li class='nav-item active'>
<a class='nav-link text-white' href='#'>Sign in</a>
</li>
<li class='nav-item'>
<a class='nav-link text-white' href='#'>Sign up</a>
</li>
</ul>
</div>
</nav>
<%= form_tag '#', method: :get, class: 'mt-4' do %>
<%= search_field_tag :search, params[:keyword], placeholder: 'Search', class: 'form-control my-2' %>
<%= select_tag :industry, options_from_collection_for_select(@industries, :id, :name, '1'), class: 'form-control my-2' %>
<%= select_tag :location, options_from_collection_for_select(@locations, :id, :city, '1'), class: 'form-control my-2' %>
<%= submit_tag 'Search', class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %>
Rails.application.routes.draw do Rails.application.routes.draw do
root to: 'home#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end end
...@@ -36,7 +36,6 @@ class CsvImport ...@@ -36,7 +36,6 @@ class CsvImport
end end
puts title puts title
rescue StandardError => e rescue StandardError => e
puts e
@logger.error "Job #{index}: #{e.message}" @logger.error "Job #{index}: #{e.message}"
end end
end end
......
...@@ -3,7 +3,7 @@ require './lib/common/csv' ...@@ -3,7 +3,7 @@ require './lib/common/csv'
require './lib/common/crawler' require './lib/common/crawler'
namespace :import_data do namespace :import_data do
logger ||= Logger.new('./log/import_data.log') logger = Logger.new('./log/import_data.log')
desc 'crawl industries locations jobs' desc 'crawl industries locations jobs'
task :crawler, %i[page_number link] => [:environment] do |_, args| task :crawler, %i[page_number link] => [:environment] do |_, args|
...@@ -15,7 +15,7 @@ namespace :import_data do ...@@ -15,7 +15,7 @@ namespace :import_data do
desc 'Download csv file from FTP and import' desc 'Download csv file from FTP and import'
task csv: :environment do task csv: :environment do
destination_dir = './lib/data' destination_dir = './lib/data'
Dir.mkdir destination_dir unless File.exists?(destination_dir) Dir.mkdir destination_dir unless File.exist?(destination_dir)
ftp = Ftp.new('192.168.1.156', 'training', 'training') ftp = Ftp.new('192.168.1.156', 'training', 'training')
ftp.download_file('jobs.zip', destination_dir) ftp.download_file('jobs.zip', destination_dir)
ftp.close ftp.close
......
require 'test_helper'
class HomeControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get home_index_url
assert_response :success
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