Commit a08e8005 by Đường Sỹ Hoàng

City list

parent c4212b67
...@@ -12,5 +12,5 @@ ...@@ -12,5 +12,5 @@
* *
*= require_tree . *= require_tree .
*= require_self *= require_self
*= require bootstrap *= require bootstrap.min
*/ */
...@@ -5,13 +5,6 @@ body { ...@@ -5,13 +5,6 @@ body {
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
} }
.center {
text-align: center;
background-color:gainsboro;
margin-left:260px;
}
/* typography */ /* typography */
h1, h2, h3, h4, h5, h6 { h1, h2, h3, h4, h5, h6 {
...@@ -41,8 +34,6 @@ p { ...@@ -41,8 +34,6 @@ p {
/* header */ /* header */
#logo { #logo {
float: left; float: left;
width: 50%; width: 50%;
...@@ -82,7 +73,6 @@ li { ...@@ -82,7 +73,6 @@ li {
font-size: 18px; font-size: 18px;
line-height: 25px; line-height: 25px;
border-radius: 4px; border-radius: 4px;
} }
li.btn-navbar { li.btn-navbar {
...@@ -91,11 +81,17 @@ li.btn-navbar { ...@@ -91,11 +81,17 @@ li.btn-navbar {
} }
li.btn-navbar:hover { li.btn-navbar:hover {
background-color: mediumblue; background-color: aquamarine;
text-decoration: none; text-decoration: none;
text-align: center; text-align: center;
} }
.Job { .Job {
display: block; display: block;
background-color: lightblue; }
div.col {
border: solid 1px;
padding: 10px;
margin: 10px;
background-color: gainsboro;
} }
class JobsController < ApplicationController class JobsController < ApplicationController
def index def index
@jobs = Job.all @latest_jobs = Job.latest_city.take(5)
@top_cities = City.sort_top_cities.take(9)
end end
end end
class City < ApplicationRecord class City < ApplicationRecord
has_many :city_jobs has_many :city_jobs
has_many :jobs, through: :city_jobs
def self.sort_top_cities
@cities||= all.sort_by(&:jobs_count).reverse
end
def jobs_count
@jobs_count = jobs.count
end
end end
class Job < ApplicationRecord class Job < ApplicationRecord
has_many :user_jobs has_many :user_jobs
has_many :city_jobs has_many :city_jobs
scope :latest_job, -> {order(created_at: :desc).limit 5}
def self.latest_city
@latest = Job.order(created_at: :desc)
end
end end
<div class="col-md-3">
<div class="col"><%= city.name %>(<%= city.jobs.count %>)</div>
</div>
<div class="row align-items-center">
<div class="col">
<h5><%= job.title %></h5>
</div>
</div>
</br>
...@@ -3,23 +3,26 @@ ...@@ -3,23 +3,26 @@
<title><%= yield(:title) %> Venjob</title> <title><%= yield(:title) %> Venjob</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
</head> </head>
<!--List of latest jobs--> <!-- List of latest jobs-->
<div class="Job list"> <div class="Job list">
<div class="Job-title-wrapper"> <div class="Job-title-wrapper">
<h3>Latest</h3> <h3>Latest Jobs</h3>
</div> </div>
<div class="row row-cols-1">
<div class="Job-content-wrapper"> <div class="Job-content-wrapper">
<% @jobs.latest_job.each do |job| %> <%= render partial: "jobs/job", collection: @latest_jobs %>
<div class="Job content info">
<h4><%= job.title %></h4>
</div>
<% end %>
</div> </div>
</div> </div>
<!--List of top cities--> </br>
<div class="City list"> <!--List of top cities-->
<div class="City-title-wrapper"> <div class="City list">
<h3>City <div class="City-title-wrapper">
</div> <h3>Top Cities</h3>
</div>
<div class="City-content-wrapper">
<div class="row row-cols-3">
<%= render partial: "cities/city", collection: @top_cities %>
</div> </div>
</div>
</div>
</div> </div>
<div class="card text-center">
<div class="card-header">
Footer
</div>
<div class="card-body">
<h5 class="card-title">Venjob project</h5>
<a href="#">@Copyright Zigexn Ventura 2019</a>
</div>
</div>
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<%= link_to image_tag("zigexn_logo.png", id: "logo", alt: "Venjob logo") %>
<nav>
<ul>
<li class="btn-navbar"><%=link_to "Login", '#' %></li>
<li class="btn-navbar"><%=link_to "Register", '#' %></li>
</ul>
<ul>
<ul>
<li class="btn-navbar"><%=link_to "Favorite", '#' %></li>
<li class="btn-navbar"><%=link_to "History", '#' %></li>
</ul>
</nav>
<%= link_to image_tag("banner.jpg", id: "banner", alt: "Venjob banner") %>
</div>
<div class="container">
<%= yield %>
</div>
</header>
...@@ -8,25 +8,11 @@ ...@@ -8,25 +8,11 @@
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head> </head>
<body> <body>
<header class="navbar navbar-fixed-top navbar-inverse"> <header>
<div class="container"> <%= render partial: "layouts/header" %>
<%= link_to image_tag("zigexn_logo.png", id: "logo", alt: "Venjob logo") %>
<nav>
<ul>
<li class="btn-navbar"><%=link_to "Login", '#' %></li>
<li class="btn-navbar"><%=link_to "Register", '#' %></li>
</ul>
<ul>
<ul>
<li class="btn-navbar"><%=link_to "Favorite", '#' %></li>
<li class="btn-navbar"><%=link_to "History", '#' %></li>
</ul>
</nav>
<%= link_to image_tag("banner.jpg", id: "banner", alt: "Venjob banner") %>
</div>
<div class="container">
<%= yield %>
</div>
</header> </header>
<footer>
<%= render partial: "layouts/footer" %>
</footer>
</body> </body>
</html> </html>
...@@ -3,8 +3,8 @@ require_relative "application" ...@@ -3,8 +3,8 @@ require_relative "application"
# Initialize the Rails application. # Initialize the Rails application.
Rails.application.initialize! Rails.application.initialize!
# # Rails.logger = Logger.new(STDOUT) # Rails.logger = Logger.new(STDOUT)
# # config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log") # config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log")
# Rails.logger = Logger.new(STDOUT) # Rails.logger = Logger.new(STDOUT)
# Rails.logger.level = Logger::DEBUG # Rails.logger.level = Logger::DEBUG
# Rails.logger.datetime_format = "%Y-%m-%d %H:%M:%S" # Rails.logger.datetime_format = "%Y-%m-%d %H:%M:%S"
Rails.application.routes.draw do Rails.application.routes.draw do
root to: "jobs#index" root "jobs#index"
get 'jobs/index' resource :jobs
devise_for :users devise_for :users
resource :jobs do
collection {post :import}
end
end end
require "csv" require "csv"
namespace :job do namespace :job do
desc "Import CSV file into database" desc "Import CSV file into database"
task import_csv: :environment do task import_csv: :environment do
csv_file = Settings.import_job.csv_file csv_file = Settings.import_job.csv_file
CSV.foreach(csv_file, headers: true) do |row| CSV.foreach(csv_file, headers: true) do |row|
company_params = { company_params = {
email: row["contact email"], email: row["contact email"],
name: row["company name"], name: row["company name"],
address: row["company address"] address: row["company address"]
} }
company = Company.find_or_initialize_by(code: row["company id"]) company = Company.find_or_initialize_by(code: row["company id"])
company.update(company_params) company.update(company_params)
job_params = { job_params = {
description: row["description"], description: row["description"],
position: row["level"], position: row["level"],
salary: row["salary"], salary: row["salary"],
requirement: row["requirement"] requirement: row["requirement"]
} }
job = Job.find_or_initialize_by(title: row["name"], company_id: company.id) job = Job.find_or_initialize_by(title: row["name"], company_id: company.id)
job.update(job_params) job.update(job_params)
city_params = { city_params = { region: row["company province"] }
region: row["company province"]
}
city = City.find_or_initialize_by(name: row["work place"]) city = City.find_or_initialize_by(name: row["work place"])
city.update(city_params) city.update(city_params)
city_job_params = { city_job_params = { city_id: city.id }
city_id: city.id
}
city_job = CityJob.find_or_initialize_by(job_id: job.id) city_job = CityJob.find_or_initialize_by(job_id: job.id)
city_job.update(city_job_params) city_job.update(city_job_params)
rescue rescue
......
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