Files
growstuff/app/serializers/seed_form_serializer.rb
T
Brenda WallaceandDaniel O'Connor 75595350bc Easier recording of harvests from the front page (#5077)
* Implement AddSeedsPicker component and enhance planting selection UI; update styles and serializers for better seed management

* Enhance PlantingPicker component: add hints and titles for harvest and seed actions; update test to reflect changes in seed saving behavior

* Enhance harvest recording: allow harvesting from crops without plantings; update forms and modals for better user experience

* Refactor code structure for improved readability and maintainability

* Remove AddSeedsPicker component and its associated tests

* Add planting picker functionality for harvesting and seed saving

- Introduced PlantingPickersController to handle JSON responses for member's plantings.
- Updated HomeHelper to include crop ID in planting picker properties.
- Refactored PlantPicker and PlantSomethingModal components to support multiple gardens.
- Created PlantingFlow component to manage planting actions (harvest and save seeds).
- Implemented RecordDialog component to handle server-rendered links for harvesting and seed saving.
- Updated various views to include data attributes for triggering the record dialog.
- Added routes for planting picker and corresponding request specs for testing.
- Adjusted styles in _plantings.scss for better layout and spacing.

* Add job management features including job creation and wishlist functionality

* Remove WishlistJobsController and associated views and tests

* Add suggestion links rendering and fix routes formatting

* Refactor AddJobModal and JobPicker components to simplify props and enhance user experience

* Update seed addition test to check dialog presence and current path

* Apply suggestion from @CloCkWeRX

---------

Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2026-10-26 21:38:12 +10:30

27 lines
1019 B
Ruby

# frozen_string_literal: true
# What the React save-seeds dialog needs to fill in its form: the crop and
# planting the seeds are from, today's date (they are being saved now), the
# choices for who they can be traded to, and where the member says they are, as
# trading is by location. Served by GET /plantings/:slug/seeds/new.json, and
# by GET /seeds/new.json?crop_id= for seeds with no planting.
class SeedFormSerializer
# Seeds saved without a planting (bought ones, say) are of a crop alone.
def initialize(planting, member:, crop: nil)
@planting = planting
@crop = planting&.crop || crop
@member = member
end
def as_json(*)
{
crop: { id: @crop.id, name: @crop.name },
parent_planting_id: @planting&.id,
saved_at: Time.zone.today,
tradable_to_values: Seed::TRADABLE_TO_VALUES,
location: @member.location.presence,
settings_url: Rails.application.routes.url_helpers.edit_member_registration_path
}
end
end