{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
module Villefort.New (makeNewPage) where
import Control.Monad.Reader (MonadReader,MonadIO,liftIO)
import Villefort.Definitions (VConfig(..))
import System.IO.Strict as S (readFile)
import Paths_Villefort (getDataFileName)
import Data.List.Split (splitOn)
import Villefort.Database (getSubjects)
makeNewPage :: (MonadReader VConfig m, MonadIO m) => m String
makeNewPage = do
headerPath <-liftIO $ getDataFileName "templates/header"
htmlHeader <- liftIO $ S.readFile headerPath
addPath <- liftIO $ getDataFileName "templates/add.html"
add <- liftIO $ S.readFile addPath
let splitWeeks = splitOn "?" add
subjects <- getSubjects
let radiobuttons = map makeRadio subjects
return (htmlHeader ++ (splitWeeks !! 0) ++ (concat radiobuttons) ++ (splitWeeks !! 1))
makeRadio :: String -> String
makeRadio x = "<dd><input type='radio' name='subject' value='"++ x ++ "'> " ++ x ++ "</br> \n"