diff --git a/Gemfile b/Gemfile
index 6d9f6a4..576ae5f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -43,8 +43,6 @@ gem 'rails_admin'
gem 'jquery-ui-rails'
gem 'american_date'
-
-
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
diff --git a/app/assets/stylesheets/_badges.css.scss b/app/assets/stylesheets/_badges.css.scss
new file mode 100644
index 0000000..07c0047
--- /dev/null
+++ b/app/assets/stylesheets/_badges.css.scss
@@ -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);
+ }
+ }
+}
diff --git a/app/assets/stylesheets/vacation_time.css.scss b/app/assets/stylesheets/vacation_time.css.scss
new file mode 100644
index 0000000..e87f3a7
--- /dev/null
+++ b/app/assets/stylesheets/vacation_time.css.scss
@@ -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/
diff --git a/app/controllers/homes_controller.rb b/app/controllers/homes_controller.rb
index 12a92f3..8d605a6 100644
--- a/app/controllers/homes_controller.rb
+++ b/app/controllers/homes_controller.rb
@@ -1,5 +1,6 @@
class HomesController < ApplicationController
def show
@profiles = Profile.all
+ @office_branches = OfficeBranch.all
end
end
diff --git a/app/controllers/job_title_users_controller.rb b/app/controllers/job_title_users_controller.rb
new file mode 100644
index 0000000..a2e7b44
--- /dev/null
+++ b/app/controllers/job_title_users_controller.rb
@@ -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
diff --git a/app/controllers/office_branches_controller.rb b/app/controllers/office_branches_controller.rb
index c9ba017..4ca0106 100644
--- a/app/controllers/office_branches_controller.rb
+++ b/app/controllers/office_branches_controller.rb
@@ -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
diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
index fed7808..10f88d8 100644
--- a/app/controllers/profiles_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -8,6 +8,7 @@ def show
def new
@profile = Profile.new
+ @user = @profile.user
end
def create
@@ -18,6 +19,7 @@ def create
def edit
@profile = find_profile
@user = @profile.user
+ @job_title_user = JobTitleUser.new
end
def update
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index c17228a..bfe441f 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -31,7 +31,9 @@ def user_params
:email,
:password,
:department_id,
- :office_branch_id
+ :office_branch_id,
+ :job_title_users,
+ :job_titles
)
end
diff --git a/app/helpers/vacation_time_helper.rb b/app/helpers/vacation_time_helper.rb
new file mode 100644
index 0000000..53a3331
--- /dev/null
+++ b/app/helpers/vacation_time_helper.rb
@@ -0,0 +1,2 @@
+module VacationTimeHelper
+end
diff --git a/app/models/job_title.rb b/app/models/job_title.rb
new file mode 100644
index 0000000..17d9163
--- /dev/null
+++ b/app/models/job_title.rb
@@ -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
diff --git a/app/models/job_title_user.rb b/app/models/job_title_user.rb
new file mode 100644
index 0000000..a5ffaa4
--- /dev/null
+++ b/app/models/job_title_user.rb
@@ -0,0 +1,4 @@
+class JobTitleUser < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :job_title
+end
diff --git a/app/models/null_job_title.rb b/app/models/null_job_title.rb
new file mode 100644
index 0000000..f7a7ee0
--- /dev/null
+++ b/app/models/null_job_title.rb
@@ -0,0 +1,5 @@
+class NullJobTitle
+ def name
+ "No Current Job"
+ end
+end
diff --git a/app/models/null_profile.rb b/app/models/null_profile.rb
index c32d895..a254788 100644
--- a/app/models/null_profile.rb
+++ b/app/models/null_profile.rb
@@ -7,4 +7,5 @@ def to_partial_path
def present?
false
end
+
end
diff --git a/app/models/office_branch.rb b/app/models/office_branch.rb
index 1d71630..8a28337 100644
--- a/app/models/office_branch.rb
+++ b/app/models/office_branch.rb
@@ -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
diff --git a/app/models/user.rb b/app/models/user.rb
index b7032da..7678e06 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
+
+ def current_job
+ job_titles.last || NullJobTitle.new
+ end
def has_any_contact_information?
address ||
diff --git a/app/views/homes/show.html.erb b/app/views/homes/show.html.erb
index a8d2a37..3ca5727 100644
--- a/app/views/homes/show.html.erb
+++ b/app/views/homes/show.html.erb
@@ -32,9 +32,9 @@
- Departments
+ Office Branches
- 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.
+ <%= geo_chart @office_branches.group(:country).count %>
diff --git a/app/views/office_branches/_office_branch.html.erb b/app/views/office_branches/_office_branch.html.erb
index 50f730f..506c94b 100644
--- a/app/views/office_branches/_office_branch.html.erb
+++ b/app/views/office_branches/_office_branch.html.erb
@@ -1,5 +1,5 @@
- <%= link_to office_branch.location, office_branch %>
+ <%= link_to office_branch.city %>
diff --git a/app/views/office_branches/new.html.erb b/app/views/office_branches/new.html.erb
index 16fe178..932c212 100644
--- a/app/views/office_branches/new.html.erb
+++ b/app/views/office_branches/new.html.erb
@@ -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 %>
diff --git a/app/views/office_branches/show.html.erb b/app/views/office_branches/show.html.erb
index 509d260..7cedfb9 100644
--- a/app/views/office_branches/show.html.erb
+++ b/app/views/office_branches/show.html.erb
@@ -1,4 +1,4 @@
-<%= @office_branch.location %>
+<%= @office_branch.city %>, <%= @office_branch.state %>
<%= link_to "Office Branches Index", office_branches_path %>
diff --git a/app/views/profiles/edit.html.erb b/app/views/profiles/edit.html.erb
index 234c47c..6e88636 100644
--- a/app/views/profiles/edit.html.erb
+++ b/app/views/profiles/edit.html.erb
@@ -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 %>
-
\ No newline at end of file
+
+
+ <%= 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 %>
+
diff --git a/app/views/profiles/show.html.erb b/app/views/profiles/show.html.erb
index 502b4ad..e19257d 100644
--- a/app/views/profiles/show.html.erb
+++ b/app/views/profiles/show.html.erb
@@ -27,6 +27,10 @@
Department: <%= @department.name %>
+
+ Job Title: <%= @user.current_job.name %>
+
+
<%= link_to "Delete Profile", @profile, method: :delete %>
diff --git a/config/routes.rb b/config/routes.rb
index 7e892cd..8befd22 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -17,4 +17,6 @@
resources :salaries, only: [:show, :new, :create, :index]
end
+ resource :job_title_users, only: ['create']
+
end
diff --git a/db/migrate/20140417015751_create_salaries.rb b/db/migrate/20140417015751_create_salaries.rb
index a9962cf..3fff597 100644
--- a/db/migrate/20140417015751_create_salaries.rb
+++ b/db/migrate/20140417015751_create_salaries.rb
@@ -1,4 +1,4 @@
-class CreateSalaries < ActiveRecord::Migration
+rails class CreateSalaries < ActiveRecord::Migration
def change
create_table :salaries do |t|
t.decimal :salary
diff --git a/db/migrate/20140417185226_add_state_to_office_branch.rb b/db/migrate/20140417185226_add_state_to_office_branch.rb
new file mode 100644
index 0000000..add15a8
--- /dev/null
+++ b/db/migrate/20140417185226_add_state_to_office_branch.rb
@@ -0,0 +1,6 @@
+class AddStateToOfficeBranch < ActiveRecord::Migration
+ def change
+ rename_column :office_branches, :location, :city
+ add_column :office_branches, :state, :string
+ end
+end
diff --git a/db/migrate/20140417195701_add_country_to_office_branches.rb b/db/migrate/20140417195701_add_country_to_office_branches.rb
new file mode 100644
index 0000000..48b19ef
--- /dev/null
+++ b/db/migrate/20140417195701_add_country_to_office_branches.rb
@@ -0,0 +1,5 @@
+class AddCountryToOfficeBranches < ActiveRecord::Migration
+ def change
+ add_column :office_branches, :country, :string
+ end
+end
diff --git a/db/migrate/20140421134024_create_job_titles.rb b/db/migrate/20140421134024_create_job_titles.rb
new file mode 100644
index 0000000..6f74ec5
--- /dev/null
+++ b/db/migrate/20140421134024_create_job_titles.rb
@@ -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
diff --git a/db/migrate/20140421140719_remove_user_id_from_job_titles.rb b/db/migrate/20140421140719_remove_user_id_from_job_titles.rb
new file mode 100644
index 0000000..f1dff61
--- /dev/null
+++ b/db/migrate/20140421140719_remove_user_id_from_job_titles.rb
@@ -0,0 +1,5 @@
+class RemoveUserIdFromJobTitles < ActiveRecord::Migration
+ def change
+ remove_column :job_titles, :user_id
+ end
+end
diff --git a/db/migrate/20140421142854_add_job_title_id_to_job_titles.rb b/db/migrate/20140421142854_add_job_title_id_to_job_titles.rb
new file mode 100644
index 0000000..d314dce
--- /dev/null
+++ b/db/migrate/20140421142854_add_job_title_id_to_job_titles.rb
@@ -0,0 +1,5 @@
+class AddJobTitleIdToJobTitles < ActiveRecord::Migration
+ def change
+ add_column :job_titles, :job_title_id, :integer
+ end
+end
diff --git a/db/migrate/20140421143134_create_job_title_users.rb b/db/migrate/20140421143134_create_job_title_users.rb
new file mode 100644
index 0000000..69b8ba2
--- /dev/null
+++ b/db/migrate/20140421143134_create_job_title_users.rb
@@ -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
diff --git a/db/migrate/20140421152018_remove_date_from_job_title.rb b/db/migrate/20140421152018_remove_date_from_job_title.rb
new file mode 100644
index 0000000..26d0dbc
--- /dev/null
+++ b/db/migrate/20140421152018_remove_date_from_job_title.rb
@@ -0,0 +1,6 @@
+class RemoveDateFromJobTitle < ActiveRecord::Migration
+ def change
+ remove_column :job_titles, :date
+ remove_column :job_titles, :job_title_id
+ end
+end
diff --git a/db/migrate/20140421152233_add_date_to_job_title_users.rb b/db/migrate/20140421152233_add_date_to_job_title_users.rb
new file mode 100644
index 0000000..aa06ac2
--- /dev/null
+++ b/db/migrate/20140421152233_add_date_to_job_title_users.rb
@@ -0,0 +1,5 @@
+class AddDateToJobTitleUsers < ActiveRecord::Migration
+ def change
+ add_column :job_title_users, :date, :date
+ end
+end
diff --git a/db/migrate/20140421182936_change_job_title_to_name.rb b/db/migrate/20140421182936_change_job_title_to_name.rb
new file mode 100644
index 0000000..f6545b6
--- /dev/null
+++ b/db/migrate/20140421182936_change_job_title_to_name.rb
@@ -0,0 +1,5 @@
+class ChangeJobTitleToName < ActiveRecord::Migration
+ def change
+ rename_column :job_titles, :job_title, :name
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 796c0f5..5ffb784 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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"
@@ -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|
diff --git a/db/seeds.rb b/db/seeds.rb
index 4edb1e8..a65ba91 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -5,3 +5,13 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
+job_list = [
+ ["Paper Sales"],
+ ["Branch Manager"],
+ ["Warehouse"],
+ ["Secretary"]
+]
+
+job_list.each do |job|
+ JobTitle.create( :job_title => job[0])
+end