Commit 914fc19b authored by Alexandre Delanoë's avatar Alexandre Delanoë

[REFACT] Forest Tree Node Box -> actionSearch

parent 793d4013
...@@ -298,8 +298,7 @@ nodeActionsNodeListCpt = R.hooksComponent "G.C.F.T.N.B.nodeActionsNodeList" cpt ...@@ -298,8 +298,7 @@ nodeActionsNodeListCpt = R.hooksComponent "G.C.F.T.N.B.nodeActionsNodeList" cpt
] ]
type NodeListUpdateButtonProps = type NodeListUpdateButtonProps =
( ( listId :: GT.ListId
listId :: GT.ListId
, nodeId :: ID , nodeId :: ID
, nodeType :: GT.TabSubType GT.CTabNgramType , nodeType :: GT.TabSubType GT.CTabNgramType
, session :: Session , session :: Session
...@@ -315,10 +314,11 @@ nodeListUpdateButtonCpt = R.hooksComponent "G.C.F.T.N.B.nodeListUpdateButton" cp ...@@ -315,10 +314,11 @@ nodeListUpdateButtonCpt = R.hooksComponent "G.C.F.T.N.B.nodeListUpdateButton" cp
cpt { listId, nodeId, nodeType, session, triggerRefresh } _ = do cpt { listId, nodeId, nodeType, session, triggerRefresh } _ = do
enabled <- R.useState' true enabled <- R.useState' true
pure $ H.div { className: "update-button " <> if (fst enabled) then "enabled" else "disabled text-muted" } [ pure $ H.div { className: "update-button "
H.span { className: "fa fa-refresh" <> if (fst enabled) then "enabled" else "disabled text-muted"
, on: { click: onClick enabled } } [] } [ H.span { className: "fa fa-refresh"
] , on: { click: onClick enabled } } []
]
where where
onClick (false /\ _) _ = pure unit onClick (false /\ _) _ = pure unit
onClick (true /\ setEnabled) _ = do onClick (true /\ setEnabled) _ = do
...@@ -344,8 +344,8 @@ mAppRouteId (Just (Routes.Texts _ id)) = Just id ...@@ -344,8 +344,8 @@ mAppRouteId (Just (Routes.Texts _ id)) = Just id
mAppRouteId (Just (Routes.Lists _ id)) = Just id mAppRouteId (Just (Routes.Lists _ id)) = Just id
mAppRouteId (Just (Routes.Annuaire _ id)) = Just id mAppRouteId (Just (Routes.Annuaire _ id)) = Just id
mAppRouteId (Just (Routes.UserPage _ id)) = Just id mAppRouteId (Just (Routes.UserPage _ id)) = Just id
mAppRouteId (Just (Routes.Document _ id _ )) = Just id mAppRouteId (Just (Routes.Document _ id _ )) = Just id
mAppRouteId (Just (Routes.ContactPage _ id _ )) = Just id mAppRouteId (Just (Routes.ContactPage _ id _ )) = Just id
mAppRouteId (Just (Routes.CorpusDocument _ id _ _)) = Just id mAppRouteId (Just (Routes.CorpusDocument _ id _ _)) = Just id
mAppRouteId _ = Nothing mAppRouteId _ = Nothing
...@@ -360,11 +360,10 @@ type NodePopupProps = ...@@ -360,11 +360,10 @@ type NodePopupProps =
) )
type NodePopupS = type NodePopupS =
( ( action :: Maybe NodeAction
action :: Maybe NodeAction , id :: ID
, id :: ID , name :: Name
, name :: Name , nodeType :: GT.NodeType
, nodeType :: GT.NodeType
) )
iconAStyle :: { color :: String iconAStyle :: { color :: String
...@@ -476,7 +475,6 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt ...@@ -476,7 +475,6 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
, session : p.session , session : p.session
} }
type ActionState = type ActionState =
( action :: Maybe NodeAction ( action :: Maybe NodeAction
, id :: ID , id :: ID
...@@ -484,7 +482,6 @@ type ActionState = ...@@ -484,7 +482,6 @@ type ActionState =
, nodeType :: GT.NodeType , nodeType :: GT.NodeType
) )
type ButtonClickProps = type ButtonClickProps =
( action :: NodeAction ( action :: NodeAction
, state :: R.State (Record ActionState) , state :: R.State (Record ActionState)
...@@ -540,10 +537,10 @@ panelAction p = R.createElement panelActionCpt p [] ...@@ -540,10 +537,10 @@ panelAction p = R.createElement panelActionCpt p []
panelActionCpt :: R.Component PanelActionProps panelActionCpt :: R.Component PanelActionProps
panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
where where
cpt {action: Documentation nodeType} _ = actionDoc nodeType cpt {action: Documentation nodeType} _ = actionDoc nodeType
cpt {action: Download, id, nodeType, session} _ = actionDownload nodeType id session cpt {action: Download, id, nodeType, session} _ = actionDownload nodeType id session
cpt {action: Upload, dispatch, id, nodeType, session} _ = actionUpload nodeType id session dispatch cpt {action: Upload, dispatch, id, nodeType, session} _ = actionUpload nodeType id session dispatch
cpt {action: Delete, nodeType, dispatch} _ = actionDelete nodeType dispatch cpt {action: Delete, nodeType, dispatch} _ = actionDelete nodeType dispatch
cpt {action: Add xs, dispatch, id, name, nodePopup: p, nodeType} _ = do cpt {action: Add xs, dispatch, id, name, nodePopup: p, nodeType} _ = do
pure $ createNodeView {dispatch, id, name, nodeType, nodeTypes: xs} pure $ createNodeView {dispatch, id, name, nodeType, nodeTypes: xs}
...@@ -551,46 +548,43 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt ...@@ -551,46 +548,43 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
cpt {action: CopyFromCorpus, dispatch, id, nodeType, session} _ = do cpt {action: CopyFromCorpus, dispatch, id, nodeType, session} _ = do
pure $ copyFromCorpusView {dispatch, id, nodeType, session} pure $ copyFromCorpusView {dispatch, id, nodeType, session}
cpt {action: Link _} _ = pure $ fragmentPT "Soon, you will be able to link the corpus with your Annuaire (and reciprocally)." cpt {action: Link _} _ = pure $ fragmentPT $ "Soon, you will be able "
<> "to link the corpus with your Annuaire"
<> " (and reciprocally)."
cpt props@{action: SearchBox, search, session, dispatch, nodePopup} _ =
cpt props@{action: SearchBox, search, session} _ = do actionSearch search session dispatch nodePopup
pure $ R.fragment [ H.p {"style": {"margin" :"10px"}}
[ H.text $ "Search and create a private corpus with the search query as corpus name." ]
, searchBar {langs: allLangs, onSearch: searchOn props, search, session}
]
where
searchOn :: Record PanelActionProps -> GT.AsyncTaskWithType -> Effect Unit
searchOn {dispatch, nodePopup: p} task = do
_ <- launchAff $ dispatch (SearchQuery task)
-- close popup
-- TODO
--snd p $ const Nothing
pure unit
{-
cpt {action: Refresh, nodeType: GT.Graph, id, session} _ = do
pure $ H.div {className: "panel-footer"}
[ H.a { type: "button"
, className: "btn glyphicon glyphicon-trash"
, id: "delete"
, title: "Delete"
, on: {click: \_ -> post session (GR.GraphAPI id $ GT.asyncTaskTypePath GT.GraphT) {}
-- TODO pure $ GT.AsyncTaskWithType { task, typ: GT.GraphT }
}
}
[H.text " Yes, delete!"]
]
--}
cpt _ _ = do cpt _ _ = do
pure $ H.div {} [] pure $ H.div {} []
-- | Action : Search
actionSearch :: R.State Search
-> Session
-> (Action -> Aff Unit)
-> Maybe NodePopup
-> R.Hooks R.Element
actionSearch search session dispatch nodePopup =
pure $ R.fragment [ H.p {"style": {"margin" :"10px"}}
[ H.text $ "Search and create a private "
<> "corpus with the search query as corpus name." ]
, searchBar {langs: allLangs, onSearch: searchOn dispatch nodePopup, search, session}
]
where
searchOn :: (Action -> Aff Unit)
-> Maybe NodePopup
-> GT.AsyncTaskWithType
-> Effect Unit
searchOn dispatch p task = do
_ <- launchAff $ dispatch (SearchQuery task)
-- close popup
-- TODO
--snd p $ const Nothing
pure unit
-- | Action : Delete -- | Action : Delete
actionDelete :: NodeType -> Dispatch -> R.Hooks R.Element actionDelete :: NodeType -> (Action -> Aff Unit) -> R.Hooks R.Element
actionDelete NodeUser _ = do actionDelete NodeUser _ = do
pure $ R.fragment [ pure $ R.fragment [
H.div {style: {margin: "10px"}} H.div {style: {margin: "10px"}}
...@@ -603,7 +597,12 @@ actionDelete NodeUser _ = do ...@@ -603,7 +597,12 @@ actionDelete NodeUser _ = do
actionDelete _ dispatch = do actionDelete _ dispatch = do
pure $ R.fragment [ pure $ R.fragment [
H.div {style: {margin: "10px"}} (map (\t -> H.p {} [H.text t]) ["Are your sure you want to delete it ?", "If yes, click again below."]) H.div {style: {margin: "10px"}}
(map (\t -> H.p {} [H.text t])
[ "Are your sure you want to delete it ?"
, "If yes, click again below."
]
)
, reallyDelete dispatch , reallyDelete dispatch
] ]
where where
...@@ -710,11 +709,11 @@ docOf GT.FolderShared = ["Soon, you will be able to build teams folders to shar ...@@ -710,11 +709,11 @@ docOf GT.FolderShared = ["Soon, you will be able to build teams folders to shar
docOf nodeType = ["More information on " <> show nodeType] docOf nodeType = ["More information on " <> show nodeType]
fragmentPT :: String -> R.Element
fragmentPT text = H.div {style: {margin: "10px"}} [H.text text] fragmentPT text = H.div {style: {margin: "10px"}} [H.text text]
-------------------- --------------------
-- | Iframes -- | Iframes
searchIframes :: Record NodePopupProps searchIframes :: Record NodePopupProps
-> R.State Search -> R.State Search
-> R.Ref (Nullable DOM.Element) -> R.Ref (Nullable DOM.Element)
...@@ -766,4 +765,3 @@ iframeWith url (search /\ setSearch) iframeRef = ...@@ -766,4 +765,3 @@ iframeWith url (search /\ setSearch) iframeRef =
Tuple (NQP.keyFromString "query") (Just (NQP.valueFromString term)) Tuple (NQP.keyFromString "query") (Just (NQP.valueFromString term))
] ]
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