diff --git a/app/helpers/records_helper.rb b/app/helpers/records_helper.rb index e63c599..02734b3 100644 --- a/app/helpers/records_helper.rb +++ b/app/helpers/records_helper.rb @@ -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 diff --git a/app/models/manager.rb b/app/models/manager.rb index 1518051..6c0f4f0 100644 --- a/app/models/manager.rb +++ b/app/models/manager.rb @@ -1,3 +1,4 @@ class Manager < ApplicationRecord has_many :activities end + diff --git a/app/views/records/_activity_fields.erb b/app/views/records/_activity_fields.erb index fdc9d17..e3123ad 100644 --- a/app/views/records/_activity_fields.erb +++ b/app/views/records/_activity_fields.erb @@ -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 %>

<%= link_to_remove_association f do %> diff --git a/app/views/records/_record_form.html.erb b/app/views/records/_record_form.html.erb index 4519811..d2c5aae 100644 --- a/app/views/records/_record_form.html.erb +++ b/app/views/records/_record_form.html.erb @@ -3,7 +3,7 @@ <%= simple_form_for(@record, html: { class: 'form-horizontal' }) do |f| %>

- <%= f.association :manager, label_method: :first_name, value_method: :id, include_blank: false %> + <%= f.hidden_field :manager_id, :value => get_manager_id(current_user)%>

<%= f.association :client, label_method: :first_name, value_method: :id, required: true%> diff --git a/app/views/records/show.html.erb b/app/views/records/show.html.erb index fdc4c3a..135d81f 100644 --- a/app/views/records/show.html.erb +++ b/app/views/records/show.html.erb @@ -14,6 +14,12 @@ <%=Client.find(@record.client_id).initials%> <%end%>

+

+ Manager: + <%if @record.manager_id != nil%> + <%=Manager.find(@record.manager_id).first_name%> + <%end%> +

Start Date: <%=@record.start_date.strftime("%b %d, %y")%> diff --git a/db/migrate/20180101175308_add_emailto_managers.rb b/db/migrate/20180101175308_add_emailto_managers.rb new file mode 100644 index 0000000..e7969b8 --- /dev/null +++ b/db/migrate/20180101175308_add_emailto_managers.rb @@ -0,0 +1,5 @@ +class AddEmailtoManagers < ActiveRecord::Migration[5.1] + def change + add_column :managers, :email, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index ec9dbc9..631c19a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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|