add basic resume support

with in place editing
This commit is contained in:
Torsten Ruger 2016-04-30 19:39:04 +03:00
parent c03c209610
commit e87654d67d
23 changed files with 342 additions and 9 deletions

View File

@ -16,6 +16,7 @@ gem 'high_voltage'
gem 'pundit'
gem 'simple_form'
gem 'animate-scss' , :github => "ejholmes/animate.scss"
gem "best_in_place"
group :development do
gem 'web-console', '~> 2.0'

View File

@ -59,6 +59,9 @@ GEM
autoprefixer-rails (6.3.4)
execjs
bcrypt (3.1.11)
best_in_place (3.1.0)
actionpack (>= 3.2)
railties (>= 3.2)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
@ -357,6 +360,7 @@ PLATFORMS
DEPENDENCIES
administrate
animate-scss!
best_in_place
better_errors
bootstrap-sass
byebug

View File

@ -13,6 +13,7 @@
//= require jquery2
//= require smoothscroll
//= require jquery_ujs
//= require best_in_place
//= require bootstrap/alert
//= require bootstrap/collapse
//= require bootstrap/dropdown

View File

@ -25,3 +25,13 @@ jQuery(document).ready ->
# fadeIn needs to be an available animate class, ie included
jQuery('.js-rotating').Morphext({separator: ";" , animation: "fadeIn" , speed: 6000})
return
$(document).ready ->
### Activating Best In Place ###
jQuery('.best_in_place').best_in_place()
return
$(document).ready ->
### fading alerts ###
jQuery('.alert').delay(5000).fadeOut 'slow'
return

View File

@ -342,3 +342,18 @@
left: 0
width: 100% !important
height: 100% !important
.authform
margin-left: 30%
margin-right: 30%
max-width: 40%
@media only screen and (max-width: 1024px)
.authform
margin-left: 25%
margin-right: 25%
max-width: 50%
@media only screen and (max-width: 600px)
.authform
margin-left: 15%
margin-right: 15%
max-width: 70%

View File

@ -0,0 +1,40 @@
class ResumesController < ApplicationController
before_action :set_resume, only: [:show, :edit, :update, :destroy]
def index
@resumes = Resume.all
end
def show
end
# PATCH/PUT /resumes/1.json
def update
respond_to do |format|
if @resume.update(resume_params)
format.html { redirect_to @resume, notice: 'Resume was successfully updated.' }
format.json { render :show, status: :ok, location: @resume }
else
format.html { render :edit }
format.json { render json: @resume.errors, status: :unprocessable_entity }
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_resume
if params[:id]
@resume = Resume.find(params[:id])
else
@resume = current_user.resume
end
end
# Never trust parameters from the scary internet, only allow the white list through.
def resume_params
params.require(:resume).permit(:street, :city, :country, :user_id ,
:school, :uni, :internship, :work, :tech_skills,
:soft_skills, :projects, :other, :interests, :motivation)
end
end

View File

@ -3,4 +3,22 @@ module ApplicationHelper
image_tag( "brands/1.jpg" , "data-src" => asset_path(pic) , class: 'swiper-lazy') +
raw("<div class='swiper-lazy-preloader swiper-lazy-preloader-white'></div>")
end
def brr txt
txt
end
# define a bunch of defaults for the best_in_place call
def resume_in_place field , txt , attributes = {}
br = proc {|txtt| raw(txtt.to_s.gsub("\n" , "<br>")) }
defaults = { :url => resume_path , place_holder: txt , display_with: br}
unless [:street , :city , :country].include? field
defaults.merge! ok_button: "Edit", ok_button_class: "btn btn-success" ,
cancel_button: "Cancel" , cancel_button_class: "btn btn-warning",
inner_class: "form-control" , as: :textarea ,
sanitize: false , html_attrs: {rows: 10}
end
attributes.reverse_merge! defaults
best_in_place(@resume , field , attributes)
end
end

View File

@ -0,0 +1,2 @@
module ResumesHelper
end

3
app/models/resume.rb Normal file
View File

@ -0,0 +1,3 @@
class Resume < ActiveRecord::Base
belongs_to :user
end

View File

@ -1,4 +1,6 @@
class User < ActiveRecord::Base
enum role: [:user, :vip, :admin]
after_initialize :set_default_role, :if => :new_record?
@ -6,6 +8,9 @@ class User < ActiveRecord::Base
self.role ||= :user
end
def resume
Resume.find_or_create_by( :user_id => self.id)
end
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,

View File

@ -1,6 +1,6 @@
.authform
%h3
Edit #{resource_name.to_s.humanize}
Edit Profile
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :role => 'form'}) do |f|
= devise_error_messages!
.form-group

View File

@ -13,8 +13,3 @@
= f.label :password
= f.password_field :password, class: 'form-control'
= f.submit 'Sign in', :class => 'button right'
- if devise_mapping.rememberable?
.checkbox{:style => "width:150px"}
%label
= f.check_box :remember_me
Remember me

View File

@ -54,7 +54,8 @@
%ul.footer-links.list-unstyled
-if user_signed_in?
%li= link_to "Sign out" , destroy_user_session_path , method: :delete
%li= link_to "Account" , user_path(current_user)
%li= link_to "Account" , edit_user_registration_path
%li= link_to "Resume" , resume_path
-else
%li
= simple_form_for(:user, :url => session_path(:user), :html => { :role => 'form' , class: "form-horizontal"}) do |f|
@ -68,6 +69,7 @@
= f.password_field :password, class: 'form-control' , placeholder: :password
%span.input-group-btn
= f.submit "Sign in" , class: "btn btn-success"
%li= link_to "Sign In Page" , new_user_session_path
.margin-top-20
%a.social-icon.social-icon-border.social-facebook.pull-left{"data-placement" => "top", :href => "#", :title => "Facebook"}
%i.icon-facebook

