Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/observation multiple evidences #480

Merged
merged 23 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
42e1974
create observation document - observation join table
tsubik Dec 22, 2023
fa336a2
move evidence type to observation document and name it as document_type
tsubik Jan 3, 2024
4f2804f
fix migration
tsubik Jan 5, 2024
7e29cff
add observation_report reference to observation documents
tsubik Jan 5, 2024
70a3f5e
API changes for multiple evidences
tsubik Jan 9, 2024
0ba3e6e
fix observation document uploader
tsubik Jan 9, 2024
fa1d577
remove evidence_type from obs histories as this is no needed
tsubik Jan 11, 2024
66ee048
update migration saving old evidence_type as evidence_type_v0 in pape…
tsubik Jan 11, 2024
1d35c7b
fixing specs
tsubik Jan 11, 2024
f08477c
update model annotations
tsubik Jan 25, 2024
1bbfc41
add observation-report-id to observation document resource to not hav…
tsubik Jan 26, 2024
03151e8
add deleted_at to obs-documents-observations join table, update gener…
tsubik Jan 26, 2024
e6cab37
admin observation report show page: add documents/evidences
tsubik Jan 26, 2024
4d4dc1f
fix not visible documents on index page after moving observation to r…
tsubik Jan 26, 2024
8004ba0
change how admin can add and attach evidences to observations
tsubik Mar 20, 2024
00050a2
tweak observation form, show only relevant evidence inputs based on e…
tsubik Mar 20, 2024
db41407
fix problem with evidences that does not belong to report somehow
tsubik Mar 21, 2024
4a776f6
fix issue with uploader, validate evidence attachment
tsubik Mar 21, 2024
f8f947b
validate name for observation evidence
tsubik Mar 21, 2024
04a9c2d
fixing specs
tsubik Mar 21, 2024
077bc37
remove user from observation documents as it is not even used
tsubik Mar 21, 2024
d822b2f
fix permissions
tsubik Mar 21, 2024
8e24cc9
user reference was removed from observation document
tsubik Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add observation_report reference to observation documents
  • Loading branch information
tsubik committed Mar 25, 2024
commit 7e29cffe7923506d8a7350324c54851659d3c0f8
6 changes: 6 additions & 0 deletions app/admin/observation_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

index do
column :id
column :observation_report
column :observations
column :name
column :document_type
Expand All @@ -62,6 +63,9 @@
end

filter :observations, as: :select, collection: -> { Observation.joins(:observation_documents).distinct.order(:id).pluck(:id) }
filter :observation_report,
label: -> { I18n.t("activerecord.models.observation_report") }, as: :select,
collection: -> { ObservationReport.where(id: ObservationDocument.select(:observation_report_id)).order(:title) }
filter :name, as: :select
filter :attachment, as: :select
filter :user
Expand All @@ -72,6 +76,7 @@
form do |f|
f.semantic_errors(*f.object.errors.attribute_names)
f.inputs do
f.input :observation_report, input_html: {disabled: true}
f.input :observations, input_html: {disabled: true}
f.input :user, input_html: {disabled: true}
f.input :name
Expand All @@ -85,6 +90,7 @@
show do
attributes_table do
row :id
row :observation_report
row :observations
row :document_type
row :attachment do |o|
Expand Down
1 change: 1 addition & 0 deletions app/models/observation_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ObservationDocument < ApplicationRecord

# TODO: only nils in the database, maybe that should be removed?
belongs_to :user, inverse_of: :observation_documents, touch: true, optional: true
belongs_to :observation_report, inverse_of: :observation_documents, touch: true, optional: true
has_and_belongs_to_many :observations, inverse_of: :observation_documents

skip_callback :commit, :after, :remove_attachment!
Expand Down
1 change: 1 addition & 0 deletions app/models/observation_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ObservationReport < ApplicationRecord
has_many :observation_report_observers, dependent: :destroy
has_many :observers, through: :observation_report_observers, after_add: :self_touch, after_remove: :self_touch
has_many :observations, dependent: :destroy
has_many :observation_documents, inverse_of: :observation_report, dependent: :destroy

validates :attachment, presence: true
validates :observers, presence: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class AddObservationReportToObservationDocument < ActiveRecord::Migration[7.0]
def change
add_reference :observation_documents, :observation_report, foreign_key: true, index: true

reversible do |dir|
dir.up do
execute(
<<~SQL
UPDATE observation_documents SET observation_report_id = o.observation_report_id
FROM observations o
INNER JOIN observation_documents_observations odo ON odo.observation_id = o.id
WHERE odo.observation_document_id = observation_documents.id
SQL
)
end
end
end
end
5 changes: 4 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_12_22_171303) do
ActiveRecord::Schema[7.0].define(version: 2024_01_05_172847) 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 @@ -392,8 +392,10 @@
t.integer "user_id"
t.datetime "deleted_at", precision: nil
t.integer "document_type", default: 0, null: false
t.bigint "observation_report_id"
t.index ["deleted_at"], name: "index_observation_documents_on_deleted_at"
t.index ["name"], name: "index_observation_documents_on_name"
t.index ["observation_report_id"], name: "index_observation_documents_on_observation_report_id"
t.index ["user_id"], name: "index_observation_documents_on_user_id"
end

Expand Down Expand Up @@ -1125,6 +1127,7 @@
add_foreign_key "notifications", "notification_groups", on_delete: :nullify
add_foreign_key "notifications", "operator_documents", on_delete: :cascade
add_foreign_key "notifications", "users", on_delete: :cascade
add_foreign_key "observation_documents", "observation_reports"
add_foreign_key "observation_documents", "users"
add_foreign_key "observation_documents_observations", "observation_documents", on_delete: :cascade
add_foreign_key "observation_documents_observations", "observations", on_delete: :cascade
Expand Down