diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-25 18:04:49 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-25 18:04:49 +0100 |
commit | f515803694d7f8430b064f16a5a923b09ba70650 (patch) | |
tree | 1e5104f784e28a41a4d030e23e0841bb1173cb22 /spec | |
parent | e6e3823982cb9755b7cb4727fb08171eed5b4332 (diff) | |
download | thermoprint-f515803694d7f8430b064f16a5a923b09ba70650.tar thermoprint-f515803694d7f8430b064f16a5a923b09ba70650.tar.gz thermoprint-f515803694d7f8430b064f16a5a923b09ba70650.tar.bz2 thermoprint-f515803694d7f8430b064f16a5a923b09ba70650.tar.xz thermoprint-f515803694d7f8430b064f16a5a923b09ba70650.zip |
Job/Printer list
Diffstat (limited to 'spec')
-rw-r--r-- | spec/src/Thermoprint/API.hs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index 3ffd239..5b9c266 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs | |||
@@ -7,7 +7,7 @@ | |||
7 | -- | A specification of an API for interacting with a set of printers | 7 | -- | A specification of an API for interacting with a set of printers |
8 | module Thermoprint.API | 8 | module Thermoprint.API |
9 | ( PrinterStatus(..) | 9 | ( PrinterStatus(..) |
10 | , JobStatus(..) | 10 | , JobStatus(..), queueSort |
11 | , PrintingError(..) | 11 | , PrintingError(..) |
12 | , DraftTitle | 12 | , DraftTitle |
13 | , Range(..), contains | 13 | , Range(..), contains |
@@ -25,6 +25,7 @@ import Data.Aeson | |||
25 | 25 | ||
26 | import Data.Monoid | 26 | import Data.Monoid |
27 | import Data.Maybe | 27 | import Data.Maybe |
28 | import Data.Function (on) | ||
28 | 29 | ||
29 | import Data.Set (Set) | 30 | import Data.Set (Set) |
30 | import Data.Map (Map) | 31 | import Data.Map (Map) |
@@ -70,6 +71,15 @@ data JobStatus = Queued PrinterId | |||
70 | | Failed PrintingError | 71 | | Failed PrintingError |
71 | deriving (Generic, Show, FromJSON, ToJSON) | 72 | deriving (Generic, Show, FromJSON, ToJSON) |
72 | 73 | ||
74 | queueSort :: JobStatus -> JobStatus -> Ordering | ||
75 | -- ^ Sort 'JobStatus' by their qualitative position in a printers queue | ||
76 | queueSort = compare `on` index | ||
77 | where | ||
78 | index (Queued _) = -1 | ||
79 | index (Printing _) = 0 | ||
80 | index Done = 1 | ||
81 | index (Failed _) = 1 | ||
82 | |||
73 | deriving instance Generic EncodingException | 83 | deriving instance Generic EncodingException |
74 | deriving instance NFData EncodingException | 84 | deriving instance NFData EncodingException |
75 | deriving instance FromJSON EncodingException | 85 | deriving instance FromJSON EncodingException |