Greg Weber | 1 Aug 2012 01:28
Gravatar

Re: mongodb example for persistent

The preferred way of getting a working example is to do a `yesod init`
with the mongodb option. There is an example of using that with the
raw driver [2]. There is an open issue for yesod init not generating
the test functions properly with mongodb [1] that I will make sure to
fix before the 1.1 release.

[1] https://github.com/yesodweb/yesod/issues/349
[2] https://github.com/yesodweb/yesod/wiki/Rawmongo

On Tue, Jul 31, 2012 at 1:45 PM, Victor <victor.kam@...> wrote:
> Hi!  Haskell newbie here.  Actually, I already made a post on stackoverflow,
> but I'm hoping that this list gets more attention than stackoverflow.
>
> http://stackoverflow.com/questions/11731953/mongodb-example-for-yesod-persistent
>
> So basically, if someone can provide a working example of MongoDB for
> Persistent I would greatly appreciate it.
>
> Thanks in advance!
>
>
>
>

Magicloud Magiclouds | 1 Aug 2012 04:32
Picon

Re: I think "Nothing" and "Just """ are the same?

It occur to me yesterday that this might be a sqlite's problem.

And Michael, following is a few lines of my code, first I just had
Nothing and Just _ matched. And it never went into Nothing. Then I add
Just "", it worked.

User
    login Text
    secret Text Maybe
    mobile Text Maybe
    UniqueUser login

runPool dbconf (insert $ User name Nothing mobile) p

  Entity userId user_ <- runDB $ getBy404 $ UniqueUser login
  user <- case userSecret user_ of
    Nothing ->  do
      now <- liftIO $ epochTime
      runDB $ update userId [UserSecret =. (Just $ T.pack $ generate now)]
      Entity _ user__ <- runDB $ getBy404 $ UniqueUser login
      liftIO $ systemUser (T.unpack login)
      liftIO $ pamUser (T.unpack login) (generate now) pin
      return user__
    Just "" -> do
      now <- liftIO $ epochTime
      runDB $ update userId [UserSecret =. (Just $ T.pack $ generate now)]
      Entity _ user__ <- runDB $ getBy404 $ UniqueUser login
      liftIO $ systemUser (T.unpack login)
      liftIO $ pamUser (T.unpack login) (generate now) pin
      return user__
(Continue reading)

Michael Snoyman | 1 Aug 2012 08:08
Favicon
Gravatar

Re: I think "Nothing" and "Just """ are the same?

Can you put this together into a standalone program that demonstrates
the problem? I have not been able to reproduce any ambiguity between
`Nothing` and `Just ""`.

On Wed, Aug 1, 2012 at 5:32 AM, Magicloud Magiclouds
<magicloud.magiclouds@...> wrote:
> It occur to me yesterday that this might be a sqlite's problem.
>
> And Michael, following is a few lines of my code, first I just had
> Nothing and Just _ matched. And it never went into Nothing. Then I add
> Just "", it worked.
>
> User
>     login Text
>     secret Text Maybe
>     mobile Text Maybe
>     UniqueUser login
>
> runPool dbconf (insert $ User name Nothing mobile) p
>
>   Entity userId user_ <- runDB $ getBy404 $ UniqueUser login
>   user <- case userSecret user_ of
>     Nothing ->  do
>       now <- liftIO $ epochTime
>       runDB $ update userId [UserSecret =. (Just $ T.pack $ generate now)]
>       Entity _ user__ <- runDB $ getBy404 $ UniqueUser login
>       liftIO $ systemUser (T.unpack login)
>       liftIO $ pamUser (T.unpack login) (generate now) pin
>       return user__
>     Just "" -> do
(Continue reading)

Gaël DEEST | 1 Aug 2012 14:26
Picon

Toggling CSS class based on active page in defaultLayout

Hi,

I am experimenting with Yesod and Bootstrap. As you already know, Bootstrap provides a convenient set of pre-defined CSS classes, as well as a solid grid layout system that allows quick website prototyping and takes much of the pain out of writing CSS (and I hate CSS), so I thought Yesod and Bootstrap would make a good mix :)

I started by decompressing the bootstrap bundle in a directory, serving static assets, and writing my own defaultLayout. I kept it quite simple: a left navbar and a page body. Then I started populating my navbar with links to my yesod pages, but it occurred to me that I should add an active class on the link to the active page in order to follow Bootstrap's conventions and get the nice rendering.

How would you do that ? I'm sure it's somehow possible, but I can't think of a way to do this.

Here is my code, if you're interested, but there's nothing fantastic there:

http://hastebin.com/suvinakalo.hs

Thanks !

Gaël

Michael Snoyman | 1 Aug 2012 14:59
Favicon
Gravatar

Last call: Persistent 1.0 and Yesod 1.1

Hi all,

I've just pushed some commits to the persistent and yesod repos which,
AFAIK, close all issues we intend to resolve for the next release. I
still have some sanity-checking and general testing to perform, but I
believe the code is feature complete and just about ready for release.
This is a final call for input before release.

By the way: the changes for this upgrade are very minor, if anyone is
interested in writing up an upgrade report for a live site, please be
in touch and I'll provide some guidance.

Michael

Michael Snoyman | 1 Aug 2012 15:30
Favicon
Gravatar

Re: Web components

On Mon, Jul 30, 2012 at 10:22 PM, Paul Brauner <polux2001@...> wrote:
> Hello,
>
> I was looking at Web Components
> (https://plus.google.com/103330502635338602217/posts,
> http://dvcs.w3.org/hg/webcomponents/raw-file/tip/explainer/index.html) and
> it strongly reminded me of Yesod widgets. It's been a while I didn't play
> with Yesod but as I remember, widgets encapsulate html/css/js together,
> which is exactly what web components do.
>
> Are you aware of it? Maybe it would be worth compiling widgets to web
> components in the long term?
>
> Paul

I can't say that I know very much about web components. But my take is
that while they're sitting in roughly the same solution space
(reusable HTML/CSS/JS), the approach is different enough that I don't
see any clear way to generate web components from widgets. But if
someone out there who knows web components better (i.e., almost
everyone) has concrete ideas, I'd be interested in hearing them.

Michael

Michael Snoyman | 1 Aug 2012 15:54
Favicon
Gravatar

Re: Yesod forms with page flow

On Tue, Jul 31, 2012 at 6:04 PM, David Flemström
<david.flemstrom@...> wrote:
> On Tue, Jul 31, 2012 at 4:34 AM, Michael Snoyman <michael@...>
> wrote:
>>
>> What I meant was that the path would be the same, but the query string
>> would be different. This would still allow the back button to work
>> correctly.
>
>
> For clarity, I'm referring to something like a link <a
> href="/wizard?page=first&field1=foo">Back</a> (which is how the link would
> have to look for your single-route system), not the browser's back button
> (accessed via [backspace] in most browsers). Is that the kind of system you
> meant (Obviously with the field1 part being encrypted/stored in the
> session/whatever)?
>
> I definitely see that working, but one could also simply provide a
> route<->wizard page isomorphism to the runFormWizard function, so this is
> really a non-issue anyways (i.e. one could trivially replace
> "/wizard?page=first" with "/wizard/first")

We're completely on the same page (pardon the pun). I was strictly
speaking from an ease-of-use perspective, the two approaches are
completely isomorphic.

>
>> I'm also not sure what you mean about the wall with
>> yesod-form: you're free to use separate routes for GET and POST if you
>> want, it's mostly for convenience that all the examples use the same
>> route.
>
>
> Yes, now I do of course simply use generateFormGet and generateFormPost, but
> were those two always separated? Maybe I'm confusing yesod-form with
> digestive-functors (that definitely had that issue for a long time), but the
> point remains that the API you displayed in that short code snippet wouldn't
> allow for that separation of responsibilities. : )

Actually, for *almost* all use cases, you can just call runFormPost
and ignore the result, and it will act like generateFormPost. The one
exception is if you use it from a POST handler for a previously
submitted form, in which case runFormPost will pick up the old
results. That was the purpose of adding the generateFormPost function.
(generateFormGet is a bit more important, as it's more likely to have
previous query-string parameters.)

I would recommend for a wizard API to have both a `generate` and `run`
function, but in most cases you should be able to get full usability
from just the `run` versions.

>
> I'll start working on some prototypes of this. Things that concern me
> include that if one wants a static guarantee that all pages of a wizard have
> been filled out (so that the user does't do pure def >>> wizardPage1 >>>
> wizardPage3 (imagine some form of kleisli arrows) which would leave some
> fields of the data structure potentially undefined). Using Applicative for
> the form fields is definitely not enough, because then there can't be a
> tree-like wizard structure, but I could see the Monad interface working,
> albeit sans some of the static safety guarantees an Arrow would allow for.

