Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE MultiParamTypeClasses #-}
- {-# LANGUAGE OverloadedStrings #-}
- {-# LANGUAGE QuasiQuotes #-}
- {-# LANGUAGE TemplateHaskell #-}
- {-# LANGUAGE TypeFamilies #-}
- import Control.Applicative ((<$>), (<*>))
- import Data.Text (Text)
- import Data.Time (Day)
- import Yesod
- import Yesod.Form.Jquery
- import Data.List (elemIndex)
- import Control.Monad (forM)
- import Data.String (fromString)
- data App = App
- mkYesod "App" [parseRoutes|
- / HomeR GET
- /person PersonR POST
- |]
- instance Yesod App
- -- Tells our application to use the standard English messages.
- -- If you want i18n, then you can supply a translating function instead.
- instance RenderMessage App FormMessage where
- renderMessage _ _ = defaultFormMessage
- -- And tell us where to find the jQuery libraries. We'll just use the defaults,
- -- which point to the Google CDN.
- instance YesodJquery App
- -- The datatype we wish to receive from the form
- tempdat = [4,8,7,9,5,2,3,1,6,6,1,9,4,3,8,2,7,5,3,5,2,7,1,6,9,8,4,9,4,5,1,2,7,6,3,8,1,7,8,3,6,4,5,9,2,2,6,3,8,9,5,7,4,1,7,2,4,5,8,3,1,6,9,5,3,1,6,4,9,8,2,7,8,9,6,2,7,1,4,5,3]
- -----------------The Labelling Function---------------
- labelling :: [Integer] -> [(String,Integer)]
- labelling xs = labelling' xs 0 (length xs)
- labelling' (x:xs) z y = [helper x z] ++ (labelling' xs (z+1) (y-1))
- labelling' [] z 0 = []
- --Gives the (label,value)
- helper x y = ( "r" ++ (rownum y) ++ "c" ++ (colnum y) , x )
- --Gives row number and column number
- rownum y = (show ((quot y 9)+1) )
- colnum y = (show ((rem y 9)+1) )
- --Gives the Integer
- help::(Num x) => (Maybe x) -> x
- help (Just x) = x
- lis = labelling tempdat
- --------------------------------------------------------
- --------Splits the 81 element list to list of list with each element having 9 elements----------------
- fun [] = []
- fun xs =
- let (a,b) = (splitAt 9 xs)
- in a:(fun b)
- ------------------------------------------------------------------------------------------------------
- --------The Sudoku table------------------
- ------This is the part I wanted to modify. I wanted to to remove the 'widget' and generate it in the hamlet file----
- listEditMForm extra = do
- ifields <- forM lis (\(s,i) -> mreq intField (fromString s) (Just i))
- let (iresults,iviews) = unzip ifields
- let y = fun iviews
- let widget = [whamlet|
- #{extra}
- <table class="table table-bordered" #outer cellspacing="0" cellpadding="0">
- $forall ivlist <- y
- <tr>
- $forall iv <- ivlist
- <td>^{fvInput iv}
- |]
- return ((FormSuccess iresults), widget)
- -- The GET handler displays the form
- getHomeR :: Handler Html
- getHomeR = do
- -- Generate the form to be displayed
- (widget, enctype) <- generateFormPost listEditMForm
- defaultLayout $ do
- toWidget [lucius| h1 { text-align : center;}|]
- [whamlet|
- <div class="jumbotron">
- <h1><span class="glyphicon glyphicon-th"></span>Sudoku
- <p>You can solve sudoku puzzels or ask for solutions
- <div >
- <div #contentlayout align="left">
- <p><h3>Instructions:
- <ul>
- <li>Use <strong>Refresh</strong> to get new puzzle
- <li>Use <strong>Solve</strong> to get the solution
- <div #contentlayout align="center">
- ^{widget}
- <div #contentlayout >
- <div>
- <button .btn .btn-primary type="submit">New Puzzle <span class="glyphicon glyphicon-refresh"></span>
- <div><br>
- <div>
- <button .btn .btn-primary type="submit">Solve <span class="glyphicon glyphicon-circle-arrow-right"></span>
- <div><br>
- <div>
- <button .btn .btn-primary type="submit">Validate<span class="glyphicon glyphicon-circle-arrow-right"></span>
- |]
- -- The POST handler processes the form. If it is successful, it displays the
- -- parsed person. Otherwise, it displays the form again with error messages.
- postPersonR :: Handler Html
- postPersonR = error "not implemented"
- main :: IO ()
- main = warp 3000 App
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement