Browse Source

Display locations

pull/705/head
Stéphane Meny 3 years ago
parent
commit
a62c6cd34a
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 1
      app/models/case_log.rb
  2. 21
      app/models/form/setup/questions/location.rb
  3. 4
      app/models/form/setup/questions/scheme_id.rb
  4. 5
      db/migrate/20220630154441_add_location_to_case_log.rb
  5. 9
      db/schema.rb
  6. 2
      spec/models/form/setup/questions/location_spec.rb

1
app/models/case_log.rb

@ -36,6 +36,7 @@ class CaseLog < ApplicationRecord
belongs_to :managing_organisation, class_name: "Organisation", optional: true belongs_to :managing_organisation, class_name: "Organisation", optional: true
belongs_to :created_by, class_name: "User", optional: true belongs_to :created_by, class_name: "User", optional: true
belongs_to :scheme, optional: true belongs_to :scheme, optional: true
belongs_to :location, optional: true
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :filter_by_status, ->(status, _user = nil) { where status: } scope :filter_by_status, ->(status, _user = nil) { where status: }

21
app/models/form/setup/questions/location.rb

@ -3,16 +3,29 @@ class Form::Setup::Questions::Location < ::Form::Question
super super
@id = "location" @id = "location"
@check_answer_label = "Location" @check_answer_label = "Location"
@header = "Which location used by is this log for?" @header = "Which location is this log for?"
@hint_text = "" @hint_text = ""
@type = "radio" @type = "radio"
@answer_options = location_answers
@derived = true unless FeatureToggle.supported_housing_schemes_enabled? @derived = true unless FeatureToggle.supported_housing_schemes_enabled?
@page = page @page = page
@answer_options = answer_options
end end
def location_answers def answer_options
{} answer_opts = {}
return answer_opts unless ActiveRecord::Base.connected?
Location.select(:id, :postcode).each_with_object(answer_opts) do |location, hsh|
hsh[location.id] = location.postcode
hsh
end
end
def displayed_answer_options(case_log)
return {} unless case_log.scheme
scheme_location_ids = Location.where("scheme_id = #{case_log.scheme.id}").map(&:id)
answer_options.select { |k, _v| scheme_location_ids.include?(k) }
end end
def hidden_in_check_answers?(case_log, _current_user = nil) def hidden_in_check_answers?(case_log, _current_user = nil)

4
app/models/form/setup/questions/scheme_id.rb

@ -13,7 +13,7 @@ class Form::Setup::Questions::SchemeId < ::Form::Question
return answer_opts unless ActiveRecord::Base.connected? return answer_opts unless ActiveRecord::Base.connected?
Scheme.select(:id, :service_name).each_with_object(answer_opts) do |scheme, hsh| Scheme.select(:id, :service_name).each_with_object(answer_opts) do |scheme, hsh|
hsh[scheme.id] = scheme.service_name hsh[scheme.id.to_s] = scheme.service_name
hsh hsh
end end
end end
@ -21,7 +21,7 @@ class Form::Setup::Questions::SchemeId < ::Form::Question
def displayed_answer_options(case_log) def displayed_answer_options(case_log)
return {} unless case_log.created_by return {} unless case_log.created_by
user_org_scheme_ids = Scheme.where("organisation_id = #{case_log.created_by.organisation_id}").map(&:id) user_org_scheme_ids = Scheme.where(organisation_id: case_log.created_by.organisation_id).map(&:id).map(&:to_s)
answer_options.select { |k, _v| user_org_scheme_ids.include?(k) } answer_options.select { |k, _v| user_org_scheme_ids.include?(k) }
end end

5
db/migrate/20220630154441_add_location_to_case_log.rb

@ -0,0 +1,5 @@
class AddLocationToCaseLog < ActiveRecord::Migration[7.0]
def change
add_reference :case_logs, :location, foreign_key: true
end
end

9
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_06_17_102313) do ActiveRecord::Schema[7.0].define(version: 2022_06_30_154441) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -191,15 +191,17 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_17_102313) do
t.integer "joint" t.integer "joint"
t.bigint "created_by_id" t.bigint "created_by_id"
t.integer "illness_type_0" t.integer "illness_type_0"
t.integer "retirement_value_check"
t.integer "tshortfall_known" t.integer "tshortfall_known"
t.integer "sheltered" t.integer "sheltered"
t.integer "retirement_value_check"
t.integer "pregnancy_value_check" t.integer "pregnancy_value_check"
t.integer "hhtype" t.integer "hhtype"
t.integer "new_old" t.integer "new_old"
t.integer "vacdays" t.integer "vacdays"
t.bigint "scheme_id" t.bigint "scheme_id"
t.bigint "location_id"
t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id"
t.index ["location_id"], name: "index_case_logs_on_location_id"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"
@ -251,7 +253,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_17_102313) do
create_table "logs_exports", force: :cascade do |t| create_table "logs_exports", force: :cascade do |t|
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }
t.datetime "started_at", null: false t.datetime "started_at", precision: nil, null: false
t.integer "base_number", default: 1, null: false t.integer "base_number", default: 1, null: false
t.integer "increment_number", default: 1, null: false t.integer "increment_number", default: 1, null: false
t.boolean "empty_export", default: false, null: false t.boolean "empty_export", default: false, null: false
@ -367,6 +369,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_17_102313) do
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
end end
add_foreign_key "case_logs", "locations"
add_foreign_key "case_logs", "schemes" add_foreign_key "case_logs", "schemes"
add_foreign_key "locations", "schemes" add_foreign_key "locations", "schemes"
add_foreign_key "schemes", "organisations" add_foreign_key "schemes", "organisations"

2
spec/models/form/setup/questions/location_spec.rb

@ -16,7 +16,7 @@ RSpec.describe Form::Setup::Questions::Location, type: :model do
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("Which location used by #{scheme.service_name} is this log for?") expect(question.header).to eq("Which location is this log for?")
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do

Loading…
Cancel
Save