diff --git a/Gemfile b/Gemfile index 37e85ab..6fdee1e 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f462ed2..31f227e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -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 . diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index ede9da5..48aa108 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -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"; \ No newline at end of file + */ \ No newline at end of file diff --git a/app/assets/stylesheets/custom.sass b/app/assets/stylesheets/custom.sass index fcfe67f..040ac7a 100644 --- a/app/assets/stylesheets/custom.sass +++ b/app/assets/stylesheets/custom.sass @@ -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 */ diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 49d3848..7e9cbde 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,6 +1,9 @@ class Admin::UsersController < Admin::ApplicationController + autocomplete :role, :name, :full => true + def index + @users = User.all end def new @@ -11,7 +14,7 @@ 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 @@ -19,10 +22,12 @@ def create 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| @@ -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 \ No newline at end of file diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index c79039a..5dced34 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/job_controller.rb b/app/controllers/job_controller.rb new file mode 100644 index 0000000..0cf84a0 --- /dev/null +++ b/app/controllers/job_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 3becc99..401fe70 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -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 diff --git a/app/helpers/job_helper.rb b/app/helpers/job_helper.rb new file mode 100644 index 0000000..9671624 --- /dev/null +++ b/app/helpers/job_helper.rb @@ -0,0 +1,6 @@ +module JobHelper + + def can_post_new_job? + current_user.can_publish? + end +end diff --git a/app/models/job.rb b/app/models/job.rb index 819bf39..ee2d8a5 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -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 \ No newline at end of file diff --git a/app/models/role_user.rb b/app/models/role_user.rb new file mode 100644 index 0000000..ee0e4bf --- /dev/null +++ b/app/models/role_user.rb @@ -0,0 +1,2 @@ +class RoleUser < ActiveRecord::Base +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 9a62d3f..03627b5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 @@ -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 diff --git a/app/views/admin/home/index.html.erb b/app/views/admin/home/index.html.erb index c589653..38d3fb1 100644 --- a/app/views/admin/home/index.html.erb +++ b/app/views/admin/home/index.html.erb @@ -1,5 +1,5 @@ -
<%= link_to "Create New Editor", "#" %>
-
<%= link_to "View All Users", "#" %>
+
<%= link_to "Create New Editor", new_admin_user_path %>
+
<%= link_to "View All Users", admin_users_path %>
<%= link_to "View All Drafted Posts", "#" %>
<%= link_to "View All Published Posts", "#" %>
<%= link_to "Create new resume", "#" %>
diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb new file mode 100644 index 0000000..2e1b688 --- /dev/null +++ b/app/views/admin/users/index.html.erb @@ -0,0 +1,40 @@ +
+

All Users

+ <%= link_to "Create User", new_admin_user_path if current_user.is_admin? %> +
+
+ + + + + + + + + + <% @users.each do |user| %> + + + + + + + <% end %> + +
User IdUser NameUser Email
<%= user.id %><%= user.name %><%= user.email %>
+
+ + \ No newline at end of file diff --git a/app/views/admin/users/new.html.erb b/app/views/admin/users/new.html.erb index 89f236b..a8615a6 100644 --- a/app/views/admin/users/new.html.erb +++ b/app/views/admin/users/new.html.erb @@ -2,24 +2,34 @@
<%= f.fields_for :role do |r| %>
- <%= f.label :name, :class => "table_column_item" %> <%= f.text_field :name, :class => "table_column_item" %> - *Required + <%= f.label :name, :class => "table_column_item" %> <%= f.text_field :name, :class => "table_column_item", :placeholder => "*Required" %>
- <%= f.label :email, :class => "table_column_item" %> <%= f.email_field :email, :class => "table_column_item" %> - *Required + <%= f.label :email, :class => "table_column_item" %> <%= f.email_field :email, :class => "table_column_item", :placeholder => "*Required" %>
- <%= f.label :password, :class => "table_column_item" %> <%= f.password_field :password, :class => "table_column_item" %> - *Required + <%= f.label :phone, :class => "table_column_item" %> <%= f.phone_field :phone, :class => "table_column_item", :placeholder => "*Required" %>
- <%= f.label :password_confirmation, :class => "table_column_item" %> <%= f.password_field :password_confirmation, :class => "table_column_item" %> - *Required + <%= f.label :password, :class => "table_column_item" %> <%= f.password_field :password, :class => "table_column_item", :placeholder => "*Required" %>
+
+ <%= f.label :password_confirmation, :class => "table_column_item" %> <%= f.password_field :password_confirmation, :class => "table_column_item", :placeholder => "*Required" %> +
+ + <%= f.fields_for :role do |r| %> + <%= r.hidden_field :id, :id=>"role_id" %> +
+ <%= 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" %> +
+ <% end %> +
<%= f.submit "Create", :class => "button " %> <%= link_to "Cancel", admin_home_index_path, :class=> "button" %> diff --git a/app/views/job/index.html.erb b/app/views/job/index.html.erb new file mode 100644 index 0000000..d5f1e12 --- /dev/null +++ b/app/views/job/index.html.erb @@ -0,0 +1,46 @@ +
+

All Published Posts

+ <% if can_post_new_job? %> + <%= link_to "Post New Job", new_job_path %> + <% end %> + *Click on Job to apply +
+
+ + + + + + + + + + <% @jobs.each do |job| %> + + + + + + <% end %> + +
Owner NameJob TitleApplication Deadline
<%= User.find(job.owner_id).name %><%= link_to job.title, job_path(:id => job.id), :class => "job_body_link" %>
+
+ + \ No newline at end of file diff --git a/app/views/job/new.html.erb b/app/views/job/new.html.erb new file mode 100644 index 0000000..15efc97 --- /dev/null +++ b/app/views/job/new.html.erb @@ -0,0 +1,31 @@ +<%= form_for @job, :url => job_index_path do |f| %> +
+
+ <%= f.label :title, :class => "table_column_item" %> <%= f.text_field :title, :class => "table_column_item", :size => 30, :placeholder => "*required" %> +
+
+ <%= f.label :description, :class => "table_column_item" %> <%= f.text_area :description, :class => "table_column_item", :rows=>10, :columns => 50, :size => 500, :placeholder => "*required" %> +
+ + <%= f.hidden_field :category_id, :id=>"category_cat_id" %> +
+ <%= f.label :category, :class => "table_column_item" %> <%= f.autocomplete_field :category, autocomplete_category_name_job_index_path, + :update_elements => {:id => '#category_cat_id'}, + :class => "table_column_item", :size => 30, + :placeholder => "*required" %> +
+ +
+ <%= f.label :salary, :class => "table_column_item" %> <%= f.text_field :salary, :class => "table_column_item", :size => 30 %> +
+ +
+ <%= f.label :deadline, :class => "table_column_item" %> <%= f.text_field :deadline, :class => "table_column_item", :size => 30, :placeholder => "*required" %> +
+ +
+ <%= f.submit "Create", :class => "button " %> + <%= link_to "Cancel", create_redirector_path, :class=> "button job_cancel" %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/job/show.html.erb b/app/views/job/show.html.erb new file mode 100644 index 0000000..f692efd --- /dev/null +++ b/app/views/job/show.html.erb @@ -0,0 +1,15 @@ +
+ <%= @job.title %> +
+
+ <%= @job.description %> +
+
+ <%= @job.salary %> +
+
+ <%= @job.deadline %> +
+
+ <%= link_to "Apply", job_apply_path(:job_id=>@job.id), :confirm => "Your profile information will be used for this job application. Are you sure you wish to proceed?" %> +
\ No newline at end of file diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index e134a9a..a0f3ca9 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -2,7 +2,7 @@