Browse Source

Add organisations page, controller and merge model

CLDC-2055-which-organisations-are-merging
Kat 2 years ago
parent
commit
616528cd15
  1. 42
      app/controllers/merge_controller.rb
  2. 6
      app/models/merge.rb
  3. 41
      app/views/merge/organisations.html.erb

42
app/controllers/merge_controller.rb

@ -0,0 +1,42 @@
class MergeController < ApplicationController
before_action :authenticate_user!
def show
render form.view_path
end
def update
if form.valid? && form.save!
redirect_to form.next_path
else
render form.view_path
end
end
def organisations
@answer_options = answer_options
@merge = Merge.new(form_params)
@merging_organisations_list = Organisation.where(id: @merge.merging_organisations)
end
def answer_options
answer_options = { "" => "Select an option" }
Organisation.all.pluck(:id, :name).each do |organisation|
answer_options[organisation[0]] = organisation[1]
end
answer_options
end
private
def form_params
merge_params = params.fetch(:merge, {}).permit(:merging_organisations)
if merge_params[:merging_organisations].blank?
merge_params[:merging_organisations] = [params[:id]]
else
merge_params[:merging_organisations] = merge_params[:merging_organisations].split(" ") << params[:merge][:merging_organisation]
end
merge_params
end
end

6
app/models/merge.rb

@ -0,0 +1,6 @@
class Merge
include ActiveModel::Model
include ActiveModel::Attributes
attribute :merging_organisations, array: true, default: []
end

41
app/views/merge/organisations.html.erb

@ -0,0 +1,41 @@
<% title = "Tell us if your organisation is merging" %>
<% content_for :title, title %>
<%= govuk_back_link href: organisation_path %>
<h2 class="govuk-heading-l">Tell us if your organisation is merging</h2>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<p class="govuk-body">Start typing to search for your managing agent</p>
<%= form_with model: @merge, url: merge_organisations_organisation_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: {
field: :merging_organisation,
question: Form::Question.new("", { "answer_options" => @answer_options }, nil),
f:,
} %>
<%= f.hidden_field :merging_organisations %>
<%= f.govuk_submit "Add organisation", classes: "govuk-button--secondary" %>
<%= govuk_table do |table| %>
<% @merging_organisations_list.each do |merging_organisation| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: merging_organisation.name) %>
<% if current_user.data_coordinator? || current_user.support? %>
<% row.cell(html_attributes: {
scope: "row",
class: "govuk-!-text-align-right",
}) do %>
<%= govuk_link_to("Remove", merge_organisations_organisation_path) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<%= govuk_button_link_to "Continue", merge_organisations_organisation_path, button: true %>
</div>
Loading…
Cancel
Save