Commit e13a1318 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] Upload File with FR Lang

parent 666c37ac
...@@ -327,8 +327,8 @@ performAction = performAction' where ...@@ -327,8 +327,8 @@ performAction = performAction' where
performAction' (SharePublic { params }) p = sharePublic params p performAction' (SharePublic { params }) p = sharePublic params p
performAction' (AddContact params) p = addContact params p performAction' (AddContact params) p = addContact params p
performAction' (AddNode name nodeType) p = addNode' name nodeType p performAction' (AddNode name nodeType) p = addNode' name nodeType p
performAction' (UploadFile nodeType fileType fileFormat mName contents selection) p = performAction' (UploadFile nodeType fileType fileFormat lang mName contents selection) p =
uploadFile' nodeType fileType fileFormat mName contents p selection uploadFile' nodeType fileType fileFormat lang mName contents p selection
performAction' (UploadArbitraryFile fileFormat mName blob selection) p = performAction' (UploadArbitraryFile fileFormat mName blob selection) p =
uploadArbitraryFile' fileFormat mName blob p selection uploadArbitraryFile' fileFormat mName blob p selection
performAction' DownloadNode _ = liftEffect $ here.log "[performAction] DownloadNode" performAction' DownloadNode _ = liftEffect $ here.log "[performAction] DownloadNode"
...@@ -391,8 +391,8 @@ performAction = performAction' where ...@@ -391,8 +391,8 @@ performAction = performAction' where
addContact params { nodeId: id, session } = addContact params { nodeId: id, session } =
void $ Contact.contactReq session id params void $ Contact.contactReq session id params
uploadFile' nodeType fileType fileFormat mName contents { boxes: { errors, tasks }, nodeId: id, session } selection = do uploadFile' nodeType fileType fileFormat lang mName contents { boxes: { errors, tasks }, nodeId: id, session } selection = do
eTask <- uploadFile { contents, fileType, fileFormat, id, nodeType, mName, selection, session } eTask <- uploadFile { contents, fileType, fileFormat, lang, id, nodeType, mName, selection, session }
handleRESTError errors eTask $ \task -> liftEffect $ do handleRESTError errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks GAT.insert id task tasks
here.log2 "[performAction] UploadFile, uploaded, task:" task here.log2 "[performAction] UploadFile, uploaded, task:" task
......
...@@ -345,8 +345,8 @@ addNode' name nodeType p@{ boxes: { errors, forestOpen }, session, tree: (NTree ...@@ -345,8 +345,8 @@ addNode' name nodeType p@{ boxes: { errors, forestOpen }, session, tree: (NTree
liftEffect $ T.modify_ (openNodesInsert (mkNodeId session id)) forestOpen liftEffect $ T.modify_ (openNodesInsert (mkNodeId session id)) forestOpen
refreshTree p refreshTree p
uploadFile' nodeType fileType fileFormat mName contents p@{ boxes: { errors, tasks }, session, tree: (NTree (LNode { id }) _) } selection = do uploadFile' nodeType fileType fileFormat lang mName contents p@{ boxes: { errors, tasks }, session, tree: (NTree (LNode { id }) _) } selection = do
eTask <- uploadFile { contents, fileFormat, fileType, id, mName, nodeType, selection, session } eTask <- uploadFile { contents, fileFormat, fileType, id, lang, mName, nodeType, selection, session }
handleRESTError errors eTask $ \task -> liftEffect $ do handleRESTError errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks GAT.insert id task tasks
here.log2 "[uploadFile'] UploadFile, uploaded, task:" task here.log2 "[uploadFile'] UploadFile, uploaded, task:" task
...@@ -399,8 +399,8 @@ performAction (SharePublic { params }) p = sharePublic para ...@@ -399,8 +399,8 @@ performAction (SharePublic { params }) p = sharePublic para
performAction (AddContact params) p = addContact params p performAction (AddContact params) p = addContact params p
performAction (AddNode name nodeType) p = addNode' name nodeType p performAction (AddNode name nodeType) p = addNode' name nodeType p
performAction UploadFrameCalc p = uploadFrameCalc' p performAction UploadFrameCalc p = uploadFrameCalc' p
performAction (UploadFile nodeType fileType fileFormat mName contents selection) p = performAction (UploadFile nodeType fileType fileFormat lang mName contents selection) p =
uploadFile' nodeType fileType fileFormat mName contents p selection uploadFile' nodeType fileType fileFormat lang mName contents p selection
performAction (UploadArbitraryFile fileFormat mName blob selection) p = performAction (UploadArbitraryFile fileFormat mName blob selection) p =
uploadArbitraryFile' fileFormat mName blob p selection uploadArbitraryFile' fileFormat mName blob p selection
performAction DownloadNode _ = liftEffect $ here.log "[performAction] DownloadNode" performAction DownloadNode _ = liftEffect $ here.log "[performAction] DownloadNode"
......
...@@ -42,7 +42,7 @@ icon (ShareTeam _) = glyphiconNodeAction Share ...@@ -42,7 +42,7 @@ icon (ShareTeam _) = glyphiconNodeAction Share
icon (AddContact _) = glyphiconNodeAction Share icon (AddContact _) = glyphiconNodeAction Share
icon (SharePublic _ ) = glyphiconNodeAction (Publish { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }}) icon (SharePublic _ ) = glyphiconNodeAction (Publish { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (DoSearch _) = glyphiconNodeAction SearchBox icon (DoSearch _) = glyphiconNodeAction SearchBox
icon (UploadFile _ _ _ _ _ _) = glyphiconNodeAction Upload icon (UploadFile _ _ _ _ _ _ _) = glyphiconNodeAction Upload
icon (UploadArbitraryFile _ _ _ _ ) = glyphiconNodeAction Upload icon (UploadArbitraryFile _ _ _ _ ) = glyphiconNodeAction Upload
icon UploadFrameCalc = glyphiconNodeAction Upload icon UploadFrameCalc = glyphiconNodeAction Upload
icon RefreshTree = glyphiconNodeAction Refresh icon RefreshTree = glyphiconNodeAction Refresh
...@@ -66,7 +66,7 @@ text (ShareTeam _ ) = "Share with team !" ...@@ -66,7 +66,7 @@ text (ShareTeam _ ) = "Share with team !"
text (AddContact _ ) = "Add contact !" text (AddContact _ ) = "Add contact !"
text (SharePublic _ ) = "Publish !" text (SharePublic _ ) = "Publish !"
text (DoSearch _ ) = "Launch search !" text (DoSearch _ ) = "Launch search !"
text (UploadFile _ _ _ _ _ _) = "Upload File !" text (UploadFile _ _ _ _ _ _ _) = "Upload File !"
text (UploadArbitraryFile _ _ _ _) = "Upload arbitrary file !" text (UploadArbitraryFile _ _ _ _) = "Upload arbitrary file !"
text UploadFrameCalc = "Upload frame calc" text UploadFrameCalc = "Upload frame calc"
text RefreshTree = "Refresh Tree !" text RefreshTree = "Refresh Tree !"
......
module Gargantext.Components.Forest.Tree.Node.Action.Types where module Gargantext.Components.Forest.Tree.Node.Action.Types where
import Gargantext.Prelude
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe) import Data.Maybe (Maybe)
import Gargantext.Components.Forest.Tree.Node.Action.Contact.Types (AddContactParams) import Gargantext.Components.Forest.Tree.Node.Action.Contact.Types (AddContactParams)
import Gargantext.Components.Forest.Tree.Node.Action.Update.Types (UpdateNodeParams) import Gargantext.Components.Forest.Tree.Node.Action.Update.Types (UpdateNodeParams)
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileFormat, FileType, UploadFileBlob) import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileFormat, FileType, UploadFileBlob)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeOut) import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeOut)
import Gargantext.Components.Lang (Lang(..))
import Gargantext.Components.ListSelection.Types (Selection) import Gargantext.Components.ListSelection.Types (Selection)
import Gargantext.Prelude
import Gargantext.Types as GT import Gargantext.Types as GT
data Action = AddNode String GT.NodeType data Action = AddNode String GT.NodeType
...@@ -16,7 +16,7 @@ data Action = AddNode String GT.NodeType ...@@ -16,7 +16,7 @@ data Action = AddNode String GT.NodeType
| RenameNode String | RenameNode String
| UpdateNode UpdateNodeParams | UpdateNode UpdateNodeParams
| DoSearch GT.AsyncTaskWithType | DoSearch GT.AsyncTaskWithType
| UploadFile GT.NodeType FileType FileFormat (Maybe String) String Selection | UploadFile GT.NodeType FileType FileFormat Lang (Maybe String) String Selection
| UploadArbitraryFile FileFormat (Maybe String) UploadFileBlob Selection | UploadArbitraryFile FileFormat (Maybe String) UploadFileBlob Selection
| UploadFrameCalc | UploadFrameCalc
| DownloadNode | DownloadNode
...@@ -42,8 +42,8 @@ instance Eq Action where ...@@ -42,8 +42,8 @@ instance Eq Action where
eq (RenameNode s1) (RenameNode s2) = eq s1 s2 eq (RenameNode s1) (RenameNode s2) = eq s1 s2
eq (UpdateNode un1) (UpdateNode un2) = eq un1 un2 eq (UpdateNode un1) (UpdateNode un2) = eq un1 un2
eq (DoSearch at1) (DoSearch at2) = eq at1 at2 eq (DoSearch at1) (DoSearch at2) = eq at1 at2
eq (UploadFile nt1 ft1 ff1 s1 _ _) (UploadFile nt2 ft2 ff2 s2 _ _) = eq (UploadFile nt1 ft1 ff1 l1 s1 _ _) (UploadFile nt2 ft2 ff2 l2 s2 _ _) =
(eq nt1 nt2) && (eq ft1 ft2) && (eq ff1 ff2) && (eq s1 s2) (eq nt1 nt2) && (eq ft1 ft2) && (eq ff1 ff2) && (eq l1 l2) && (eq s1 s2)
eq (UploadArbitraryFile ff1 s1 _ _) (UploadArbitraryFile ff2 s2 _ _) = (eq ff1 ff2) && (eq s1 s2) eq (UploadArbitraryFile ff1 s1 _ _) (UploadArbitraryFile ff2 s2 _ _) = (eq ff1 ff2) && (eq s1 s2)
eq UploadFrameCalc UploadFrameCalc = true eq UploadFrameCalc UploadFrameCalc = true
eq DownloadNode DownloadNode = true eq DownloadNode DownloadNode = true
...@@ -68,7 +68,7 @@ instance Show Action where ...@@ -68,7 +68,7 @@ instance Show Action where
show (AddContact _ ) = "AddContact" show (AddContact _ ) = "AddContact"
show (SharePublic _ ) = "SharePublic" show (SharePublic _ ) = "SharePublic"
show (DoSearch _ ) = "SearchQuery" show (DoSearch _ ) = "SearchQuery"
show (UploadFile _ _ _ _ _ _) = "UploadFile" show (UploadFile _ _ _ _ _ _ _) = "UploadFile"
show (UploadArbitraryFile _ _ _ _) = "UploadArbitraryFile" show (UploadArbitraryFile _ _ _ _) = "UploadArbitraryFile"
show UploadFrameCalc = "UploadFrameCalc" show UploadFrameCalc = "UploadFrameCalc"
show RefreshTree = "RefreshTree" show RefreshTree = "RefreshTree"
......
...@@ -59,11 +59,15 @@ actionUploadCpt :: R.Component ActionUpload ...@@ -59,11 +59,15 @@ actionUploadCpt :: R.Component ActionUpload
actionUploadCpt = here.component "actionUpload" cpt where actionUploadCpt = here.component "actionUpload" cpt where
cpt { nodeType: Corpus, dispatch, id, session } _ = cpt { nodeType: Corpus, dispatch, id, session } _ =
pure $ uploadFileView { dispatch, id, nodeType: GT.Corpus, session } pure $ uploadFileView { dispatch, id, nodeType: GT.Corpus, session }
cpt { nodeType: NodeList, dispatch, id, session } _ = cpt { nodeType: NodeList, dispatch, id, session } _ =
pure $ uploadTermListView { dispatch, id, nodeType: GT.NodeList, session } [] pure $ uploadTermListView { dispatch, id, nodeType: GT.NodeList, session } []
cpt props@{ nodeType: NodeFrameCalc } _ = pure $ uploadFrameCalcView props [] cpt props@{ nodeType: NodeFrameCalc } _ = pure $ uploadFrameCalcView props []
cpt props@{ nodeType: Annuaire, dispatch, id, session } _ = do
cpt props@{ nodeType: Annuaire, dispatch, id, session } _ =
pure $ uploadListView { dispatch, id, nodeType: GT.Annuaire, session } pure $ uploadListView { dispatch, id, nodeType: GT.Annuaire, session }
cpt props@{ nodeType: _ } _ = pure $ actionUploadOther props [] cpt props@{ nodeType: _ } _ = pure $ actionUploadOther props []
{- {-
...@@ -103,15 +107,15 @@ uploadFileViewCpt = here.component "uploadFileView" cpt ...@@ -103,15 +107,15 @@ uploadFileViewCpt = here.component "uploadFileView" cpt
where where
cpt { dispatch, id, nodeType, session } _ = do cpt { dispatch, id, nodeType, session } _ = do
-- mFile :: R.State (Maybe UploadFile) <- R.useState' Nothing -- mFile :: R.State (Maybe UploadFile) <- R.useState' Nothing
mFile <- T.useBox (Nothing :: Maybe UploadFile) mFile <- T.useBox (Nothing :: Maybe UploadFile)
fileType <- T.useBox CSV fileType <- T.useBox CSV
fileFormat <- T.useBox Plain fileFormat <- T.useBox Plain
lang <- T.useBox EN lang <- T.useBox EN
selection <- T.useBox ListSelection.MyListsFirst selection <- T.useBox ListSelection.MyListsFirst
let setFileType' val = T.write_ val fileType let setFileType' val = T.write_ val fileType
let setFileFormat' val = T.write_ val fileFormat let setFileFormat' val = T.write_ val fileFormat
let setLang' val = T.write_ val lang let setLang' val = T.write_ val lang
let bodies = let bodies =
[ R2.row [ R2.row
...@@ -148,7 +152,8 @@ uploadFileViewCpt = here.component "uploadFileView" cpt ...@@ -148,7 +152,8 @@ uploadFileViewCpt = here.component "uploadFileView" cpt
[ formChoiceSafe { items: [EN, FR, No_extraction, Universal] [ formChoiceSafe { items: [EN, FR, No_extraction, Universal]
, default: EN , default: EN
, callback: setLang' , callback: setLang'
, print: show } [] , print: show
} []
] ]
] ]
, R2.row , R2.row
...@@ -195,6 +200,7 @@ type UploadButtonProps = ...@@ -195,6 +200,7 @@ type UploadButtonProps =
uploadButton :: R2.Component UploadButtonProps uploadButton :: R2.Component UploadButtonProps
uploadButton = R.createElement uploadButtonCpt uploadButton = R.createElement uploadButtonCpt
uploadButtonCpt :: R.Component UploadButtonProps uploadButtonCpt :: R.Component UploadButtonProps
uploadButtonCpt = here.component "uploadButton" cpt uploadButtonCpt = here.component "uploadButton" cpt
where where
...@@ -206,10 +212,11 @@ uploadButtonCpt = here.component "uploadButton" cpt ...@@ -206,10 +212,11 @@ uploadButtonCpt = here.component "uploadButton" cpt
, nodeType , nodeType
, selection , selection
} _ = do } _ = do
fileType' <- T.useLive T.unequal fileType fileType' <- T.useLive T.unequal fileType
fileFormat' <- T.useLive T.unequal fileFormat fileFormat' <- T.useLive T.unequal fileFormat
mFile' <- T.useLive T.unequal mFile mFile' <- T.useLive T.unequal mFile
selection' <- T.useLive T.unequal selection lang' <- T.useLive T.unequal lang
selection' <- T.useLive T.unequal selection
onPending /\ onPendingBox <- R2.useBox' false onPending /\ onPendingBox <- R2.useBox' false
let disabled = isNothing mFile' || onPending let disabled = isNothing mFile' || onPending
...@@ -237,6 +244,7 @@ uploadButtonCpt = here.component "uploadButton" cpt ...@@ -237,6 +244,7 @@ uploadButtonCpt = here.component "uploadButton" cpt
fileFormat' fileFormat'
fileType' fileType'
mFile' mFile'
lang'
selection' selection'
onPendingBox onPendingBox
} }
...@@ -246,7 +254,7 @@ uploadButtonCpt = here.component "uploadButton" cpt ...@@ -246,7 +254,7 @@ uploadButtonCpt = here.component "uploadButton" cpt
where where
onClick fileFormat' fileType' mFile' selection' onPendingBox e = do onClick fileFormat' fileType' mFile' lang' selection' onPendingBox e = do
let { blob, name } = unsafePartial $ fromJust mFile' let { blob, name } = unsafePartial $ fromJust mFile'
T.write_ true onPendingBox T.write_ true onPendingBox
here.log2 "[uploadButton] fileType" fileType' here.log2 "[uploadButton] fileType" fileType'
...@@ -258,7 +266,7 @@ uploadButtonCpt = here.component "uploadButton" cpt ...@@ -258,7 +266,7 @@ uploadButtonCpt = here.component "uploadButton" cpt
contents <- case fileFormat' of contents <- case fileFormat' of
Plain -> readUFBAsText blob Plain -> readUFBAsText blob
ZIP -> readUFBAsBase64 blob ZIP -> readUFBAsBase64 blob
dispatch $ UploadFile nodeType fileType' fileFormat' (Just name) contents selection' dispatch $ UploadFile nodeType fileType' fileFormat' lang' (Just name) contents selection'
liftEffect $ do liftEffect $ do
T.write_ Nothing mFile T.write_ Nothing mFile
T.write_ CSV fileType T.write_ CSV fileType
...@@ -485,7 +493,7 @@ fileTypeViewCpt = here.component "fileTypeView" cpt ...@@ -485,7 +493,7 @@ fileTypeViewCpt = here.component "fileTypeView" cpt
}) droppedFile }) droppedFile
renderOption opt = H.option {} [ H.text $ show opt ] renderOption opt = H.option {} [ H.text $ show opt ]
panelFooter (DroppedFile { blob, fileType }) = panelFooter (DroppedFile { blob, fileType, lang}) =
H.div {className: "card-footer"} H.div {className: "card-footer"}
[ [
case fileType of case fileType of
...@@ -496,7 +504,7 @@ fileTypeViewCpt = here.component "fileTypeView" cpt ...@@ -496,7 +504,7 @@ fileTypeViewCpt = here.component "fileTypeView" cpt
T.write_ Nothing droppedFile T.write_ Nothing droppedFile
launchAff $ do launchAff $ do
contents <- readUFBAsText blob contents <- readUFBAsText blob
dispatch $ UploadFile nodeType ft Plain Nothing contents (SelectedLists []) dispatch $ UploadFile nodeType ft Plain lang Nothing contents (SelectedLists [])
} }
} [H.text "Upload"] } [H.text "Upload"]
Nothing -> Nothing ->
...@@ -522,6 +530,7 @@ uploadFile :: { contents :: String ...@@ -522,6 +530,7 @@ uploadFile :: { contents :: String
, fileFormat :: FileFormat , fileFormat :: FileFormat
, fileType :: FileType , fileType :: FileType
, id :: ID , id :: ID
, lang :: Lang
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
, mName :: Maybe String , mName :: Maybe String
, selection :: ListSelection.Selection , selection :: ListSelection.Selection
...@@ -537,21 +546,24 @@ uploadFile session NodeList id JSON { mName, contents } = do ...@@ -537,21 +546,24 @@ uploadFile session NodeList id JSON { mName, contents } = do
task <- post session url body task <- post session url body
pure $ GT.AsyncTaskWithType { task, typ: GT.Form } pure $ GT.AsyncTaskWithType { task, typ: GT.Form }
-} -}
uploadFile { contents, fileFormat, fileType, id, nodeType, mName, session } = do uploadFile { contents, fileFormat, lang, fileType, id, nodeType, mName, session } = do
-- contents <- readAsText blob -- contents <- readAsText blob
eTask :: Either RESTError GT.AsyncTask <- postWwwUrlencoded session p body eTask :: Either RESTError GT.AsyncTask <- postWwwUrlencoded session p body
pure $ (\task -> GT.AsyncTaskWithType { task, typ }) <$> eTask pure $ (\task -> GT.AsyncTaskWithType { task, typ }) <$> eTask
--postMultipartFormData session p fileContents --postMultipartFormData session p fileContents
where where
bodyParams = [ Tuple "_wf_data" (Just contents) bodyParams = [ Tuple "_wf_data" (Just contents)
, Tuple "_wf_filetype" (Just $ show fileType) , Tuple "_wf_filetype" (Just $ show fileType)
, Tuple "_wf_fileformat" (Just $ show fileFormat) , Tuple "_wf_fileformat" (Just $ show fileFormat)
, Tuple "_wf_name" mName , Tuple "_wf_lang" (Just $ show lang)
, Tuple "_wf_name" mName
] ]
csvBodyParams = [ Tuple "_wtf_data" (Just contents) csvBodyParams = [ Tuple "_wtf_data" (Just contents)
, Tuple "_wtf_filetype" (Just $ show NodeList) , Tuple "_wtf_filetype" (Just $ show NodeList)
, Tuple "_wtf_fileformat" (Just $ show fileFormat) , Tuple "_wtf_fileformat" (Just $ show fileFormat)
, Tuple "_wtf_name" mName ] , Tuple "_wf_lang" (Just $ show lang)
, Tuple "_wtf_name" mName
]
(typ /\ p /\ body) = case nodeType of (typ /\ p /\ body) = case nodeType of
Corpus -> GT.CorpusFormUpload /\ (GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.CorpusFormUpload) /\ bodyParams Corpus -> GT.CorpusFormUpload /\ (GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.CorpusFormUpload) /\ bodyParams
...@@ -685,7 +697,7 @@ uploadTermButtonCpt = here.component "uploadTermButton" cpt ...@@ -685,7 +697,7 @@ uploadTermButtonCpt = here.component "uploadTermButton" cpt
let {name, blob} = unsafePartial $ fromJust mFile' let {name, blob} = unsafePartial $ fromJust mFile'
void $ launchAff do void $ launchAff do
contents <- readUFBAsText blob contents <- readUFBAsText blob
_ <- dispatch $ UploadFile nodeType uploadType' Plain (Just name) contents (SelectedLists []) _ <- dispatch $ UploadFile nodeType uploadType' Plain EN (Just name) contents (SelectedLists [])
liftEffect $ do liftEffect $ do
T.write_ Nothing mFile T.write_ Nothing mFile
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
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