Skip to content

Commit

Permalink
add admin_comment to operator_documents and perform qc process in adm…
Browse files Browse the repository at this point in the history
…in panel
  • Loading branch information
tsubik committed Mar 25, 2024
1 parent 17a7478 commit ad08a2f
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 31 deletions.
6 changes: 3 additions & 3 deletions app/admin/observation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def permitted_params
end

member_action :perform_qc, method: [:put, :get] do
@page_title = I18n.t("active_admin.observations_page.perform_qc")
@page_title = I18n.t("active_admin.shared.perform_qc")
if request.get?
if resource.validation_status == "QC in progress"
render "perform_qc"
Expand Down Expand Up @@ -119,7 +119,7 @@ def permitted_params

action_item :start_qc, only: :show do
if resource.validation_status == "Ready for QC"
link_to I18n.t("active_admin.observations_page.start_qc"), start_qc_admin_observation_path(observation),
link_to I18n.t("active_admin.shared.start_qc"), start_qc_admin_observation_path(observation),
method: :put, notice: I18n.t("active_admin.observations_page.in_qc")
end
end
Expand Down Expand Up @@ -405,7 +405,7 @@ def permitted_params
column :updated_at
column :deleted_at
column(I18n.t("active_admin.shared.actions")) do |observation|
a I18n.t("active_admin.observations_page.start_qc"), href: start_qc_admin_observation_path(observation), "data-method": :put if observation.validation_status == "Ready for QC"
a I18n.t("active_admin.shared.start_qc"), href: start_qc_admin_observation_path(observation), "data-method": :put if observation.validation_status == "Ready for QC"
a I18n.t("active_admin.observations_page.needs_revision"), href: perform_qc_admin_observation_path(observation) if observation.validation_status == "QC in progress"
a I18n.t("active_admin.observations_page.ready_to_publish"), href: ready_for_publication_admin_observation_path(observation), "data-method": :put if observation.validation_status == "QC in progress"
end
Expand Down
57 changes: 34 additions & 23 deletions app/admin/operator_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,37 @@ def scoped_collection
redirect_to collection_path, notice: I18n.t("active_admin.operator_documents_page.other_confirmed")
end

member_action :perform_qc, method: [:put, :get] do
@page_title = I18n.t("active_admin.shared.perform_qc")
if request.get?
if resource.doc_pending?
render "perform_qc"
else
redirect_to collection_path, alert: I18n.t("active_admin.operator_documents_page.document_not_pending_to_start_qc")
end
elsif resource.update permitted_params[:operator_document]
notice = if resource.doc_invalid?
I18n.t("active_admin.operator_documents_page.rejected")
else
I18n.t("active_admin.operator_documents_page.approved")
end
redirect_to collection_path, notice: notice
else
render "perform_qc"
end
end

member_action :approve, method: :put do
if resource.reason.present?
resource.update(status: OperatorDocument.statuses[:doc_not_required])
resource.update!(status: OperatorDocument.statuses[:doc_not_required])
else
resource.update(status: OperatorDocument.statuses[:doc_valid])
resource.update!(status: OperatorDocument.statuses[:doc_valid])
end
redirect_to collection_path, notice: I18n.t("active_admin.operator_documents_page.approved")
end

member_action :reject, method: :put do
resource.update(status: OperatorDocument.statuses[:doc_invalid], reason: nil)
resource.update!(status: OperatorDocument.statuses[:doc_invalid], reason: nil)

redirect_to collection_path, notice: I18n.t("active_admin.operator_documents_page.rejected")
end
Expand All @@ -95,7 +115,7 @@ def scoped_collection
actions :all, except: [:destroy, :new]
permit_params :name, :public, :required_operator_document_id,
:operator_id, :type, :status, :expire_date, :start_date,
:uploaded_by, :reason, :note, :response_date,
:uploaded_by, :admin_comment, :reason, :note, :response_date,
:source, :source_info, document_file_attributes: [:id, :attachment, :filename]

csv do
Expand All @@ -104,6 +124,7 @@ def scoped_collection
end
column :public
column :status
column :admin_comment
column :id
column :required_operator_document do |o|
o.required_operator_document.name
Expand Down Expand Up @@ -214,11 +235,15 @@ def scoped_collection
links.join(" ").html_safe
end
# rubocop:enable Rails/OutputSafety
column :admin_comment
column :reason
column :note
column :response_date
column(I18n.t("active_admin.approve")) { |observation| link_to I18n.t("active_admin.approve"), approve_admin_operator_document_path(observation), method: :put }
column(I18n.t("active_admin.reject")) { |observation| link_to I18n.t("active_admin.reject"), reject_admin_operator_document_path(observation), method: :put }
column(I18n.t("active_admin.shared.actions")) do |document|
a I18n.t("active_admin.shared.start_qc"), href: perform_qc_admin_operator_document_path(document) if document.doc_pending?
a I18n.t("active_admin.approve"), href: approve_admin_operator_document_path(document), "data-method": :put if document.doc_pending?
a I18n.t("active_admin.reject"), href: perform_qc_admin_operator_document_path(document) if document.doc_pending?
end
actions
end

Expand Down Expand Up @@ -261,6 +286,7 @@ def scoped_collection
f.input :source
f.input :source_info
f.input :status, include_blank: false
f.input :admin_comment
f.input :public
f.inputs for: [:document_file_attributes, f.object.document_file || DocumentFile.new] do |df|
df.input :attachment
Expand All @@ -275,23 +301,8 @@ def scoped_collection
end

show title: proc { "#{resource.operator.name} - #{resource.required_operator_document.name}" } do
attributes_table do
row :public
tag_row :status
row :required_operator_document
row :operator
row :fmu, unless: resource.is_a?(OperatorDocumentCountry)
row :uploaded_by
row I18n.t("active_admin.operator_documents_page.attachment") do |r|
link_to r.document_file&.attachment&.identifier, r.document_file&.attachment&.url
end
row :reason
row :start_date
row :expire_date
row :created_at
row :updated_at
row :deleted_at
end
render partial: "attributes_table", locals: {operator_document: resource}

active_admin_comments
end
end
2 changes: 2 additions & 0 deletions app/admin/operator_document_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
links.join(" ").html_safe
end
# rubocop:enable Rails/OutputSafety
column :admin_comment
column :reason
column :note
column :response_date
Expand All @@ -80,6 +81,7 @@
column :public
tag_column :status
column :id
column :admin_comment
column :operator_document do |od|
if od.operator_document.present?
link_to od.operator_document&.required_operator_document&.name, admin_operator_document_path(od.operator_document&.id)
Expand Down
7 changes: 7 additions & 0 deletions app/models/countries_observer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: countries_observers
#
# country_id :integer not null
# observer_id :integer not null
#
class CountriesObserver < ApplicationRecord
belongs_to :country
belongs_to :observer
Expand Down
2 changes: 2 additions & 0 deletions app/models/operator_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# source :integer default("company")
# source_info :string
# document_file_id :integer
# admin_comment :text
#

class OperatorDocument < ApplicationRecord
Expand All @@ -48,6 +49,7 @@ class OperatorDocument < ApplicationRecord

validates :start_date, presence: {if: :document_file_id?}
validates :expire_date, presence: {if: :document_file_id?}
validates :admin_comment, presence: {if: :doc_invalid?}
validate :reason_or_file

before_save :set_type
Expand Down
1 change: 1 addition & 0 deletions app/models/operator_document_country.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# source :integer default("company")
# source_info :string
# document_file_id :integer
# admin_comment :text
#

class OperatorDocumentCountry < OperatorDocument
Expand Down
1 change: 1 addition & 0 deletions app/models/operator_document_country_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# deleted_at :datetime
# operator_document_updated_at :datetime not null
# operator_document_created_at :datetime not null
# admin_comment :text
#
class OperatorDocumentCountryHistory < OperatorDocumentHistory
end
1 change: 1 addition & 0 deletions app/models/operator_document_fmu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# source :integer default("company")
# source_info :string
# document_file_id :integer
# admin_comment :text
#

class OperatorDocumentFmu < OperatorDocument
Expand Down
1 change: 1 addition & 0 deletions app/models/operator_document_fmu_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# deleted_at :datetime
# operator_document_updated_at :datetime not null
# operator_document_created_at :datetime not null
# admin_comment :text
#
class OperatorDocumentFmuHistory < OperatorDocumentHistory
end
1 change: 1 addition & 0 deletions app/models/operator_document_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# deleted_at :datetime
# operator_document_updated_at :datetime not null
# operator_document_created_at :datetime not null
# admin_comment :text
#
class OperatorDocumentHistory < ApplicationRecord
acts_as_paranoid
Expand Down
21 changes: 21 additions & 0 deletions app/views/admin/operator_documents/_attributes_table.html.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
panel I18n.t("active_admin.operator_documents_page.details") do
attributes_table_for operator_document do
row :public
tag_row :status
row :reason if operator_document.reason.present?
row :admin_comment if operator_document.admin_comment.present?
row :required_operator_document
row :operator
row :fmu, unless: operator_document.is_a?(OperatorDocumentCountry)
row :uploaded_by
row I18n.t("active_admin.operator_documents_page.attachment") do |r|
link_to r.document_file&.attachment&.identifier, r.document_file&.attachment&.url
end
row :note
row :start_date
row :expire_date
row :created_at
row :updated_at
row :deleted_at
end
end
15 changes: 15 additions & 0 deletions app/views/admin/operator_documents/perform_qc.html.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
active_admin_form_for [:admin, resource], url: perform_qc_admin_operator_document_path(resource), method: :put do |f|
f.semantic_errors(*f.object.errors.attribute_names)

f.inputs do
f.input :admin_comment, hint: "Reason for rejection (required if document is invalid)"
end

f.actions do
f.button "Approve", class: "button", name: "operator_document[status]", value: :doc_valid
f.button "Reject", class: "button", name: "operator_document[status]", value: :doc_invalid
end
end

# loading a fresh object as resource could have changed validation status or other properties after validation errors
render partial: "attributes_table", locals: {operator_document: OperatorDocument.find(resource.id)}
5 changes: 3 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ en:
operator_activated: 'Operator activated'
new_shape: 'New shape'
current_shape: 'Current shape'
perform_qc: 'Perform Quality Control'
start_qc: 'Start QC'
menu:
dashboard:
dashboard: 'Dashboard'
Expand Down Expand Up @@ -370,6 +372,7 @@ en:
annexes: 'Annexes'
operator_document_id: 'Operator Document ID'
with_deleted: 'With deleted'
document_not_pending_to_start_qc: "Document must be in a pending state to start QC"
operator_document_annexes_page:
approved: 'Annex approved'
not_approved: 'Annex could not be approved'
Expand All @@ -380,7 +383,6 @@ en:
details: 'Operator Document Annex Details'
observations_page:
not_modified: 'Observation NOT modified'
perform_qc: 'Perform Quality Control'
performed_qc: 'Quality Control performed'
moved_ready: 'Observation moved to Ready for Publication'
moved_needs_revision: 'Observation moved to Needs Revision'
Expand All @@ -391,7 +393,6 @@ en:
needs_revision: 'Needs revision'
confirm_needs_revision: 'Do you want to notify the IM this needs revision?'
obs_needs_revision: 'Observation Needs revision'
start_qc: 'Start QC'
qc_started: 'QC started'
in_qc: 'Observation in QC'
bulk_confirm_qc: 'Are you sure you want to start QC for all these observations?'
Expand Down
5 changes: 3 additions & 2 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ fr:
operator_activated: 'Operator activated'
new_shape: 'Nouvelle forme'
current_shape: 'Forme actuelle'
perform_qc: 'Effectuer un contrôle qualité'
start_qc: 'Démarrer le CQ'
menu:
dashboard:
dashboard: 'Tableau de bord'
Expand Down Expand Up @@ -379,6 +381,7 @@ fr:
annexes: 'Annexes'
operator_document_id: "ID de document de l'opérateur"
with_deleted: 'Avec supprimé'
document_not_pending_to_start_qc: "Le document doit être en attente pour démarrer le contrôle qualité"
operator_document_annexes_page:
approved: 'Annexe approuvée'
not_approved: "L'annexe n'a pas pu être approuvée"
Expand All @@ -389,7 +392,6 @@ fr:
details: "Détails de l'annexe du document de l'opérateur"
observations_page:
not_modified: 'Observation NON modifiée'
perform_qc: 'Effectuer un contrôle qualité'
performed_qc: 'Contrôle qualité effectué'
moved_ready: 'Observation déplacée vers Prêt pour publication'
moved_needs_revision: 'Observation déplacée vers Nécessite une révision'
Expand All @@ -400,7 +402,6 @@ fr:
needs_revision: 'Nécessite une révision'
confirm_needs_revision: 'Voulez-vous informer le MI que cela doit être révisé?'
obs_needs_revision: 'Observation Nécessite une révision'
start_qc: 'Démarrer le CQ'
qc_started: 'Le CQ a commencé'
in_qc: 'Observation au CQ'
bulk_confirm_qc: 'Êtes-vous sûr de vouloir démarrer le CQ pour toutes ces observations?'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddAdminCommentToOperatorDocument < ActiveRecord::Migration[7.0]
def change
add_column :operator_documents, :admin_comment, :text
add_column :operator_document_histories, :admin_comment, :text
end
end
4 changes: 3 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.0].define(version: 2023_11_30_113839) do
ActiveRecord::Schema[7.0].define(version: 2024_03_22_163118) do
# These are extensions that must be enabled in order to support this database
enable_extension "address_standardizer"
enable_extension "address_standardizer_data_us"
Expand Down Expand Up @@ -657,6 +657,7 @@
t.datetime "deleted_at", precision: nil
t.datetime "operator_document_updated_at", precision: nil, null: false
t.datetime "operator_document_created_at", precision: nil, null: false
t.text "admin_comment"
t.index ["deleted_at"], name: "index_operator_document_histories_on_deleted_at"
t.index ["document_file_id"], name: "index_operator_document_histories_on_document_file_id"
t.index ["expire_date"], name: "index_operator_document_histories_on_expire_date"
Expand Down Expand Up @@ -712,6 +713,7 @@
t.integer "source", default: 1
t.string "source_info"
t.integer "document_file_id"
t.text "admin_comment"
t.index ["deleted_at"], name: "index_operator_documents_on_deleted_at"
t.index ["document_file_id"], name: "index_operator_documents_on_document_file_id"
t.index ["expire_date"], name: "index_operator_documents_on_expire_date"
Expand Down
9 changes: 9 additions & 0 deletions spec/factories/holdings.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# == Schema Information
#
# Table name: holdings
#
# id :integer not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
#
FactoryBot.define do
factory :holding do
sequence(:name) { |n| "Holding #{n}" }
Expand Down
1 change: 1 addition & 0 deletions spec/factories/operator_document_histories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# deleted_at :datetime
# operator_document_updated_at :datetime not null
# operator_document_created_at :datetime not null
# admin_comment :text
#

FactoryBot.define do
Expand Down
1 change: 1 addition & 0 deletions spec/factories/operator_documents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# source :integer default("company")
# source_info :string
# document_file_id :integer
# admin_comment :text
#

FactoryBot.define do
Expand Down
1 change: 1 addition & 0 deletions spec/models/operator_document_country_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# source :integer default("company")
# source_info :string
# document_file_id :integer
# admin_comment :text
#

require "rails_helper"
Expand Down
Loading

0 comments on commit ad08a2f

Please sign in to comment.