diff --git a/app/controllers/organizations/staff/default_pet_tasks_controller.rb b/app/controllers/organizations/staff/default_pet_tasks_controller.rb index 391616e2d..bbe01f5d9 100644 --- a/app/controllers/organizations/staff/default_pet_tasks_controller.rb +++ b/app/controllers/organizations/staff/default_pet_tasks_controller.rb @@ -5,7 +5,7 @@ class Organizations::Staff::DefaultPetTasksController < Organizations::BaseContr layout "dashboard" def index - @default_pet_tasks = authorized_scope(DefaultPetTask.all) + @default_pet_tasks = authorized_scope(DefaultPetTask.all).sort_by { |task| task.species } end def new @@ -43,7 +43,7 @@ def destroy private def task_params - params.require(:default_pet_task).permit(:name, :description, :due_in_days, :recurring) + params.require(:default_pet_task).permit(:name, :description, :due_in_days, :species, :recurring) end def set_task diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 52585047a..d49c06aff 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -7,4 +7,14 @@ def human_enum_name(enum) value = send(enum) I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{enum_i18n_key}.#{value}") end + + def self.human_enum_names(enum) + enum_i18n_key = enum.to_s.singularize + names = [] + send(enum).each_key do |key| + names << I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{enum_i18n_key}.#{key}") + end + + names + end end diff --git a/app/models/default_pet_task.rb b/app/models/default_pet_task.rb index 7694e3fd0..0bc226d04 100644 --- a/app/models/default_pet_task.rb +++ b/app/models/default_pet_task.rb @@ -7,6 +7,7 @@ # due_in_days :integer # name :string not null # recurring :boolean default(FALSE) +# species :integer # created_at :datetime not null # updated_at :datetime not null # organization_id :bigint not null @@ -24,4 +25,6 @@ class DefaultPetTask < ApplicationRecord validates :name, presence: true validates_numericality_of :due_in_days, only_integer: true, greater_than_or_equal_to: 0, allow_nil: true + + enum :species, ["All", *Pet.species.keys], default: 0 end diff --git a/app/models/pet.rb b/app/models/pet.rb index e254dea1b..78de93673 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -62,7 +62,7 @@ class Pet < ApplicationRecord validate :sensible_placement_type - enum species: ["Dog", "Cat"] + enum species: {"Dog" => 1, "Cat" => 2} enum placement_type: ["Adoptable", "Fosterable", "Adoptable and Fosterable"] WEIGHT_UNIT_LB = "lb".freeze diff --git a/app/services/organizations/default_pet_task_service.rb b/app/services/organizations/default_pet_task_service.rb index 0ccd117d5..b9f79d6d2 100644 --- a/app/services/organizations/default_pet_task_service.rb +++ b/app/services/organizations/default_pet_task_service.rb @@ -2,7 +2,7 @@ class Organizations::DefaultPetTaskService def initialize(pet) @pet = pet - @default_pet_tasks = DefaultPetTask.all + @default_pet_tasks = DefaultPetTask.where(species: DefaultPetTask.species.values_at("All", pet.species)) end def default_tasks_array diff --git a/app/views/organizations/staff/default_pet_tasks/_form.html.erb b/app/views/organizations/staff/default_pet_tasks/_form.html.erb index 41ea31ba6..5dc5bc358 100644 --- a/app/views/organizations/staff/default_pet_tasks/_form.html.erb +++ b/app/views/organizations/staff/default_pet_tasks/_form.html.erb @@ -7,6 +7,12 @@
<%= f.text_area :description, class: 'form-control', rows: 3 %>
+
+ <%= f.select :species, + options_for_select(DefaultPetTask.human_enum_names(:species), task.human_enum_name(:species)), + { prompt: t('general.please_select') }, + { class: 'form-control' } %> +
<%= f.number_field :due_in_days, class: 'form-control', help: 'The task will be due this number of days after the pet is created.' %>
diff --git a/app/views/organizations/staff/default_pet_tasks/index.html.erb b/app/views/organizations/staff/default_pet_tasks/index.html.erb index 883934cb3..bfb2b5347 100644 --- a/app/views/organizations/staff/default_pet_tasks/index.html.erb +++ b/app/views/organizations/staff/default_pet_tasks/index.html.erb @@ -13,10 +13,21 @@ - - - - + + + + + @@ -29,6 +40,9 @@ + diff --git a/config/locales/en.yml b/config/locales/en.yml index ca7ed6b5c..88a0a0381 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -355,6 +355,12 @@ en: withdrawn: Withdrawn successful_applicant: Successful Applicant adoption_made: Adoption Made + default_pet_task: + species: + one: "Species" + All: All + Dog: Dog + Cat: Cat errors: attributes: general: @@ -442,9 +448,15 @@ en: error: "Default Pet Task not found." error: "Default Pet Task not found." index: + name: "Name" + description: "Description" + species: "Species" + due_after: "Due After" + recurring: "Recurring" default_pet_tasks: "Default Pet Tasks" create_default_task: "Create Default Task" are_you_sure_delete: "Are you sure you want to delete this default pet task?" + new: new_default_pet_task: "New Default Pet Task" edit: diff --git a/db/migrate/20240529060957_add_species_to_default_pet_tasks.rb b/db/migrate/20240529060957_add_species_to_default_pet_tasks.rb new file mode 100644 index 000000000..f113d713b --- /dev/null +++ b/db/migrate/20240529060957_add_species_to_default_pet_tasks.rb @@ -0,0 +1,5 @@ +class AddSpeciesToDefaultPetTasks < ActiveRecord::Migration[7.1] + def change + add_column :default_pet_tasks, :species, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 0c1786399..cfbc6806f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -129,6 +129,7 @@ t.datetime "updated_at", null: false t.integer "due_in_days" t.boolean "recurring", default: false + t.integer "species" t.index ["organization_id"], name: "index_default_pet_tasks_on_organization_id" end diff --git a/db/seeds/01_alta.rb b/db/seeds/01_alta.rb index 401f7029d..94eed7cec 100644 --- a/db/seeds/01_alta.rb +++ b/db/seeds/01_alta.rb @@ -328,7 +328,7 @@ weight_unit: Pet::WEIGHT_UNITS.sample, breed: Faker::Creature::Dog.breed, description: "He just loves a run and a bum scratch at the end of the day", - species: 0, + species: Pet.species["Dog"], placement_type: 0, published: true ) @@ -362,7 +362,7 @@ weight_unit: Pet::WEIGHT_UNITS.sample, breed: Faker::Creature::Dog.breed, description: Faker::Lorem.sentence, - species: 0, + species: Pet.species["Dog"], placement_type: "Fosterable", published: true ) diff --git a/db/seeds/02_baja.rb b/db/seeds/02_baja.rb index 2fd692794..0dd34c7c3 100644 --- a/db/seeds/02_baja.rb +++ b/db/seeds/02_baja.rb @@ -281,7 +281,7 @@ weight_unit: Pet::WEIGHT_UNITS.sample, breed: Faker::Creature::Dog.breed, description: "He just loves a run and a bum scratch at the end of the day", - species: 0, + species: Pet.species["Dog"], placement_type: 1, published: true ) @@ -315,7 +315,7 @@ weight_unit: Pet::WEIGHT_UNITS.sample, breed: Faker::Creature::Dog.breed, description: Faker::Lorem.sentence, - species: 0, + species: Pet.species["Dog"], placement_type: "Fosterable", published: true ) diff --git a/test/factories/pets.rb b/test/factories/pets.rb index 000e8b8e8..e73605435 100644 --- a/test/factories/pets.rb +++ b/test/factories/pets.rb @@ -8,7 +8,7 @@ placement_type { "Adoptable and Fosterable" } published { true } sex { Faker::Creature::Dog.gender } - species { Faker::Number.within(range: 0..1) } + species { Faker::Number.within(range: 1..2) } weight_from { 10 } weight_to { 20 } weight_unit { "lb" }
NameDescriptionDue AfterRecurring + <%= t('.name') %> + + <%= t('.description') %> + + <%= t('.species') %> + + <%= t('.due_after') %> + + <%= t('.recurring') %> +
<%= task.description %> + <%= task.human_enum_name(:species) %> + <%= task.due_in_days ? pluralize(task.due_in_days, "day") : "" %>