Commit e004b064 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graphql] ethercalc csv download graphql frontend

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