generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new files for uploading contract handover pack
- Loading branch information
1 parent
6d7aaf5
commit cee00bc
Showing
19 changed files
with
328 additions
and
3 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
app/controllers/support/cases/upload_contract_handovers_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/views/support/cases/upload_contract_handovers/_form.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
45 changes: 45 additions & 0 deletions
45
app/views/support/cases/upload_contract_handovers/_uploaded_documents.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
app/views/support/cases/upload_contract_handovers/destroy.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
8 changes: 8 additions & 0 deletions
8
app/views/support/cases/upload_contract_handovers/edit.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
db/migrate/20250225120657_add_support_upload_contract_handovers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
5 changes: 5 additions & 0 deletions
5
db/migrate/20250225122027_add_has_uploaded_contract_handovers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.