Commit e004b064 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graphql] ethercalc csv download graphql frontend

parent 7ea0fe74
module Gargantext.Components.GraphQL where
import Gargantext.Prelude
import Affjax.RequestHeader as ARH
import Data.Argonaut.Decode (JsonDecodeError)
import Data.Bifunctor (lmap)
import Data.List.Types (NonEmptyList)
import Data.Maybe (Maybe)
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Foreign (unsafeToForeign, ForeignError)
import Gargantext.Components.GraphQL.Node (Node)
import Gargantext.Components.GraphQL.Node (EthercalcCSVDownloadM, Node)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.Components.GraphQL.Task (AsyncTaskWithType)
import Gargantext.Prelude
import Gargantext.Sessions (Session(..))
import Gargantext.Types (NodeType)
import Gargantext.Utils.Reactix as R2
import GraphQL.Client.Args (type (==>))
import GraphQL.Client.BaseClients.Urql (UrqlClient, createClient)
......@@ -73,4 +73,5 @@ type Schema
}
type Mutation
= { update_user_info :: UserInfoM ==> Int }
= { ethercalc_csv_download :: EthercalcCSVDownloadM ==> Maybe AsyncTaskWithType
, update_user_info :: UserInfoM ==> Int }
......@@ -5,15 +5,18 @@ import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Gargantext.Components.GraphQL (queryGql)
import Gargantext.Components.GraphQL (getClient, queryGql)
import Gargantext.Components.GraphQL.Node
import Gargantext.Components.GraphQL.User
import Gargantext.Config.REST (AffRESTError, RESTError(..))
import Gargantext.Prelude
import Gargantext.Sessions (Session)
import Gargantext.Types (NodeType)
import Gargantext.Types (AsyncTaskWithType(..), AsyncTask(..), AsyncTaskType(..), NodeType)
import Gargantext.Utils.Reactix as R2
import GraphQL.Client.Args (onlyArgs)
import GraphQL.Client.Query (mutation)
import GraphQL.Client.Variables (withVars)
import Simple.JSON as JSON
here :: R2.Here
here = R2.here "Gargantext.Components.GraphQL.Endpoints"
......@@ -34,3 +37,23 @@ getUserInfo session id = do
Nothing -> Left (CustomError $ "user with id " <> show id <> " not found")
-- NOTE Contact is at G.C.N.A.U.C.Types
Just ui -> Right ui
triggerEthercalcCSVDownload :: Session -> Int -> Int -> Aff (Maybe AsyncTaskWithType)
triggerEthercalcCSVDownload session corpusId nodeId = do
client <- liftEffect $ getClient session
res <- mutation
client
"trigger ethercalc CSV download"
{ ethercalc_csv_download: onlyArgs { corpusId
, nodeId } }
pure $ case res.ethercalc_csv_download of
Nothing -> Nothing
Just { task: { id, status }, typ } ->
case JSON.readJSON typ of
Left _ -> Nothing
Right typ_ ->
case JSON.readJSON status of
Left _ -> Nothing
Right status_ ->
Just $ AsyncTaskWithType { task: AsyncTask { id, status: status_ }
, typ: typ_ }
......@@ -27,3 +27,7 @@ nodeParentQuery = { node_parent: { node_id: Var :: _ "id" Int
, parent_id: unit
, type_id: unit }
}
type EthercalcCSVDownloadM
= { corpusId :: Int
, nodeId :: Int }
module Gargantext.Components.GraphQL.Task where
import Gargantext.Types (AsyncTaskID)
type AsyncTaskStatus = String
type AsyncTaskType = String
type AsyncTask =
{ id :: AsyncTaskID
, status :: AsyncTaskStatus}
type AsyncTaskWithType =
{ task :: AsyncTask
, typ :: AsyncTaskType }
......@@ -33,7 +33,7 @@ import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import GraphQL.Client.Args (IgnoreArg(..), OrArg(..), onlyArgs)
import GraphQL.Client.Query (mutationOpts)
import GraphQL.Client.Query (mutation)
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
......@@ -198,8 +198,7 @@ saveContactHyperdata session id = put session (Routes.NodeAPI Node (Just id) "")
saveUserInfo :: Session -> Int -> UserInfo -> AffRESTError Int
saveUserInfo session id ui = do
client <- liftEffect $ getClient session
res <- mutationOpts
(\m -> m)
res <- mutation
client
"update user_info"
{ update_user_info: onlyArgs { ui_id: id
......
......@@ -16,7 +16,7 @@ import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.FolderView as FV
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..))
import Gargantext.Components.GraphQL.Endpoints (getNodeParent)
import Gargantext.Components.GraphQL.Endpoints (getNodeParent, triggerEthercalcCSVDownload)
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Config.REST (RESTError, AffRESTError, logRESTError)
import Gargantext.Hooks.Loader (useLoader)
......@@ -153,17 +153,18 @@ importIntoListButtonCpt = here.component "importIntoListButton" cpt where
Nothing -> liftEffect $ here.log2 "[importIntoListButton] corpusNodes empty" corpusNodes
Just { head: corpusNode } -> do
-- Use that corpus id
eCsv <- EC.downloadCSV base frame_id
case eCsv of
Left err -> liftEffect $ here.log2 "[importIntoListButton] error with csv" err
Right csv -> do
let uploadPath = GR.NodeAPI NodeList (Just corpusNode.id) $ GT.asyncTaskTypePath GT.ListCSVUpload
eTask :: Either RESTError GT.AsyncTaskWithType <- postWwwUrlencoded
session
uploadPath
[ Tuple "_wf_data" (Just csv.body)
, Tuple "_wf_filetype" (Just $ show CSV)
, Tuple "_wf_name" (Just frame_id) ]
triggerEthercalcCSVDownload session corpusNode.id nodeId
-- eCsv <- EC.downloadCSV base frame_id
-- case eCsv of
-- Left err -> liftEffect $ here.log2 "[importIntoListButton] error with csv" err
-- Right csv -> do
-- let uploadPath = GR.NodeAPI NodeList (Just corpusNode.id) $ GT.asyncTaskTypePath GT.ListCSVUpload
-- eTask :: Either RESTError GT.AsyncTaskWithType <- postWwwUrlencoded
-- session
-- uploadPath
-- [ Tuple "_wf_data" (Just csv.body)
-- , Tuple "_wf_filetype" (Just $ show CSV)
-- , Tuple "_wf_name" (Just frame_id) ]
pure unit
type NodeFrameVisioProps =
......
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