yesod-pnotify 0.6.0 → 1.0.0
raw patch · 3 files changed
+157/−15 lines, 3 filesnew-component:exe:samplePVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Yesod.Goodies.PNotify: Bootstrap :: NotifyStyling
- Yesod.Goodies.PNotify: urlPnotifyIconsCss :: YesodJqueryPnotify a => a -> Either (Route a) Text
+ Yesod.Goodies.PNotify: Bootstrap3 :: NotifyStyling
+ Yesod.Goodies.PNotify: BrightTheme :: NotifyStyling
+ Yesod.Goodies.PNotify: FontAwesome :: NotifyStyling
+ Yesod.Goodies.PNotify: urlBootstrap3Css :: YesodJqueryPnotify a => a -> Either (Route a) Text
+ Yesod.Goodies.PNotify: urlBootstrap3Js :: YesodJqueryPnotify a => a -> Either (Route a) Text
+ Yesod.Goodies.PNotify: urlBrightThemeCss :: YesodJqueryPnotify a => a -> Either (Route a) Text
+ Yesod.Goodies.PNotify: urlFontAwesomeCss :: YesodJqueryPnotify a => a -> Either (Route a) Text
+ Yesod.Goodies.PNotify: urlJqueryJs :: YesodJqueryPnotify a => a -> Either (Route a) Text
+ Yesod.Goodies.PNotify: urlJqueryUiCss :: YesodJqueryPnotify a => a -> Either (Route a) Text
- Yesod.Goodies.PNotify: class YesodJquery a => YesodJqueryPnotify a where urlPnotifyJs _ = Right "http://cdn.jsdelivr.net/pnotify/1.2/jquery.pnotify.min.js" urlPnotifyCss _ = Right "http://cdn.jsdelivr.net/pnotify/1.2/jquery.pnotify.default.css" urlPnotifyIconsCss _ = Right "http://cdn.jsdelivr.net/pnotify/1.2/jquery.pnotify.default.icons.css"
+ Yesod.Goodies.PNotify: class YesodJquery a => YesodJqueryPnotify a where urlJqueryJs _ = Right "//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" urlJqueryUiCss _ = Right "//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css" urlPnotifyJs _ = Right "//cdnjs.cloudflare.com/ajax/libs/pnotify/2.1.0/pnotify.core.min.js" urlPnotifyCss _ = Right "//cdnjs.cloudflare.com/ajax/libs/pnotify/2.1.0/pnotify.core.min.css" urlBootstrap3Js _ = Right "//netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" urlBootstrap3Css _ = Right "//netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" urlBrightThemeCss _ = Right "//cdnjs.cloudflare.com/ajax/libs/pnotify/2.1.0/pnotify.brighttheme.min.css" urlFontAwesomeCss _ = Right "//netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"
Files
- Yesod/Goodies/PNotify.hs +39/−14
- sample.hs +92/−0
- yesod-pnotify.cabal +26/−1
Yesod/Goodies/PNotify.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE OverloadedStrings, QuasiQuotes, TemplateHaskell, MultiParamTypeClasses, TypeFamilies #-} module Yesod.Goodies.PNotify ( PNotify(..) , NotifyType(..)@@ -11,7 +10,7 @@ ) where import Yesod-import Yesod.Form.Jquery+import Yesod.Form.Jquery hiding (urlJqueryJs, urlJqueryUiCss) import Data.Text (Text) import Data.Monoid ((<>), mempty)@@ -32,28 +31,48 @@ data NotifyType = Notice | Info | Success | Error deriving (Show, Read) -data NotifyStyling = JqueryUI | Bootstrap+data NotifyStyling = JqueryUI | Bootstrap3 | BrightTheme | FontAwesome deriving (Show, Read) class YesodJquery a => YesodJqueryPnotify a where+ urlJqueryJs :: a -> Either (Route a) Text+ urlJqueryJs _ = Right "//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"+ urlJqueryUiCss :: a -> Either (Route a) Text+ urlJqueryUiCss _ = Right "//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"+ urlPnotifyJs :: a -> Either (Route a) Text- urlPnotifyJs _ = Right "http://cdn.jsdelivr.net/pnotify/1.2/jquery.pnotify.min.js"+ urlPnotifyJs _ = Right "//cdnjs.cloudflare.com/ajax/libs/pnotify/2.1.0/pnotify.core.min.js" urlPnotifyCss :: a -> Either (Route a) Text- urlPnotifyCss _ = Right "http://cdn.jsdelivr.net/pnotify/1.2/jquery.pnotify.default.css"- urlPnotifyIconsCss :: a -> Either (Route a) Text- urlPnotifyIconsCss _ = Right "http://cdn.jsdelivr.net/pnotify/1.2/jquery.pnotify.default.icons.css"+ urlPnotifyCss _ = Right "//cdnjs.cloudflare.com/ajax/libs/pnotify/2.1.0/pnotify.core.min.css" + urlBootstrap3Js :: a -> Either (Route a) Text+ urlBootstrap3Js _ = Right "//netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"+ urlBootstrap3Css :: a -> Either (Route a) Text+ urlBootstrap3Css _ = Right "//netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"++ urlBrightThemeCss :: a -> Either (Route a) Text+ urlBrightThemeCss _ = Right "//cdnjs.cloudflare.com/ajax/libs/pnotify/2.1.0/pnotify.brighttheme.min.css"++ urlFontAwesomeCss :: a -> Either (Route a) Text+ urlFontAwesomeCss _ = Right "//netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"+ notifyKey :: Text notifyKey = "_PNotify" +toText :: [PNotify] -> Text+toText = T.concat . TL.toChunks . TL.pack . show++fromText :: Text -> [PNotify]+fromText = read . T.unpack+ _setPNotify :: [PNotify] -> HandlerT site IO ()-_setPNotify = setSession notifyKey . T.concat . TL.toChunks . TL.pack . show+_setPNotify = setSession notifyKey . toText getPNotify :: HandlerT site IO (Maybe [PNotify]) getPNotify = runMaybeT $ do ns <- MaybeT $ lookupSession notifyKey lift $ deleteSession notifyKey- return $ read $ T.unpack ns+ return $ fromText ns setPNotify :: PNotify -> HandlerT site IO () setPNotify n = do@@ -67,11 +86,17 @@ Nothing -> return () Just ps -> do addScriptEither $ urlJqueryJs y- addScriptEither $ urlJqueryUiJs y- addStylesheetEither $ urlJqueryUiCss y addScriptEither $ urlPnotifyJs y addStylesheetEither $ urlPnotifyCss y- addStylesheetEither $ urlPnotifyIconsCss y- let toJs p = [julius|{styling:'#{rawJS $ map toLower $ show $ sty p}',title:'#{rawJS $ ttl p}',text:'#{rawJS $ msg p}',type:'#{rawJS $ map toLower $ show $ typ p}'},|]+ addScriptEither $ urlBootstrap3Js y+ addStylesheetEither $ urlBootstrap3Css y+ addStylesheetEither $ urlBrightThemeCss y+ addStylesheetEither $ urlJqueryUiCss y+ addStylesheetEither $ urlFontAwesomeCss y+ let toJs p = [julius|{styling:'#{rawJS $ map toLower $ show $ sty p}'+ ,title:'#{rawJS $ ttl p}'+ ,text:'#{rawJS $ msg p}'+ ,type:'#{rawJS $ map toLower $ show $ typ p}'+ },|] ws = foldr ((<>).toJs) mempty ps- toWidget [julius|$(document).ready(function(e){var ws=[^{ws}];for(var i in ws){$.pnotify(ws[i]);}});|]+ toWidget [julius|$(function(){var ws=[^{ws}];for(var i in ws){new PNotify(ws[i]);}});|]
+ sample.hs view
@@ -0,0 +1,92 @@+import Yesod+import Yesod.Form.Jquery+import Data.Text (Text)+import Control.Applicative ((<$>),(<*>))++import Yesod.Goodies.PNotify++data Devel = Devel++mkYesod "Devel" [parseRoutes|+/ PersonR GET POST+|]++++instance Yesod Devel where+ defaultLayout widget = do+ y <- getYesod+ pc <- widgetToPageContent $ do+ widget+ pnotify y+ withUrlRenderer [hamlet|+$doctype 5+<html>+ <head>+ <title>#{pageTitle pc}+ <meta charset=utf-8>+ ^{pageHead pc}+ <body>+ <article>+ ^{pageBody pc}+|]++instance YesodJquery Devel+instance YesodJqueryPnotify Devel where++instance RenderMessage Devel FormMessage where+ renderMessage _ _ = defaultFormMessage++data Person = Person { name :: Text+ , age :: Int+ }+ deriving (Show)+personForm :: Html -> MForm Handler (FormResult Person, Widget)+personForm = renderDivs $ Person+ <$> areq textField "Name" Nothing+ <*> areq intField "Age" Nothing++getPersonR :: Handler Html+getPersonR = do+ (widget, enctype) <- generateFormPost personForm+ defaultLayout [whamlet|+<form method=post action=@{PersonR} enctype=#{enctype}>+ ^{widget}+ <input type=submit>+|]++postPersonR :: Handler Html+postPersonR = do+ ((result, _), _) <- runFormPost personForm+ case result of+ FormSuccess _ -> do++ setPNotify $ PNotify JqueryUI Success "Updated" "Update User profile."+ setPNotify $ PNotify JqueryUI Notice "Notice" "More notice."+ setPNotify $ PNotify JqueryUI Info "Information" "And more information."+ setPNotify $ PNotify JqueryUI Error "Error" "Fail to update user profile"+ + setPNotify $ PNotify Bootstrap3 Success "Updated" "Update User profile."+ setPNotify $ PNotify Bootstrap3 Notice "Notice" "More notice."+ setPNotify $ PNotify Bootstrap3 Info "Information" "And more information."+ setPNotify $ PNotify Bootstrap3 Error "Error" "Fail to update user profile"+ + setPNotify $ PNotify BrightTheme Success "Updated" "Update User profile."+ setPNotify $ PNotify BrightTheme Notice "Notice" "More notice."+ setPNotify $ PNotify BrightTheme Info "Information" "And more information."+ setPNotify $ PNotify BrightTheme Error "Error" "Fail to update user profile"++ setPNotify $ PNotify FontAwesome Success "Updated" "Update User profile."+ setPNotify $ PNotify FontAwesome Notice "Notice" "More notice."+ setPNotify $ PNotify FontAwesome Info "Information" "And more information."+ setPNotify $ PNotify FontAwesome Error "Error" "Fail to update user profile"++ redirect PersonR+ _ -> do+ setPNotify $ PNotify JqueryUI Error "Error" "Fail to update user profile"+ setPNotify $ PNotify Bootstrap3 Error "Error" "Fail to update user profile"+ setPNotify $ PNotify BrightTheme Error "Error" "Fail to update user profile"+ redirect PersonR++main :: IO ()+main = warp 3000 Devel
yesod-pnotify.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: yesod-pnotify-version: 0.6.0+version: 1.0.0 synopsis: Yet another getMessage/setMessage using pnotify jquery plugins description: Yet another getMessage/setMessage using pnotify jquery plugins homepage: https://github.com/cutsea110/yesod-pnotify@@ -17,10 +17,35 @@ library exposed-modules: Yesod.Goodies.PNotify+ -- other-modules: ++ extensions: OverloadedStrings+ , QuasiQuotes+ , TemplateHaskell+ , MultiParamTypeClasses+ , TypeFamilies+ build-depends: base >= 4.6 && < 4.9 , yesod >= 1.2 && < 1.5 , yesod-form >= 1.3 && < 1.5 , text >= 0.11 && < 1.3 , transformers >= 0.3 && < 0.5 , shakespeare >= 2.0 && < 2.1++executable sample+ main-is: sample.hs++ extensions: OverloadedStrings+ , QuasiQuotes+ , TemplateHaskell+ , MultiParamTypeClasses+ , TypeFamilies++ build-depends: base >= 4.6 && < 4.9+ , yesod >= 1.2 && < 1.5+ , yesod-form >= 1.3 && < 1.5+ , text >= 0.11 && < 1.3+ , transformers >= 0.3 && < 0.5+ , shakespeare >= 2.0 && < 2.1+