Browse Source

Create merge request list

pull/2561/head
Manny Dinssa 2 years ago
parent
commit
490d6f0195
  1. 2
      app/controllers/merge_requests_controller.rb
  2. 1
      app/controllers/organisations_controller.rb
  3. 8
      app/helpers/tag_helper.rb
  4. 17
      app/models/merge_request.rb
  5. 55
      app/views/organisations/_merge_request_list.html.erb
  6. 27
      app/views/organisations/index.html.erb

2
app/controllers/merge_requests_controller.rb

@ -25,7 +25,7 @@ class MergeRequestsController < ApplicationController
def create
ActiveRecord::Base.transaction do
@merge_request = MergeRequest.create!(merge_request_params.merge(status: :unsubmitted))
@merge_request = MergeRequest.create!(merge_request_params.merge(status: :incomplete))
MergeRequestOrganisation.create!({ merge_request: @merge_request, merging_organisation: @merge_request.requesting_organisation })
end
redirect_to organisations_merge_request_path(@merge_request)

1
app/controllers/organisations_controller.rb

@ -16,6 +16,7 @@ class OrganisationsController < ApplicationController
all_organisations = Organisation.order(:name)
@pagy, @organisations = pagy(filtered_collection(all_organisations.visible, search_term))
@merge_requests = MergeRequest.visible.order(:new_organisation_name)
@searched = search_term.presence
@total_count = all_organisations.visible.size
end

8
app/helpers/tag_helper.rb

@ -15,6 +15,10 @@ module TagHelper
deleted: "Deleted",
merged: "Merged",
unconfirmed: "Unconfirmed",
merge_issues: "Merge issues",
request_merged: "Merged",
ready_to_merge: "Ready to merge",
processing: "Processing",
}.freeze
COLOUR = {
@ -31,6 +35,10 @@ module TagHelper
deleted: "red",
merged: "orange",
unconfirmed: "blue",
merge_issues: "orange",
request_merged: "green",
ready_to_merge: "blue",
processing: "yellow",
}.freeze
def status_tag(status, classes = [])

17
app/models/merge_request.rb

@ -7,11 +7,24 @@ class MergeRequest < ApplicationRecord
validates :new_telephone_number, presence: true, if: -> { telephone_number_correct == false }
STATUS = {
"unsubmitted" => 0,
"submitted" => 1,
"merge_issues" => 0,
"incomplete" => 1,
"ready_to_merge" => 2,
"processing" => 3,
"request_merged" => 4,
}.freeze
enum status: STATUS
scope :not_merged, -> { where.not(status: "request_merged") }
scope :visible, lambda {
open_collection_period_start_date = FormHandler.instance.start_date_of_earliest_open_collection_period
where(
"(status != :merged_status) OR (status = :merged_status AND merge_date >= :open_collection_period_start_date)",
merged_status: 4,
open_collection_period_start_date:,
)
}
def organisation_name_uniqueness
if Organisation.where("lower(name) = ?", new_organisation_name&.downcase).exists?
errors.add(:new_organisation_name, :invalid)

55
app/views/organisations/_merge_request_list.html.erb

@ -0,0 +1,55 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<strong><%= @merge_requests.where.not(status: 4).count %></strong> unresolved merge requests
<% end %>
<%= table.with_head do |head| %>
<%= head.with_row do |row| %>
<% row.with_cell(header: true, text: "Absorbing organisation", html_attributes: {
scope: "col",
}) %>
<% row.with_cell(header: true, text: "Merge date", html_attributes: {
scope: "col",
}) %>
<% row.with_cell(header: true, text: "Status", html_attributes: {
scope: "col",
}) %>
<% row.with_cell(header: true, text: "", html_attributes: {
scope: "col",
}) %>
<% end %>
<% end %>
<% @merge_requests.each do |merge_request| %>
<%= table.with_body do |body| %>
<%= body.with_row do |row| %>
<% absorbing_organisation_name = merge_request.new_organisation_name %>
<% if absorbing_organisation_name.blank? %>
<% row.with_cell(text: "You didn't answer this question",
html_attributes: {
scope: "row",
class: "app-!-colour-muted",
}) %>
<% else %>
<% row.with_cell(text: merge_request.new_organisation_name) %>
<% end %>
<% merge_date = merge_request.merge_date %>
<% if merge_date.nil? %>
<% row.with_cell(text: "You didn't answer this question",
html_attributes: {
scope: "row",
class: "app-!-colour-muted",
}) %>
<% else %>
<% row.with_cell(text: merge_date.strftime("%d %B %Y")) %>
<% end %>
<% row.with_cell(text: status_tag(merge_request.status)) %>
<% row.with_cell(html_attributes: {
scope: "row",
}) do %>
<%= govuk_link_to("View details", "/merge-request/#{merge_request.id}/organisations") %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</section>

27
app/views/organisations/index.html.erb

@ -5,13 +5,26 @@
<%= render partial: "organisations/headings", locals: request.path == organisations_path ? { main: "Organisations", sub: nil } : { main: @organisation.name, sub: "Organisations" } %>
<% if current_user.support? %>
<%= govuk_button_link_to "Create a new organisation", new_organisation_path, html: { method: :get } %>
<% end %>
<div class="app-tab__list-view">
<%= govuk_tabs(title: "Collection resources", classes: %w[app-tab__large-headers]) do |c| %>
<% c.with_tab(label: "All organisations") do %>
<%= govuk_button_link_to "Create a new organisation", new_organisation_path, html: { method: :get } %>
<%= render SearchComponent.new(current_user:, search_label: "Search by organisation name", value: @searched) %>
<%= govuk_section_break(visible: true, size: "m") %>
<%= render partial: "organisation_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %>
<% end %>
<% c.with_tab(label: "Merge requests") do %>
<%= govuk_button_link_to "Create new merge request", "/organisations/#{current_user.organisation_id}/merge-request", html: { method: :get } %>
<%= render partial: "merge_request_list", locals: { merge_requests: @merge_requests, title: "Merge requests", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<% end %>
<% end %>
</div>
<%= render SearchComponent.new(current_user:, search_label: "Search by organisation name", value: @searched) %>
<%= govuk_section_break(visible: true, size: "m") %>
<%= render partial: "organisation_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %>

Loading…
Cancel
Save