Commit 3a73ed0b authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams] score sorting work

parent 69038bce
......@@ -30,6 +30,7 @@ import Gargantext.Components.DocsTable.Types
import Gargantext.Components.Table.Types as T
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Nodes.Texts.Types (SidePanelTriggers)
import Gargantext.Components.Score as GCS
import Gargantext.Components.Table as T
import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoader, useLoaderWithCacheAPI, HashedResponse(..))
......@@ -360,7 +361,7 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh
, localCategories
, params } _ = do
reload <- R.useState' 0
reload <- GUR.new
pure $ T.table
{ syncResetButton : [ H.div {} [] ]
......@@ -389,21 +390,22 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh
row dv@(DocumentsView r) =
{ row:
T.makeRow [ -- H.div {} [ H.a { className, style, on: {click: click Favorite} } [] ]
H.div { className: "" }
[ docChooser { listId, mCorpusId, nodeId: r._id, selected, sidePanelTriggers, tableReload: reload } []
]
--, H.div { className: "column-tag flex" } [ caroussel { category: cat, nodeId, row: dv, session, setLocalCategories } [] ]
, H.div { className: "column-tag flex" }
[ rating { score: cat, nodeId, row: dv, session, setLocalCategories } [] ]
H.div { className: "" }
[ docChooser { listId, mCorpusId, nodeId: r._id, selected, sidePanelTriggers, tableReload: reload } []
]
--, H.div { className: "column-tag flex" } [ caroussel { category: cat, nodeId, row: dv, session, setLocalCategories } [] ]
, H.div { className: "column-tag flex" }
[ rating { score: cat, nodeId, row: dv, session, setLocalCategories } [] ]
--, H.input { type: "checkbox", defaultValue: checked, on: {click: click Trash} }
-- TODO show date: Year-Month-Day only
, H.div { className: tClassName } [ R2.showText r.date ]
, H.div { className: tClassName }
[ H.a { href: url frontends $ corpusDocument r._id, target: "_blank"}
[ H.a { href: url frontends $ corpusDocument r._id, target: "_blank" }
[ H.text r.title ]
]
, H.div { className: tClassName } [ H.text $ if r.source == "" then "Source" else r.source ]
, H.div {} [ H.text $ maybe "-" show r.ngramCount ]
-- , H.div {} [ H.text $ maybe "-" show r.score ]
, H.div { className: tClassName } [ GCS.scoreEl { docId: r._id, nodeId, score: r.score, session, tableReload: reload } [] ]
]
, delete: true }
where
......
module Gargantext.Components.Score where
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>), encodeJson)
import Data.Int (fromString)
import Data.Maybe (Maybe(..), maybe)
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, sessionId, get, delete, put)
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
type Score = Int
type DocID = Int
thisModule :: String
thisModule = "Gargantext.Components.Score"
type Props = (
docId ::DocID
, nodeId :: GT.NodeID
, score :: Maybe Score
, session :: Session
, tableReload :: GUR.ReloadS
)
type Choice = Maybe Score
scoreEl :: R2.Component Props
scoreEl = R.createElement scoreElCpt
scoreElCpt :: R.Component Props
scoreElCpt = R.hooksComponentWithModule thisModule "scoreEl" cpt
where
cpt { docId, nodeId, score, session, tableReload } _ = do
pure $ R2.select { className: "form-control"
, defaultValue: showChoice score
, on: { change: onChange session nodeId docId tableReload }
} (map option choices)
onChange session nodeId docId reloadS e = do
-- TODO change score via api
let query = ScoreQuery { nodeIds: [ docId ]
, score: readChoice $ R.unsafeEventValue e }
launchAff_ $ do
_ <- putScore session nodeId query
liftEffect $ GUR.bump reloadS
option :: Choice -> R.Element
option c = H.option { value: showChoice c } [ H.text $ showChoice c ]
choices = [ Nothing
, Just 5
, Just 10
, Just 15 ]
showChoice :: Choice -> String
showChoice Nothing = "-"
showChoice (Just c) = show c
readChoice = fromString
newtype ScoreQuery =
ScoreQuery { nodeIds :: Array DocID
, score :: Choice
}
instance encodeJsonScoreQuery :: EncodeJson ScoreQuery where
encodeJson (ScoreQuery post) =
"nts_nodesId" := post.nodeIds
~> "nts_score" := encodeJson post.score
~> jsonEmptyObject
putScore :: Session -> GT.NodeID -> ScoreQuery -> Aff (Array Int)
putScore session nodeId = put session $ scoreRoute nodeId
where
scoreRoute :: GT.NodeID -> SessionRoute
scoreRoute nodeId = NodeAPI GT.Node (Just nodeId) "score"
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