<commit_before>{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}

module View.Project
    ( editProjectForm
    , projectContactForm
    , inviteForm
    , Preview (..)
    , ProjectBlog (..)
    , projectBlogForm
    , projectConfirmPledgeForm
    , previewBlogPost
    , renderBlogPost
    , renderProject
    , viewForm
    ) where


import Import

import Control.Applicative (liftA2)
import qualified Data.Text as T

import Data.Filter
import Data.Order
import DeprecatedBootstrap
import Handler.Utils
import Mechanism (payoutHistory)
import Model.Markdown
import Model.Project
import Model.Shares
import Model.User
import Model.Role
import Model.Comment
import View.Time
import View.User (userNameWidget)
import Widgets.Markdown
import Widgets.Preview
import qualified Mechanism as Mech

renderProject :: Maybe ProjectId
              -> Project
              -> Maybe UserId
              -> Bool
              -> WidgetT App IO ()
renderProject maybe_project_id project mviewer_id is_watching = do
    let discussion =
            DiscussionOnProject
                (Entity (fromMaybe (key $ PersistInt64 (-1)) maybe_project_id)
                        project)
        description =
            markdownWidgetWith (fixLinks (projectHandle project) discussion)
                               (projectDescription project)

    userIsAdmin <- case maybe_project_id of
        Just project_id ->
            maybe (pure False)
                  (\u -> runDB $ userIsProjectAdminDB u project_id) mviewer_id
        Nothing -> pure False

    now <- liftIO getCurrentTime

    amounts <- handlerToWidget (runDB (payoutHistory project now))

    ((_, update_pledge), _) <-
        handlerToWidget
            (generateFormGet
                (maybe previewPledgeForm pledgeForm maybe_project_id))

    (mechUser, _mechProject) <- runDB $ do
        u <- sequence $ fmap Mech.fetchUser mviewer_id
        p <- sequence $ fmap Mech.fetchProject maybe_project_id
        return (u,p)

    $(widgetFile "project")

data Preview = Preview | NotPreview deriving Eq

renderBlogPost :: Text -> BlogPost -> Preview -> WidgetT App IO ()
renderBlogPost project_handle blog_post preview = do
    (comment_count, project) <- handlerToWidget $ runYDB $ do
        project@(Entity project_id _) <-<commit_msg>Update View.Project to use Mech module prefix<commit_after>{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}

module View.Project
    ( editProjectForm
    , projectContactForm
    , inviteForm
    , Preview (..)
    , ProjectBlog (..)
    , projectBlogForm
    , projectConfirmPledgeForm
    , previewBlogPost
    , renderBlogPost
    , renderProject
    , viewForm
    ) where


import Import

import Control.Applicative (liftA2)
import qualified Data.Text as T

import Data.Filter
import Data.Order
import DeprecatedBootstrap
import Handler.Utils
import Model.Markdown
import Model.Project
import Model.Shares
import Model.User
import Model.Role
import Model.Comment
import View.Time
import View.User (userNameWidget)
import Widgets.Markdown
import Widgets.Preview
import qualified Mechanism as Mech

renderProject :: Maybe ProjectId
              -> Project
              -> Maybe UserId
              -> Bool
              -> WidgetT App IO ()
renderProject maybe_project_id project mviewer_id is_watching = do
    let discussion =
            DiscussionOnProject
                (Entity (fromMaybe (key $ PersistInt64 (-1)) maybe_project_id)
                        project)
        description =
            markdownWidgetWith (fixLinks (projectHandle project) discussion)
                               (projectDescription project)

    userIsAdmin <- case maybe_project_id of
        Just project_id ->
            maybe (pure False)
                  (\u -> runDB $ userIsProjectAdminDB u project_id) mviewer_id
        Nothing -> pure False

    now <- liftIO getCurrentTime

    amounts <- handlerToWidget (runDB (Mech.payoutHistory project now))

    ((_, update_pledge), _) <-
        handlerToWidget
            (generateFormGet
                (maybe previewPledgeForm pledgeForm maybe_project_id))

    (mechUser, _mechProject) <- runDB $ do
        u <- sequence $ fmap Mech.fetchUser mviewer_id
        p <- sequence $ fmap Mech.fetchProject maybe_project_id
        return (u,p)

    $(widgetFile "project")

data Preview = Preview | NotPreview deriving Eq

renderBlogPost :: Text -> BlogPost -> Preview -> WidgetT App IO ()
renderBlogPost project_handle blog_post preview = do
    (comment_count, project) <- handlerToWidget $ runYDB $ do
        project@(Entity project_id _) <-
{'fraction_non_alphanumeric': 0.07260869565217391, 'fraction_numerical': 0.0017391304347826088, 'mean_word_length': 2.55564142194745, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '3193726', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1239, 'n_words': 353}