From 4016194ecb67fc843c3cc6350ae551d1bee317d2 Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Mon, 7 Sep 2015 03:03:23 +0200 Subject: [PATCH] added order-overview page. still needs tweaking and polish. --- Application.hs | 1 + Handler/Orders.hs | 64 +++++++++++++++++++++++++++ Handler/Update.hs | 2 +- config/routes | 1 + neat.cabal | 1 + templates/login-layout-wrapper.hamlet | 1 + test/Handler/OrdersSpec.hs | 10 +++++ test/Handler/ProfitItemsSpec.hs | 10 +++++ 8 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Handler/Orders.hs create mode 100644 test/Handler/OrdersSpec.hs create mode 100644 test/Handler/ProfitItemsSpec.hs diff --git a/Application.hs b/Application.hs index 08fc2c7..91ae1fd 100644 --- a/Application.hs +++ b/Application.hs @@ -37,6 +37,7 @@ import Handler.Settings import Handler.Update import Handler.Stock import Handler.ProfitItems +import Handler.Orders -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the diff --git a/Handler/Orders.hs b/Handler/Orders.hs new file mode 100644 index 0000000..3e0ae8d --- /dev/null +++ b/Handler/Orders.hs @@ -0,0 +1,64 @@ +{-# LANGUAGE ScopedTypeVariables #-} + +module Handler.Orders where + +import Import +import Database.Persist.Sql +import qualified Eve.Api.Char.MarketOrders as MO + +getOrdersR :: Handler Html +getOrdersR = loginOrDo (\(uid,user) -> do + -- using raw because model does not know about CCP-Data-Dump + let sql = "select ??, t.\"typeName\" from \"order\" join \"invTypes\" t on (\"order\".type_id = t.\"typeID\") where \"user\"=? order by \"order\".is_sell asc, t.\"typeName\" asc" + (orders :: [(Entity Order, Single Text)]) <- runDB $ rawSql sql [toPersistValue uid] + let sellorders = filter (\(Entity _ o, _) -> orderIsSell o && orderOrderState o == (fromIntegral . fromEnum) MO.Open) orders + let buyorders = filter (\(Entity _ o, _) -> not (orderIsSell o) && orderOrderState o == (fromIntegral . fromEnum) MO.Open) orders + loginLayout user [whamlet| +
+
Current Sell Orders: + + + +
Last changed + Item + Price + Quantity (min) + Range + Duration + Escrow + Station + $forall (Entity _ o, Single name) <- sellorders +
#{showDateTime $ orderIssued $ o} + #{name} + #{prettyISK $ orderPriceCents o} + #{orderVolRemaining o}/#{orderVolEntered o} (#{orderMinVolume o}) + Range + #{orderDuration o} + #{prettyISK $ orderEscrowCents o} + StationName + +
+
Current Buy Orders: + + + +
Last changed + Item + Price + Quantity (min) + Range + Duration + Escrow + Station + $forall (Entity _ o, Single name) <- buyorders +
#{showDateTime $ orderIssued $ o} + #{name} + #{prettyISK $ orderPriceCents o} + #{orderVolRemaining o}/#{orderVolEntered o} (#{orderMinVolume o}) + Range + #{orderDuration o} + #{prettyISK $ orderEscrowCents o} + StationName + + |] + ) diff --git a/Handler/Update.hs b/Handler/Update.hs index 7579b82..e549b51 100644 --- a/Handler/Update.hs +++ b/Handler/Update.hs @@ -108,7 +108,7 @@ getUpdateR = loginOrDo (\(uid,user) -> do update uid [UserOrderTimeout =. time'] --update escrow-worth (cache) let ordersql = "update \"user\" set \ - escrow_cents = COALESCE((select sum(escrow_cents) from \"order\" where \"user\"=\"user\".id),0) \ + escrow_cents = COALESCE((select sum(escrow_cents) from \"order\" where \"user\"=\"user\".id and \"order\".order_state=0),0) \ where id=?" rawExecute ordersql [toPersistValue uid] _ -> return () diff --git a/config/routes b/config/routes index f5c4fd9..5fd208b 100644 --- a/config/routes +++ b/config/routes @@ -13,3 +13,4 @@ /stock StockR GET /analysis/items ProfitItemsR GET /analysis/items/#Int64 ProfitItemsDetailsR GET +/orders OrdersR GET diff --git a/neat.cabal b/neat.cabal index 8d20698..3c3371c 100644 --- a/neat.cabal +++ b/neat.cabal @@ -27,6 +27,7 @@ library Handler.Update Handler.Stock Handler.ProfitItems + Handler.Orders if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT diff --git a/templates/login-layout-wrapper.hamlet b/templates/login-layout-wrapper.hamlet index f95d94b..3a61b10 100644 --- a/templates/login-layout-wrapper.hamlet +++ b/templates/login-layout-wrapper.hamlet @@ -46,6 +46,7 @@ $newline never