Commit b27de217 by Son Do Hong

Merge branch 'feature/top_page' into 'master'

feature/top page/ top industries

See merge request !4
parents 79a857e7 bfdd8fe0
//= link_tree ../images //= link_tree ../images
//= link_directory ../stylesheets .css //= link_directory ../stylesheets .css
//= link application.js
...@@ -12,4 +12,5 @@ ...@@ -12,4 +12,5 @@
* *
*= require_tree . *= require_tree .
*= require_self *= require_self
*= require bootstrap.min
*/ */
This source diff could not be displayed because it is too large. You can view the blob instead.
/* universal */
$font-stack: Arial,Helvetica, sans-serif;
$primary-color: #B6B6B6;
$sub-color: gainsboro;
body {
margin: 0;
font-family: $font-stack;
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
}
}
/* header */
#logo {
float: left;
width: 50%;
}
#banner {
width: 100%;
padding: 0px;
}
.btn-outline-success {
color: $sub-color;
border-color:blue;
background: #01548c;
}
.col {
padding: 5px;
margin: 5px;
background-color: $primary-color;
}
.row {
padding: 5px;
margin: 5px;
background-color: $sub-color;
}
.col-sm {
margin: 5px;
padding: 5px;
background-color: $primary-color;
}
.form-inline-city {
padding: 5px;
}A
.form-inline-industry {
padding: 5px;
}
class TopController < ApplicationController
def index
@latest_jobs = Job.latest_jobs.take(Settings.top.job.limit)
@top_cities = City.sort_top_cities.take(Settings.top.city.limit)
@top_industries = Industry.sort_top_industries.take(Settings.top.industry.limit)
end
end
module JobsHelper
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 Industry < ApplicationRecord class Industry < ApplicationRecord
has_many :industry_jobs has_many :industry_jobs
has_many :jobs, through: :industry_jobs
def self.sort_top_industries
@industries ||= 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
def self.latest_jobs
@latest ||= Job.order(created_at: :desc)
end
end end
<div class="container">
<div class="row justify-content-md-center">
<div class="col-sm">
<%= city.name %>
(<%= city.jobs.count %>)
</div>
</div>
</div>
<div class="container">
<div class="row justify-content-md-center">
<div class="col-sm">
<%= industry.name %>
(<%= industry.jobs.count %>)
</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 class="navbar navbar-light bg-light">
<form class="form-inline">
<button class="btn btn-outline-success" type="button">Login</button>
<button class="btn btn-outline-success" type="button">Register</button>
<button class="btn btn-outline-success" type="button">Favorite</button>
<button class="btn btn-outline-success" type="button">History</button>
</form>
</nav>
<%= link_to image_tag("banner.jpg", id: "banner", alt: "Venjob banner") %>
</div>
</header>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>VenJob</title> <title><%= yield(:title) %>Venjob</title>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
<%= csp_meta_tag %> <%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head> </head>
<body> <body>
<%= render "layouts/header" %>
<div class="container">
<%= yield %> <%= yield %>
</div>
<footer>
<%= render "layouts/footer" %>
</footer>
</body> </body>
</html> </html>
<div class="row align-items-center">
<div class="col">
<%= job.title %>
</div>
</div>
</br>
<div class="center jumbotron">
<head>
<title><%= yield(:title) %> Venjob</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="text-center">
<h4>Total Jobs:<%= Job.count %></h4>
</div>
</head>
</div>
<!-- List of latest jobs-->
<div class="Job list">
<div class="Job-title-wrapper">
<h3>Latest Jobs</h3>
</div>
<div class="row row-cols-1">
<div class="Job-content-wrapper">
<%= render partial: "top/job", collection: @latest_jobs %>
</div>
</div>
</br>
<!--List of top cities-->
<div class="City list">
<div class="City-title-wrapper">
<h3>Top Cities</h3>
</div>
<div class="City-content-wrapper">
<div class="row row-cols-3">
<%= render partial: "cities/city", collection: @top_cities %>
<form class="form-inline-city">
<button class="btn btn-outline-success" type="button">All cities</button>
</form>
</div>
</div>
</div>
</br>
<div class="Industry list">
<div class="Industry-title-wrapper">
<h3>Top Industries</h3>
</div>
<div class="Industry-content-wrapper">
<div class="row row-cols-3">
<%= render partial: "industries/industry", collection: @top_industries %>
<form class="form-inline-industry">
<button class="btn btn-outline-success" type="button">All industries</button>
</form>
</div>
</div>
</div>
</div>
...@@ -3,8 +3,3 @@ require_relative "application" ...@@ -3,8 +3,3 @@ require_relative "application"
# Initialize the Rails application. # Initialize the Rails application.
Rails.application.initialize! Rails.application.initialize!
# # Rails.logger = Logger.new(STDOUT)
# # config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log")
# Rails.logger = Logger.new(STDOUT)
# Rails.logger.level = Logger::DEBUG
# Rails.logger.datetime_format = "%Y-%m-%d %H:%M:%S"
Rails.application.routes.draw do Rails.application.routes.draw do
root "top#index"
resource :top, only: :index
devise_for :users devise_for :users
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end end
import_job: import_job:
csv_file: db/Venjob.csv csv_file: db/Venjob.csv
top:
job:
limit: 5
city:
limit: 9
industry:
limit: 9
This source diff could not be displayed because it is too large. You can view the blob instead.
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
...@@ -8,14 +8,12 @@ namespace :job do ...@@ -8,14 +8,12 @@ namespace :job do
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"]
code: row["company id"]
} }
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 = {
title: row["name"],
description: row["description"], description: row["description"],
position: row["level"], position: row["level"],
salary: row["salary"], salary: row["salary"],
...@@ -23,10 +21,20 @@ namespace :job do ...@@ -23,10 +21,20 @@ namespace :job do
} }
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 = { region: row["work place"] }
city = City.find_or_initialize_by(name: row["company province"])
city.update(city_params)
CityJob.find_or_create_by(job_id: job.id, city_id: city.id)
industry_params = { name: row["category"] }
industry = Industry.find_or_initialize_by(name: row["category"])
industry.update(industry_params)
IndustryJob.find_or_create_by(job_id: job.id, industry_id: industry.id)
rescue rescue
import_logger = ActiveSupport::Logger.new("log/import.log") import_logger = ActiveSupport::Logger.new("log/import.log")
import_logger.error "Skip #{row}" import_logger.error "Skip #{row}"
next next
end end
end end
end end
require 'test_helper'
class JobsControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get jobs_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