Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to record that a meeting took place in pre-app #2141

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/components/task_list_items/assessment/meeting_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module TaskListItems
module Assessment
class MeetingComponent < TaskListItems::BaseComponent
def initialize(planning_application:)
@planning_application = planning_application
end

private

attr_reader :planning_application

delegate :meeting, to: :planning_application

def link_text
"Meeting"
end

def link_path
if @planning_application.meetings.any?
planning_application_assessment_meetings_path(@planning_application)
else
new_planning_application_assessment_meeting_path(@planning_application)
end
end

def status_tag_component
StatusTags::BaseComponent.new(
status: @planning_application.meetings.any? ? @planning_application.meetings.last.status : "not_started"
)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

module PlanningApplications
module Assessment
class MeetingsController < AuthenticationController
before_action :set_planning_application
before_action :build_meeting, only: %i[new create index]

def index
@meetings = @planning_application.meetings.by_occurred_at_desc.includes(:created_by)
respond_to do |format|
format.html
end
end

def show
respond_to do |format|
format.html
end
end

def new
respond_to do |format|
format.html
end
end

def create
respond_to do |format|
if @meeting.update(meeting_params)
format.html do
redirect_to planning_application_assessment_tasks_path(@planning_application), notice: t(".success")
end
else
format.html { render :new }
end
end
end

private

def meeting_params
params.require(:meeting)
.permit(:occurred_at, :comment)
.merge(created_by: current_user, status: "complete")
end

def build_meeting
@meeting = @planning_application.meetings.new
end
end
end
end
24 changes: 24 additions & 0 deletions app/models/meeting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class Meeting < ApplicationRecord
include DateValidateable

belongs_to :created_by, class_name: "User"

belongs_to :planning_application

validates :status, presence: true

validates :occurred_at,
presence: true,
date: {
on_or_before: :current
}

enum :status, %i[
not_started
complete
].index_with(&:to_s)

scope :by_occurred_at_desc, -> { order(occurred_at: :desc) }
end
1 change: 1 addition & 0 deletions app/models/planning_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class WithdrawOrCancelError < RuntimeError; end
has_many :planning_application_constraints_queries
has_many :constraints, through: :planning_application_constraints, source: :constraint
has_many :site_histories
has_many :meetings, -> { by_occurred_at_desc }
has_many :site_notices
has_many :site_visits, -> { by_created_at_desc }
has_many :policy_classes, -> { order(:section) }
Expand Down
18 changes: 18 additions & 0 deletions app/views/planning_applications/assessment/meetings/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%= form_with(
model: @meeting,
class: "govuk-!-margin-top-5",
url: planning_application_assessment_meetings_path(@planning_application, @meeting),
method: :post
) do |form| %>

<%= form.govuk_date_field(:occurred_at, rows: 6, legend: {text: "Meeting date"}) %>

<%= form.govuk_text_area(:comment, rows: 6, label: {text: "Add notes (optional)"}) %>

<div class="govuk-button-group govuk-!-padding-top-7">
<%= form.submit "Save and mark as complete", class: "govuk-button govuk-button--primary" %>

<%= back_link %>
</div>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">
<%= meeting.occurred_at&.to_date&.to_fs %>
</th>
<td class="govuk-table__cell">
<%= meeting.created_by.name %>
</td>
<td class="govuk-table__cell">
<%= meeting.comment %>
</td>
</tr>
</tbody>
41 changes: 41 additions & 0 deletions app/views/planning_applications/assessment/meetings/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<% content_for :page_title do %>
Meetings - <%= t("page_title") %>
<% end %>

<%= render(
partial: "shared/proposal_header",
locals: {heading: "View meetings"}
) %>

<div class=govuk-width-container>
<% if @meetings.any? %>
<table class="govuk-table">
<caption class="govuk-table__caption govuk-table__caption--m">Meeting history</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Meeting date</th>
<th scope="col" class="govuk-table__header">Case officer</th>
<th scope="col" class="govuk-table__header">Notes (optional)</th>
</tr>
</thead>
<% @meetings.each do |meeting| %>
<% if meeting.persisted? %>
<%= render "overview", meeting: meeting %>
<% end %>
<% end %>
</table>
<% end %>

<details class="govuk-details govuk-!-padding-top-5" data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
Add a new meeting
</span>
</summary>
<%= render "form" %>
</details>

<div class="govuk-button-group govuk-!-padding-top-7">
<%= back_link %>
</div>
</div>
23 changes: 23 additions & 0 deletions app/views/planning_applications/assessment/meetings/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% content_for :page_title do %>
Meeting - <%= t("page_title") %>
<% end %>

<%= render(
partial: "shared/assessment_task_breadcrumbs",
locals: {planning_application: @planning_application}
) %>
<% content_for :title, "Meeting" %>

<%= render(
partial: "shared/proposal_header",
locals: {heading: "Add a meeting"}
) %>
<div class="govuk-warning-text">
<span class="govuk-warning-text__icon" aria-hidden="true">!</span>
<strong class="govuk-warning-text__text">
<span class="govuk-visually-hidden">Warning</span>
This is NOT public.
</strong>
</div>

<%= render "form" %>
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
)
) %>
<% end %>

<% if @planning_application.additional_services.find_by(name: "meeting") %>
<%= render(
TaskListItems::Assessment::MeetingComponent.new(
planning_application: @planning_application
)
) %>
<% end %>
</ul>
</li>
12 changes: 12 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ en:
invalid: Enter a valid url for the legislation
title:
blank: Enter a title for the legislation
meeting:
attributes:
occurred_at:
date_blank: Provide the date when the meeting took place
date_invalid: The date the meeting took place must be a valid date
date_not_on_or_after: The date the meeting took place must be on or after the consultation start date
date_not_on_or_before: The date the meeting took place must be on or before today
new_policy_class:
attributes:
name:
Expand Down Expand Up @@ -1292,6 +1299,9 @@ en:
success: Informative was successfully saved
update:
success: Informatives were successfully saved
meetings:
create:
success: Meeting record was successfully added.
ownership_certificates:
update:
success: Ownership certificate was checked
Expand Down Expand Up @@ -2244,6 +2254,8 @@ en:
email_consultees: Send emails to consultees
fee_component:
check_fee: Check fee
meeting_component:
meeting: Meeting
neighbour_responses_component:
neighbour_responses: View neighbour responses
other_change_request_component:
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@

resources :site_visits, except: %i[destroy]

resources :meetings, except: %i[edit update destroy]

resources :heads_of_terms, only: %i[index new] do
get :edit, on: :collection
get :edit
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20250128164930_create_meetings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class CreateMeetings < ActiveRecord::Migration[7.2]
def change
create_table :meetings do |t|
t.references :created_by, null: false, foreign_key: {to_table: :users}, type: :bigint
t.references :planning_application, foreign_key: true
t.string :status, default: "not_started", null: false
t.text :comment
t.datetime :occurred_at, null: false

t.timestamps
end
end
end
14 changes: 14 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,18 @@
t.index ["local_policy_id"], name: "ix_local_policy_areas_on_local_policy_id"
end

create_table "meetings", force: :cascade do |t|
t.bigint "created_by_id", null: false
t.bigint "planning_application_id"
t.string "status", default: "not_started", null: false
t.text "comment"
t.datetime "occurred_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["created_by_id"], name: "ix_meetings_on_created_by_id"
t.index ["planning_application_id"], name: "ix_meetings_on_planning_application_id"
end

create_table "neighbour_letter_batches", force: :cascade do |t|
t.bigint "consultation_id"
t.string "text"
Expand Down Expand Up @@ -1146,6 +1158,8 @@
add_foreign_key "local_authority_policy_references", "local_authorities"
add_foreign_key "local_policies", "planning_applications"
add_foreign_key "local_policy_areas", "local_policies"
add_foreign_key "meetings", "planning_applications"
add_foreign_key "meetings", "users", column: "created_by_id"
add_foreign_key "neighbour_letter_batches", "consultations"
add_foreign_key "neighbour_letters", "neighbour_letter_batches", column: "batch_id"
add_foreign_key "neighbour_letters", "neighbours"
Expand Down
11 changes: 11 additions & 0 deletions spec/factories/additional_services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

FactoryBot.define do
factory :additional_service do
planning_application

trait :with_meeting do
name { "meeting" }
end
end
end
11 changes: 11 additions & 0 deletions spec/factories/meeting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

FactoryBot.define do
factory :meeting do
association :created_by, factory: :user
planning_application

comment { "A comment about the meeting" }
occurred_at { 1.day.ago }
end
end
45 changes: 45 additions & 0 deletions spec/models/meeting_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Meeting do
describe "validations" do
subject(:meeting) { described_class.new }

describe "#planning_application" do
it "validates presence" do
expect { meeting.valid? }.to change { meeting.errors[:planning_application] }.to ["must exist"]
end
end

describe "#created_by" do
it "validates presence" do
expect { meeting.valid? }.to change { meeting.errors[:created_by] }.to ["must exist"]
end
end

describe "#occurred_at" do
let!(:planning_application) { create(:planning_application, :pre_application) }

it "validates presence" do
meeting = described_class.build

expect { meeting.save }.to change { meeting.errors[:occurred_at] }.to ["Provide the date when the meeting took place"]
end
end

describe "scopes" do
describe ".by_occurred_at_desc" do
let!(:default_local_authority) { create(:local_authority, :default) }
let!(:planning_application) { create(:planning_application, :pre_application, local_authority: default_local_authority) }
let!(:meetings1) { create(:meeting, occurred_at: 1.day.ago, planning_application: planning_application) }
let!(:meetings2) { create(:meeting, occurred_at: Time.zone.now, planning_application: planning_application) }
let!(:meetings3) { create(:meeting, occurred_at: 2.days.ago, planning_application: planning_application) }

it "returns meetings sorted by occurred at desc (i.e. most recent first)" do
expect(described_class.by_occurred_at_desc).to eq([meetings2, meetings1, meetings3])
end
end
end
end
end
Loading