Make project compile again
This commit also adds a few other files that I've been working on, although most of it will get deleted again. This is just so I have them logged in git.
This commit is contained in:
parent
2da41951e1
commit
bff0656806
7 changed files with 180 additions and 21 deletions
|
|
@ -1,10 +1,13 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
|
||||
module TaskMachine.Database
|
||||
module TaskMachine.Database where
|
||||
{-
|
||||
( TaskRow(..)
|
||||
, IntFormula(..)
|
||||
, BoolFormula(..)
|
||||
, TaskID
|
||||
, Duration
|
||||
, initializeNewDB
|
||||
, updateTasks
|
||||
, selectRelevantTasks
|
||||
|
|
@ -58,11 +61,12 @@ instance DB.FromField BoolFormula where
|
|||
Just expr -> DB.Ok BoolFormula{ boolFormulaText = text, boolFormulaExpr = expr }
|
||||
|
||||
type TaskID = Integer
|
||||
type Duration = Integer
|
||||
|
||||
data TaskRow = TaskRow
|
||||
{ rowID :: TaskID
|
||||
, rowDeadline :: Maybe Day
|
||||
, rowDuration :: Integer -- If there is no deadline, the duration is irrelevant
|
||||
, rowDuration :: Maybe Integer -- If there is no deadline, duration is irrelevant
|
||||
, rowBoolFormula :: Maybe BoolFormula -- Deadline formula
|
||||
, rowIntFormula :: Maybe IntFormula -- Info formula (e. g. age for birthdays)
|
||||
, rowDescription :: T.Text
|
||||
|
|
@ -228,3 +232,4 @@ doTask c taskID = DB.execute c incrementTotal (DB.Only taskID)
|
|||
\ SET repetitions_done = repetitions_done + 1\
|
||||
\ WHERE id = ?\
|
||||
\ AND repetitions_done < repetitions_total"
|
||||
-}
|
||||
|
|
|
|||
93
src/TaskMachine/Task.hs
Normal file
93
src/TaskMachine/Task.hs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
{-# LANGUAGE RecordWildCards #-}
|
||||
|
||||
-- | Task related stuff.
|
||||
--
|
||||
-- This module will be used by both the UI and the database modules.
|
||||
-- It contains some functionality independent of any of those modules.
|
||||
--
|
||||
-- (Although I don't really know what exactly that will be.)
|
||||
|
||||
module TaskMachine.Task
|
||||
( Task(..)
|
||||
, Subtask(..)
|
||||
) where
|
||||
|
||||
import qualified Data.Text as T
|
||||
|
||||
import qualified TaskMachine.DateExpr as TM
|
||||
import qualified TaskMachine.Deadline as TM
|
||||
|
||||
type SubtaskID = Integer
|
||||
|
||||
data Subtask = Subtask
|
||||
{ subID :: SubtaskID
|
||||
, subLabel :: T.Text
|
||||
, subRepetitionsTotal :: Integer
|
||||
, subRepetitionsDone :: Integer
|
||||
}
|
||||
|
||||
type TaskID = Integer
|
||||
|
||||
data Task = Task
|
||||
{ taskID :: TaskID
|
||||
, taskDeadlines :: [TM.Deadline]
|
||||
, taskFormula :: Maybe TM.IntExpr
|
||||
, taskDescription :: T.Text
|
||||
, taskDetails :: T.Text
|
||||
, taskSubtasks :: [Subtask]
|
||||
}
|
||||
|
||||
{-
|
||||
( Task(..)
|
||||
, Deadline(..)
|
||||
, fromTaskRow
|
||||
, toTaskRow
|
||||
) where
|
||||
|
||||
import qualified Data.Text as T
|
||||
import Data.Time.Calendar
|
||||
|
||||
import qualified TaskMachine.Database as TM
|
||||
|
||||
data Task = Task
|
||||
{ taskID :: TM.TaskID
|
||||
, taskDeadline :: Deadline
|
||||
, taskIntFormula :: Maybe TM.IntFormula
|
||||
, taskDescription :: T.Text
|
||||
, taskDetails :: T.Text
|
||||
, taskRepetitionsTotal :: Integer
|
||||
, taskRepetitionsDone :: Integer
|
||||
}
|
||||
|
||||
data Deadline
|
||||
= DeadlineNone
|
||||
| DeadlineDay Day (Maybe TM.Duration)
|
||||
| DeadlineFormula TM.BoolFormula TM.Duration
|
||||
|
||||
getDeadline :: TM.TaskRow -> Deadline
|
||||
getDeadline row = case TM.rowBoolFormula row of
|
||||
Just formula -> DeadlineFormula formula $ fromMaybe 1 $ TM.rowDuration row
|
||||
Nothing -> case TM.rowDeadline row of
|
||||
Just day -> DeadlineDay day $ TM.rowDuration row
|
||||
Nothing -> DeadlineNone
|
||||
|
||||
fromTaskRow :: TM.TaskRow -> Task
|
||||
fromTaskRow row =
|
||||
let taskID = TM.rowID row
|
||||
taskDeadline = getDeadline row
|
||||
taskIntFormula = TM.rowIntFormula row
|
||||
taskDescription = TM.rowDescription row
|
||||
taskDetails = TM.rowDetails row
|
||||
taskRepetitionsTotal = TM.rowRepetitionsTotal
|
||||
taskRepetitionsDone = TM.rowRepetitionsDone
|
||||
in Task{..}
|
||||
|
||||
toTaskRow :: Task -> TM.TaskRow
|
||||
toTaskRow task = undefined task
|
||||
|
||||
nextDeadline :: Day -> Deadline -> Maybe Day
|
||||
updateDeadline (DeadlineFormula formula duration) =
|
||||
let expr = boolFormulaExpr formula
|
||||
in Just $ TM.findNext expr day duration
|
||||
updateDeadline _ = Nothing
|
||||
-}
|
||||
|
|
@ -4,11 +4,26 @@ module TaskMachine.UI where
|
|||
|
||||
import Data.Monoid
|
||||
|
||||
import qualified Brick as B
|
||||
import qualified Brick.Themes as B
|
||||
import qualified Graphics.Vty as VTY
|
||||
import qualified Brick as B
|
||||
import qualified Brick.Themes as B
|
||||
import qualified Database.SQLite.Simple as DB
|
||||
import qualified Graphics.Vty as VTY
|
||||
|
||||
import qualified TaskMachine.Config as TM
|
||||
import qualified TaskMachine.Config as TM
|
||||
--import qualified TaskMachine.UI.ListScreen as TM
|
||||
|
||||
data ResourceName = Asdf
|
||||
deriving (Eq, Ord)
|
||||
|
||||
data UIState = UIState
|
||||
{ uiConfig :: TM.Config
|
||||
, uiDBConnection :: DB.Connection
|
||||
, uiScreenState :: ScreenState
|
||||
}
|
||||
|
||||
data ScreenState
|
||||
= Dummy
|
||||
-- = ScreenList TM.ListScreen
|
||||
|
||||
defaultTheme :: B.Theme
|
||||
defaultTheme = B.newTheme VTY.defAttr
|
||||
|
|
@ -17,13 +32,6 @@ defaultTheme = B.newTheme VTY.defAttr
|
|||
]
|
||||
where withStyle = flip VTY.withStyle
|
||||
|
||||
data ResourceName = Asdf
|
||||
deriving (Eq, Ord)
|
||||
|
||||
data State = State
|
||||
{ sConfig :: TM.Config
|
||||
}
|
||||
|
||||
myApp :: B.App () () ResourceName
|
||||
myApp = B.App
|
||||
{ B.appDraw = \_ -> [myTestWidget]
|
||||
|
|
|
|||
42
src/TaskMachine/UI/ListScreen.hs
Normal file
42
src/TaskMachine/UI/ListScreen.hs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
module TaskMachine.UI.ListScreen where
|
||||
{-
|
||||
( ListScreen
|
||||
, newListScreen
|
||||
, renderListScreen
|
||||
, updateListScreen
|
||||
) where
|
||||
|
||||
import qualified Brick as B
|
||||
import qualified Brick.Widgets.List as B
|
||||
import Data.Time
|
||||
import qualified Graphics.Vty.Input.Events as VTY
|
||||
import qualified Data.Vector as V
|
||||
import qualified Database.SQLite.Simple as DB
|
||||
|
||||
import qualified TaskMachine.Database as TM
|
||||
import qualified TaskMachine.Task as TM
|
||||
import qualified TaskMachine.UI.Types as TM
|
||||
|
||||
type Res = TM.ResourceName
|
||||
|
||||
newtype ListScreen = ListScreen (B.List Res TM.Task)
|
||||
|
||||
newListScreen :: DB.Connection -> IO ListScreen
|
||||
newListScreen conn = do
|
||||
today <- utctDay <$> getCurrentTime
|
||||
relevant <- map TM.fromTaskRow <$> TM.selectRelevantTasks conn today
|
||||
let sorted = relevant -- TM.sort??? relevant
|
||||
vector = V.fromList sorted
|
||||
list = B.list TM.RTaskList vector 1
|
||||
return $ ListScreen list
|
||||
|
||||
renderTask :: Bool -> TM.Task -> B.Widget Res
|
||||
renderTask _ task = B.txt $ TM.taskDescription task
|
||||
|
||||
renderListScreen :: Bool -> ListScreen -> B.Widget Res
|
||||
renderListScreen focused (ListScreen list) = B.renderList renderTask focused list
|
||||
|
||||
updateListScreen :: VTY.Event -> ListScreen -> B.EventM Res ListScreen
|
||||
updateListScreen event (ListScreen list) =
|
||||
ListScreen <$> B.handleListEventVi B.handleListEvent event list
|
||||
-}
|
||||
7
src/TaskMachine/UI/Types.hs
Normal file
7
src/TaskMachine/UI/Types.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module TaskMachine.UI.Types
|
||||
( ResourceName(..)
|
||||
) where
|
||||
|
||||
data ResourceName
|
||||
= RTaskList
|
||||
deriving (Eq, Ord, Show)
|
||||
Loading…
Add table
Add a link
Reference in a new issue