From 44e9bacde5d420b45b2d15d779d25f7e13c3d093 Mon Sep 17 00:00:00 2001 From: Rob Sterner Date: Tue, 19 Dec 2023 14:51:57 -0500 Subject: [PATCH] properly set the beginning of the week we're looking at --- app/components/work_week_component.html.erb | 1 + app/controllers/staff_plans/work_weeks_controller.rb | 6 ++++++ app/views/staff_plans/work_weeks/create.turbo_stream.erb | 2 +- app/views/staff_plans/work_weeks/update.turbo_stream.erb | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/components/work_week_component.html.erb b/app/components/work_week_component.html.erb index 73ba0700..cf3599a8 100644 --- a/app/components/work_week_component.html.erb +++ b/app/components/work_week_component.html.erb @@ -4,6 +4,7 @@ <%= tag.turbo_frame id: turbo_frame_id do %> <%= form_for @work_week, url: form_path, data: { work_week_target: "form" } do |form| %> <%= hidden_field_tag :assignment_id, @assignment.id %> + <%= hidden_field_tag :beginning_of_week, @beginning_of_week %> <%= form.hidden_field :cweek %> <%= form.hidden_field :year %> <%= form.hidden_field :beginning_of_week %> diff --git a/app/controllers/staff_plans/work_weeks_controller.rb b/app/controllers/staff_plans/work_weeks_controller.rb index 20918049..a91c321c 100644 --- a/app/controllers/staff_plans/work_weeks_controller.rb +++ b/app/controllers/staff_plans/work_weeks_controller.rb @@ -1,4 +1,6 @@ class StaffPlans::WorkWeeksController < ApplicationController + + before_action :set_beginning_of_week def create @work_week = assignment.work_weeks.create(create_work_week_params) end @@ -10,6 +12,10 @@ def update private + def set_beginning_of_week + @beginning_of_week = params[:beginning_of_week].to_i + end + def create_work_week_params params.require(:work_week).permit(:estimated_hours, :actual_hours, :cweek, :year, :beginning_of_week) end diff --git a/app/views/staff_plans/work_weeks/create.turbo_stream.erb b/app/views/staff_plans/work_weeks/create.turbo_stream.erb index 8fe6dd3b..e65a57b0 100644 --- a/app/views/staff_plans/work_weeks/create.turbo_stream.erb +++ b/app/views/staff_plans/work_weeks/create.turbo_stream.erb @@ -5,7 +5,7 @@ work_week: @work_week, assignment: @work_week.assignment, work_week_beginning_of_week: @work_week.beginning_of_week, - beginning_of_week: @work_week.beginning_of_week, + beginning_of_week: @beginning_of_week, render_td: false )) ) %> \ No newline at end of file diff --git a/app/views/staff_plans/work_weeks/update.turbo_stream.erb b/app/views/staff_plans/work_weeks/update.turbo_stream.erb index 946df2e0..9bcc329a 100644 --- a/app/views/staff_plans/work_weeks/update.turbo_stream.erb +++ b/app/views/staff_plans/work_weeks/update.turbo_stream.erb @@ -5,7 +5,7 @@ work_week: @work_week, assignment: @work_week.assignment, work_week_beginning_of_week: @work_week.beginning_of_week, - beginning_of_week: @work_week.beginning_of_week, + beginning_of_week: @beginning_of_week, render_td: false )) ) %> \ No newline at end of file