Skip to content

Commit 5615e29

Browse files
authored
Merge branch 'main' into dependabot/bundler/sqlite3-2.8.0
2 parents 6b8fe31 + a92b5ca commit 5615e29

15 files changed

Lines changed: 495 additions & 15 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# typed: false
2+
3+
class PatAssessmentsController < ApplicationController
4+
include AssessmentController
5+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# typed: true
2+
# frozen_string_literal: true
3+
4+
class Assessments::PatAssessment < ApplicationRecord
5+
extend T::Sig
6+
include AssessmentLogging
7+
include AssessmentCompletion
8+
include FormConfigurable
9+
include ValidationConfigurable
10+
11+
self.primary_key = "inspection_id"
12+
13+
belongs_to :inspection
14+
15+
after_update :log_assessment_update, if: :saved_changes?
16+
end

app/models/inspection.rb

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class Inspection < ApplicationRecord
5353

5454
enum :inspection_type, {
5555
bouncy_castle: "BOUNCY_CASTLE",
56-
bouncing_pillow: "BOUNCING_PILLOW"
56+
bouncing_pillow: "BOUNCING_PILLOW",
57+
pat_testable: "PAT_TESTABLE"
5758
}
5859

5960
CASTLE_ASSESSMENT_TYPES = {
@@ -70,8 +71,14 @@ class Inspection < ApplicationRecord
7071
fan_assessment: Assessments::FanAssessment
7172
}.freeze
7273

74+
PAT_TESTABLE_ASSESSMENT_TYPES = {
75+
pat_assessment: Assessments::PatAssessment
76+
}.freeze
77+
7378
ALL_ASSESSMENT_TYPES =
74-
CASTLE_ASSESSMENT_TYPES.merge(PILLOW_ASSESSMENT_TYPES).freeze
79+
CASTLE_ASSESSMENT_TYPES
80+
.merge(PILLOW_ASSESSMENT_TYPES)
81+
.merge(PAT_TESTABLE_ASSESSMENT_TYPES).freeze
7582

7683
USER_EDITABLE_PARAMS = %i[
7784
has_slide
@@ -218,15 +225,19 @@ def complete?
218225

219226
sig { returns(T::Hash[Symbol, T.class_of(ApplicationRecord)]) }
220227
def assessment_types
221-
bouncing_pillow? ? PILLOW_ASSESSMENT_TYPES : CASTLE_ASSESSMENT_TYPES
228+
case
229+
when pat_testable? then PAT_TESTABLE_ASSESSMENT_TYPES
230+
when bouncing_pillow? then PILLOW_ASSESSMENT_TYPES
231+
else CASTLE_ASSESSMENT_TYPES
232+
end
222233
end
223234

224235
sig { returns(T::Hash[Symbol, T.class_of(ApplicationRecord)]) }
225236
def applicable_assessments
226-
if bouncing_pillow?
227-
pillow_applicable_assessments
228-
else
229-
castle_applicable_assessments
237+
case
238+
when pat_testable? then pat_testable_applicable_assessments
239+
when bouncing_pillow? then pillow_applicable_assessments
240+
else castle_applicable_assessments
230241
end
231242
end
232243

@@ -253,6 +264,11 @@ def pillow_applicable_assessments
253264
PILLOW_ASSESSMENT_TYPES
254265
end
255266

267+
sig { returns(T::Hash[Symbol, T.class_of(ApplicationRecord)]) }
268+
def pat_testable_applicable_assessments
269+
PAT_TESTABLE_ASSESSMENT_TYPES
270+
end
271+
256272
public
257273

258274
# Iterate over only applicable assessments with a block
@@ -279,7 +295,7 @@ def applicable_tabs
279295
applicable = applicable_assessments.keys.map { |k| k.to_s.chomp("_assessment") }
280296

281297
# Add tabs in the correct UI order
282-
ordered_tabs = %w[user_height slide structure anchorage materials fan enclosed]
298+
ordered_tabs = %w[user_height slide structure anchorage materials fan enclosed pat]
283299
ordered_tabs.each do |tab|
284300
tabs << tab if applicable.include?(tab)
285301
end
@@ -293,10 +309,14 @@ def applicable_tabs
293309
# Advanced methods
294310
sig { returns(T::Boolean) }
295311
def can_be_completed?
296-
unit.present? &&
312+
base_requirements_met = unit.present? &&
297313
all_assessments_complete? &&
298314
!passed.nil? &&
299-
inspection_date.present? &&
315+
inspection_date.present?
316+
317+
return base_requirements_met if pat_testable?
318+
319+
base_requirements_met &&
300320
width.present? &&
301321
length.present? &&
302322
height.present? &&
@@ -396,8 +416,12 @@ def field_label(form, field)
396416

397417
sig { returns(T::Array[Symbol]) }
398418
def inspection_tab_incomplete_fields
399-
# Fields required for the inspection tab specifically (excludes passed which is on results tab)
419+
# Excludes passed which is on results tab
400420
fields = REQUIRED_TO_COMPLETE_FIELDS - [:passed]
421+
422+
# PAT testable only needs inspection_date
423+
fields = fields & [:inspection_date] if pat_testable?
424+
401425
fields
402426
.reject { |f| f.end_with?("_comment") }
403427
.select { |f| send(f).nil? }
@@ -526,6 +550,7 @@ def assessment_validation_data
526550
enclosed
527551
fan
528552
materials
553+
pat
529554
slide
530555
structure
531556
user_height

app/models/unit.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class Unit < ApplicationRecord
3838

3939
enum :unit_type, {
4040
bouncy_castle: "BOUNCY_CASTLE",
41-
bouncing_pillow: "BOUNCING_PILLOW"
41+
bouncing_pillow: "BOUNCING_PILLOW",
42+
pat_testable: "PAT_TESTABLE"
4243
}
4344

4445
belongs_to :user

app/views/units/_form.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
<%= render 'chobble_forms/select', field: :unit_type,
3131
options: options_for_select([
3232
[t('units.unit_types.bouncy_castle'), 'bouncy_castle'],
33-
[t('units.unit_types.bouncing_pillow'), 'bouncing_pillow']
33+
[t('units.unit_types.bouncing_pillow'), 'bouncing_pillow'],
34+
[t('units.unit_types.pat_testable'), 'pat_testable']
3435
], unit.unit_type),
3536
required: true %>
3637
<% end %>

config/forms/pat_assessment.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
form_fields:
3+
- legend_i18n_key: equipment_details
4+
fields:
5+
- partial: :number_pass_fail_comment
6+
field: :equipment_class
7+
attributes:
8+
min: 1
9+
max: 2
10+
- partial: :integer_comment
11+
field: :equipment_power
12+
attributes:
13+
min: 0
14+
- legend_i18n_key: visual_inspection
15+
fields:
16+
- partial: :pass_fail_comment
17+
field: :visual
18+
- partial: :pass_fail_comment
19+
field: :appliance_plug_check
20+
- legend_i18n_key: electrical_tests
21+
fields:
22+
- partial: :number_pass_fail_comment
23+
field: :fuse_rating
24+
attributes:
25+
min: 0
26+
max: 32
27+
- partial: :number_pass_fail_comment
28+
field: :earth_ohms
29+
attributes:
30+
min: 0
31+
step: 0.01
32+
- partial: :number_pass_fail_comment
33+
field: :insulation_mohms
34+
attributes:
35+
min: 0
36+
- partial: :number_pass_fail_comment
37+
field: :leakage_ma
38+
attributes:
39+
min: 0
40+
step: 0.01
41+
- legend_i18n_key: functional_tests
42+
fields:
43+
- partial: :pass_fail_comment
44+
field: :load_test
45+
- partial: :number_pass_fail_comment
46+
field: :rcd_trip_time_ms
47+
attributes:
48+
min: 0
49+
step: 0.01

config/locales/forms/pat.en.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
en:
3+
forms:
4+
pat:
5+
header: PAT Assessment
6+
sections:
7+
equipment_details: Equipment Details
8+
visual_inspection: Visual Inspection
9+
electrical_tests: Electrical Tests
10+
functional_tests: Functional Tests
11+
fields:
12+
equipment_class: Equipment Class (I or II)
13+
equipment_power: Power Rating (W)
14+
visual: Visual Inspection
15+
appliance_plug_check: Plug & Cable Check
16+
fuse_rating: Fuse Rating (A)
17+
earth_ohms: Earth Continuity (Ω)
18+
insulation_mohms: Insulation Resistance (MΩ)
19+
leakage_ma: Earth Leakage (mA)
20+
load_test: Load/Function Test
21+
rcd_trip_time_ms: RCD Trip Time (ms)
22+
submit: Save Assessment
23+
submit_continue: Save & Continue

config/locales/inspections.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ en:
264264
enclosed_incomplete: Totally Enclosed Assessment incomplete
265265
fan_incomplete: Fan Assessment incomplete
266266
materials_incomplete: Materials Assessment incomplete
267+
pat_incomplete: PAT Assessment incomplete
267268
slide_incomplete: Slide Assessment incomplete
268269
structure_incomplete: Structure Assessment incomplete
269270
user_height_incomplete: User Height Assessment incomplete

config/locales/units.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ en:
6767
unit_types:
6868
bouncy_castle: Bouncy Castle
6969
bouncing_pillow: Bouncing Pillow
70+
pat_testable: PAT Testable Appliance
7071
labels:
7172
inspection_date: Inspection Date
7273
dimensions: Dimensions
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# typed: false
2+
# frozen_string_literal: true
3+
4+
class CreatePatAssessments < ActiveRecord::Migration[8.0]
5+
def change
6+
create_table :pat_assessments, id: false do |t|
7+
t.string :inspection_id, limit: 12, null: false
8+
add_equipment_fields(t)
9+
add_visual_fields(t)
10+
add_electrical_fields(t)
11+
add_functional_fields(t)
12+
t.timestamps
13+
end
14+
15+
add_index :pat_assessments, :inspection_id,
16+
unique: true, name: "pat_assessments_pkey"
17+
add_foreign_key :pat_assessments, :inspections
18+
end
19+
20+
private
21+
22+
def add_equipment_fields(t)
23+
t.integer :equipment_class
24+
t.boolean :equipment_class_pass
25+
t.text :equipment_class_comment
26+
t.integer :equipment_power
27+
t.text :equipment_power_comment
28+
end
29+
30+
def add_visual_fields(t)
31+
t.boolean :visual_pass
32+
t.text :visual_comment
33+
t.boolean :appliance_plug_check_pass
34+
t.text :appliance_plug_check_comment
35+
end
36+
37+
def add_electrical_fields(t)
38+
t.integer :fuse_rating
39+
t.boolean :fuse_rating_pass
40+
t.text :fuse_rating_comment
41+
t.decimal :earth_ohms, precision: 8, scale: 2
42+
t.boolean :earth_ohms_pass
43+
t.text :earth_ohms_comment
44+
t.integer :insulation_mohms
45+
t.boolean :insulation_mohms_pass
46+
t.text :insulation_mohms_comment
47+
t.decimal :leakage_ma, precision: 8, scale: 2
48+
t.boolean :leakage_ma_pass
49+
t.text :leakage_ma_comment
50+
end
51+
52+
def add_functional_fields(t)
53+
t.boolean :load_test_pass
54+
t.text :load_test_comment
55+
t.decimal :rcd_trip_time_ms, precision: 8, scale: 2
56+
t.boolean :rcd_trip_time_ms_pass
57+
t.text :rcd_trip_time_ms_comment
58+
end
59+
end

0 commit comments

Comments
 (0)