Skip to content

Commit

Permalink
Most functionality working.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanil Puri committed Sep 27, 2014
1 parent f1caf4c commit 5f840b0
Show file tree
Hide file tree
Showing 23 changed files with 289 additions and 32 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ group :assets do
end

gem 'jquery-rails'
gem 'rails4-autocomplete', '~> 1.1.1'
gem 'jquery-ui-rails'
gem 'turbolinks'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require autocomplete-rails
//= require turbolinks
//= require bootstrap
//= require bootstrap-modal
//= require autocomplete-rails
//= require popup
//= require_tree .
4 changes: 2 additions & 2 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*= require bootstrap
*= require jquery-ui/autocomplete
*= require_self
*= require_tree .
*/
@import "bootstrap";
*/
4 changes: 2 additions & 2 deletions app/assets/stylesheets/custom.sass
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ p
float: left
margin-right: 10px
font-size: 1.7em
color: white
color: #000000
text-transform: uppercase
letter-spacing: -1px
padding-top: 9px
font-weight: bold
line-height: 1
&:hover
color: white
color: #ff0000
text-decoration: none

/* footer */
Expand Down
15 changes: 12 additions & 3 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class Admin::UsersController < Admin::ApplicationController

autocomplete :role, :name, :full => true

def index
@users = User.all
end

def new
Expand All @@ -11,18 +14,20 @@ def create
user = User.new
@errors = []
ActiveRecord::Base.transaction do
update_new_user user, params["user"]
update_new_user user, user_params
end
redirect_to admin_home_index_path if @errors.blank?
end

private

def update_new_user user, new_user_hash
puts new_user_hash
user.update_attributes(new_user_hash)

if user.errors.blank?
user.save!
user.roles << Role.find_by_name("Editor")
# user.roles << Role.find(assigned_role[:id])
else
@errors = user.errors.full_messages
@errors.each do |e|
Expand All @@ -33,6 +38,10 @@ def update_new_user user, new_user_hash
end

def user_params
params.require(:user).permit()
params.require(:user).permit(:name, :phone, :email, :password, :password_confirmation, {:role => [:id, :name]})
end

# def role_params
# params.require(:role).permit(:id, :name)
# end
end
6 changes: 4 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class HomeController < ApplicationController
def index
if current_user.is_employer
redirect_to employer_home_path
if current_user.is_admin?
redirect_to admin_home_index_path
else
redirect_to root_path
end
end
end
61 changes: 61 additions & 0 deletions app/controllers/job_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class JobController < ApplicationController

skip_before_filter :authenticate_job!, :only => [:index]

autocomplete :category, :name, :full => true

def index
@jobs = Job.all
end

def new
@job = Job.new
end

def show
@job = Job.find(params[:id])
end

def create
job = Job.new

update_params = job_params
update_params[:owner_id] = current_user.id

update_new_job job, update_params
end

def apply
if current_user.is_jobseeker?
current_user.jobs << Job.find(params[:job_id])
redirect_to job_index_path
else
flash[:notice] = "You are not allowed to apply for the job. Please create a new jobseeker account."
redirect_to root_path
end
end

def destroy

end

private

def update_new_job job, new_job_hash
job.update_attributes(new_job_hash)
if job.errors.blank?
job.save!
redirect_to job_index_path
else
@errors = job.errors.full_messages
@errors.each do |e|
flash[:error] = e
end
redirect_to new_job_path
end
end

def job_params
params.require(:job).permit(:title, :description, :category_id, :deadline, :salary)
end
end
4 changes: 4 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class SessionsController < Devise::SessionsController
def after_sign_in_path_for(resource)
puts "#################\n\n"
puts resource
if resource.is_a?(User)
puts "#################"
puts "this should be called"
resource.is_admin? ? admin_home_index_path : root_path
else
super
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/job_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module JobHelper

def can_post_new_job?
current_user.can_publish?
end
end
3 changes: 2 additions & 1 deletion app/models/job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Job < ActiveRecord::Base
has_and_belongs_to_many :tags
has_and_belongs_to_many :users
has_one :category

validates :owner_id, :title, :description, :category, :deadline, presence: true
validates :owner_id, :title, :description, :category_id, :deadline, presence: true
end
2 changes: 2 additions & 0 deletions app/models/role_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class RoleUser < ActiveRecord::Base
end
21 changes: 14 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class User < ActiveRecord::Base
has_many :skills
has_and_belongs_to_many :jobs
has_and_belongs_to_many :jobs, :through => "JobApplications"
has_many :permissions, :through => :roles
has_one :resume, :foreign_key => :owner_id
has_and_belongs_to_many :roles
Expand All @@ -26,23 +26,30 @@ class User < ActiveRecord::Base
scope :get_all_employers, lambda{Role.find_by(:name => "Employer").users.pluck(:name)}
scope :get_all_jobseekers, lambda{Role.find_by(:name => "Jobseeker").users.pluck(:name)}

def has_role? role
self.roles.include? role
end

def is_admin?
self.has_permission? "application_admin"
end

def can_publish?
def is_employer?
self.has_permission? "can_publish"
end

def can_apply_to_job?
def is_jobseeker?
self.has_permission? "can_apply"
end

private
def has_role? role
self.roles.include? role
end

def can_publish?
self.has_permission? "can_publish"
end

def can_apply_to_job?
self.has_permission? "can_apply"
end

##
# Function: Checks the permissions of the user against the requested permissions
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div><%= link_to "Create New Editor", "#" %></div>
<div><%= link_to "View All Users", "#" %></div>
<div><%= link_to "Create New Editor", new_admin_user_path %></div>
<div><%= link_to "View All Users", admin_users_path %></div>
<div><%= link_to "View All Drafted Posts", "#" %></div>
<div><%= link_to "View All Published Posts", "#" %></div>
<div><%= link_to "Create new resume", "#" %></div>
40 changes: 40 additions & 0 deletions app/views/admin/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="create_header">
<h1>All Users</h1>
<%= link_to "Create User", new_admin_user_path if current_user.is_admin? %>
</div>
<div class="data_container">
<table id = "application_users_list" class="display data_table">
<thead>
<tr class="even">
<th>User Id</th>
<th>User Name</th>
<th>User Email</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.id %></td>
<td><%= user.name %></td>
<!--<td><%#= user.posts.count %></td>-->
<td><%= user.email %></td>
</tr>
<% end %>
</tbody>
</table>
</div>

<script type="text/javascript">
$(document).ready(function() {
$('#application_users_list').dataTable({
sPaginationType: "full_numbers",
"sDom": '<"top"if>rt<"bottom"lp><"clear">;', // add the 'f' in top tag to enable searching like <"top"f>
"bJQueryUI": true,
"aoColumns": [
null,
null,
// { "bSearchable": false },
null
] } );
});
</script>
26 changes: 18 additions & 8 deletions app/views/admin/users/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@
<div class="table_body">
<%= f.fields_for :role do |r| %>
<div class="table_list_item">
<%= f.label :name, :class => "table_column_item" %> <%= f.text_field :name, :class => "table_column_item" %>
<span class="table_column_item">*Required</span>
<%= f.label :name, :class => "table_column_item" %> <%= f.text_field :name, :class => "table_column_item", :placeholder => "*Required" %>
</div>
<div class="table_list_item">
<%= f.label :email, :class => "table_column_item" %> <%= f.email_field :email, :class => "table_column_item" %>
<span class="table_column_item">*Required</span>
<%= f.label :email, :class => "table_column_item" %> <%= f.email_field :email, :class => "table_column_item", :placeholder => "*Required" %>
</div>

<div class="table_list_item">
<%= f.label :password, :class => "table_column_item" %> <%= f.password_field :password, :class => "table_column_item" %>
<span class="table_column_item">*Required</span>
<%= f.label :phone, :class => "table_column_item" %> <%= f.phone_field :phone, :class => "table_column_item", :placeholder => "*Required" %>
</div>

<div class="table_list_item">
<%= f.label :password_confirmation, :class => "table_column_item" %> <%= f.password_field :password_confirmation, :class => "table_column_item" %>
<span class="table_column_item">*Required</span>
<%= f.label :password, :class => "table_column_item" %> <%= f.password_field :password, :class => "table_column_item", :placeholder => "*Required" %>
</div>

<div class="table_list_item">
<%= f.label :password_confirmation, :class => "table_column_item" %> <%= f.password_field :password_confirmation, :class => "table_column_item", :placeholder => "*Required" %>
</div>

<%= f.fields_for :role do |r| %>
<%= r.hidden_field :id, :id=>"role_id" %>
<div class="table_list_item">
<%= r.label :role, :class => "table_column_item" %> <%= r.autocomplete_field :role, autocomplete_role_name_admin_users_path,
:update_elements => {:id => '#role_id'},
:class => "table_column_item", :size => 30,
:placeholder => "*required" %>
</div>
<% end %>

<div class="table_list_item">
<span class ="table_column_item"><%= f.submit "Create", :class => "button " %></span>
<span><%= link_to "Cancel", admin_home_index_path, :class=> "button" %></span>
Expand Down
46 changes: 46 additions & 0 deletions app/views/job/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class="create_header">
<h1>All Published Posts</h1>
<% if can_post_new_job? %>
<%= link_to "Post New Job", new_job_path %>
<% end %>
<span>*Click on Job to apply</span>
</div>
<div class="data_container">
<table id = "jobs_table" class="display data_table">
<thead>
<tr class="even">
<th>Owner Name</th>
<th>Job Title</th>
<th>Application Deadline</th>
</tr>
</thead>
<tbody>
<% @jobs.each do |job| %>
<tr>
<td><%= User.find(job.owner_id).name %></td>
<td><%= link_to job.title, job_path(:id => job.id), :class => "job_body_link" %></td>
<td class = "job_body_link"><%= job.deadline %></td>
</tr>
<% end %>
</tbody>
</table>
</div>

<script type="text/javascript">
$(document).ready(function() {
$('#jobs_table').dataTable({
sPaginationType: "full_numbers",
"sDom": '<"top"if>rt<"bottom"lp><"clear">;', // add the 'f' in top tag to enable searching like <"top"f>
"bJQueryUI": true,
"aoColumns": [
null,
null,
null
]});
$(".job_body_link").on("click", function(e){
e.preventDefault();
var path = $(this).attr("href");
show_common_popup(path, '');
});
});
</script>
Loading

0 comments on commit 5f840b0

Please sign in to comment.