I think a Monad interface should work perfectly, you would just need
to have some short-circuiting logic. Something like:

x <- form1
case x of
    Foo -> do
        y <- foo
        return $ Left y
    Bar -> do
        y <- bar1
        z <- bar2
        return $ Right (y, z)

If you get to `bar1` and the form hasn't been submitted yet, then a
new form will be returned immediately. I guess we would need some kind
of combination of Writer (for the previously parsed values) and Error.

Michael

Michael Snoyman | 1 Aug 2012 16:01
Favicon
Gravatar

Re: Toggling CSS class based on active page in defaultLayout

On Wed, Aug 1, 2012 at 3:26 PM, Gaël DEEST <gael.deest@...> wrote:
> Hi,
>
> I am experimenting with Yesod and Bootstrap. As you already know, Bootstrap
> provides a convenient set of pre-defined CSS classes, as well as a solid
> grid layout system that allows quick website prototyping and takes much of
> the pain out of writing CSS (and I hate CSS), so I thought Yesod and
> Bootstrap would make a good mix :)
>
> I started by decompressing the bootstrap bundle in a directory, serving
> static assets, and writing my own defaultLayout. I kept it quite simple: a
> left navbar and a page body. Then I started populating my navbar with links
> to my yesod pages, but it occurred to me that I should add an active class
> on the link to the active page in order to follow Bootstrap's conventions
> and get the nice rendering.
>
> How would you do that ? I'm sure it's somehow possible, but I can't think of
> a way to do this.
>
> Here is my code, if you're interested, but there's nothing fantastic there:
>
> http://hastebin.com/suvinakalo.hs
>
> Thanks !
>
> Gaël
>

My standard approach to this is to call getCurrentRoute[1] in the
defaultLayout function, and then conditionally add the attribute
depending on the value. Something like this:

        mcurrSub <- getCurrentRoute
        toMaster <- getRouteToMaster
        let mcurr = fmap toMaster mcurrSub

        [whamlet|
              <a href= <at> {FooR} :Just FooR == mcurr:.active>Foo
        |]

Maybe it's worth adding a getCurrentRouteMaster function, any thoughts?

Michael

[1] http://hackage.haskell.org/packages/archive/yesod-core/1.0.1.3/doc/html/Yesod-Handler.html#v:getCurrentRoute

Greg Weber | 1 Aug 2012 16:34
Gravatar

Re: An exception in Persistent's select*?

François, and other selectKeys users: are you happy with selectKeys
returning a Source or do you want a List?

On Fri, Jul 27, 2012 at 7:44 AM, Michael Snoyman <michael@...> wrote:
> On Fri, Jul 27, 2012 at 12:01 AM, François Gannaz
> <francois.gannaz@...> wrote:
>> Hi
>>
>> After I read the chapter "Persistent" of the Yesod book, I assumed that
>> `selectKeys` would take two parameters, like `selectList`. I was wrong,
>> there's a condition but no option[^1]. That's too bad, I needed to sort
>> and limit the results, so I'll have to use raw SQL again.
>>
>> But the book is totally misleading: « All the select functions use a
>> similar interface, with slightly different outputs ». That's true for
>> `selectList`, `selectFirst` and `selectSource`, but `selectKeys` is an
>> exception. Could the documentation be fixed, or the API evolve?
>>
>> Regards
>> --
>> François
>>
>>
>> [^1]:
>> http://hackage.haskell.org/packages/archive/persistent/0.9.0.4/doc/html/Database-Persist-Query.html
>
> I think the book is still accurate: the interfaces *are* similar, but
> not identical. That said, I have no objections to allowing
> `selectKeys` to have ordering applied. I think I originally left it
> off for efficiency reasons, but those reasons are not really relevant
> any more.
>
> Michael

François Gannaz | 1 Aug 2012 19:33
Picon

Re: An exception in Persistent's select*?

On 2012-08-01, Greg Weber <greg@...> wrote:
> François, and other selectKeys users: are you happy with selectKeys
> returning a Source or do you want a List?

I'm inexperienced both in Haskell and in Yesod, and my use cases may be
limited and not representative of the other users.
Despite this warning, I'd prefer something like:

    selectKeys :: [Filter val] -> [SelectOpt val] -> b m [Key b val]

--
François


Gmane