Skip to content

Commit

Permalink
updates for managers and logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
hpkent committed Jan 2, 2018
1 parent 47fd71f commit 9a06bb7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
17 changes: 17 additions & 0 deletions app/helpers/records_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
module RecordsHelper
def get_manager_id(current_user)
if current_user != nil
if current_user.email != nil
manager = Manager.where(email:current_user.email)
if manager.length == 1
manager_id = manager.first.id
elsif manager.length > 1
puts "too many managers"
manager_id == 1
elsif manager.length < 1
puts "no manager"
manager_id == 1
end
end
end
manager_id
end
end
1 change: 1 addition & 0 deletions app/models/manager.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Manager < ApplicationRecord
has_many :activities
end

4 changes: 2 additions & 2 deletions app/views/records/_activity_fields.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<%= f.input :start_date, ampm: true, as: :datetime, order: [:day, :month, :year], required: true %>
<%= f.input :activity_type_id, collection: ActivityType.all, required: true %>
<%= f.input :duration, label: 'Duration (hrs)', :class =>'form-control', :input_html => {:style=> 'width: 150px' }, required: true %>
<%= f.hidden_field :manager_id, :value => 1 %>
<%= f.hidden_field :client_id, :value => 1 %>
<%= f.hidden_field :manager%>
<%= f.hidden_field :client%>
<%= f.hidden_field :provider_id, :value => 1 %>
<p>
<%= link_to_remove_association f do %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/records/_record_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= simple_form_for(@record, html: { class: 'form-horizontal' }) do |f| %>

<p>
<%= f.association :manager, label_method: :first_name, value_method: :id, include_blank: false %>
<%= f.hidden_field :manager_id, :value => get_manager_id(current_user)%>
</p>
<p>
<%= f.association :client, label_method: :first_name, value_method: :id, required: true%>
Expand Down
6 changes: 6 additions & 0 deletions app/views/records/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<span id="name"><%=Client.find(@record.client_id).initials%></span>
<%end%>
</p>
<p>
<span id="label"> Manager: </span>
<%if @record.manager_id != nil%>
<span id="name"><%=Manager.find(@record.manager_id).first_name%></span>
<%end%>
</p>
<p>
<span id="label"> Start Date: </span>
<span id="name"><%=@record.start_date.strftime("%b %d, %y")%></span>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180101175308_add_emailto_managers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEmailtoManagers < ActiveRecord::Migration[5.1]
def change
add_column :managers, :email, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171205225036) do
ActiveRecord::Schema.define(version: 20180101175308) do

create_table "activities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.datetime "start_date"
Expand Down Expand Up @@ -123,6 +123,7 @@
t.string "last_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "email"
end

create_table "outcomes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
Expand Down

0 comments on commit 9a06bb7

Please sign in to comment.