Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added job title functionality #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ gem 'jquery-ui-rails'
gem 'american_date'


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete another line here


group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
Expand Down
43 changes: 43 additions & 0 deletions app/assets/stylesheets/_badges.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.badges {
$badge-background: $medium-gray;
$badge-dark-color: $dark-gray;
$badge-error-color: $error-color;
$badge-notice-color: $notice-color;
$badge-success-color: $success-color;
$badge-font-color: #fff;
$badge-font-size: $base-font-size * .75;

display: block;
margin-bottom: $base-line-height;

.badge {
@include inline-block;
background: $badge-background;
border-radius: 2em;
color: $badge-font-color;
font-size: $badge-font-size;
font-weight: 600;
line-height: 1;
padding: .25em 1em;
text-align: center;

&.dark {
background: $badge-dark-color;
}

&.error {
background: $badge-error-color;
color: darken($badge-error-color, 60);
}

&.notice {
background: $badge-notice-color;
color: darken($badge-error-color, 60);
}

&.success {
background: $badge-success-color;
color: darken($badge-success-color, 60);
}
}
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/vacation_time.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the vacation_time controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this file for?

1 change: 1 addition & 0 deletions app/controllers/homes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class HomesController < ApplicationController
def show
@profiles = Profile.all
@office_branches = OfficeBranch.all
end
end
17 changes: 17 additions & 0 deletions app/controllers/job_title_users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class JobTitleUsersController < ApplicationController
def create
@job_title = JobTitleUser.new(job_title_params)
if @job_title.save
redirect_to root_path
else
render :new
end
end

private

def job_title_params
params.require(:job_title_user).permit(:job_title_id, :user_id)
end

end
2 changes: 1 addition & 1 deletion app/controllers/office_branches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def destroy
private

def office_branch_params
params.require(:office_branch).permit(:location)
params.require(:office_branch).permit(:city, :state, :country)
end

def find_office_branch
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def show

def new
@profile = Profile.new
@user = @profile.user
end

def create
Expand All @@ -18,6 +19,7 @@ def create
def edit
@profile = find_profile
@user = @profile.user
@job_title_user = JobTitleUser.new
end

def update
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def user_params
:email,
:password,
:department_id,
:office_branch_id
:office_branch_id,
:job_title_users,
:job_titles
)
end

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/vacation_time_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module VacationTimeHelper
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is empty and should be removed.

end
8 changes: 8 additions & 0 deletions app/models/job_title.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class JobTitle < ActiveRecord::Base
has_many :job_title_users
has_many :users, through: :job_title_users

def name
super || NullJobTitle.new
end
end
4 changes: 4 additions & 0 deletions app/models/job_title_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class JobTitleUser < ActiveRecord::Base
belongs_to :user
belongs_to :job_title
end
5 changes: 5 additions & 0 deletions app/models/null_job_title.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class NullJobTitle
def name
"No Current Job"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

end
end
1 change: 1 addition & 0 deletions app/models/null_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ def to_partial_path
def present?
false
end

end
4 changes: 3 additions & 1 deletion app/models/office_branch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class OfficeBranch < ActiveRecord::Base
validates :location, presence: true
validates :city, presence: true
validates :country, presence: true

has_many :users

def profiles
Expand Down
10 changes: 10 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ class User < ActiveRecord::Base
has_many :salaries, dependent: :destroy
belongs_to :department
belongs_to :office_branch
has_many :job_title_users
has_many :job_titles, through: :job_title_users

def job_titles
super || NullJobTitles.new
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.


def current_job
job_titles.last || NullJobTitle.new
end

