Early bird field to db
This commit is contained in:
@@ -39,6 +39,7 @@ defmodule Osuuspuutarha.Orders.Order do
|
|||||||
field :pcode, :string
|
field :pcode, :string
|
||||||
field :phone, :string
|
field :phone, :string
|
||||||
field :split_invoice, :boolean, default: false
|
field :split_invoice, :boolean, default: false
|
||||||
|
field :early_bird, :boolean, default: false
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
@@ -58,7 +59,8 @@ defmodule Osuuspuutarha.Orders.Order do
|
|||||||
:email,
|
:email,
|
||||||
:is_member,
|
:is_member,
|
||||||
:split_invoice,
|
:split_invoice,
|
||||||
:even_weeks
|
:even_weeks,
|
||||||
|
:early_bird
|
||||||
])
|
])
|
||||||
|> validate_required([
|
|> validate_required([
|
||||||
:order_type,
|
:order_type,
|
||||||
@@ -71,7 +73,8 @@ defmodule Osuuspuutarha.Orders.Order do
|
|||||||
:phone,
|
:phone,
|
||||||
:email,
|
:email,
|
||||||
:is_member,
|
:is_member,
|
||||||
:split_invoice
|
:split_invoice,
|
||||||
|
:early_bird
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,14 +24,23 @@
|
|||||||
],
|
],
|
||||||
prompt: "Ei valintaa"
|
prompt: "Ei valintaa"
|
||||||
%>
|
%>
|
||||||
<%= if @action == :edit && @changeset.data.order_type == :everyother do %>
|
<%= error_tag f, :order_type %>
|
||||||
|
|
||||||
|
<%= if @action == :edit && (@changeset.data.order_type == :everyother || @changeset.data.order_type == :everyother_pikku) do %>
|
||||||
<div class="checkbox-container">
|
<div class="checkbox-container">
|
||||||
<%= checkbox f, :even_weeks, class: "checkbox" %>
|
<%= checkbox f, :even_weeks, class: "checkbox" %>
|
||||||
<%= label f, :even_weeks, "Parilliset viikot" %>
|
<%= label f, :even_weeks, "Parilliset viikot" %>
|
||||||
<%= error_tag f, :even_weeks %>
|
<%= error_tag f, :even_weeks %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= error_tag f, :order_type %>
|
|
||||||
|
<%= if @action == :edit do %>
|
||||||
|
<div class="checkbox-container">
|
||||||
|
<%= checkbox f, :early_bird, class: "checkbox" %>
|
||||||
|
<%= label f, :early_bird, "Early Bird" %>
|
||||||
|
<%= error_tag f, :early_bird %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= label f, :location, "Valitse jakopaikka" %>
|
<%= label f, :location, "Valitse jakopaikka" %>
|
||||||
<%= select f,
|
<%= select f,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ defmodule OsuuspuutarhaWeb.OrderLive.Index do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, _session, socket) do
|
def mount(_params, _session, socket) do
|
||||||
{:ok, assign(socket, :orders, Orders.list_orders())}
|
{:ok, assign(socket, :orders, Orders.get_sorted_by(:desc, :inserted_at))}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|||||||
@@ -84,6 +84,13 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</th>
|
</th>
|
||||||
<th class="table_header">
|
<th class="table_header">
|
||||||
|
<%= cond do %>
|
||||||
|
<% @live_action==:sorted_desc && @column==:early_bird -> %> <%= link "Early Bird? ↓" , to: Routes.order_index_path(@socket, :sorted_asc, :early_bird) %>
|
||||||
|
<% @live_action==:sorted_asc && @column==:early_bird -> %> <%= link "Early Bird? ↑" , to: Routes.order_index_path(@socket, :sorted_desc, :early_bird) %>
|
||||||
|
<% true -> %> <%= link "Early Bird?" , to: Routes.order_index_path(@socket, :sorted_asc, :early_bird) %>
|
||||||
|
<% end %>
|
||||||
|
</th>
|
||||||
|
<th class="table_header">
|
||||||
<%= cond do %>
|
<%= cond do %>
|
||||||
<% @live_action == :sorted_desc && @column == :inserted_at -> %> <%= link "Lisätty ↓", to: Routes.order_index_path(@socket, :sorted_asc, :inserted_at) %>
|
<% @live_action == :sorted_desc && @column == :inserted_at -> %> <%= link "Lisätty ↓", to: Routes.order_index_path(@socket, :sorted_asc, :inserted_at) %>
|
||||||
<% @live_action == :sorted_asc && @column == :inserted_at -> %> <%= link "Lisätty ↑", to: Routes.order_index_path(@socket, :sorted_desc, :inserted_at) %>
|
<% @live_action == :sorted_asc && @column == :inserted_at -> %> <%= link "Lisätty ↑", to: Routes.order_index_path(@socket, :sorted_desc, :inserted_at) %>
|
||||||
@@ -113,6 +120,7 @@
|
|||||||
<td><%= Osuuspuutarha.Orders.Parser.parse_boolean(order.is_member) %></td>
|
<td><%= Osuuspuutarha.Orders.Parser.parse_boolean(order.is_member) %></td>
|
||||||
<td><%= Osuuspuutarha.Orders.Parser.parse_boolean(order.split_invoice) %></td>
|
<td><%= Osuuspuutarha.Orders.Parser.parse_boolean(order.split_invoice) %></td>
|
||||||
<td><%= Osuuspuutarha.Orders.Parser.parse_boolean(order.even_weeks) %></td>
|
<td><%= Osuuspuutarha.Orders.Parser.parse_boolean(order.even_weeks) %></td>
|
||||||
|
<td><%= Osuuspuutarha.Orders.Parser.parse_boolean(order.early_bird) %></td>
|
||||||
<td><%= Osuuspuutarha.Orders.Parser.parse_date(order.inserted_at) %></td>
|
<td><%= Osuuspuutarha.Orders.Parser.parse_date(order.inserted_at) %></td>
|
||||||
<td><%= Osuuspuutarha.Orders.Parser.parse_date(order.updated_at) %></td>
|
<td><%= Osuuspuutarha.Orders.Parser.parse_date(order.updated_at) %></td>
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,9 @@
|
|||||||
|
|
||||||
<%= if @live_action in [:edit] do %>
|
<%= if @live_action in [:edit] do %>
|
||||||
<.modal return_to={Routes.order_show_path(@socket, :show, @order)}>
|
<.modal return_to={Routes.order_show_path(@socket, :show, @order)}>
|
||||||
<.live_component
|
<.live_component module={OsuuspuutarhaWeb.OrderLive.FormComponent} id={@order.id} title={@page_title}
|
||||||
module={OsuuspuutarhaWeb.OrderLive.FormComponent}
|
action={@live_action} submit_text="Tallenna" has_privacy_consent={false} order={@order}
|
||||||
id={@order.id}
|
return_to={Routes.order_show_path(@socket, :show, @order)} />
|
||||||
title={@page_title}
|
|
||||||
action={@live_action}
|
|
||||||
submit_text="Tallenna"
|
|
||||||
has_privacy_consent={false}
|
|
||||||
order={@order}
|
|
||||||
return_to={Routes.order_show_path(@socket, :show, @order)}
|
|
||||||
/>
|
|
||||||
</.modal>
|
</.modal>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
@@ -77,6 +70,11 @@
|
|||||||
<%= @order.even_weeks %>
|
<%= @order.even_weeks %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<strong>Early bird:</strong>
|
||||||
|
<%= @order.early_bird %>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<strong>Lisätty:</strong>
|
<strong>Lisätty:</strong>
|
||||||
<%= @order.inserted_at.day %>.<%= @order.inserted_at.month %>.<%= @order.inserted_at.year %>
|
<%= @order.inserted_at.day %>.<%= @order.inserted_at.month %>.<%= @order.inserted_at.year %>
|
||||||
@@ -89,5 +87,9 @@
|
|||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<span><%= live_patch "Muokkaa", to: Routes.order_show_path(@socket, :edit, @order), class: "button" %></span> |
|
<span>
|
||||||
<span><%= live_redirect "Takaisin", to: Routes.order_index_path(@socket, :index) %></span>
|
<%= live_patch "Muokkaa" , to: Routes.order_show_path(@socket, :edit, @order), class: "button" %>
|
||||||
|
</span> |
|
||||||
|
<span>
|
||||||
|
<%= live_redirect "Takaisin" , to: Routes.order_index_path(@socket, :index) %>
|
||||||
|
</span>
|
||||||
@@ -47,6 +47,7 @@ defmodule OsuuspuutarhaWeb.Exports.OrderView do
|
|||||||
Parser.parse_location(order.location),
|
Parser.parse_location(order.location),
|
||||||
Parser.parse_boolean(order.even_weeks),
|
Parser.parse_boolean(order.even_weeks),
|
||||||
Parser.parse_boolean(order.split_invoice),
|
Parser.parse_boolean(order.split_invoice),
|
||||||
|
Parser.parse_boolean(order.early_bird),
|
||||||
Parser.parse_date(order.inserted_at),
|
Parser.parse_date(order.inserted_at),
|
||||||
Parser.parse_date(order.updated_at)
|
Parser.parse_date(order.updated_at)
|
||||||
]
|
]
|
||||||
|
|||||||
9
priv/repo/migrations/20240116170443_add_early_bird.exs
Normal file
9
priv/repo/migrations/20240116170443_add_early_bird.exs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
defmodule Osuuspuutarha.Repo.Migrations.AddEarlyBird do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:orders) do
|
||||||
|
add :early_bird, :boolean, default: false, null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -8,7 +8,21 @@ defmodule Osuuspuutarha.OrdersTest do
|
|||||||
|
|
||||||
import Osuuspuutarha.OrdersFixtures
|
import Osuuspuutarha.OrdersFixtures
|
||||||
|
|
||||||
@invalid_attrs %{address: nil, city: nil, email: nil, even_weeks: nil, fname: nil, is_member: nil, lname: nil, location: nil, order_type: nil, pcode: nil, phone: nil, split_invoice: nil}
|
@invalid_attrs %{
|
||||||
|
address: nil,
|
||||||
|
city: nil,
|
||||||
|
email: nil,
|
||||||
|
even_weeks: nil,
|
||||||
|
fname: nil,
|
||||||
|
is_member: nil,
|
||||||
|
lname: nil,
|
||||||
|
location: nil,
|
||||||
|
order_type: nil,
|
||||||
|
pcode: nil,
|
||||||
|
phone: nil,
|
||||||
|
split_invoice: nil,
|
||||||
|
early_bird: nil
|
||||||
|
}
|
||||||
|
|
||||||
test "list_orders/0 returns all orders" do
|
test "list_orders/0 returns all orders" do
|
||||||
order = order_fixture()
|
order = order_fixture()
|
||||||
@@ -21,7 +35,21 @@ defmodule Osuuspuutarha.OrdersTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "create_order/1 with valid data creates a order" do
|
test "create_order/1 with valid data creates a order" do
|
||||||
valid_attrs = %{address: "some address", city: "some city", email: "some email", even_weeks: true, fname: "some fname", is_member: true, lname: "some lname", location: :koroinen, order_type: :full, pcode: "some pcode", phone: "some phone", split_invoice: true}
|
valid_attrs = %{
|
||||||
|
address: "some address",
|
||||||
|
city: "some city",
|
||||||
|
email: "some email",
|
||||||
|
even_weeks: true,
|
||||||
|
fname: "some fname",
|
||||||
|
is_member: true,
|
||||||
|
lname: "some lname",
|
||||||
|
location: :koroinen,
|
||||||
|
order_type: :full,
|
||||||
|
pcode: "some pcode",
|
||||||
|
phone: "some phone",
|
||||||
|
split_invoice: true,
|
||||||
|
early_bird: true
|
||||||
|
}
|
||||||
|
|
||||||
assert {:ok, %Order{} = order} = Orders.create_order(valid_attrs)
|
assert {:ok, %Order{} = order} = Orders.create_order(valid_attrs)
|
||||||
assert order.address == "some address"
|
assert order.address == "some address"
|
||||||
@@ -36,6 +64,7 @@ defmodule Osuuspuutarha.OrdersTest do
|
|||||||
assert order.pcode == "some pcode"
|
assert order.pcode == "some pcode"
|
||||||
assert order.phone == "some phone"
|
assert order.phone == "some phone"
|
||||||
assert order.split_invoice == true
|
assert order.split_invoice == true
|
||||||
|
assert order.early_bird == true
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create_order/1 with invalid data returns error changeset" do
|
test "create_order/1 with invalid data returns error changeset" do
|
||||||
@@ -44,7 +73,22 @@ defmodule Osuuspuutarha.OrdersTest do
|
|||||||
|
|
||||||
test "update_order/2 with valid data updates the order" do
|
test "update_order/2 with valid data updates the order" do
|
||||||
order = order_fixture()
|
order = order_fixture()
|
||||||
update_attrs = %{address: "some updated address", city: "some updated city", email: "some updated email", even_weeks: false, fname: "some updated fname", is_member: false, lname: "some updated lname", location: :ocean, order_type: :everyother, pcode: "some updated pcode", phone: "some updated phone", split_invoice: false}
|
|
||||||
|
update_attrs = %{
|
||||||
|
address: "some updated address",
|
||||||
|
city: "some updated city",
|
||||||
|
email: "some updated email",
|
||||||
|
even_weeks: false,
|
||||||
|
fname: "some updated fname",
|
||||||
|
is_member: false,
|
||||||
|
lname: "some updated lname",
|
||||||
|
location: :ocean,
|
||||||
|
order_type: :everyother,
|
||||||
|
pcode: "some updated pcode",
|
||||||
|
phone: "some updated phone",
|
||||||
|
split_invoice: false,
|
||||||
|
early_bird: false
|
||||||
|
}
|
||||||
|
|
||||||
assert {:ok, %Order{} = order} = Orders.update_order(order, update_attrs)
|
assert {:ok, %Order{} = order} = Orders.update_order(order, update_attrs)
|
||||||
assert order.address == "some updated address"
|
assert order.address == "some updated address"
|
||||||
@@ -59,6 +103,7 @@ defmodule Osuuspuutarha.OrdersTest do
|
|||||||
assert order.pcode == "some updated pcode"
|
assert order.pcode == "some updated pcode"
|
||||||
assert order.phone == "some updated phone"
|
assert order.phone == "some updated phone"
|
||||||
assert order.split_invoice == false
|
assert order.split_invoice == false
|
||||||
|
assert order.early_bird == false
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update_order/2 with invalid data returns error changeset" do
|
test "update_order/2 with invalid data returns error changeset" do
|
||||||
|
|||||||
@@ -4,9 +4,51 @@ defmodule OsuuspuutarhaWeb.OrderLiveTest do
|
|||||||
import Phoenix.LiveViewTest
|
import Phoenix.LiveViewTest
|
||||||
import Osuuspuutarha.OrdersFixtures
|
import Osuuspuutarha.OrdersFixtures
|
||||||
|
|
||||||
@create_attrs %{address: "some address", city: "some city", email: "some email", even_weeks: true, fname: "some fname", is_member: true, lname: "some lname", location: :koroinen, order_type: :full, pcode: "some pcode", phone: "some phone", split_invoice: true}
|
@create_attrs %{
|
||||||
@update_attrs %{address: "some updated address", city: "some updated city", email: "some updated email", even_weeks: false, fname: "some updated fname", is_member: false, lname: "some updated lname", location: :ocean, order_type: :everyother, pcode: "some updated pcode", phone: "some updated phone", split_invoice: false}
|
address: "some address",
|
||||||
@invalid_attrs %{address: nil, city: nil, email: nil, even_weeks: false, fname: nil, is_member: false, lname: nil, location: nil, order_type: nil, pcode: nil, phone: nil, split_invoice: false}
|
city: "some city",
|
||||||
|
email: "some email",
|
||||||
|
even_weeks: true,
|
||||||
|
fname: "some fname",
|
||||||
|
is_member: true,
|
||||||
|
lname: "some lname",
|
||||||
|
location: :koroinen,
|
||||||
|
order_type: :full,
|
||||||
|
pcode: "some pcode",
|
||||||
|
phone: "some phone",
|
||||||
|
split_invoice: true,
|
||||||
|
early_bird: true
|
||||||
|
}
|
||||||
|
@update_attrs %{
|
||||||
|
address: "some updated address",
|
||||||
|
city: "some updated city",
|
||||||
|
email: "some updated email",
|
||||||
|
even_weeks: false,
|
||||||
|
fname: "some updated fname",
|
||||||
|
is_member: false,
|
||||||
|
lname: "some updated lname",
|
||||||
|
location: :ocean,
|
||||||
|
order_type: :everyother,
|
||||||
|
pcode: "some updated pcode",
|
||||||
|
phone: "some updated phone",
|
||||||
|
split_invoice: false,
|
||||||
|
early_bird: false
|
||||||
|
}
|
||||||
|
@invalid_attrs %{
|
||||||
|
address: nil,
|
||||||
|
city: nil,
|
||||||
|
email: nil,
|
||||||
|
even_weeks: false,
|
||||||
|
fname: nil,
|
||||||
|
is_member: false,
|
||||||
|
lname: nil,
|
||||||
|
location: nil,
|
||||||
|
order_type: nil,
|
||||||
|
pcode: nil,
|
||||||
|
phone: nil,
|
||||||
|
split_invoice: false,
|
||||||
|
early_bird: false
|
||||||
|
}
|
||||||
|
|
||||||
defp create_order(_) do
|
defp create_order(_) do
|
||||||
order = order_fixture()
|
order = order_fixture()
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ defmodule Osuuspuutarha.OrdersFixtures do
|
|||||||
order_type: :full,
|
order_type: :full,
|
||||||
pcode: "some pcode",
|
pcode: "some pcode",
|
||||||
phone: "some phone",
|
phone: "some phone",
|
||||||
split_invoice: true
|
split_invoice: true,
|
||||||
|
early_bird: true
|
||||||
})
|
})
|
||||||
|> Osuuspuutarha.Orders.create_order()
|
|> Osuuspuutarha.Orders.create_order()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user