Browse Source

Add bulk upload button and add org id to upload your file

pull/2629/head
Manny Dinssa 2 years ago
parent
commit
b6c3a1be64
  1. 2
      app/controllers/bulk_upload_lettings_logs_controller.rb
  2. 2
      app/controllers/bulk_upload_sales_logs_controller.rb
  3. 10
      app/models/forms/bulk_upload_lettings/upload_your_file.rb
  4. 8
      app/models/forms/bulk_upload_sales/upload_your_file.rb
  5. 10
      app/views/logs/_create_for_org_actions.html.erb

2
app/controllers/bulk_upload_lettings_logs_controller.rb

@ -51,7 +51,7 @@ private
when "needstype"
Forms::BulkUploadLettings::Needstype.new(form_params)
when "upload-your-file"
Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:))
Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:, organisation_id: params[:org]))
when "checking-file"
Forms::BulkUploadLettings::CheckingFile.new(form_params)
else

2
app/controllers/bulk_upload_sales_logs_controller.rb

@ -49,7 +49,7 @@ private
when "guidance"
Forms::BulkUploadSales::Guidance.new(form_params.merge(referrer: params[:referrer]))
when "upload-your-file"
Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:))
Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:, organisation_id: params[:org]))
when "checking-file"
Forms::BulkUploadSales::CheckingFile.new(form_params)
else

10
app/models/forms/bulk_upload_lettings/upload_your_file.rb

@ -11,6 +11,7 @@ module Forms
attribute :needstype, :integer
attribute :file
attribute :current_user
attribute :organisation_id
validates :file, presence: true
validate :validate_file_is_csv
@ -20,8 +21,12 @@ module Forms
end
def back_path
page_id = year == 2022 ? "needstype" : "prepare-your-file"
bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: })
if organisation_id.present?
lettings_logs_organisation_path(organisation_id)
else
page_id = year == 2022 ? "needstype" : "prepare-your-file"
bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: })
end
end
def year_combo
@ -39,6 +44,7 @@ module Forms
year:,
needstype:,
filename: file.original_filename,
organisation_id: organisation_id || current_user.organisation_id,
)
storage_service.write_file(bulk_upload.identifier, File.read(file.path))

8
app/models/forms/bulk_upload_sales/upload_your_file.rb

@ -10,6 +10,7 @@ module Forms
attribute :year, :integer
attribute :file
attribute :current_user
attribute :organisation_id
validates :file, presence: true
validate :validate_file_is_csv
@ -19,7 +20,11 @@ module Forms
end
def back_path
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
if organisation_id.present?
sales_logs_organisation_path(organisation_id)
else
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
end
end
def year_combo
@ -36,6 +41,7 @@ module Forms
log_type: BulkUpload.log_types[:sales],
year:,
filename: file.original_filename,
organisation_id: organisation_id || current_user.organisation_id,
)
storage_service.write_file(bulk_upload.identifier, File.read(file.path))

10
app/views/logs/_create_for_org_actions.html.erb

@ -1,10 +1,12 @@
<div class="govuk-button-group app-filter-toggle">
<% if @organisation.data_protection_confirmed? %>
<% if current_page?(controller: 'organisations', action: 'lettings_logs') %>
<%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %>
<% end %>
<%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post), class: "govuk-!-margin-right-6" %>
<%= govuk_button_link_to "Upload lettings logs in bulk", bulk_upload_lettings_log_path(id: "upload-your-file", form: { year: FormHandler.instance.current_collection_start_year }, org: @organisation.id), secondary: true %>
<% end %>
<% if current_page?(controller: 'organisations', action: 'sales_logs') %>
<%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post) %>
<% end %>
<%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post), class: "govuk-!-margin-right-6" %>
<%= govuk_button_link_to "Upload sales logs in bulk", bulk_upload_sales_log_path(id: "upload-your-file", form: { year: FormHandler.instance.current_collection_start_year }, org: @organisation.id), secondary: true %>
<% end %>
<% end %>
</div>

Loading…
Cancel
Save