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 to upload completed documents
- Loading branch information
1 parent
99a8bc9
commit 532f303
Showing
25 changed files
with
389 additions
and
21 deletions.
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
app/controllers/evaluation/upload_completed_documents_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,71 @@ | ||
module Evaluation | ||
class UploadCompletedDocumentsController < ApplicationController | ||
before_action :set_current_case | ||
before_action :check_user_is_evaluator | ||
before_action { @back_url = evaluation_task_path(@current_case) } | ||
before_action :uploaded_files | ||
def show | ||
@document_uploader = @current_case.document_uploader | ||
end | ||
|
||
def create | ||
@document_uploader = @current_case.document_uploader(document_uploader_params) | ||
if @document_uploader.valid? | ||
@document_uploader.save_evaluation_document!(current_user.email) | ||
current_evaluator.update!(case_document_uploader_params) | ||
redirect_to @back_url | ||
else | ||
render :show | ||
end | ||
end | ||
|
||
def destroy | ||
@uploaded_document = Support::EvaluatorsUploadDocument.find(params[:document_id]) | ||
@support_document = Support::Document.find(@uploaded_document.attachable_id) | ||
@back_url = evaluation_upload_completed_document_path(@current_case) | ||
return unless params[:confirm] | ||
|
||
@uploaded_document.destroy! | ||
@support_document.destroy! | ||
if @uploaded_files.empty? | ||
reset_uploaded_documents | ||
end | ||
redirect_to evaluation_upload_completed_document_path(case_id: @current_case.id), | ||
notice: I18n.t("support.cases.upload_documents.flash.destroyed", name: @uploaded_document.file_name) | ||
end | ||
|
||
private | ||
|
||
helper_method def current_evaluator | ||
return @current_evaluator if defined? @current_evaluator | ||
|
||
@current_evaluator = Support::Evaluator.where("support_case_id = ? AND LOWER(email) = LOWER(?)", params[:case_id], current_user.email).first | ||
end | ||
def set_current_case | ||
@current_case = Support::Case.find(params[:case_id]) | ||
@evaluation_due_date = @current_case.evaluation_due_date? ? @current_case.evaluation_due_date.strftime("%d %B %Y") : nil | ||
end | ||
|
||
def document_uploader_params | ||
params.fetch(:document_uploader, {}).permit(:edit_form, files: []) | ||
end | ||
|
||
def case_document_uploader_params | ||
params.require(:document_uploader).permit(:has_uploaded_documents) | ||
end | ||
|
||
def check_user_is_evaluator | ||
return if current_evaluator.present? && current_user.email.downcase == current_evaluator.email.downcase | ||
|
||
redirect_to root_path, notice: I18n.t("evaluation.tasks.not_permitted") | ||
end | ||
|
||
def reset_uploaded_documents | ||
current_evaluator.update!(has_uploaded_documents: false) | ||
end | ||
|
||
def uploaded_files | ||
@uploaded_files ||= Support::EvaluatorsUploadDocument.where(support_case_id: params[:case_id], email: current_user.email) | ||
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
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,7 @@ | ||
module Support | ||
class EvaluatorsUploadDocument < 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
32 changes: 32 additions & 0 deletions
32
app/views/evaluation/upload_completed_documents/_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,32 @@ | ||
<%= form_with model: @document_uploader, scope: :document_uploader, url: evaluation_upload_completed_documents_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("evaluation.upload_evaluation.file_upload_confirmation") %></legend> | ||
<div class="govuk-radios"> | ||
<div class="govuk-radios__item"> | ||
<%= form.radio_button :has_uploaded_documents, true, checked: current_evaluator.present? && current_evaluator.has_uploaded_documents == true, class: "govuk-radios__input" %> | ||
<%= form.label :has_uploaded_documents, "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_documents, false, checked: current_evaluator.present? && current_evaluator.has_uploaded_documents == false, class: "govuk-radios__input" %> | ||
<%= form.label :has_uploaded_documents, "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.continue"), 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> | ||
<%= hidden_field_tag :case_id, @current_case.id %> | ||
<%= 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_files.any? ? true: false %> | ||
<% end %> |
44 changes: 44 additions & 0 deletions
44
app/views/evaluation/upload_completed_documents/_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,44 @@ | ||
<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_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" %> | ||
</span> | ||
<div class="case-files__file-actions"> | ||
<span class="case-files__file-remove"> | ||
<%= link_to I18n.t("generic.button.delete"), | ||
evaluation_upload_completed_document_path(case_id: @current_case, document_id: uploaded_file), | ||
method: :delete, | ||
class: "govuk-link govuk-link--no-visited-state" %> | ||
</span> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
app/views/evaluation/upload_completed_documents/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,13 @@ | ||
<%= 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"), | ||
evaluation_upload_completed_document_path(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"), | ||
evaluation_upload_completed_document_path(@current_case), | ||
class: "govuk-link govuk-link--no-visited-state" %> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
app/views/evaluation/upload_completed_documents/show.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,9 @@ | ||
<%= render partial: "support/cases/components/case_header", | ||
locals: { current_case: @current_case } %> | ||
<h1 class="govuk-heading-l"><%= I18n.t("evaluation.upload_evaluation.header") %></h1> | ||
<p class="govuk-body"> | ||
<%= I18n.t("evaluation.upload_evaluation.page_body_text1") %> | ||
<br> | ||
<%= I18n.t("evaluation.upload_evaluation.page_body_text2") %> | ||
</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
Oops, something went wrong.