<commit_before>
module Widgets.ProjectPledges where

import Import

import Model.Project
import Model.Currency

projectPledgeSummary :: UserId -> Widget
projectPledgeSummary user_id = do
    project_summary :: [ProjectSummary] <- handlerToWidget $ runDB $ do
        projects_pledges <- fmap (map (second return)) $ select $ from $ \ (project `InnerJoin` pledge) -> do
            on_ $ project ^. ProjectId ==. pledge ^. PledgeProject
            where_ $ pledge ^. PledgeUser ==. val user_id
            return (project, pledge)

        mapM (uncurry summarizeProject) projects_pledges

    toWidget [hamlet|
        $if null project_summary
            not supporting any projects
        $else
            <a href="@{UserPledgesR user_id}">
                $if (length project_summary) == 1
                    <p>Patron to 1 project
                $else
                    <p>Patron to (length project_summary) projects
     |]


projectPledges :: UserId -> Widget
projectPledges user_id = do
    project_summaries :: [ProjectSummary] <- handlerToWidget $ runDB $ do
        projects_pledges <- fmap (map (second return)) $ select $ from $ \ (project `InnerJoin` pledge) -> do
            on_ $ project ^. ProjectId ==. pledge ^. PledgeProject
            where_ $ pledge ^. PledgeUser ==. val user_id
            return (project, pledge)

        mapM (uncurry summarizeProject) projects_pledges

    let cost = summaryShareCost
        shares = getCount . summaryShares
        total x = cost x $* fromIntegral (shares x)

    toWidget [hamlet|
        $if null project_summaries
            not supporting any projects
        $else
            <p>
                Note: For testing purposes only.  No real money is changing hands yet.
            <table .table>
                $forall summary <- project_summaries
                    <tr>
                        <td>
                            <a href="@{ProjectR (summaryProjectHandle summary)}">
                                #{summaryName summary}
                        <td>#{show (cost summary)}/share
                        <td>
                            $if (shares summary) == 1
                                #{show (shares summary)} share
                            $else
                                #{show (shares summary)} shares
                        <td>#{show (total summary)}
     |]<commit_msg>added comments and Haddock to ProjectPledges.hs<commit_after>
module Widgets.ProjectPledges where

import Import

import Model.Project
import Model.Currency

{- projectPledgeSummary and projectPledges are most redundant with just
different widgets. We should probably just have one function and move
the widget stuff into two different hamlet files or something.
There are additional places that using the generalized function would
be useful, such as putting the summary number at /u listing perhaps-}

-- |The summary of pledging to projects shown on user's page
projectPledgeSummary :: UserId -> Widget
projectPledgeSummary user_id = do
    project_summary :: [ProjectSummary] <- handlerToWidget $ runDB $ do
        projects_pledges <- fmap (map (second return)) $ select $ from $
            \ (project `InnerJoin` pledge) -> do
                on_ $ project ^. ProjectId ==. pledge ^. PledgeProject
                where_ $ pledge ^. PledgeUser ==. val user_id
                return (project, pledge)

        mapM (uncurry summarizeProject) projects_pledges

    toWidget [hamlet|
        $if null project_summary
            not supporting any projects
        $else
            <a href="@{UserPledgesR user_id}">
                $if (length project_summary) == 1
                    <p>Patron to 1 project
                $else
                    <p>Patron to (length project_summary) projects
     |]

-- |The listing of all pledges for a given user, shown on u/#/pledges
projectPledges :: UserId -> Widget
projectPledges user_id = do
    project_summaries :: [ProjectSummary] <- handlerToWidget $ runDB $ do
        projects_pledges <- fmap (map (second return)) $ select $ from $
            \ (project `InnerJoin` pledge) -> do
                on_ $ project ^. ProjectId ==. pledge ^. PledgeProject
                where_ $ pledge ^. PledgeUser ==. val user_id
                return (project, pledge)

        mapM (uncurry summarizeProject) projects_pledges

    let cost = summaryShareCost
        shares = getCount . summaryShares
        total x = cost x $* fromIntegral (shares x)

    toWidget [hamlet|
        $if null project_summaries
            not supporting any projects
        $else
            <p>
                Note: For testing purposes only.  No real money is changing hands yet.
            <table .table>
                $forall summary <- project_summaries
                    <tr>
                        <td>
                            <a href="@{ProjectR (summaryProjectHandle summary)}">
                                #{summaryName summary}
                        <td>#{show (cost summary)}/share
                        <td>
                            $if (shares summary) == 1
                                #{show (shares summary)} share
                            $else
                                #{show (shares summary)} shares
                        <td>#{show (total summary)}
     |]

{'fraction_non_alphanumeric': 0.07979022288818131, 'fraction_numerical': 0.0011238059561715678, 'mean_word_length': 1.7065382665990876, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7215786', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1328, 'n_words': 446}