Commit 3f3693fb authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[toolbar] camera: simpler and more reliable screenshot filename gen

parent 09a5846c
...@@ -40,6 +40,7 @@ to generate this file without the comments in this block. ...@@ -40,6 +40,7 @@ to generate this file without the comments in this block.
, "foreign" , "foreign"
, "foreign-object" , "foreign-object"
, "form-urlencoded" , "form-urlencoded"
, "formatters"
, "formula" , "formula"
, "functions" , "functions"
, "graphql-client" , "graphql-client"
...@@ -47,9 +48,7 @@ to generate this file without the comments in this block. ...@@ -47,9 +48,7 @@ to generate this file without the comments in this block.
, "integers" , "integers"
, "js-timers" , "js-timers"
, "lists" , "lists"
-- , "markdown"
, "markdown-it" , "markdown-it"
--, "markdown-smolder"
, "maybe" , "maybe"
, "media-types" , "media-types"
, "milkis" , "milkis"
...@@ -75,7 +74,6 @@ to generate this file without the comments in this block. ...@@ -75,7 +74,6 @@ to generate this file without the comments in this block.
, "simple-json" , "simple-json"
, "simple-json-generics" , "simple-json-generics"
, "simplecrypto" , "simplecrypto"
-- , "smolder"
, "strings" , "strings"
, "strings-extra" , "strings-extra"
, "stringutils" , "stringutils"
......
...@@ -11,15 +11,13 @@ module Gargantext.Components.GraphExplorer.Toolbar.Buttons ...@@ -11,15 +11,13 @@ module Gargantext.Components.GraphExplorer.Toolbar.Buttons
import Prelude import Prelude
import Data.Array as A import Data.Array as A
import Data.DateTime as DDT
import Data.DateTime.Instant as DDI
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Enum (fromEnum) import Data.Formatter.DateTime as DFDT
import Data.Foldable (intercalate) import Data.Foldable (intercalate)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Sequence as Seq import Data.Sequence as Seq
import Data.String as DS
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
import Effect (Effect)
import Effect.Aff (launchAff_) import Effect.Aff (launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Now as EN import Effect.Now as EN
...@@ -64,34 +62,34 @@ centerButton sigmaRef = B.button ...@@ -64,34 +62,34 @@ centerButton sigmaRef = B.button
type CameraButtonProps = type CameraButtonProps =
( id :: Int ( id :: Int
, hyperdataGraph :: GET.HyperdataGraph , hyperdataGraph :: GET.HyperdataGraph
, reloadForest :: T2.ReloadS
, session :: Session , session :: Session
, sigmaRef :: R.Ref Sigmax.Sigma , sigmaRef :: R.Ref Sigmax.Sigma
, reloadForest :: T2.ReloadS
) )
screenshotFilename :: Effect String
cameraButton :: Record CameraButtonProps -> R.Element screenshotFilename = do
cameraButton { id nowdt <- EN.nowDateTime
pure $ case DFDT.formatDateTime "YYYY-MM-DDTHH:mm:ss" nowdt of
Left err -> err
Right s -> s <> "-screenshot.png"
cameraButton :: R2.Leaf CameraButtonProps
cameraButton = R2.leaf cameraButtonCpt
cameraButtonCpt :: R.Component CameraButtonProps
cameraButtonCpt = here.component "cameraButton" cpt
where
cpt { id
, hyperdataGraph: GET.HyperdataGraph { graph: GET.GraphData hyperdataGraph } , hyperdataGraph: GET.HyperdataGraph { graph: GET.GraphData hyperdataGraph }
, reloadForest
, session , session
, sigmaRef , sigmaRef } _ = do
, reloadForest } = B.button pure $ B.button
{ callback: \_ -> do
{ variant: OutlinedButtonVariant Secondary filename <- screenshotFilename
, callback: \_ -> do
let sigma = R.readRef sigmaRef let sigma = R.readRef sigmaRef
Sigmax.dependOnSigma sigma "[cameraButton] sigma: Nothing" $ \s -> do Sigmax.dependOnSigma sigma "[cameraButton] sigma: Nothing" $ \s -> do
screen <- Sigma.takeScreenshot s screen <- Sigma.takeScreenshot s
now <- EN.now
let nowdt = DDI.toDateTime now
nowd = DDT.date nowdt
nowt = DDT.time nowdt
nowStr = DS.joinWith "-" [ show $ fromEnum $ DDT.year nowd
, show $ fromEnum $ DDT.month nowd
, show $ fromEnum $ DDT.day nowd
, show $ fromEnum $ DDT.hour nowt
, show $ fromEnum $ DDT.minute nowt
, show $ fromEnum $ DDT.second nowt ]
let graph = Sigma.graph s let graph = Sigma.graph s
edges = Graphology.edges graph edges = Graphology.edges graph
nodes = Graphology.nodes graph nodes = Graphology.nodes graph
...@@ -104,13 +102,13 @@ cameraButton { id ...@@ -104,13 +102,13 @@ cameraButton { id
case eClonedGraphId of case eClonedGraphId of
Left err -> liftEffect $ log2 "[cameraButton] RESTError" err Left err -> liftEffect $ log2 "[cameraButton] RESTError" err
Right clonedGraphId -> do Right clonedGraphId -> do
eRet <- uploadArbitraryData session clonedGraphId Plain (Just $ nowStr <> "-" <> "screenshot.png") screen eRet <- uploadArbitraryData session clonedGraphId Plain (Just filename) screen
case eRet of case eRet of
Left err -> liftEffect $ log2 "[cameraButton] RESTError" err Left err -> liftEffect $ log2 "[cameraButton] RESTError" err
Right _ret -> do Right _ret -> do
liftEffect $ T2.reload reloadForest liftEffect $ T2.reload reloadForest
} , variant: OutlinedButtonVariant Secondary
[ H.text "Screenshot" ] } [ H.text "Screenshot" ]
------------------------------------------------------ ------------------------------------------------------
......
...@@ -185,9 +185,9 @@ controlsCpt = R.memo' $ here.component "controls" cpt where ...@@ -185,9 +185,9 @@ controlsCpt = R.memo' $ here.component "controls" cpt where
cameraButton cameraButton
{ id: graphId' { id: graphId'
, hyperdataGraph: hyperdataGraph' , hyperdataGraph: hyperdataGraph'
, reloadForest
, session: session , session: session
, sigmaRef: sigmaRef , sigmaRef: sigmaRef
, reloadForest
} }
] ]
, ,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment