Skip to content

Commit

Permalink
Remove dynamic category list for requirements
Browse files Browse the repository at this point in the history
Just use a static based on the document tags
  • Loading branch information
pixeltrix committed Feb 18, 2025
1 parent 06e3f8e commit 3203bf3
Show file tree
Hide file tree
Showing 29 changed files with 87 additions and 496 deletions.
1 change: 0 additions & 1 deletion app/models/local_authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class LocalAuthority < ApplicationRecord
with_options dependent: :destroy do
has_many :users
has_many :planning_applications, -> { kept }
has_many :categories
has_many :constraints
has_many :contacts
has_many :informatives
Expand Down
48 changes: 0 additions & 48 deletions app/models/local_authority/category.rb

This file was deleted.

4 changes: 4 additions & 0 deletions app/models/local_authority/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

class LocalAuthority < ApplicationRecord
class Requirement < ApplicationRecord
enum :category, %i[drawings evidence supporting_documents other].index_with(&:to_s)

belongs_to :local_authority

validates :category, presence: true

validates :description,
uniqueness: {scope: :local_authority},
presence: true
Expand Down
1 change: 1 addition & 0 deletions app/views/requirements/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

json.array! @requirements do |requirement|
json.category t(requirement.category, scope: :"requirements.categories")
json.description requirement.description
json.guidelines requirement.guidelines
json.url requirement.url
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,12 @@ en:
resend_message_label: Additional message to include in the email (optional)
send: No, I’m sending to new consultees
refused: Refused
requirements:
categories:
drawings: Drawings
evidence: evidence
other: Other requirements
supporting_documents: Supporting documents
response_tag_component:
privacy: Privacy
review:
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20250218155701_drop_local_authority_categories_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

class DropLocalAuthorityCategoriesTable < ActiveRecord::Migration[7.2]
def change
safety_assured do
drop_table :local_authority_categories do |t|
t.references :local_authority, null: false, index: true, foreign_key: true
t.string :description, null: false
t.virtual :search, type: :tsvector, as: category_sql, stored: true

t.timestamps

t.index [:local_authority_id, :description], unique: true
t.index [:local_authority_id, :search], using: :gin
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

class AddCategoryToLocalAuthorityRequirement < ActiveRecord::Migration[7.2]
class LocalAuthorityRequirement < ActiveRecord::Base; end

def change
safety_assured do
add_column :local_authority_requirements, :category, :string, limit: 30

up_only do
LocalAuthorityRequirement.find_each do |requirement|
requirement.update!(category: "other")
end

change_column_null :local_authority_requirements, :category, false
end
end
end
end
15 changes: 2 additions & 13 deletions 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.2].define(version: 2025_02_13_184646) do
ActiveRecord::Schema[7.2].define(version: 2025_02_18_160812) do
# These are extensions that must be enabled in order to support this database
enable_extension "btree_gin"
enable_extension "plpgsql"
Expand Down Expand Up @@ -513,17 +513,6 @@
t.index ["subdomain"], name: "index_local_authorities_on_subdomain", unique: true
end

create_table "local_authority_categories", force: :cascade do |t|
t.bigint "local_authority_id", null: false
t.string "description", null: false
t.virtual "search", type: :tsvector, as: "to_tsvector('simple'::regconfig, (description)::text)", stored: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["local_authority_id", "description"], name: "ix_local_authority_categories_on_local_authority_id__descriptio", unique: true
t.index ["local_authority_id", "search"], name: "ix_local_authority_categories_on_local_authority_id__search", using: :gin
t.index ["local_authority_id"], name: "ix_local_authority_categories_on_local_authority_id"
end

create_table "local_authority_informatives", force: :cascade do |t|
t.bigint "local_authority_id"
t.string "title"
Expand Down Expand Up @@ -587,6 +576,7 @@
t.virtual "search", type: :tsvector, as: "to_tsvector('simple'::regconfig, (description)::text)", stored: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "category", limit: 30, null: false
t.index ["local_authority_id", "description"], name: "ix_local_authority_requirements_on_local_authority_id__descript", unique: true
t.index ["local_authority_id", "search"], name: "ix_local_authority_requirements_on_local_authority_id__search", using: :gin
t.index ["local_authority_id"], name: "ix_local_authority_requirements_on_local_authority_id"
Expand Down Expand Up @@ -1174,7 +1164,6 @@
add_foreign_key "evidence_groups", "immunity_details"
add_foreign_key "fee_calculations", "planning_applications"
add_foreign_key "immunity_details", "planning_applications"
add_foreign_key "local_authority_categories", "local_authorities"
add_foreign_key "local_authority_policy_areas", "local_authorities"
add_foreign_key "local_authority_policy_areas_references", "local_authority_policy_areas", column: "policy_area_id"
add_foreign_key "local_authority_policy_areas_references", "local_authority_policy_references", column: "policy_reference_id"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def requirement_params
end

def requirement_attributes
%i[description guidelines url]
%i[category description guidelines url]
end
end
end

This file was deleted.

This file was deleted.

24 changes: 0 additions & 24 deletions engines/bops_admin/app/views/bops_admin/categories/edit.html.erb

This file was deleted.

54 changes: 0 additions & 54 deletions engines/bops_admin/app/views/bops_admin/categories/index.html.erb

This file was deleted.

Loading

0 comments on commit 3203bf3

Please sign in to comment.