diff --git a/assets/css/live/yield.css b/assets/css/live/yield.css index 6a12396..0951858 100644 --- a/assets/css/live/yield.css +++ b/assets/css/live/yield.css @@ -7,3 +7,16 @@ .date-picker select { max-width: 8rem; } + +.new-yield-link a { + padding: 1em; +} + +.new-yield-link { + margin: 1.5em; + padding-top: 5px; + font-size: large; + font-weight: bold; + background-color: #e5e5ea; + border-radius: 5%; +} diff --git a/lib/osuuspuutarha/harvest/parser.ex b/lib/osuuspuutarha/harvest/parser.ex index bfa2bec..2e97955 100644 --- a/lib/osuuspuutarha/harvest/parser.ex +++ b/lib/osuuspuutarha/harvest/parser.ex @@ -114,4 +114,18 @@ defmodule Osuuspuutarha.Harvest.Parser do def parse_plant(:corn) do "Corn" end + + @spec parse_date(atom | %{:day => any, :month => any, :year => any, optional(any) => any}) :: + <<_::16, _::_*8>> + def parse_date(date) do + "#{date.day}.#{date.month}.#{date.year}" + end + + def parse_unit(:kg) do + "kg" + end + + def parse_unit(:kpl) do + "kpl" + end end diff --git a/lib/osuuspuutarha_web/controllers/exports/yield_controller.ex b/lib/osuuspuutarha_web/controllers/exports/yield_controller.ex new file mode 100644 index 0000000..39b3e66 --- /dev/null +++ b/lib/osuuspuutarha_web/controllers/exports/yield_controller.ex @@ -0,0 +1,14 @@ +defmodule OsuuspuutarhaWeb.Exports.YieldController do + use OsuuspuutarhaWeb, :controller + + alias Osuuspuutarha.Harvest + + def index(conn, _params) do + yields = Harvest.list_yields() + + conn + |> put_resp_content_type("text/xlsx") + |> put_resp_header("content-disposition", "attachment; filename=\"korjuut.xlsx\"") + |> render("korjuut.xlsx", %{yields: yields}) + end +end diff --git a/lib/osuuspuutarha_web/live/yield_live/index.html.heex b/lib/osuuspuutarha_web/live/yield_live/index.html.heex index 8639830..e5e8596 100644 --- a/lib/osuuspuutarha_web/live/yield_live/index.html.heex +++ b/lib/osuuspuutarha_web/live/yield_live/index.html.heex @@ -13,7 +13,9 @@ <% end %> -<%= live_patch "New Yield", to: Routes.yield_index_path(@socket, :new) %> +<%= live_patch "New Yield", to: Routes.yield_index_path(@socket, :new) %> + +<%= link "Download as Excel", to: Routes.exports_yield_path(@socket, :index) %>