Change to correct plant names

This commit is contained in:
2023-06-25 22:03:07 +03:00
parent 8d7b91abb0
commit ca47202a87
8 changed files with 99 additions and 10 deletions

View 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

View File

@@ -5,7 +5,23 @@ defmodule Osuuspuutarha.Harvest.Yield do
schema "yields" do schema "yields" do
field :amount, :decimal field :amount, :decimal
field :date, :date 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] field :unit, Ecto.Enum, values: [:kg, :kpl]
timestamps() timestamps()

View File

@@ -13,13 +13,27 @@
<%= label f, :date %> <%= label f, :date %>
<div class="date-picker" > <div class="date-picker" >
<%= date_select f, :date, default: DateTime.now!("Etc/UTC"), builder: fn b -> %> <%= 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 %> <% end %>
<%= error_tag f, :date %> <%= error_tag f, :date %>
</div> </div>
<%= label f, :plant %> <%= 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 %> <%= error_tag f, :plant %>
<%= label f, :amount %> <%= label f, :amount %>

View File

@@ -28,7 +28,7 @@
<%= for yield <- @yields do %> <%= for yield <- @yields do %>
<tr id={"yield-#{yield.id}"}> <tr id={"yield-#{yield.id}"}>
<td><%= yield.date.day %>.<%= yield.date.month %>.<%= yield.date.year %></td> <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.amount %></td>
<td><%= yield.unit %></td> <td><%= yield.unit %></td>

View File

@@ -22,7 +22,7 @@
<li> <li>
<strong>Plant:</strong> <strong>Plant:</strong>
<%= @yield.plant %> <%= Osuuspuutarha.Harvest.Parser.parse_plant(@yield.plant) %>
</li> </li>
<li> <li>

View File

@@ -21,12 +21,12 @@ defmodule Osuuspuutarha.HarvestTest do
end end
test "create_yield/1 with valid data creates a yield" do 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 {:ok, %Yield{} = yield} = Harvest.create_yield(valid_attrs)
assert yield.amount == Decimal.new("120.5") assert yield.amount == Decimal.new("120.5")
assert yield.date == ~D[2023-06-07] assert yield.date == ~D[2023-06-07]
assert yield.plant == :salad assert yield.plant == :lettuce
assert yield.unit == :kg assert yield.unit == :kg
end end

View File

@@ -4,8 +4,18 @@ defmodule OsuuspuutarhaWeb.YieldLiveTest do
import Phoenix.LiveViewTest import Phoenix.LiveViewTest
import Osuuspuutarha.HarvestFixtures import Osuuspuutarha.HarvestFixtures
@create_attrs %{amount: "120.5", date: %{day: 7, month: 6, year: 2023}, plant: :salad, unit: :kg} @create_attrs %{
@update_attrs %{amount: "456.7", date: %{day: 8, month: 6, year: 2023}, plant: :carrot, unit: :kpl} 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} @invalid_attrs %{amount: nil, date: %{day: 30, month: 2, year: 2023}, plant: nil, unit: nil}
defp create_yield(_) do defp create_yield(_) do

View File

@@ -13,7 +13,7 @@ defmodule Osuuspuutarha.HarvestFixtures do
|> Enum.into(%{ |> Enum.into(%{
amount: "120.5", amount: "120.5",
date: ~D[2023-06-07], date: ~D[2023-06-07],
plant: :salad, plant: :lettuce,
unit: :kg unit: :kg
}) })
|> Osuuspuutarha.Harvest.create_yield() |> Osuuspuutarha.Harvest.create_yield()