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

[LANG] upload WIP

parent 1d04806e
......@@ -10,6 +10,7 @@ import Effect.Aff (Aff)
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get, put, post, delete)
import Gargantext.Types (NodeType(..), AsyncTask(..))
import Gargantext.Components.Search.Types (Lang(..))
import Prelude hiding (div)
data Action = Submit String
......@@ -20,7 +21,7 @@ data Action = Submit String
-----------------------------------------------------
-- UploadFile Action
-- file upload types
data FileType = CSV | CSV_HAL | PresseRIS
data FileType = CSV | CSV_HAL | WOS | PresseRIS
derive instance genericFileType :: Generic FileType _
......@@ -31,14 +32,16 @@ instance showFileType :: Show FileType where
show = genericShow
readFileType :: String -> Maybe FileType
readFileType "CSV_HAL" = Just CSV_HAL
readFileType "CSV" = Just CSV
readFileType "CSV_HAL" = Just CSV_HAL
readFileType "PresseRIS" = Just PresseRIS
readFileType "WOS" = Just WOS
readFileType _ = Nothing
data DroppedFile = DroppedFile {
contents :: UploadFileContents
, fileType :: Maybe FileType
, lang :: Maybe Lang
}
type FileHash = String
......@@ -48,7 +51,6 @@ type Reload = Int
newtype UploadFileContents = UploadFileContents String
createNode :: Session -> ID -> CreateValue -> Aff (Array ID)
createNode session parentId = post session $ NodeAPI Node (Just parentId) ""
......@@ -91,7 +93,6 @@ type Tree = { tree :: FTree, asyncTasks :: Array AsyncTask }
instance ntreeFunctor :: Functor NTree where
map f (NTree x ary) = NTree (f x) (map (map f) ary)
newtype LNode = LNode { id :: ID
, name :: Name
, nodeType :: NodeType
......
......@@ -13,7 +13,7 @@ import Reactix as R
import Reactix.DOM.HTML as H
import URI.Extra.QueryPairs as QP
import Web.File.FileReader.Aff (readAsText)
import Gargantext.Components.Search.Types (readLang, Lang(..))
import Gargantext.Components.Forest.Tree.Node.Action
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, postWwwUrlencoded)
......@@ -36,18 +36,35 @@ uploadFileViewCpt d = R.hooksComponent "UploadFileView" cpt
cpt {id} _ = do
mContents :: R.State (Maybe UploadFileContents) <- R.useState' Nothing
fileType :: R.State FileType <- R.useState' CSV
lang :: R.State (Maybe Lang) <- R.useState' (Just EN)
pure $ H.div {} [
H.div {} [ H.text "Upload file!" ]
, H.div {} [ H.input {type: "file", placeholder: "Choose file", on: {change: onChangeContents mContents}} ]
, H.div {}
[ R2.select {className: "col-md-12 form-control"
, H.div {} [ H.input { type: "file"
, placeholder: "Choose file"
, on: {change: onChangeContents mContents}
}
]
, H.div {} [ R2.select {className: "col-md-12 form-control"
, on: {change: onChangeFileType fileType}
}
(map renderOption [CSV, CSV_HAL])
( map renderOption [ CSV
, CSV_HAL
, WOS
, PresseRIS
]
, H.div {}
[ uploadButton d id mContents fileType ]
)
]
, H.div {} [ R2.select {className: "col-md-12 form-control"
, on: {change: onChangeLang lang}
} (map renderOption [EN, FR])
]
, H.div {} [ uploadButton d id mContents fileType lang ]
]
renderOption opt = H.option {} [ H.text $ show opt ]
......@@ -62,10 +79,26 @@ uploadFileViewCpt d = R.hooksComponent "UploadFileView" cpt
setMContents $ const $ Just $ UploadFileContents contents
onChangeFileType (fileType /\ setFileType) e = do
setFileType $ const $ unsafePartial $ fromJust $ readFileType $ R2.unsafeEventValue e
uploadButton :: (Action -> Aff Unit) -> Int -> R.State (Maybe UploadFileContents) -> R.State FileType -> R.Element
uploadButton d id (mContents /\ setMContents) (fileType /\ setFileType) =
setFileType $ const
$ unsafePartial
$ fromJust
$ readFileType
$ R2.unsafeEventValue e
onChangeLang (lang /\ setLang) e = do
setLang $ const
$ unsafePartial
$ readLang
$ R2.unsafeEventValue e
uploadButton :: (Action -> Aff Unit)
-> Int
-> R.State (Maybe UploadFileContents)
-> R.State FileType
-> R.State (Maybe Lang)
-> R.Element
uploadButton d id (mContents /\ setMContents) (fileType /\ setFileType) (lang /\ setLang) =
H.button {className: "btn btn-primary", disabled, on: {click: onClick}} [ H.text "Upload" ]
where
disabled = case mContents of
......@@ -79,6 +112,7 @@ uploadButton d id (mContents /\ setMContents) (fileType /\ setFileType) =
liftEffect $ do
setMContents $ const $ Nothing
setFileType $ const $ CSV
setLang $ const $ Just EN
-- START File Type View
type FileTypeProps =
......@@ -127,11 +161,14 @@ fileTypeView d p (Just (DroppedFile {contents, fileType}) /\ setDroppedFile) (_
[ R2.select {className: "col-md-12 form-control"
, on: {change: onChange}
}
(map renderOption [CSV, CSV_HAL])
(map renderOption [CSV, CSV_HAL, WOS])
]
where
onChange e =
setDroppedFile $ const $ Just $ DroppedFile $ {contents, fileType: readFileType $ R2.unsafeEventValue e}
onChange e l =
setDroppedFile $ const $ Just $ DroppedFile $ { contents
, fileType: readFileType $ R2.unsafeEventValue e
, lang : readLang $ R2.unsafeEventValue l
}
renderOption opt = H.option {} [ H.text $ show opt ]
panelFooter =
H.div {className: "panel-footer"}
......
......@@ -22,7 +22,7 @@ import Gargantext.Components.Forest.Tree.Node.Action.Add (NodePopup(..), createN
import Gargantext.Components.Forest.Tree.Node.Action.Rename (renameBox)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFileView, fileTypeView)
import Gargantext.Components.Forest.Tree.Node.ProgressBar (asyncProgressBar)
import Gargantext.Components.Search.Types (allLangs)
import Gargantext.Components.Search.Types (allLangs, Lang(EN))
import Gargantext.Components.Search.SearchBar (searchBar)
import Gargantext.Components.Search.SearchField (Search, defaultSearch, isIsTex)
......@@ -132,6 +132,7 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
$ Just
$ DroppedFile { contents: (UploadFileContents contents)
, fileType: Just CSV
, lang: Just EN
}
onDragOverHandler (_ /\ setIsDragOver) e = do
-- prevent redirection when file is dropped
......
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