def has_any_contact_information?
address ||
Expand Down
4 changes: 2 additions & 2 deletions app/views/homes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
</section>
</li>
<li class="tab-header-and-content">
<a href="#" class="tab-link">Departments</a>
<a href="#" class="tab-link">Office Branches</a>
<section>
<p>Donec mattis mauris gravida metus laoreet non rutrum sem viverra. Aenean nibh libero, viverra vel vestibulum in, porttitor ut sapien. Phasellus tempor lorem id justo ornare tincidunt. Nulla faucibus, purus eu placerat fermentum, velit mi iaculis nunc, bibendum tincidunt ipsum justo eu mauris. Nulla facilisi. Vestibulum vel lectus ac purus tempus suscipit nec sit amet eros. Nullam fringilla, enim eu lobortis dapibus, quam magna tincidunt nibh, sit amet imperdiet dolor justo congue turpis.</p>
<%= geo_chart @office_branches.group(:country).count %> <hr>
</section>
</li>
<li class="tab-header-and-content">
Expand Down
2 changes: 1 addition & 1 deletion app/views/office_branches/_office_branch.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ul>
<li>
<%= link_to office_branch.location, office_branch %>
<%= link_to office_branch.city %>
</li>
</ul>
4 changes: 3 additions & 1 deletion app/views/office_branches/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<%= form_for(@office_branch) do |form| %>
<%= render "form_errors", target: @office_branch %>
<%= form.text_field :location, placeholder: "Location" %>
<%= form.text_field :city, placeholder: "City" %>
<%= form.text_field :state, placeholder: "State" %>
<%= form.text_field :country, placeholder: "Country" %>
<%= form.submit "Create Office Branch" %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/office_branches/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h2><%= @office_branch.location %></h2>
<h2><%= @office_branch.city %>, <%= @office_branch.state %></h2>
<nav>
<ul>
<li><%= link_to "Office Branches Index", office_branches_path %></li>
Expand Down
10 changes: 8 additions & 2 deletions app/views/profiles/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
<%= form_for(@user) do |form| %>
<%= render "form_errors", target: @user %>
<%= form.collection_select :department_id, Department.order(:name), :id, :name, include_blank: true %>
<%= form.collection_select :office_branch_id, OfficeBranch.order(:location), :id, :location, include_blank: true %>
<%= form.submit "Update Branch & Department" %>
<% end %>
</div>
</div>
<div>
<%= form_for(@job_title_user) do |form| %>
<%= form.hidden_field :user_id, value: @user.id %>
<%= form.collection_select :job_title_id, JobTitle.all, :id, :name, include_blank: true %>
<%= form.submit "Update Job Title" %>
<% end %>
</div>
4 changes: 4 additions & 0 deletions app/views/profiles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<strong>Department: </strong> <%= @department.name %>
</div>

<div>
<strong>Job Title: </strong> <%= @user.current_job.name %>
</div>

<div>
<%= link_to "Delete Profile", @profile, method: :delete %>
</div>
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
resources :salaries, only: [:show, :new, :create, :index]
end

resource :job_title_users, only: ['create']

end
2 changes: 1 addition & 1 deletion db/migrate/20140417015751_create_salaries.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateSalaries < ActiveRecord::Migration
rails class CreateSalaries < ActiveRecord::Migration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rails shouldn't be here.

def change
create_table :salaries do |t|
t.decimal :salary
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20140417185226_add_state_to_office_branch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddStateToOfficeBranch < ActiveRecord::Migration
def change
rename_column :office_branches, :location, :city
add_column :office_branches, :state, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140417195701_add_country_to_office_branches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCountryToOfficeBranches < ActiveRecord::Migration
def change
add_column :office_branches, :country, :string
end
end
9 changes: 9 additions & 0 deletions db/migrate/20140421134024_create_job_titles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateJobTitles < ActiveRecord::Migration
def change
create_table :job_titles do |t|
t.date :date
t.string :job_title
t.integer :user_id
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140421140719_remove_user_id_from_job_titles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveUserIdFromJobTitles < ActiveRecord::Migration
def change
remove_column :job_titles, :user_id
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140421142854_add_job_title_id_to_job_titles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddJobTitleIdToJobTitles < ActiveRecord::Migration
def change
add_column :job_titles, :job_title_id, :integer
end
end
9 changes: 9 additions & 0 deletions db/migrate/20140421143134_create_job_title_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateJobTitleUsers < ActiveRecord::Migration
def change
create_table :job_title_users do |t|
t.integer :user_id
t.integer :job_title_id
t.timestamps
end
end
end
6 changes: 6 additions & 0 deletions db/migrate/20140421152018_remove_date_from_job_title.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RemoveDateFromJobTitle < ActiveRecord::Migration
def change
remove_column :job_titles, :date
remove_column :job_titles, :job_title_id
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140421152233_add_date_to_job_title_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDateToJobTitleUsers < ActiveRecord::Migration
def change
add_column :job_title_users, :date, :date
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140421182936_change_job_title_to_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeJobTitleToName < ActiveRecord::Migration
def change
rename_column :job_titles, :job_title, :name
end
end
18 changes: 16 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140417132943) do
ActiveRecord::Schema.define(version: 20140421182936) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -23,10 +23,24 @@
t.datetime "updated_at"
end

create_table "job_title_users", force: true do |t|
t.integer "user_id"
t.integer "job_title_id"
t.datetime "created_at"
t.datetime "updated_at"
t.date "date"
end

create_table "job_titles", force: true do |t|
t.string "name"
end

create_table "office_branches", force: true do |t|
t.string "location", null: false
t.string "city", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "state"
t.string "country"
end

create_table "profiles", force: true do |t|
Expand Down
10 changes: 10 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
job_list = [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just create an array of strings, instead of an array of arrays?

job_list = [
  "Paper Sales",
  "Branch Manager",
  "Warehouse",
  "Secretary"
]

["Paper Sales"],
["Branch Manager"],
["Warehouse"],
["Secretary"]
]

job_list.each do |job|
JobTitle.create( :job_title => job[0])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change the arrays above, this can be job instead of job[0].

end