Merge.purs 2.87 KB
Newer Older
1
module Gargantext.Components.Forest.Tree.Node.Action.Merge where
2

3 4
import Gargantext.Prelude

5
import Data.Maybe (Maybe(..))
6
import Data.Set as Set
7
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
8
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel, checkbox, checkboxesListGroup)
9
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView, SubTreeParamsIn)
10
import Gargantext.Config.REST (AffRESTError)
11 12
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
13
import Gargantext.Types as GT
14
import Gargantext.Utils.Reactix as R2
15 16 17
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
18

19
here :: R2.Here
20
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Merge"
21

22
mergeNodeReq :: Session -> GT.ID -> GT.ID -> AffRESTError (Array GT.ID)
23 24 25
mergeNodeReq session fromId toId =
  put_ session $ NodeAPI GT.Node (Just fromId) ("merge/" <> show toId)

26 27 28
mergeNode :: R2.Component SubTreeParamsIn
mergeNode = R.createElement mergeNodeCpt
mergeNodeCpt :: R.Component SubTreeParamsIn
29
mergeNodeCpt = here.component "mergeNode" cpt
30
  where
31
    cpt { boxes, dispatch, id, nodeType, session, subTreeParams } _ = do
32 33
      action <- T.useBox (MergeNode { params: Nothing })
      action' <- T.useLive T.unequal action
Alexandre Delanoë's avatar
Alexandre Delanoë committed
34

35 36
      merge   <- T.useBox false
      options <- T.useBox (Set.singleton GT.MapTerm)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
37

38
      let button = case action' of
39 40 41 42
            MergeNode {params} -> case params of
              Just val -> submitButton (MergeNode {params: Just val}) dispatch
              Nothing -> H.div {} []
            _                   -> H.div {} []
43

44 45
      pure $ panel
        [ subTreeView { action
46
                      , boxes
47 48 49 50 51
                      , dispatch
                      , id
                      , nodeType
                      , session
                      , subTreeParams
52
                      } []
53 54 55
                  , H.ul { className:"merge mx-auto list-group"}
                     ([ H.li { className: "list-group-item" }
                       [ H.h5 { className: "mb-1" } [ H.text "Merge which list?" ]
56 57
                       , checkboxesListGroup { groups: [ GT.MapTerm, GT.CandidateTerm, GT.StopTerm ]
                                             , options } []
58
                       ]
59
                     ])
60 61 62 63 64 65
                  , H.ul { className:"merge mx-auto list-group"}
                     [ H.li { className: "list-group-item" }
                       [ H.h5 { className: "mb-1" } [ H.text "Title" ]
                       ]
                     , H.li { className: "list-group-item" }
                       [ H.div { className: " form-check" }
66
                         [ checkbox { value: merge }
67 68 69 70 71 72
                         , H.label { className: "form-check-label" } [ H.text "Merge data?" ]
                         ]
                       ]
                     ]
                  ]
                  button