Commit b0a93a6e by Thanh Hung Pham

Add admin page

parent acb70184
# 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/
// Place all the styles related to the Admins controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class AdminsController < ApplicationController
def applies
@cities = City.all.map { |c| [c.name, c.id] }
@categories = Category.all.map { |c| [c.name, c.id] }
@applied_jobs = Apply.all.page params[:page]
end
def search
@applied_jobs = Apply.all.page params[:page]
redirect_to admins_applies_path
end
end
module AdminsHelper
end
class Admin < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :trackable, :validatable
end
class Apply < ApplicationRecord
belongs_to :user
belongs_to :job
paginates_per 20
end
<%- provide(:title, 'Applied Jobs') -%>
<div class="well">
<h3>Applied Jobs</h3>
<%= form_tag admins_search_path do %>
<div class="form_group">
<label>Email:</label><br />
<%= text_field_tag 'email', '', class: 'form-control' %>
</div>
<div class="form-group">
<label>City:</label><br />
<%= select_tag(:city_id, options_for_select(@cities), include_blank: "Select city", class: 'form-control') %>
</div>
<div class="form-group">
<label>Industry:</label><br />
<%= select_tag(:category_id, options_for_select(@categories), include_blank: "Select industry", class: 'form-control') %>
</div>
<div class="form-group">
<label>Date:</label><br />
<%= date_select('from_date', 'from_date', order: [:day, :month, :year], class: 'form-control') %>
<label></label>
<%= date_select('to_date', 'to_date', order: [:day, :month, :year], class: 'form-control') %>
</div>
<div class="form-group">
<%= submit_tag 'Search', class: 'btn btn-primary' %>
<%= link_to 'CSV Download', root_path, class: 'btn btn-primary' %>
</div>
<%- end -%>
</div>
<div class="well">
<%= paginate @applied_jobs %>
<div class="table-responsive">
<table class="table">
<thead>
<th> Job </th>
<th> Candidate Name </th>
<th> Candidate's CV </th>
<th> Candidate's Email </th>
<th> Applied At </th>
</thead>
<tbody>
<%- @applied_jobs.each do |apply| -%>
<tr>
<td> <%= link_to apply.job.name, jobs_detail_path(id: apply.job.id) %></td>
<td> <%= link_to apply.user.fullname, registrations_show_path %></td>
<td> <%= link_to apply.user.cv_name, registrations_download_file_path %></td>
<td> <%= apply.user.email %></td>
<td> <%= apply.applied_at.strftime('%F') %></td>
</tr>
<%- end -%>
</tbody>
</table>
</div>
<%= paginate @applied_jobs %>
</div>
......@@ -3,6 +3,10 @@
<%= link_to image_tag('http://images.careerbuilder.vn/background/ok_cb_vipbn_vtlc_1440x430_1496992170.jpg', width: '100px'), root_path, id: 'logo'%>
<nav>
<ul class="nav navbar-nav navbar-right">
<%- if admin_signed_in? -%>
<li> <%= link_to 'Applied Jobs', admins_applies_path %> </li>
<li> <%= link_to 'Log out', destroy_admin_session_path, method: :delete %> </li>
<%- else -%>
<%- if user_signed_in? -%>
<li> <%= link_to 'My profile', registrations_show_path %> </li>
<li> <%= link_to 'Log out', destroy_user_session_path, method: :delete %> </li>
......@@ -14,7 +18,7 @@
<li> <%= link_to 'Favorite', new_user_session_path %> </li>
<li> <%= link_to 'History', new_user_session_path %> </li>
<%- end -%>
<%- end -%>
</ul>
</nav>
</div>
......
Rails.application.routes.draw do
get 'admins/applies'
devise_for :admins
root 'static_pages#home'
get 'static_pages/home'
......@@ -19,6 +22,9 @@ Rails.application.routes.draw do
get 'jobs/favorited_jobs', to: 'jobs#favorited_jobs'
get 'jobs/history_jobs', to: 'jobs#history_jobs'
get 'admins/applies', to: 'admins#applies'
post 'admins/search', to: 'admins#search'
resource :cities
devise_scope :user do
post '/confirmations/update_confirm', to: 'confirmations#update_confirm'
......
......@@ -3,7 +3,6 @@ class CreateUsers < ActiveRecord::Migration[5.1]
create_table :users do |t|
t.string :password
t.string :fullname
t.boolean :admin
t.string :cv_name
t.timestamps
......
class DeviseCreateAdmins < ActiveRecord::Migration[5.1]
def change
create_table :admins do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
# t.string :reset_password_token
# t.datetime :reset_password_sent_at
## Rememberable
# t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
t.timestamps null: false
end
add_index :admins, :email, unique: true
# add_index :admins, :reset_password_token, unique: true
# add_index :admins, :confirmation_token, unique: true
# add_index :admins, :unlock_token, unique: true
end
end
class AddAdminToUsers < ActiveRecord::Migration[5.1]
def change
add_column :users, :admin, :boolean, default: false
end
end
......@@ -10,7 +10,23 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170705034837) do
ActiveRecord::Schema.define(version: 20170718022445) do
create_table "admins", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_admins_on_email", unique: true
end
create_table "applies", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.bigint "user_id"
......@@ -126,7 +142,6 @@ ActiveRecord::Schema.define(version: 20170705034837) do
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "password"
t.string "fullname"
t.boolean "admin"
t.string "cv_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
......@@ -147,6 +162,7 @@ ActiveRecord::Schema.define(version: 20170705034837) do
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at"
t.boolean "admin", default: false
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
......
......@@ -5,5 +5,11 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
Area.new(name: 'Viet Nam').save
Area.new(name: 'International').save
Area.find_or_create_by(name: 'Viet Nam')
Area.find_or_create_by(name: 'International')
admin = Admin.create! do |u|
u.email = 'sample@sample.com'
u.password = 'password'
u.password_confirmation = 'password'
end
require 'test_helper'
class AdminsControllerTest < ActionDispatch::IntegrationTest
test "should get applies" do
get admins_applies_url
assert_response :success
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
require 'test_helper'
class AdminTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# 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