From 2e7937cbc36ed0c3ebb680b6bffab98ac3ea65f8 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 1 Jan 2020 21:35:37 -0500 Subject: [PATCH] ensure commission items are sorted by price --- .../controllers/profile/commission_controller.ex | 10 +++++++--- lib/textile/parser.ex | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/philomena_web/controllers/profile/commission_controller.ex b/lib/philomena_web/controllers/profile/commission_controller.ex index 80aacb58..ede16ef6 100644 --- a/lib/philomena_web/controllers/profile/commission_controller.ex +++ b/lib/philomena_web/controllers/profile/commission_controller.ex @@ -16,13 +16,17 @@ defmodule PhilomenaWeb.Profile.CommissionController do def show(conn, _params) do commission = conn.assigns.user.commission - item_descriptions = + items = commission.items + |> Enum.sort(&Decimal.cmp(&1.base_price, &2.base_price) != :gt) + + item_descriptions = + items |> Enum.map(&%{body: &1.description }) |> Renderer.render_collection(conn) item_add_ons = - commission.items + items |> Enum.map(&%{body: &1.add_ons}) |> Renderer.render_collection(conn) @@ -45,7 +49,7 @@ defmodule PhilomenaWeb.Profile.CommissionController do will_not_create: will_not_create } - items = Enum.zip([item_descriptions, item_add_ons, commission.items]) + items = Enum.zip([item_descriptions, item_add_ons, items]) render(conn, "show.html", title: "Showing Commission", rendered: rendered, commission: commission, items: items, layout_class: "layout--wide") end diff --git a/lib/textile/parser.ex b/lib/textile/parser.ex index 241fb02a..a11b457b 100644 --- a/lib/textile/parser.ex +++ b/lib/textile/parser.ex @@ -5,7 +5,7 @@ defmodule Textile.Parser do def parse(parser, input) do parser = Map.put(parser, :state, %{}) - with {:ok, tokens, _1, _2, _3, _4} <- Lexer.lex(String.trim(input)), + with {:ok, tokens, _1, _2, _3, _4} <- Lexer.lex(String.trim(input || "")), {:ok, tree, []} <- repeat(&textile/2, parser, tokens) do partial_flatten(tree)