Kat
2 years ago
13 changed files with 215 additions and 19 deletions
@ -0,0 +1,43 @@
|
||||
module Forms |
||||
module BulkUploadLettings |
||||
class Template |
||||
include ActiveModel::Model |
||||
include ActiveModel::Attributes |
||||
include Rails.application.routes.url_helpers |
||||
|
||||
attribute :ordered_template, :boolean |
||||
attribute :year, :integer |
||||
attribute :needstype, :integer |
||||
|
||||
validates :ordered_template, presence: true |
||||
|
||||
def view_path |
||||
"bulk_upload_lettings_logs/forms/template" |
||||
end |
||||
|
||||
def options |
||||
[ |
||||
OpenStruct.new(id: true, name: "Legacy-style template"), |
||||
OpenStruct.new(id: false, name: "New-style template"), |
||||
] |
||||
end |
||||
|
||||
def back_path |
||||
page_id = year == 2022 ? "needstype" : "prepare-your-file" |
||||
bulk_upload_lettings_log_path(id: page_id, form: { year:, needstype: }) |
||||
end |
||||
|
||||
def next_path |
||||
bulk_upload_lettings_log_path(id: "upload-your-file", form: { year:, needstype:, ordered_template: }) |
||||
end |
||||
|
||||
def save! |
||||
true |
||||
end |
||||
|
||||
def year_combo |
||||
"#{year}/#{year + 1 - 2000}" |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,20 @@
|
||||
<% 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-from-desktop"> |
||||
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "template"), method: :patch do |f| %> |
||||
<%= f.govuk_error_summary %> |
||||
<%= f.hidden_field :year %> |
||||
|
||||
<%= f.govuk_collection_radio_buttons :ordered_template, |
||||
@form.options, |
||||
:id, |
||||
:name, |
||||
legend: { text: "Which style of template is being uploaded?", size: "l" }, |
||||
caption: { text: "Upload lettings logs in bulk (#{@form.year_combo})", size: "l" }%> |
||||
|
||||
<%= f.govuk_submit %> |
||||
<% end %> |
||||
</div> |
||||
</div> |
@ -0,0 +1,7 @@
|
||||
class AddOrderedTemplate < ActiveRecord::Migration[7.0] |
||||
def change |
||||
change_table :bulk_uploads, bulk: true do |t| |
||||
t.column :ordered_template, :boolean |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,12 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Forms::BulkUploadLettings::Template do |
||||
subject(:form) { described_class.new } |
||||
|
||||
describe "#options" do |
||||
it "returns correct templates" do |
||||
expect(form.options.map(&:id)).to eq([true, false]) |
||||
expect(form.options.map(&:name)).to eq(["Legacy-style template", "New-style template"]) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue