Skip to content

Commit

Permalink
Added new files for uploading contract handover pack
Browse files Browse the repository at this point in the history
  • Loading branch information
edwin-jebaraj committed Feb 27, 2025
1 parent 6d7aaf5 commit cee00bc
Show file tree
Hide file tree
Showing 19 changed files with 328 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module Support
class Cases::UploadContractHandoversController < Cases::ApplicationController
before_action :set_current_case
before_action { @back_url = support_case_path(@current_case, anchor: "tasklist") }
before_action { @uploaded_handover_packs = current_case.upload_contract_handovers }
def edit
@document_uploader = current_case.document_uploader
@uploaded_handover_packs = current_case.upload_contract_handovers
end

def create
@document_uploader = current_case.document_uploader(upload_contract_handover_params)
if @document_uploader.valid?
@document_uploader.save_contract_handover_pack!
@current_case.update!(case_contract_handover_params)
redirect_to @back_url
else
render :edit
end
end

def destroy
@uploaded_document = Support::UploadContractHandover.find(params[:document_id])
@support_document = Support::Document.find(@uploaded_document.attachable_id)

@back_url = edit_support_case_upload_contract_handover_path
return unless params[:confirm]

@uploaded_document.destroy!
@support_document.destroy!

if @uploaded_handover_packs.empty?
reset_uploaded_contract_handover
end
redirect_to edit_support_case_upload_contract_handover_path,
notice: I18n.t("support.cases.upload_documents.flash.destroyed", name: @uploaded_document.file_name)
end

private

def set_current_case
@current_case = Support::Case.find(params[:case_id])
end

def upload_contract_handover_params
params.fetch(:document_uploader, {}).permit(:edit_form, files: [])
end

def case_contract_handover_params
params.require(:document_uploader).permit(:has_uploaded_contract_handovers)
end

def reset_uploaded_contract_handover
@current_case.update!(has_uploaded_contract_handovers: false)
end
end
end
1 change: 1 addition & 0 deletions app/controllers/support/document_downloads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DocumentDownloadsController < Cases::ApplicationController
"Support::EmailTemplateAttachment",
"Support::CaseUploadDocument",
"Support::EvaluatorsUploadDocument",
"Support::UploadContractHandover",
].freeze

def show
Expand Down
2 changes: 2 additions & 0 deletions app/models/support/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Case < ApplicationRecord

has_many :contract_recipients, class_name: "Support::ContractRecipient", foreign_key: :support_case_id

has_many :upload_contract_handovers, class_name: "Support::UploadContractHandover", foreign_key: :support_case_id

# Support level
#
# L1 - Advice and guidance only
Expand Down
13 changes: 13 additions & 0 deletions app/models/support/case/document_uploadable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,17 @@ def upload_evaluation_document_files(files:, email:)
)
end
end

def upload_contract_handover_files(files:)
return if files.blank?

files.each do |file|
upload_contract_handovers.create!(
attachable: Support::Document.create!(case: self, file_type: file.content_type, file:),
file_type: file.content_type,
file_name: file.original_filename,
file_size: file.size,
)
end
end
end
4 changes: 4 additions & 0 deletions app/models/support/case/document_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def save_evaluation_document!(email)
support_case.upload_evaluation_document_files(files:, email:)
end

def save_contract_handover_pack!
support_case.upload_contract_handover_files(files:)
end

private

def files_safe
Expand Down
10 changes: 10 additions & 0 deletions app/models/support/upload_contract_handover.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Support
class UploadContractHandover < ApplicationRecord
belongs_to :case, class_name: "Support::Case", foreign_key: :support_case_id
belongs_to :attachable, polymorphic: true, optional: true

delegate :file, :file_type, to: :attachable
end
end
8 changes: 8 additions & 0 deletions app/presenters/support/case_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ def document_upload_in_progress?
!has_uploaded_documents && upload_documents.any?
end

def upload_contract_handover_complete?
has_uploaded_contract_handovers
end

def upload_contract_handover_in_progress?
!has_uploaded_contract_handovers && upload_contract_handovers.any?
end

def evaluation_in_progress?
evaluators.where(evaluation_approved: false).any? && evaluators.where(evaluation_approved: true).any?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<% @uploaded_files.each do |uploaded_file| %>
<div class="case-files__file">
<span class="case-files__file-name">
<%= link_to uploaded_file.file_name, evaluation_download_document_path(@current_case, document_type: uploaded_file.class, document_id: uploaded_file.id), method: :put, class: "govuk-link" %>
<%= link_to uploaded_file.file_name, support_document_download_path(@current_case, document_type: uploaded_file.class, document_id: uploaded_file.id), method: :put, class: "govuk-link" %>
</span>
<div class="case-files__file-actions">
<span class="case-files__file-remove">
Expand Down
10 changes: 9 additions & 1 deletion app/views/support/cases/show/_tasklist.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@

task_list.with_item(title: I18n.t("support.case.label.tasklist.item.add_contract_recipients"), href: support_case_contract_recipients_path(@current_case), status: add_contract_recipients_status)

task_list.with_item(title: I18n.t("support.case.label.tasklist.item.upload_contract_handover_pack"), href: '#', status: govuk_tag(text: I18n.t("support.case.label.tasklist.status.to_do")))
if @current_case.upload_contract_handover_complete?
upload_contract_handover_status = govuk_tag(text: I18n.t("support.case.label.tasklist.status.complete"), colour: "green")
elsif @current_case.upload_contract_handover_in_progress?
upload_contract_handover_status = govuk_tag(text: I18n.t("support.case.label.tasklist.status.in_progress"))
else
upload_contract_handover_status = govuk_tag(text: I18n.t("support.case.label.tasklist.status.to_do"))
end

task_list.with_item(title: I18n.t("support.case.label.tasklist.item.upload_contract_handover_pack"), href: edit_support_case_upload_contract_handover_path(@current_case), status: upload_contract_handover_status)

task_list.with_item(title: I18n.t("support.case.label.tasklist.item.share_handover_pack")) do | item |
item.with_status(text: govuk_tag(text: I18n.t("support.case.label.tasklist.status.cannot_start"), colour: "grey"), cannot_start_yet: true)
Expand Down
38 changes: 38 additions & 0 deletions app/views/support/cases/upload_contract_handovers/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<%= form_with model: @document_uploader, scope: :document_uploader, url: support_case_upload_contract_handover_path,
html: { "data-controller" => "case-files" } do |form| %>

<h2 class="govuk-heading-m"><%= I18n.t("support.cases.upload_documents.choose_file_title") %></h2>

<%= form.govuk_error_summary %>

<span class="govuk-button govuk-button--secondary" role="button"
data-case-files-target="btnDisplayFileDialog">
<%= I18n.t("support.cases.upload_documents.button.choose_file") %>
</span>

<%= render "uploaded_documents" %>

<div class="govuk-form-group govuk-!-margin-top-7">
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--s"><%= I18n.t("support.cases.upload_documents.file_upload_confirmation") %></legend>
<div class="govuk-radios">
<div class="govuk-radios__item">
<%= form.radio_button :has_uploaded_contract_handovers, true, checked: @current_case.has_uploaded_contract_handovers == true, class: "govuk-radios__input" %>
<%= form.label :has_uploaded_contract_handovers, "Yes, I have uploaded all documents", value: true, class: "govuk-label govuk-radios__label" %>
</div>
<div class="govuk-radios__item">
<%= form.radio_button :has_uploaded_contract_handovers, false, checked: @current_case.has_uploaded_contract_handovers == false, class: "govuk-radios__input" %>
<%= form.label :has_uploaded_contract_handovers, "No", value: false, class: "govuk-label govuk-radios__label" %>
</div>
</div>
</fieldset>
</div>

<div class="govuk-button-group flex-align-center">
<%= form.submit I18n.t("generic.button.next"), class: "govuk-button", role: "button", "data-action" => "case-files#submit", data: { disable_with: "Uploading..." } %>
<%= link_to I18n.t("generic.button.cancel"), @back_url, class: "govuk-link govuk-link--no-visited-state" %>
</div>

<%= form.govuk_file_field :files, multiple: true, include_hidden: false, class: "govuk-!-display-none", "data-case-files-target" => "filesField", form_group: { class: "govuk-!-display-none" } %>
<%= form.hidden_field :edit_form, value: @uploaded_handover_packs.any? ? true: false %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h3 class="govuk-heading-s govuk-!-margin-bottom-2"><%= I18n.t("support.cases.upload_documents.file_uploaded") %></h3>
</div>
</div>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-!-display-none" data-case-files-target="fileList">
<div data-case-files-target="filePreview">
<div data-case-files-target="previewTemplate">
<div class="case-files__file">
<span class="case-files__file-name" data-dz-name></span>
<div class="case-files__file-actions">
<span class="case-files__file-remove">
<a class="govuk-link govuk-link--no-visited-state" href="#" data-dz-remove><%= I18n.t("generic.button.delete") %></a>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<% @uploaded_handover_packs.each do |handover_pack| %>
<div class="case-files__file">
<span class="case-files__file-name">
<%= link_to handover_pack.file_name, support_document_download_path(@current_case, document_type: handover_pack.class, document_id: handover_pack.id), method: :put, class: "govuk-link" %>
</span>
<div class="case-files__file-actions">
<span class="case-files__file-remove">
<%= link_to I18n.t("generic.button.delete"),
support_case_upload_contract_handover_path(case_id: @current_case, document_id: handover_pack),
method: :delete,
class: "govuk-link govuk-link--no-visited-state" %>
</span>
</div>
</div>
<% end %>
</div>
</div>
16 changes: 16 additions & 0 deletions app/views/support/cases/upload_contract_handovers/destroy.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%= render partial: "support/cases/components/case_header", locals: { current_case: @current_case } %>

<h1 class="govuk-heading-l">
<%= I18n.t("support.cases.upload_documents.delete_confirmation", name:@uploaded_document.file_name) %>
</h1>

<div class="govuk-button-group flex-align-center">
<%= link_to I18n.t("generic.button.delete"),
support_case_upload_contract_handover_path(@uploaded_document, case_id: @current_case, confirm: true, document_id: @uploaded_document.id),
method: :delete,
class: "govuk-button govuk-button--warning" %>

<%= link_to I18n.t("generic.button.cancel"),
edit_support_case_upload_contract_handover_path(case_id: @current_case),
class: "govuk-link govuk-link--no-visited-state" %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= render partial: "support/cases/components/case_header", locals: { current_case: @current_case } %>
<h1 class="govuk-heading-l"><%= I18n.t("support.cases.upload_contract_handover.header") %></h1>
<p class="govuk-body-m govuk-!-static-margin-bottom-8">
<%= I18n.t("support.cases.upload_contract_handover.hint1") %><br>
<%= I18n.t("support.cases.upload_contract_handover.hint2") %>
</p>

<%= render "form" %>
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,10 @@ en:
destroyed: "%{name} successfully removed"
delete_confirmation: Are you sure you want to delete %{name}?
is_document_uploaded: Please select uploaded option
upload_contract_handover:
header: Upload handover pack
hint1: Select the relevant contract documents to share and upload them.
hint2: You may want to upload these as a zip file.
email_evaluators:
header: Email evaluators
hint: Check and then send the emails to notify people that the files have been shared. Files will only be accessible to email addresses added.
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
resource :email_evaluators, except: %i[show]
resource :review_evaluation, except: %i[show]
resources :contract_recipients, except: %i[show]
resource :upload_contract_handover, except: %i[show]
resource :email, only: %i[create] do
scope module: :emails do
resources :content, only: %i[show], param: :template
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20250225120657_add_support_upload_contract_handovers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AddSupportUploadContractHandovers < ActiveRecord::Migration[7.2]
def change
create_table "support_upload_contract_handovers", id: :uuid do |t|
t.references "support_case", type: :uuid
t.string "file_type"
t.string "file_name"
t.bigint "file_size"
t.uuid "attachable_id"
t.string "attachable_type"
t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddHasUploadedContractHandovers < ActiveRecord::Migration[7.2]
def change
add_column :support_cases, :has_uploaded_contract_handovers, :boolean, default: false
end
end
15 changes: 14 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2025_02_24_123310) do
ActiveRecord::Schema[7.2].define(version: 2025_02_25_122027) do
create_sequence "evaluation_refs"
create_sequence "framework_refs"

Expand Down Expand Up @@ -638,6 +638,7 @@
t.date "evaluation_due_date"
t.boolean "has_uploaded_documents", default: false
t.boolean "sent_email_to_evaluators", default: false
t.boolean "has_uploaded_contract_handovers", default: false
t.index ["category_id"], name: "index_support_cases_on_category_id"
t.index ["existing_contract_id"], name: "index_support_cases_on_existing_contract_id"
t.index ["new_contract_id"], name: "index_support_cases_on_new_contract_id"
Expand Down Expand Up @@ -1023,6 +1024,18 @@
t.string "title"
end

create_table "support_upload_contract_handovers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "support_case_id"
t.string "file_type"
t.string "file_name"
t.bigint "file_size"
t.uuid "attachable_id"
t.string "attachable_type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["support_case_id"], name: "index_support_upload_contract_handovers_on_support_case_id"
end

create_table "tasks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "section_id"
t.string "title", null: false
Expand Down
Loading

0 comments on commit cee00bc

Please sign in to comment.