Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Sascha Gresk
    @zmijunkie
    it just works … ;-)
    joshua-obritsch
    @joshua-obritsch

    Hi. I have a question.
    I'm trying to set up CurrentUserRecord to work with two different models: Student and Teacher in two different applications.
    When I follow the guide and enter type instance CurrentUserRecord = Teacher to Types.hs in the Teacher application, everything works fine.
    When I then add type instance CurrentUserRecord = Student to Types.hs in the Student application, I get the following error message:

    Student/Types.hs:24:15
        Conflicting family instance declarations:
          IHP.LoginSupport.Types.CurrentUserRecord = Generated.Types.Student
            -- Defined at Student/Types.hs:24:15
          IHP.LoginSupport.Types.CurrentUserRecord = Generated.Types.Teacher
            -- Defined at Teacher/Types.hs:26:15
       |
    24 | type instance CurrentUserRecord = Student
       |               ^^^^^^^^^^^^^^^^^

    Is there a way of solving this problem without merging the models into a common User model? Can type instances somehow be scoped in Haskell?

    Marc Scholten
    @mpscholten
    yes, in that case I’d avoid using CurrentUserRecord. You can define your own currentStudent and currentTeacher functions :)
    take a look at the implementation here
    basically copy currentUser and currentUserOrNothing into your Application.Helper.Controller. Then replace everything with user with Student
    you can just remove the user ~ CurrentUserRecord inside the type sig
    
    currentStudent :: (?context :: ControllerContext, HasNewSessionUrl Student, Typeable Student) => Student
    currentStudent = fromMaybe (redirectToLogin (newSessionUrl (Proxy @Student))) currentStudentOrNothing
    
    
    currentStudentOrNothing :: (?context :: ControllerContext, HasNewSessionUrl Student, Typeable Student) => Maybe Student
    currentStudentOrNothing = case unsafePerformIO (maybeFromContext @(Maybe Student)) of
        Just student -> student
        Nothing -> error "currentStudentOrNothing: initAuthentication @Student has not been called in initContext inside FrontController of this application"
    for accessing currentStudent in the view you need to do the same steps in Application.Helper.View based on these functions https://github.com/digitallyinduced/ihp/blob/master/IHP/LoginSupport/Helper/View.hs#L12
    joshua-obritsch
    @joshua-obritsch
    Sounds good. I'll give it a try. Thank you very much. :)
    Jason
    @rametta

    Hello, I'm trying to load the related records for a type and i'm getting an error. My code:

        action ShowRetroAction { retroId } = do
            retro <- fetch retroId
                >>= fetchRelated #columns

    Error is:

        * Couldn't match type `[Column]' with `QueryBuilder "columns"'
          Expected type: Retro -> IO Retro
            Actual type: Retro -> IO (Include "columns" Retro)
        * In the second argument of `(>>=)', namely `fetchRelated #columns'
          In a stmt of a 'do' block:
            retro <- fetch retroId >>= fetchRelated #columns
          In the expression:
            do retro <- fetch retroId >>= fetchRelated #columns
               render ShowView {..}
       |
    20 |             >>= fetchRelated #columns
       |

    Any ideas?

    3 replies
    s0kil
    @s0kil:matrix.org
    [m]
    Since you are fetching a Retro and also related Columns, the type is Include "columns" Retro
    Jason
    @rametta
    How would I get this to work? This is mostly just the generated code
    s0kil
    @s0kil:matrix.org
    [m]
    You don't need to touch the generated code, it's managed by IHP itself
    Jason
    @rametta
    Oh I didn't
    s0kil
    @s0kil:matrix.org
    [m]
    The type I've mentioned goes into the view
    Something like this: data ShowView = ShowView { retroWithColumns :: Include "columns" Retro }
    Jason
    @rametta

    ah yes. got it working with:

    data ShowView = ShowView { retro :: Retro' [Column] }

    Thank your for your help! We should add that to the docs, could be helpful for beginners like me

    s0kil
    @s0kil:matrix.org
    [m]
    Retro' [Column] is not idiomatic to IHP, prefer the version I've mentioned.
    Jason
    @rametta
    Yup your version works too, will switch it for yours :)
    s0kil
    @s0kil:matrix.org
    [m]
    However, it could be easy to miss it, since it's not mentioned many times in the Guide
    Jason
    @rametta
    Yeah I read that page a few times, i don't think it mentions to change the type in the view though
    oh it does, omg i'm blind
    Raphael Jacobs
    @RaphyJake_gitlab

    hi @mpscholten , i'm raphy@airmail.cc from the emails! Here's my silly question: I want to save in my database a bunch of music albums, and besides info such as Name, Artist, etc, I wanted to store associate a picture to every album. So in my database scheme I have a column called "Picture" with a string field, where (supposedly) i'd store the filepath of the image, or an URL that points to that image.

    But when I try to put something like this in my Show.hs file for my albums:
    <img src={get #picture album}>

    I get a cryptic error back, here are the first lines:

    Could not deduce (IHP.RouterSupport.AutoRoute (Maybe Text))
            arising from a use of `IHP.HtmlSupport.QQ.applyAttribute'
          from the context: (?context::ControllerContext, ?view::ShowView)
        [long cryptic error]

    So, first of all, is there a best way to store "pictures" in a database? I'm new to web programming, and if this is the right way, how do I make it work as intended in IHP?

    Marc Scholten
    @mpscholten
    hey :) the error comes because the picture field is nullable and so the type of get #picture album is Maybe Text instead of Text
    try to provide a default value
    e.g.:
    render .. = [hsx|<img src={picture}/>|]
        where
            picture = album |> get #picture |> fromMaybe „default.png"
    Raphael Jacobs
    @RaphyJake_gitlab
    Oh! I see, thank you a lot
    Sascha Gresk
    @zmijunkie
    I have done: https://ihp.digitallyinduced.com/Guide/routing.html#custom-404-page and now not found pages are returned with 200 …
    I guess I need a different solution …
    Marc Scholten
    @mpscholten
    looks like a bug, will check it in a few mins
    is there anything in between the ihp app and your browser (e.g. a proxy)?
    Marc Scholten
    @mpscholten
    just found a good way to reproduce this: https://ihpcloud.com/404test :)
    looks like it’s caused by yesodweb/wai#644
    Jason
    @rametta
    Hello, I'm trying to render a modal using setModal and jumpToAction, but it seems you can only render a modal in the context of the current controller. Is it possible to render a modal on top of an action from a different controller? If not, any plans to add that feature?
    4 replies
    Marc Scholten
    @mpscholten
    @zmijunkie pushed a fix here digitallyinduced/ihp#844 if build is green i’ll merge this into master. Then you could follow https://ihp.digitallyinduced.com/Guide/updating.html#updating-to-the-latest-git-commit to fix this locally
    10 replies
    Jason
    @rametta
    @mpscholten is there a way to deploy to ihp cloud automatically whenever a new commit is pushed?
    Marc Scholten
    @mpscholten
    not yet, but should be available very soon (it’s already live in production, but currently hidden in the UI as we’re doing some more testing)
    Jason
    @rametta
    amazing!
    Sascha Gresk
    @zmijunkie
    ah thanks - have been in the garden … the weather was amazing - will watch this !!
    Jason
    @rametta
    Hello, I'm trying to debug an issue in prod, I recently added authentication to my app, but I can't seem to create a user in prod, when locally it works perfectly
    app link: https://retros.ihpapp.com
    source code: https://github.com/rametta/retros
    I can't see the logs in ihp cloud so not sure what the issue could be. I added a migration script to delete all my data just in case it was causing problems, but didn't seem to help
    15 replies
    simara
    @simara:matrix.org
    [m]
    Hi, I have an IHP index view with a tabular listing of certain db entries. Every line in the listing has a link which toggles one particular boolean option for the given db record and then redirects back to the listing (all via a controller action). Unfortunately the option is toggled already when one hovers with the cursor over the link. I guess, it has sth. to do with turbolinks or instantclick? Any suggestions how to deal with this problem?
    1 reply
    awesome. thanks!
    works. thanks again.
    Fritz Feger
    @fritzfeger

    Hello everybody! I've followed https://ihp.digitallyinduced.com/Guide/routing.html#beautiful-urls, at least I think so, and the compiler complains:

    Web/View/Posts/Index.hs:7:34Couldn't match type ‘Id' "posts" with ‘Maybe (Id' "posts")’
            arising from a use of ‘renderPost’
        • In the second argument of ‘forEach’, namely ‘renderPost’
          In the first argument of ‘toHtml’, namely
            ‘((forEach posts) renderPost)’
          In the expression: toHtml ((forEach posts) renderPost)
      |
    7 |     html IndexView { .. } = [hsx|
      |                                  ^...

    There was an error before, which disappeared when, in Web/Types.hs, I substituted the ShowPostAction parameter for the URL slug from the Guide { postId :: !(Maybe (Id Post)), slug :: !(Maybe Text) } in all other actions as well.

    For what it's worth, the repo is at https://gitlab.com/fritzfeger/ff-com, and in the README you'll also find the IHP cloud link to the (working) app just before the changes. View all changes I've made to the working version at fritzfeger/ff-com@d159f7f. THANK YOU!

    Marcos Tirao
    @mtirao

    Hello I having problems with selectField form helper. To use for my select button, all users coming for DB. I have the following definitions in my controller a setup this

    users <- query @User |> fetch

    And in my view

    data EditView = EditView { issue :: Issue, users :: [User] }

    instance CanSelect User where
    -- Here we specify that the <option> value should contain a Id User
    type SelectValue User = Id User
    -- Here we specify how to transform the model into <option>-value
    selectValue = get #id
    -- And here we specify the <option>-text
    selectLabel = get #name

    and the form definition is like this

    renderForm issue = formFor issue [hsx|
    {(textField #number)}
    {(textField #summary)}
    {(textField #status)}
    {(checkboxField #isPsa)}
    {(textField #days)}
    {(textField #description)}
    {(textField #customerId)}
    {(selectField #userId users)}
    {submitButton}
    |]

    But it generate the error below

    Web/View/Issues/Edit.hs:29:39: error:
    • Couldn't match expected type ‘[item0]’
    with actual type ‘EditView -> [User]’
    • Probable cause: ‘users’ is applied to too few arguments
    In the second argument of ‘selectField’, namely ‘users’
    In the first argument of ‘toHtml’, namely
    ‘((selectField (fromLabel @"userId")) users)’
    In the expression:
    toHtml ((selectField (fromLabel @"userId")) users)
    |
    29 | renderForm issue = formFor issue [hsx|
    |

    1 reply
    Which could be the problem?.
    Marc Scholten
    @mpscholten
    There’s now https://github.com/digitallyinduced/awesome-ihp :) If you have some open source IHP project, it would be nice if you could add it to the awesome-ihp list