From f515803694d7f8430b064f16a5a923b09ba70650 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 25 Feb 2016 18:04:49 +0100 Subject: Job/Printer list --- spec/src/Thermoprint/API.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'spec/src/Thermoprint/API.hs') 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 @@ -- | A specification of an API for interacting with a set of printers module Thermoprint.API ( PrinterStatus(..) - , JobStatus(..) + , JobStatus(..), queueSort , PrintingError(..) , DraftTitle , Range(..), contains @@ -25,6 +25,7 @@ import Data.Aeson import Data.Monoid import Data.Maybe +import Data.Function (on) import Data.Set (Set) import Data.Map (Map) @@ -70,6 +71,15 @@ data JobStatus = Queued PrinterId | Failed PrintingError deriving (Generic, Show, FromJSON, ToJSON) +queueSort :: JobStatus -> JobStatus -> Ordering +-- ^ Sort 'JobStatus' by their qualitative position in a printers queue +queueSort = compare `on` index + where + index (Queued _) = -1 + index (Printing _) = 0 + index Done = 1 + index (Failed _) = 1 + deriving instance Generic EncodingException deriving instance NFData EncodingException deriving instance FromJSON EncodingException -- cgit v1.2.3