Browse Source
* add start of bulk upload logs journey * split upload controller into 2 * add year page to bulk upload journey * bulk upload years now dynamic * bulk upload journey: add copy for prepare file * add link to bulk upload template * add placeholder for upload your file page * handle bulk upload when not in crossover * fix tests around bulk upload redirect * fix typos in bulk upload jouneyCLDC-20-more-ac-fixes2^2 v0.2.22
Phil Lee
2 years ago
committed by
GitHub
31 changed files with 720 additions and 6 deletions
@ -0,0 +1,50 @@
|
||||
class BulkUploadLettingsLogsController < ApplicationController |
||||
before_action :authenticate_user! |
||||
|
||||
def start |
||||
if in_crossover_period? |
||||
redirect_to bulk_upload_lettings_log_path(id: "year") |
||||
else |
||||
redirect_to bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: current_year }) |
||||
end |
||||
end |
||||
|
||||
def show |
||||
render form.view_path |
||||
end |
||||
|
||||
def update |
||||
if form.valid? |
||||
redirect_to form.next_path |
||||
else |
||||
render form.view_path |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def current_year |
||||
FormHandler.instance.forms["current_lettings"].start_date.year |
||||
end |
||||
|
||||
def in_crossover_period? |
||||
FormHandler.instance.forms.values.any?(&:in_crossover_period?) |
||||
end |
||||
|
||||
def form |
||||
@form ||= case params[:id] |
||||
when "year" |
||||
Forms::BulkUploadLettings::Year.new(form_params) |
||||
when "prepare-your-file" |
||||
Forms::BulkUploadLettings::PrepareYourFile.new(form_params) |
||||
when "upload-your-file" |
||||
Forms::BulkUploadLettings::UploadYourFile.new(form_params) |
||||
else |
||||
raise "Page not found for path #{params[:id]}" |
||||
end |
||||
end |
||||
|
||||
def form_params |
||||
params.fetch(:form, {}).permit(:year) |
||||
end |
||||
end |
@ -0,0 +1,50 @@
|
||||
class BulkUploadSalesLogsController < ApplicationController |
||||
before_action :authenticate_user! |
||||
|
||||
def start |
||||
if in_crossover_period? |
||||
redirect_to bulk_upload_sales_log_path(id: "year") |
||||
else |
||||
redirect_to bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: current_year }) |
||||
end |
||||
end |
||||
|
||||
def show |
||||
render form.view_path |
||||
end |
||||
|
||||
def update |
||||
if form.valid? |
||||
redirect_to form.next_path |
||||
else |
||||
render form.view_path |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def current_year |
||||
FormHandler.instance.forms["current_sales"].start_date.year |
||||
end |
||||
|
||||
def in_crossover_period? |
||||
FormHandler.instance.forms.values.any?(&:in_crossover_period?) |
||||
end |
||||
|
||||
def form |
||||
@form ||= case params[:id] |
||||
when "year" |
||||
Forms::BulkUploadSales::Year.new(form_params) |
||||
when "prepare-your-file" |
||||
Forms::BulkUploadSales::PrepareYourFile.new(form_params) |
||||
when "upload-your-file" |
||||
Forms::BulkUploadSales::UploadYourFile.new(form_params) |
||||
else |
||||
raise "Page not found for path #{params[:id]}" |
||||
end |
||||
end |
||||
|
||||
def form_params |
||||
params.fetch(:form, {}).permit(:year) |
||||
end |
||||
end |
@ -0,0 +1,21 @@
|
||||
module LogsHelper |
||||
def log_type_for_controller(controller) |
||||
case controller.class.to_s |
||||
when "LettingsLogsController" |
||||
"lettings" |
||||
when "SalesLogsController" |
||||
"sales" |
||||
else |
||||
raise "Log type not found for #{controller.class}" |
||||
end |
||||
end |
||||
|
||||
def bulk_upload_path_for_controller(controller, id:) |
||||
case log_type_for_controller(controller) |
||||
when "lettings" |
||||
bulk_upload_lettings_log_path(id:) |
||||
when "sales" |
||||
bulk_upload_sales_log_path(id:) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,41 @@
|
||||
module Forms |
||||
module BulkUploadLettings |
||||
class PrepareYourFile |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
|
||||
def view_path |
||||
"bulk_upload_lettings_logs/forms/prepare_your_file" |
||||
end |
||||
|
||||
def back_path |
||||
if in_crossover_period? |
||||
Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year: }) |
||||
else |
||||
Rails.application.routes.url_helpers.lettings_logs_path |
||||
end |
||||
end |
||||
|
||||
def next_path |
||||
bulk_upload_lettings_log_path(id: "upload-your-file", form: { year: }) |
||||
end |
||||
|
||||
def template_path |
||||
"/files/bulk-upload-lettings-template-v1.xlsx" |
||||
end |
||||
|
||||
def year_combo |
||||
"#{year}/#{year + 1 - 2000}" |
||||
end |
||||
|
||||
private |
||||
|
||||
def in_crossover_period? |
||||
FormHandler.instance.forms.values.any?(&:in_crossover_period?) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,19 @@
|
||||
module Forms |
||||
module BulkUploadLettings |
||||
class UploadYourFile |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
|
||||
def view_path |
||||
"bulk_upload_lettings_logs/forms/upload_your_file" |
||||
end |
||||
|
||||
def back_path |
||||
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: }) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,37 @@
|
||||
module Forms |
||||
module BulkUploadLettings |
||||
class Year |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
|
||||
validates :year, presence: true |
||||
|
||||
def view_path |
||||
"bulk_upload_lettings_logs/forms/year" |
||||
end |
||||
|
||||
def options |
||||
possible_years.map do |year| |
||||
OpenStruct.new(id: year, name: "#{year}/#{year + 1}") |
||||
end |
||||
end |
||||
|
||||
def back_path |
||||
lettings_logs_path |
||||
end |
||||
|
||||
def next_path |
||||
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: }) |
||||
end |
||||
|
||||
private |
||||
|
||||
def possible_years |
||||
FormHandler.instance.lettings_forms.values.map { |form| form.start_date.year }.sort.reverse |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,41 @@
|
||||
module Forms |
||||
module BulkUploadSales |
||||
class PrepareYourFile |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
|
||||
def view_path |
||||
"bulk_upload_sales_logs/forms/prepare_your_file" |
||||
end |
||||
|
||||
def back_path |
||||
if in_crossover_period? |
||||
Rails.application.routes.url_helpers.bulk_upload_sales_log_path(id: "year", form: { year: }) |
||||
else |
||||
Rails.application.routes.url_helpers.sales_logs_path |
||||
end |
||||
end |
||||
|
||||
def next_path |
||||
bulk_upload_sales_log_path(id: "upload-your-file", form: { year: }) |
||||
end |
||||
|
||||
def template_path |
||||
"/files/bulk-upload-sales-template-v1.xlsx" |
||||
end |
||||
|
||||
def year_combo |
||||
"#{year}/#{year + 1 - 2000}" |
||||
end |
||||
|
||||
private |
||||
|
||||
def in_crossover_period? |
||||
FormHandler.instance.forms.values.any?(&:in_crossover_period?) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,19 @@
|
||||
module Forms |
||||
module BulkUploadSales |
||||
class UploadYourFile |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
|
||||
def view_path |
||||
"bulk_upload_sales_logs/forms/upload_your_file" |
||||
end |
||||
|
||||
def back_path |
||||
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: }) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,37 @@
|
||||
module Forms |
||||
module BulkUploadSales |
||||
class Year |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :year, :integer |
||||
|
||||
validates :year, presence: true |
||||
|
||||
def view_path |
||||
"bulk_upload_sales_logs/forms/year" |
||||
end |
||||
|
||||
def options |
||||
possible_years.map do |year| |
||||
OpenStruct.new(id: year, name: "#{year}/#{year + 1}") |
||||
end |
||||
end |
||||
|
||||
def back_path |
||||
sales_logs_path |
||||
end |
||||
|
||||
def next_path |
||||
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: }) |
||||
end |
||||
|
||||
private |
||||
|
||||
def possible_years |
||||
FormHandler.instance.sales_forms.values.map { |form| form.start_date.year }.sort.reverse |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,33 @@
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link href: @form.back_path %> |
||||
<% end %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "prepare-your-file"), method: :patch do |f| %> |
||||
<%= f.hidden_field :year %> |
||||
|
||||
<span class="govuk-caption-l">Upload lettings logs in bulk (<%= @form.year_combo %>)</span> |
||||
<h1 class="govuk-heading-l">Prepare your file</h1> |
||||
|
||||
<h2 class="govuk-heading-m">Create your file</h2> |
||||
<ul class="govuk-list govuk-list--bullet"> |
||||
<li>Download the <%= govuk_link_to "bulk lettings template", @form.template_path %></li> |
||||
<li>Export the data from your housing management system, matching the template</li> |
||||
<li>If you cannot export it in this format, you may have to input it manually</li> |
||||
</ul> |
||||
|
||||
<h2 class="govuk-heading-m">Check your data</h2> |
||||
<ul class="govuk-list govuk-list--bullet"> |
||||
<li>Check data is complete and formatted correctly, using data specifications (opens in a new tab)</li> |
||||
</ul> |
||||
|
||||
<h2 class="govuk-heading-m">Save your file</h2> |
||||
<ul class="govuk-list govuk-list--bullet"> |
||||
<li>Save the file (CSV format <strong>only</strong>)</li> |
||||
</ul> |
||||
|
||||
<%= f.govuk_submit %> |
||||
<% end %> |
||||
</div> |
||||
</div> |
@ -0,0 +1,17 @@
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link href: @form.back_path %> |
||||
<% end %> |
||||
|
||||
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "upload-your-file"), method: :patch do |f| %> |
||||
<%= f.govuk_error_summary %> |
||||
|
||||
<div> |
||||
Upload your file goes here |
||||
</div> |
||||
|
||||
<div> |
||||
year selected <%= @form.year %> |
||||
</div> |
||||
|
||||
<%= f.govuk_submit %> |
||||
<% end %> |
@ -0,0 +1,16 @@
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link href: @form.back_path %> |
||||
<% end %> |
||||
|
||||
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "year"), method: :patch do |f| %> |
||||
<%= f.govuk_error_summary %> |
||||
|
||||
<%= f.govuk_collection_radio_buttons :year, |
||||
@form.options, |
||||
:id, |
||||
:name, |
||||
legend: { text: "Which year are you uploading data for?", size: "l" }, |
||||
caption: { text: "Upload lettings logs in bulk", size: "l" } %> |
||||
|
||||
<%= f.govuk_submit %> |
||||
<% end %> |
@ -0,0 +1,33 @@
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link href: @form.back_path %> |
||||
<% end %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "prepare-your-file"), method: :patch do |f| %> |
||||
<%= f.hidden_field :year %> |
||||
|
||||
<span class="govuk-caption-l">Upload sales logs in bulk (<%= @form.year_combo %>)</span> |
||||
<h1 class="govuk-heading-l">Prepare your file</h1> |
||||
|
||||
<h2 class="govuk-heading-m">Create your file</h2> |
||||
<ul class="govuk-list govuk-list--bullet"> |
||||
<li>Download the <%= govuk_link_to "bulk sales template", @form.template_path %></li> |
||||
<li>Export the data from your housing management system, matching the template</li> |
||||
<li>If you cannot export it in this format, you may have to input it manually</li> |
||||
</ul> |
||||
|
||||
<h2 class="govuk-heading-m">Check your data</h2> |
||||
<ul class="govuk-list govuk-list--bullet"> |
||||
<li>Check data is complete and formatted correctly, using data specifications (opens in a new tab)</li> |
||||
</ul> |
||||
|
||||
<h2 class="govuk-heading-m">Save your file</h2> |
||||
<ul class="govuk-list govuk-list--bullet"> |
||||
<li>Save the file (CSV format <strong>only</strong>)</li> |
||||
</ul> |
||||
|
||||
<%= f.govuk_submit %> |
||||
<% end %> |
||||
</div> |
||||
</div> |
@ -0,0 +1,17 @@
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link href: @form.back_path %> |
||||
<% end %> |
||||
|
||||
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "upload-your-file"), method: :patch do |f| %> |
||||
<%= f.govuk_error_summary %> |
||||
|
||||
<div> |
||||
Upload your file goes here |
||||
</div> |
||||
|
||||
<div> |
||||
year selected <%= @form.year %> |
||||
</div> |
||||
|
||||
<%= f.govuk_submit %> |
||||
<% end %> |
@ -0,0 +1,16 @@
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link href: @form.back_path %> |
||||
<% end %> |
||||
|
||||
<%= form_with model: @form, scope: :form, url: bulk_upload_sales_log_path(id: "year"), method: :patch do |f| %> |
||||
<%= f.govuk_error_summary %> |
||||
|
||||
<%= f.govuk_collection_radio_buttons :year, |
||||
@form.options, |
||||
:id, |
||||
:name, |
||||
legend: { text: "Which year are you uploading data for?", size: "l" }, |
||||
caption: { text: "Upload sales logs in bulk", size: "l" } %> |
||||
|
||||
<%= f.govuk_submit %> |
||||
<% end %> |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,51 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe "Bulk upload lettings log" do |
||||
let(:user) { create(:user) } |
||||
|
||||
before do |
||||
sign_in user |
||||
end |
||||
|
||||
context "when during crossover period" do |
||||
it "shows journey with year option" do |
||||
Timecop.freeze(2023, 6, 1) do |
||||
visit("/lettings-logs") |
||||
expect(page).to have_link("Upload lettings logs in bulk") |
||||
click_link("Upload lettings logs in bulk") |
||||
|
||||
expect(page).to have_content("Which year") |
||||
click_button("Continue") |
||||
|
||||
expect(page).to have_content("You must select a collection period to upload for") |
||||
choose("2022/2023") |
||||
click_button("Continue") |
||||
|
||||
click_link("Back") |
||||
|
||||
expect(page.find_field("form-year-2022-field")).to be_checked |
||||
click_button("Continue") |
||||
|
||||
expect(page).to have_content("Upload lettings logs in bulk (2022/23)") |
||||
click_button("Continue") |
||||
|
||||
expect(page).to have_content("Upload your file") |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when not it crossover period" do |
||||
it "shows journey with year option" do |
||||
Timecop.freeze(2023, 10, 1) do |
||||
visit("/lettings-logs") |
||||
expect(page).to have_link("Upload lettings logs in bulk") |
||||
click_link("Upload lettings logs in bulk") |
||||
|
||||
expect(page).to have_content("Upload lettings logs in bulk (2022/23)") |
||||
click_button("Continue") |
||||
|
||||
expect(page).to have_content("Upload your file") |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,51 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe "Bulk upload sales log" do |
||||
let(:user) { create(:user) } |
||||
|
||||
before do |
||||
sign_in user |
||||
end |
||||
|
||||
context "when during crossover period" do |
||||
it "shows journey with year option" do |
||||
Timecop.freeze(2023, 6, 1) do |
||||
visit("/sales-logs") |
||||
expect(page).to have_link("Upload sales logs in bulk") |
||||
click_link("Upload sales logs in bulk") |
||||
|
||||
expect(page).to have_content("Which year") |
||||
click_button("Continue") |
||||
|
||||
expect(page).to have_content("You must select a collection period to upload for") |
||||
choose("2022/2023") |
||||
click_button("Continue") |
||||
|
||||
click_link("Back") |
||||
|
||||
expect(page.find_field("form-year-2022-field")).to be_checked |
||||
click_button("Continue") |
||||
|
||||
expect(page).to have_content("Upload sales logs in bulk (2022/23)") |
||||
click_button("Continue") |
||||
|
||||
expect(page).to have_content("Upload your file") |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when not it crossover period" do |
||||
it "shows journey with year option" do |
||||
Timecop.freeze(2023, 10, 1) do |
||||
visit("/sales-logs") |
||||
expect(page).to have_link("Upload sales logs in bulk") |
||||
click_link("Upload sales logs in bulk") |
||||
|
||||
expect(page).to have_content("Upload sales logs in bulk (2022/23)") |
||||
click_button("Continue") |
||||
|
||||
expect(page).to have_content("Upload your file") |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,12 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadLettings::Year do |
||||
subject(:form) { described_class.new } |
||||
|
||||
describe "#options" do |
||||
it "returns correct years" do |
||||
expect(form.options.map(&:id)).to eql([2022, 2021]) |
||||
expect(form.options.map(&:name)).to eql(%w[2022/2023 2021/2022]) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,12 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadSales::Year do |
||||
subject(:form) { described_class.new } |
||||
|
||||
describe "#options" do |
||||
it "returns correct years" do |
||||
expect(form.options.map(&:id)).to eql([2022, 2021]) |
||||
expect(form.options.map(&:name)).to eql(%w[2022/2023 2021/2022]) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,32 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe BulkUploadLettingsLogsController, type: :request do |
||||
let(:user) { FactoryBot.create(:user) } |
||||
let(:organisation) { user.organisation } |
||||
|
||||
before do |
||||
sign_in user |
||||
end |
||||
|
||||
describe "GET /lettings-logs/bulk-upload-logs/start" do |
||||
context "when not in crossover period" do |
||||
it "redirects to /prepare-your-file" do |
||||
Timecop.freeze(2022, 1, 1) do |
||||
get "/lettings-logs/bulk-upload-logs/start", params: {} |
||||
|
||||
expect(response).to redirect_to("/lettings-logs/bulk-upload-logs/prepare-your-file?form%5Byear%5D=2022") |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when in crossover period" do |
||||
it "redirects to /year" do |
||||
Timecop.freeze(2023, 6, 1) do |
||||
get "/lettings-logs/bulk-upload-logs/start", params: {} |
||||
|
||||
expect(response).to redirect_to("/lettings-logs/bulk-upload-logs/year") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,32 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe BulkUploadSalesLogsController, type: :request do |
||||
let(:user) { FactoryBot.create(:user) } |
||||
let(:organisation) { user.organisation } |
||||
|
||||
before do |
||||
sign_in user |
||||
end |
||||
|
||||
describe "GET /sales-logs/bulk-upload-logs/start" do |
||||
context "when not in crossover period" do |
||||
it "redirects to /prepare-your-file" do |
||||
Timecop.freeze(2022, 1, 1) do |
||||
get "/sales-logs/bulk-upload-logs/start", params: {} |
||||
|
||||
expect(response).to redirect_to("/sales-logs/bulk-upload-logs/prepare-your-file?form%5Byear%5D=2022") |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when in crossover period" do |
||||
it "redirects to /year" do |
||||
Timecop.freeze(2023, 6, 1) do |
||||
get "/sales-logs/bulk-upload-logs/start", params: {} |
||||
|
||||
expect(response).to redirect_to("/sales-logs/bulk-upload-logs/year") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue