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

[LANG] upload WIP

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