<commit_before>{-# language CPP #-}
{-# language GADTs #-}
{-# language FlexibleContexts #-}
{-# language RankNTypes #-}
{-# language RecursiveDo #-}
{-# language LambdaCase  #-}
{-# language RankNTypes  #-}
{-# language OverloadedStrings  #-}
{-# language JavaScriptFFI #-}
{-# language ScopedTypeVariables  #-}

module Frontend.Function where

import Control.Applicative (liftA2)
import Control.Monad (join)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Exception (MonadAsyncException)
import Control.Monad.Fix (MonadFix)
import Control.Monad.Ref (MonadRef, Ref)
import qualified Data.Aeson as A
import Data.Bool (bool)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.Either (isRight)
import qualified Data.Foldable as F
import Data.List (foldl', isInfixOf)
import qualified Data.Map as Map
import Data.Maybe (fromMaybe, maybe)
import Data.Monoid
import qualified Data.Text as T
import qualified Data.Text.Encoding as E
import Data.Time (getCurrentTime)
import GHC.IORef (IORef)
import GHCJS.DOM.Types (Document)
import Reflex
import Reflex.Dom
import Reflex.Dom.WebSocket
import Text.PrettyPrint.HughesPJClass (prettyShow)
import Message
import Model
import RemoteFunction
import WorkerProfile
import BrowserProfile
import EntityID
#ifdef ghcjs_HOST_OS
import GHCJS.DOM.Document (getLocation)
#endif
import GHCJS.DOM.Location

import Job
import Pretty
import Frontend.Expression
import Frontend.ImageWidget


------------------------------------------------------------------------------
-- | FunctionWidget shows profile information for a function,
--   and editing controls when the viewer has editing rights
-- data FunctionWidget t = FunctionWidget
--   { _functionWidget_profile :: Dynamic t WorkerProfile }

functionListingItem :: (DomBuilder t m, DomBuilderSpace m ~ GhcjsDomSpace, PostBuild t m) => T.Text -> Dynamic t Type -> m (Event t T.Text) -- FunctionWidget t -> m ()
functionListingItem k t = do
  item <- fmap fst $ elAttr' "div" ("class" =: "item" <> "data-value" =: k)$ do
    elAttr "span" ("class" =: "description") $ dynText $ T.pack . prettyShow <$> t
    text k
  return $ k <$ domEvent Click item


functionListing' :: forall t m .(DomBuilder t m, DomBuilderSpace m ~ GhcjsDomSpace, MonadFix m,MonadHold t m, PostBuild t m)
                => Dynamic t (Map.Map T.Text Type) -- WorkerProfileMap -- (Map.Map T.Text Function)
                -- TODO: change Function to FunctionInfo
                --       FunctionInfo might list tags,
                --       usage history, nWorkers implementing, etc
                -> m (Event t T.Text)
functionListing' funs = do
 elAttr "div" ("style" =: "min-width: 300px;") $ do
  divClass "ui fluid search selection dropdown" $ do
    elAttr "input" ("type" =: "hidden" <> "name" =: "function-search") blank
    elAttr "i" ("class" =: "dropdown icon") blank
    divClass "default text" $ text "Remote function..."
    menu :: Dynamic t (Map.Map T.Text (Event t T.Text)) <- divClass "menu" $
      listWithKey funs (functionListingItem)
    return $ switchPromptlyDyn $ leftmost . Map.elems <$> menu
<commit_msg>Add default argument to expression chosen by menu click<commit_after>{-# language CPP #-}
{-# language GADTs #-}
{-# language FlexibleContexts #-}
{-# language RankNTypes #-}
{-# language RecursiveDo #-}
{-# language LambdaCase  #-}
{-# language RankNTypes  #-}
{-# language OverloadedStrings  #-}
{-# language JavaScriptFFI #-}
{-# language ScopedTypeVariables  #-}

module Frontend.Function where

import Control.Applicative (liftA2)
import Control.Monad (join)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Exception (MonadAsyncException)
import Control.Monad.Fix (MonadFix)
import Control.Monad.Ref (MonadRef, Ref)
import qualified Data.Aeson as A
import Data.Bool (bool)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.Either (isRight)
import qualified Data.Foldable as F
import Data.List (foldl', isInfixOf)
import qualified Data.Map as Map
import Data.Maybe (fromMaybe, maybe)
import Data.Monoid
import qualified Data.Text as T
import qualified Data.Text.Encoding as E
import Data.Time (getCurrentTime)
import GHC.IORef (IORef)
import GHCJS.DOM.Types (Document)
import Reflex
import Reflex.Dom
import Reflex.Dom.WebSocket
import Text.PrettyPrint.HughesPJClass (prettyShow)
import Message
import Model
import RemoteFunction
import WorkerProfile
import BrowserProfile
import EntityID
#ifdef ghcjs_HOST_OS
import GHCJS.DOM.Document (getLocation)
#endif
import GHCJS.DOM.Location

import Job
import Pretty
import Frontend.Expression
import Frontend.ImageWidget


------------------------------------------------------------------------------
-- | FunctionWidget shows profile information for a function,
--   and editing controls when the viewer has editing rights
-- data FunctionWidget t = FunctionWidget
--   { _functionWidget_profile :: Dynamic t WorkerProfile }

functionListingItem :: (DomBuilder t m, DomBuilderSpace m ~ GhcjsDomSpace, PostBuild t m) => T.Text -> Dynamic t Type -> m (Event t T.Text) -- FunctionWidget t -> m ()
functionListingItem k t = do
  item <- fmap fst $ elAttr' "div" ("class" =: "item" <> "data-value" =: k)$ do
    elAttr "span" ("class" =: "description") $ dynText $ T.pack . prettyShow <$> t
    text k
  return $ (k <> " #1") <$ domEvent Click item


functionListing' :: forall t m .(DomBuilder t m, DomBuilderSpace m ~ GhcjsDomSpace, MonadFix m,MonadHold t m, PostBuild t m)
                => Dynamic t (Map.Map T.Text Type) -- WorkerProfileMap -- (Map.Map T.Text Function)
                -- TODO: change Function to FunctionInfo
                --       FunctionInfo might list tags,
                --       usage history, nWorkers implementing, etc
                -> m (Event t T.Text)
functionListing' funs = do
 elAttr "div" ("style" =: "min-width: 300px;") $ do
  divClass "ui fluid search selection dropdown" $ do
    elAttr "input" ("type" =: "hidden" <> "name" =: "function-search") blank
    elAttr "i" ("class" =: "dropdown icon") blank
    divClass "default text" $ text "Remote function..."
    menu :: Dynamic t (Map.Map T.Text (Event t T.Text)) <- divClass "menu" $
      listWithKey funs (functionListingItem)
    return $ switchPromptlyDyn $ leftmost . Map.elems <$> menu

{'fraction_non_alphanumeric': 0.13309296127919737, 'fraction_numerical': 0.002037936980717981, 'mean_word_length': 3.3698630136986303, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 24, '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': '4110150', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1908, 'n_words': 633}