Skip to content

Commit

Permalink
Merge pull request #436 from uclibs/420/preserve-scroll-position
Browse files Browse the repository at this point in the history
Add anchors and redirect embeds to help preserve scroll position
  • Loading branch information
Janell-Huyck authored Mar 11, 2024
2 parents 668b568 + a01d131 commit d1b28f0
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 30 deletions.
6 changes: 3 additions & 3 deletions app/controllers/con_tech_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def create
@conservation_record = ConservationRecord.find(params[:conservation_record_id])
@con_tech_record = @conservation_record.con_tech_records.create(create_params)
if @con_tech_record.valid?
redirect_to conservation_record_path(@conservation_record)
redirect_to "#{conservation_record_path(@conservation_record)}#conservators-and-technicians"
else
redirect_to conservation_record_path(@conservation_record),
redirect_to "#{conservation_record_path(@conservation_record)}#conservators-and-technicians",
notice: "Conservator/Technician record not saved: #{@con_tech_record.errors.full_messages[0]}"
end
end
Expand All @@ -20,7 +20,7 @@ def destroy
@conservation_record = ConservationRecord.find(params[:conservation_record_id])
@con_tech_record = @conservation_record.con_tech_records.find(params[:id])
@con_tech_record.destroy
redirect_to conservation_record_path(@conservation_record)
redirect_to "#{conservation_record_path(@conservation_record)}#conservators-and-technicians"
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/cost_return_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ class CostReturnReportsController < ApplicationController
def create
@conservation_record = ConservationRecord.find(params[:conservation_record_id])
CostReturnReport.create(cost_return_report_params)
redirect_to conservation_record_path(@conservation_record), notice: 'Treatment record saved successfully'
redirect_to "#{conservation_record_path(@conservation_record)}#cost-and-return-information", notice: 'Treatment record saved successfully'
end

def update
@conservation_record = ConservationRecord.find(params[:conservation_record_id])
@cost_return_report = @conservation_record.cost_return_report.update(cost_return_report_params)
redirect_to conservation_record_path(@conservation_record), notice: 'Treatment record updated'
redirect_to "#{conservation_record_path(@conservation_record)}#cost-and-return-information", notice: 'Treatment record updated'
end

def destroy
@conservation_record = ConservationRecord.find(params[:conservation_record_id])
@cost_return_report = @conservation_record.cost_return_report
@cost_return_report.destroy
redirect_to conservation_record_path(@conservation_record)
redirect_to "#{conservation_record_path(@conservation_record)}#cost-and-return-information"
end

private
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/external_repair_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ def create
@repair_record = @conservation_record.external_repair_records.create(create_params)

if @repair_record.valid?
redirect_to conservation_record_path(@conservation_record)
redirect_to "#{conservation_record_path(@conservation_record)}#external-repairs"
else
redirect_to conservation_record_path(@conservation_record), notice: "External repair not saved: #{@repair_record.errors.full_messages[0]}"
redirect_to "#{conservation_record_path(@conservation_record)}#external-repairs",
notice: "External repair not saved: #{@repair_record.errors.full_messages[0]}"
end
end

def destroy
@conservation_record = ConservationRecord.find(params[:conservation_record_id])
@repair_record = @conservation_record.external_repair_records.find(params[:id])
@repair_record.destroy
redirect_to conservation_record_path(@conservation_record)
redirect_to "#{conservation_record_path(@conservation_record)}#external-repairs"
end

private
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/in_house_repair_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ def create
@conservation_record = ConservationRecord.find(params[:conservation_record_id])
@repair_record = @conservation_record.in_house_repair_records.create(create_params)
if @repair_record.valid?
redirect_to conservation_record_path(@conservation_record)
redirect_to "#{conservation_record_path(@conservation_record)}#in-house-repairs"
else
redirect_to conservation_record_path(@conservation_record), notice: "In house repair not saved: #{@repair_record.errors.full_messages[0]}"
redirect_to "#{conservation_record_path(@conservation_record)}#in-house-repairs",
notice: "In house repair not saved: #{@repair_record.errors.full_messages[0]}"
end
end

def destroy
@conservation_record = ConservationRecord.find(params[:conservation_record_id])
@repair_record = @conservation_record.in_house_repair_records.find(params[:id])
@repair_record.destroy
redirect_to conservation_record_path(@conservation_record)
redirect_to "#{conservation_record_path(@conservation_record)}#in-house-repairs"
end

private
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/treatment_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ def create
@treatment_report.save

flash
redirect_to conservation_record_path(@treatment_report.conservation_record), notice: 'Treatment record saved successfully!'
redirect_to "#{conservation_record_path(@treatment_report.conservation_record)}#treatment-report-tab", notice: 'Treatment record saved successfully!'
end