View File

@ -0,0 +1,45 @@
%h1 Listing resumes
%table
%thead
%tr
%th School
%th Uni
%th Internship
%th Work
%th Tech skills
%th Soft skills
%th Projects
%th Other
%th Intrests
%th Motivation
%th Address1
%th City
%th Country
%th User
%th
%th
%th
%tbody
- @resumes.each do |resume|
%tr
%td= resume.school
%td= resume.uni
%td= resume.internship
%td= resume.work
%td= resume.tech_skills
%td= resume.soft_skills
%td= resume.projects
%td= resume.other
%td= resume.interests
%td= resume.motivation
%td= resume.street
%td= resume.city
%td= resume.country
%td= resume.user_id
%td= link_to 'Show', resume
%br
= link_to 'New Resume', new_resume_path

View File

@ -0,0 +1,102 @@
.row
.col-md-2
.col-md-8
%p#notice= notice
.row
.col-md-1
.col-md-1
%p
%b School:
.col-md-8
= resume_in_place :school , "What is the highest level school you went to and what were you good at"
.row
.col-md-1
.col-md-1
%p
%b Uni:
.col-md-8
= resume_in_place :uni , "Did you go to university or similar, what degree, did you finish"
.row
.col-md-1
.col-md-1
%p
%b Internship:
.col-md-8
= resume_in_place :internship , "Tell us about any relevant internships you have done"
.row
.col-md-1
.col-md-1
%p
%b Work:
.col-md-8
= resume_in_place :work , "Do you have work experience, in what field."
.row
.col-md-1
.col-md-1
%p
%b Projects:
.col-md-8
= resume_in_place :projects , "Did you do any technical project, alone or in a group"
.row
.col-md-1
.col-md-1
%p
%b Tech skills:
.col-md-8
= resume_in_place :tech_skills , "What technical skills have you already acquired"
.row
.col-md-1
.col-md-1
%p
%b Soft skills:
.col-md-8
= resume_in_place :soft_skills , "What non technical skills would you say you are good at"
.row
.col-md-1
.col-md-1
%p
%b Intrests:
.col-md-8
= resume_in_place :interests , "Tell us a bit about your general interest"
.row
.col-md-1
.col-md-1
%p
%b Motivation:
.col-md-8
= resume_in_place :motivation , "And what motivates you to apply for this course"
.row
.col-md-1
.col-md-1
%p
%b Finance plan:
.col-md-8
= resume_in_place :finance , "What is your source of finance"
.row
.col-md-1
.col-md-1
%p
%b Other:
.col-md-8
= resume_in_place :other , "Anything else you would like to mention"
.row
.col-md-1
.col-md-1
%p
%b Address:
.col-md-8
= resume_in_place :street , "Street"
.row
.col-md-1
.col-md-1
%p
%b City:
.col-md-8
= resume_in_place :city , "City"
.row
.col-md-1
.col-md-1
%p
%b Country:
.col-md-8
= resume_in_place :country , "Country"

View File

@ -0,0 +1 @@
json.extract! @resume, :id, :school, :uni, :internship, :work, :tech_skills, :soft_skills, :projects, :other, :interests, :motivation, :street, :city, :country, :user_id, :created_at, :updated_at

View File

@ -3,9 +3,11 @@ Rails.application.routes.draw do
devise_for :users, controllers: { registrations: "registrations" }
resources :users
resource :resume , except: [:destroy , :new , :edit]
namespace :admin do
resources :users
resources :resumes , except: [:destroy , :new , :edit ]
root to: "users#index"
end

View File

@ -0,0 +1,27 @@
class CreateResumes < ActiveRecord::Migration
def change
create_table :resumes do |t|
t.string :street
t.string :city
t.string :country
t.text :school
t.text :uni
t.text :internship
t.text :work
t.text :projects
t.text :soft_skills
t.text :tech_skills
t.text :interests
t.text :motivation
t.text :finance
t.text :other
t.integer :user_id
t.timestamps null: false
end
end
end

View File

@ -11,7 +11,27 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160321164502) do
ActiveRecord::Schema.define(version: 20160428072130) do
create_table "resumes", force: :cascade do |t|
t.string "street"
t.string "city"
t.string "country"
t.text "school"
t.text "uni"
t.text "internship"
t.text "work"
t.text "projects"
t.text "soft_skills"
t.text "tech_skills"
t.text "interests"
t.text "motivation"
t.text "finance"
t.text "other"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false

18
spec/factories/resumes.rb Normal file
View File

@ -0,0 +1,18 @@
FactoryGirl.define do
factory :resume do
school "MyString"
uni "MyString"
internship "MyString"
work "MyString"
tech_skills "MyString"
soft_skills "MyString"
projects "MyString"
other "MyString"
interests "MyString"
motivation "MyString"
street "MyString"
city "MyString"
country "MyString"
user_id 1
end
end

View File

@ -0,0 +1,17 @@
include Warden::Test::Helpers
Warden.test_mode!
feature 'Resume edit' do
after(:each) do
Warden.test_reset!
end
scenario 'user see own resume' do
sign_new
visit resume_path()
expect(page).to have_content("Resume")
end
end

View File

@ -35,7 +35,7 @@ feature 'User edit', :devise do
other = FactoryGirl.create(:user, email: 'other@example.com')
login_as(me, :scope => :user)
visit edit_user_registration_path(other)
expect(page).to have_content 'Edit User'
expect(page).to have_content 'Edit Profile'
expect(page).to have_field('Email', with: me.email)
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Resume, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end