Change to correct plant names
This commit is contained in:
49
lib/osuuspuutarha/harvest/parser.ex
Normal file
49
lib/osuuspuutarha/harvest/parser.ex
Normal file
@@ -0,0 +1,49 @@
|
||||
defmodule Osuuspuutarha.Harvest.Parser do
|
||||
def parse_plant(:lettuce) do
|
||||
"Lettuce"
|
||||
end
|
||||
|
||||
def parse_plant(:tomato) do
|
||||
"Tomato"
|
||||
end
|
||||
|
||||
def parse_plant(:cabbage) do
|
||||
"Cabbage"
|
||||
end
|
||||
|
||||
def parse_plant(:pumpkin) do
|
||||
"Pumpkin"
|
||||
end
|
||||
|
||||
def parse_plant(:zucchini) do
|
||||
"Zucchini"
|
||||
end
|
||||
|
||||
def parse_plant(:cucumber) do
|
||||
"Cucumber"
|
||||
end
|
||||
|
||||
def parse_plant(:melon) do
|
||||
"Melon"
|
||||
end
|
||||
|
||||
def parse_plant(:sweet_corn) do
|
||||
"Sweet Corn"
|
||||
end
|
||||
|
||||
def parse_plant(:bean) do
|
||||
"Bean"
|
||||
end
|
||||
|
||||
def parse_plant(:parsnip) do
|
||||
"Parsnip"
|
||||
end
|
||||
|
||||
def parse_plant(:carrot) do
|
||||
"Carrot"
|
||||
end
|
||||
|
||||
def parse_plant(:beetroot) do
|
||||
"Beetroot"
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,23 @@ defmodule Osuuspuutarha.Harvest.Yield do
|
||||
schema "yields" do
|
||||
field :amount, :decimal
|
||||
field :date, :date
|
||||
field :plant, Ecto.Enum, values: [:salad, :carrot, :cabbage]
|
||||
|
||||
field :plant, Ecto.Enum,
|
||||
values: [
|
||||
:lettuce,
|
||||
:tomato,
|
||||
:cabbage,
|
||||
:pumpkin,
|
||||
:zucchini,
|
||||
:cucumber,
|
||||
:melon,
|
||||
:sweet_corn,
|
||||
:bean,
|
||||
:parsnip,
|
||||
:carrot,
|
||||
:beetroot
|
||||
]
|
||||
|
||||
field :unit, Ecto.Enum, values: [:kg, :kpl]
|
||||
|
||||
timestamps()
|
||||
|
||||
@@ -13,13 +13,27 @@
|
||||
<%= label f, :date %>
|
||||
<div class="date-picker" >
|
||||
<%= date_select f, :date, default: DateTime.now!("Etc/UTC"), builder: fn b -> %>
|
||||
<%= b.(:day, []) %> / <%= b.(:month, options: [{"01", "1"}, "02", "03", "04", "05", {"06", "6"}, "07", "08", "09", "10", "11", "12"]) %> / <%= b.(:year, options: ["2023"]) %>
|
||||
<%= b.(:day, []) %> / <%= b.(:month, options: [{"01", "1"}, {"02", "2"}, {"03", "3"}, {"04", "4"}, {"05", "5"}, {"06", "6"}, {"07", "7"}, {"08", "8"}, {"09", "9"}, "10", "11", "12"]) %> / <%= b.(:year, options: ["2023"]) %>
|
||||
<% end %>
|
||||
<%= error_tag f, :date %>
|
||||
</div>
|
||||
|
||||
<%= label f, :plant %>
|
||||
<%= select f, :plant, Ecto.Enum.values(Osuuspuutarha.Harvest.Yield, :plant), prompt: "Choose a value" %>
|
||||
<%= select f, :plant, [
|
||||
"Lettuce": :lettuce,
|
||||
"Tomato": :tomato,
|
||||
"Cabbage": :cabbage,
|
||||
"Pumpkin": :pumpkin,
|
||||
"Zucchini": :zucchini,
|
||||
"Cucumber": :cucumber,
|
||||
"Melon": :melon,
|
||||
"Sweet Corn": :sweet_corn,
|
||||
"Bean": :bean,
|
||||
"Parsnip": :parsnip,
|
||||
"Carrot": :carrot,
|
||||
"Beetroot": :beetroot
|
||||
],
|
||||
prompt: "Choose a value" %>
|
||||
<%= error_tag f, :plant %>
|
||||
|
||||
<%= label f, :amount %>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<%= for yield <- @yields do %>
|
||||
<tr id={"yield-#{yield.id}"}>
|
||||
<td><%= yield.date.day %>.<%= yield.date.month %>.<%= yield.date.year %></td>
|
||||
<td><%= yield.plant %></td>
|
||||
<td><%= Osuuspuutarha.Harvest.Parser.parse_plant(yield.plant) %></td>
|
||||
<td><%= yield.amount %></td>
|
||||
<td><%= yield.unit %></td>
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<li>
|
||||
<strong>Plant:</strong>
|
||||
<%= @yield.plant %>
|
||||
<%= Osuuspuutarha.Harvest.Parser.parse_plant(@yield.plant) %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
@@ -21,12 +21,12 @@ defmodule Osuuspuutarha.HarvestTest do
|
||||
end
|
||||
|
||||
test "create_yield/1 with valid data creates a yield" do
|
||||
valid_attrs = %{amount: "120.5", date: ~D[2023-06-07], plant: :salad, unit: :kg}
|
||||
valid_attrs = %{amount: "120.5", date: ~D[2023-06-07], plant: :lettuce, unit: :kg}
|
||||
|
||||
assert {:ok, %Yield{} = yield} = Harvest.create_yield(valid_attrs)
|
||||
assert yield.amount == Decimal.new("120.5")
|
||||
assert yield.date == ~D[2023-06-07]
|
||||
assert yield.plant == :salad
|
||||
assert yield.plant == :lettuce
|
||||
assert yield.unit == :kg
|
||||
end
|
||||
|
||||
|
||||
@@ -4,8 +4,18 @@ defmodule OsuuspuutarhaWeb.YieldLiveTest do
|
||||
import Phoenix.LiveViewTest
|
||||
import Osuuspuutarha.HarvestFixtures
|
||||
|
||||
@create_attrs %{amount: "120.5", date: %{day: 7, month: 6, year: 2023}, plant: :salad, unit: :kg}
|
||||
@update_attrs %{amount: "456.7", date: %{day: 8, month: 6, year: 2023}, plant: :carrot, unit: :kpl}
|
||||
@create_attrs %{
|
||||
amount: "120.5",
|
||||
date: %{day: 7, month: 6, year: 2023},
|
||||
plant: :lettuce,
|
||||
unit: :kg
|
||||
}
|
||||
@update_attrs %{
|
||||
amount: "456.7",
|
||||
date: %{day: 8, month: 6, year: 2023},
|
||||
plant: :carrot,
|
||||
unit: :kpl
|
||||
}
|
||||
@invalid_attrs %{amount: nil, date: %{day: 30, month: 2, year: 2023}, plant: nil, unit: nil}
|
||||
|
||||
defp create_yield(_) do
|
||||
|
||||
@@ -13,7 +13,7 @@ defmodule Osuuspuutarha.HarvestFixtures do
|
||||
|> Enum.into(%{
|
||||
amount: "120.5",
|
||||
date: ~D[2023-06-07],
|
||||
plant: :salad,
|
||||
plant: :lettuce,
|
||||
unit: :kg
|
||||
})
|
||||
|> Osuuspuutarha.Harvest.create_yield()
|
||||
|
||||
Reference in New Issue
Block a user