def update
@treatment_report = TreatmentReport.find(params[:id])

@treatment_report.update(treatment_report_params)
redirect_to conservation_record_path(@treatment_report.conservation_record), notice: 'Treatment Record updated successfully!'
redirect_to "#{conservation_record_path(@treatment_report.conservation_record)}#treatment-report-tab",
notice: 'Treatment Record updated successfully!'
end

private
Expand Down
22 changes: 11 additions & 11 deletions app/views/conservation_records/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<p></p>

<div class="header">
<h3>In-House Repairs</h3>
<h3 id="in-house-repairs">In-House Repairs</h3>
<% if can? :crud, InHouseRepairRecord %>
<button type="button" class="btn btn-primary cta-btn" data-toggle="modal" data-target="#inHouseRepairModal">
Add In-House Repairs
Expand Down Expand Up @@ -96,7 +96,7 @@

<br />
<div class="header">
<h3>External Repairs</h3>
<h3 id="external-repairs">External Repairs</h3>
<% if can? :crud, ExternalRepairRecord %>
<button type="button" class="btn btn-primary cta-btn" data-toggle="modal" data-target="#externalRepairModal">
Add External Repair
Expand Down Expand Up @@ -128,7 +128,7 @@
<% end %>
<br />
<div class="header">
<h3>Conservators and Technicians</h3>
<h3 id="conservators-and-technicians">Conservators and Technicians</h3>
<% if can? :crud, ConTechRecord %>
<button type="button" class="btn btn-primary cta-btn" data-toggle="modal" data-target="#ConservatorsTechniciansModal">
Add Conservators and Technicians
Expand Down Expand Up @@ -183,7 +183,7 @@

<br>
<div class="header">
<h3>Cost and Return Information</h3>
<h3 id="cost-and-return-information">Cost and Return Information</h3>
</div>
<%= form_with(model: [@conservation_record, @conservation_record.cost_return_report], class: 'disable_input') do |f| %>

Expand Down Expand Up @@ -243,23 +243,23 @@
<div class="modal-body">
<div class="form-group">
<label for="RepairedBy">Repaired By</label>
<%= form.select(:performed_by_user_id, options_from_collection_for_select(@users, "id", "display_name"), { prompt: 'Select User' }, { :class => 'form-control' }) %>
<%= form.select(:performed_by_user_id, options_from_collection_for_select(@users, "id", "display_name"), { prompt: 'Select User' }, { :class => 'form-control', :required=> true }) %>
</div>
<div class="form-group">
<label>Repair Type</label>
<%= form.select :repair_type, options_from_collection_for_select(@repair_types, "id", "key"), { prompt: 'Select Repair Type' }, { :class => 'form-control' } %>
<%= form.select :repair_type, options_from_collection_for_select(@repair_types, "id", "key"), { prompt: 'Select Repair Type' }, { :class => 'form-control', :required=> true } %>
</div>
<div class="form-group">
<label>Minutes Spent</label>
<%= form.number_field :minutes_spent, class: "form-control", placeholder: "Minutes" %>
<%= form.number_field :minutes_spent, class: "form-control", placeholder: "Minutes", required: true %>
</div>
<div class="form-group">
<label>Other Note</label>
<%= form.text_field :other_note, class: "form-control", placeholder: "Other Notes" %>
</div>
<div class="form-group">
<label>Staff Code</label>
<%= form.select :staff_code_id, options_from_collection_for_select(@staff_codes, "id", "code"), { prompt: 'Select Staff Code' }, { :class => 'form-control' } %>
<%= form.select :staff_code_id, options_from_collection_for_select(@staff_codes, "id", "code"), { prompt: 'Select Staff Code' }, { :class => 'form-control', required: true } %>
</div>
</div>
<div class="modal-footer">
Expand All @@ -285,12 +285,12 @@
<div class="modal-body">
<div class="form-group">
<label for="RepairedBy">Repaired By</label>
<%= form.select(:performed_by_vendor_id, options_from_collection_for_select(@contract_conservators, "id", "key"), { prompt: 'Select Vendor' }, { :class => 'form-control' }) %>
<%= form.select(:performed_by_vendor_id, options_from_collection_for_select(@contract_conservators, "id", "key"), { prompt: 'Select Vendor' }, { :class => 'form-control', :required => true }) %>
</div>

