Skip to content

Commit

Permalink
Be able to record that a meeting took place in pre-app
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccaoneill committed Jan 31, 2025
1 parent 0390043 commit 8a13e13
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 0 deletions.
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
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.last.status
)
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]

def index
@meetings = @planning_application.meetings
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_created_at_desc, -> { order(created_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_created_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,6 @@
<p class="govuk-body">Response created by: <%= meeting.created_by.name %></p>
<p class="govuk-body">Response created: <%= meeting.created_at.to_fs %></p>
<% if meeting.valid? %>
<p class="govuk-body">Meeting occured at: <%= meeting.occurred_at&.to_date&.to_fs %></p>
<% end %>
<p class="govuk-body">Comment: <%= meeting.comment %></p>
37 changes: 37 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,37 @@
<% content_for :page_title do %>
Meetings - <%= t("page_title") %>
<% end %>

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

<% if @meetings.any? %>
<h2 class="govuk-heading-m">Meetings</h2>

<details class="govuk-details govuk-!-padding-top-5" data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
See previous meetings
</span>
</summary>
<div class="govuk-details__text">
<% @meetings.each do |meeting| %>
<%= render "overview", meeting: meeting %>
<p><%= govuk_link_to "View", planning_application_assessment_meeting_path(@planning_application, meeting) %></p>
<hr>
<% end %>
</div>
</details>
<% else %>
<p class="govuk-body">
No meetings have been added yet.
</p>
<% end %>

<%= govuk_link_to "Add new meeting", new_planning_application_assessment_meeting_path(@planning_application) %>

<div class="govuk-button-group govuk-!-padding-top-7">
<%= back_link %>
</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>
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,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
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[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
7 changes: 7 additions & 0 deletions spec/models/meeting_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Meeting, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 8a13e13

Please sign in to comment.