<div class="form-group">
<label>Repair Type</label>
<%= form.select :repair_type, options_from_collection_for_select(@repair_types, "id", "key"), { prompt: 'Select Repair Type' }, { :class => 'form-control' } %>
<%= form.select :repair_type, options_from_collection_for_select(@repair_types, "id", "key"), { prompt: 'Select Repair Type' }, { :class => 'form-control', :required => true } %>
</div>
<div class="form-group">
<label>Other Note</label>
Expand Down Expand Up @@ -320,7 +320,7 @@
<div class="modal-body">
<div class="form-group">
<label for="ConservationandTechnicians">Conservators and Technicians</label>
<%= form.select(:performed_by_user_id, options_from_collection_for_select(@users, "id", "display_name"), { prompt: 'Select User' }, { :class => 'form-control' }) %>
<%= form.select(:performed_by_user_id, options_from_collection_for_select(@users, "id", "display_name"), { prompt: 'Select User' }, { :class => 'form-control', :required => true }) %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/con_tech_records_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
describe 'POST #create' do
it 'creates a new conservators and technicians record' do
post :create, params: { con_tech_record: valid_attributes, conservation_record_id: conservation_record.id }
expect(response).to redirect_to(conservation_record)
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#conservators-and-technicians")
end
end

Expand All @@ -33,6 +33,7 @@
expect do
delete :destroy, params: { id: con_tech_record.to_param, conservation_record_id: conservation_record.id }
end.to change(ConTechRecord, :count).by(-1)
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#conservators-and-technicians")
end
end
end
4 changes: 3 additions & 1 deletion spec/controllers/cost_return_reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
it 'creates a new cost return report record' do
conservation_record = create(:conservation_record)
post :create, params: { conservation_record_id: conservation_record.id, cost_return_report: valid_attributes }
expect(response).to redirect_to(conservation_record_path(conservation_record))
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#cost-and-return-information")
end
end
end
Expand All @@ -41,6 +41,7 @@
expect do
delete :destroy, params: { conservation_record_id: conservation_record.id, id: cost_return_report.to_param }
end.to change(CostReturnReport, :count).by(-1)
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#cost-and-return-information")
end
end

Expand All @@ -60,6 +61,7 @@
it 'updates Cost Return Report' do
cost_return_report = CostReturnReport.create! valid_attributes
put :update, params: { conservation_record_id: conservation_record.id, id: cost_return_report.to_param, cost_return_report: new_attributes }
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#cost-and-return-information")
cost_return_report.reload
expect(cost_return_report.repair_estimate).to eq(110.10)
expect(cost_return_report.repair_cost).to eq(130.10)
Expand Down
10 changes: 9 additions & 1 deletion spec/controllers/external_repair_records_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
describe 'POST #create' do
it 'creates a new in house repair record' do
post :create, params: { external_repair_record: valid_attributes, conservation_record_id: conservation_record.id }
expect(response).to redirect_to(conservation_record)
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#external-repairs")
end

it 'validates for required params' do
valid_attributes.delete(:repair_type)
post :create, params: { external_repair_record: valid_attributes, conservation_record_id: conservation_record.id }
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#external-repairs")
expect(subject.request.flash[:notice]).to have_content('External repair not save')
end
end

Expand All @@ -36,6 +43,7 @@
expect do
delete :destroy, params: { id: external_repair_record.to_param, conservation_record_id: conservation_record.id }
end.to change(ExternalRepairRecord, :count).by(-1)
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#external-repairs")
end
end
end
3 changes: 2 additions & 1 deletion spec/controllers/in_house_repair_records_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
describe 'POST #create' do
it 'creates a new in house repair record' do
post :create, params: { in_house_repair_record: valid_attributes, conservation_record_id: conservation_record.id }
expect(response).to redirect_to(conservation_record)
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#in-house-repairs")
end

it 'does not have valid staff code to create in house repair record' do
Expand All @@ -55,6 +55,7 @@
expect do
delete :destroy, params: { id: in_house_repair_record.to_param, conservation_record_id: conservation_record.id }
end.to change(InHouseRepairRecord, :count).by(-1)
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#in-house-repairs")
end
end
end
3 changes: 2 additions & 1 deletion spec/controllers/treatment_reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
it 'creates a new conservation record' do
conservation_record = create(:conservation_record)
post :create, params: { conservation_record_id: conservation_record.id, treatment_report: valid_attributes }
expect(response).to redirect_to(conservation_record_path(conservation_record))
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#treatment-report-tab")
end
end
end
Expand Down Expand Up @@ -90,6 +90,7 @@
it 'updates the Treatment Report' do
treatment_report = TreatmentReport.create! valid_attributes
put :update, params: { conservation_record_id: conservation_record.id, id: treatment_report.to_param, treatment_report: new_attributes }
expect(response).to redirect_to("#{conservation_record_path(conservation_record)}#treatment-report-tab")
treatment_report.reload
expect(treatment_report.description_primary_support).to eq('Description Support')
end
Expand Down

0 comments on commit d1b28f0

Please sign in to comment.