Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
c9d48a87
Verified
Commit
c9d48a87
authored
May 15, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[doc table] fixes to stars (add 1 more state, refactor)
parent
d720b1a6
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
268 additions
and
154 deletions
+268
-154
spago.dhall
spago.dhall
+1
-0
Category.purs
src/Gargantext/Components/Category.purs
+36
-25
Types.purs
src/Gargantext/Components/Category/Types.purs
+87
-53
DocsTable.purs
src/Gargantext/Components/DocsTable.purs
+136
-68
Types.purs
src/Gargantext/Components/DocsTable/Types.purs
+7
-7
Layout.purs
src/Gargantext/Components/Document/Layout.purs
+0
-1
FacetsTable.purs
src/Gargantext/Components/FacetsTable.purs
+1
-0
No files found.
spago.dhall
View file @
c9d48a87
...
...
@@ -33,6 +33,7 @@ to generate this file without the comments in this block.
, "dom-simple"
, "effect"
, "either"
, "enums"
, "exceptions"
, "ffi-simple"
, "foldable-traversable"
...
...
src/Gargantext/Components/Category.purs
View file @
c9d48a87
...
...
@@ -4,6 +4,7 @@ module Gargantext.Components.Category where
import Gargantext.Prelude
import Data.Array as A
import Data.Enum (fromEnum)
import Data.Generic.Rep (class Generic)
import Data.Map as Map
import Data.Maybe (Maybe(..), fromMaybe)
...
...
@@ -12,8 +13,8 @@ import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (Variant(..))
import Gargantext.Components.Category.Types (Category(..), Star(..), cat2score, cat
egories, clickAgain, decodeStar, star2score
, stars)
import Gargantext.Components.DocsTable.Types (DocumentsView(..), LocalCategories
, LocalUserScore
)
import Gargantext.Components.Category.Types (Category(..), Star(..), cat2score, cat
2star, categories, categoryNextState, decodeCategory
, stars)
import Gargantext.Components.DocsTable.Types (DocumentsView(..), LocalCategories)
import Gargantext.Components.GraphQL.Context (NodeContext)
import Gargantext.Components.GraphQL.Endpoints (getNodeContext, updateNodeContextCategory)
import Gargantext.Config.REST (AffRESTError, RESTError(..))
...
...
@@ -36,9 +37,9 @@ type RatingProps =
( chartReload :: T2.ReloadS
, nodeId :: NodeID
, row :: DocumentsView
, score ::
Star
, score ::
Category
, session :: Session
, setLocalCategories :: R.Setter LocalUserScore
-- , setLocalCategories :: R.Setter LocalCategories
)
rating :: R2.Component RatingProps
...
...
@@ -50,11 +51,11 @@ ratingCpt = here.component "rating" cpt where
, row: DocumentsView r
, score
, session
, setLocalCategories
--
, setLocalCategories
} _ = do
pure $ renderRatingSimple { docId: r._id
, corpusId: nodeId
, category: s
tar2score s
core
, category: score
, session } []
-- -- | Behaviors
...
...
@@ -86,14 +87,17 @@ ratingCpt = here.component "rating" cpt where
-- , className: ratingClassName score s
-- }
ratingIcon Star_0 Star_0 = "recycle"
ratingIcon :: Category -> Star -> String
ratingIcon Trash Star_0 = "recycle"
ratingIcon _ Star_0 = "trash"
ratingIcon c s =
star2score c < star2score
s ? "star-o" $ "star"
ratingIcon c s =
fromEnum (cat2star c) < fromEnum
s ? "star-o" $ "star"
ratingVariant :: Star -> Star -> Variant
ratingVariant Star_0 Star_0 = Dark
ratingVariant _ Star_0 = Dark
ratingVariant _ _ = Dark
ratingClassName :: Star -> Star -> String
ratingClassName Star_0 Star_0 = "rating-group__action"
ratingClassName _ Star_0 = "rating-group__action"
ratingClassName _ _ = "rating-group__star"
...
...
@@ -118,10 +122,12 @@ ratingSimpleLoaderCpt = here.component "ratingSimpleLoader" cpt where
useLoader { errorHandler
, loader: loadDocumentContext session
, path: { docId, corpusId }
, render: \{ nc_category } -> renderRatingSimple { docId
, corpusId
, category: fromMaybe 0 nc_category
, session } [] }
, render: \{ nc_category } -> do
let category = fromMaybe UnRead $ decodeCategory <$> nc_category
renderRatingSimple { docId
, corpusId
, category
, session } [] }
where
errorHandler err = do
here.warn2 "[pageLayout] RESTError" err
...
...
@@ -139,7 +145,7 @@ loadDocumentContext session { docId, corpusId } = getNodeContext session docId c
type RenderRatingSimpleProps =
( docId :: NodeID
, corpusId :: NodeID
, category ::
Int
, category ::
Category
, session :: Session )
renderRatingSimple :: R2.Component RenderRatingSimpleProps
...
...
@@ -151,17 +157,17 @@ renderRatingSimpleCpt = here.component "renderRatingSimple" cpt where
, category
, session
} _ = do
score <- T.useBox $ decodeStar
category
categoryS <- T.useBox
category
pure $ ratingSimple { docId
, corpusId
,
score
,
category: categoryS
, session } []
type RatingSimpleProps =
( docId :: NodeID
, corpusId :: NodeID
,
score :: T.Box Star
,
category :: T.Box Category
, session :: Session )
ratingSimple :: R2.Component RatingSimpleProps
...
...
@@ -170,19 +176,21 @@ ratingSimpleCpt :: R.Component RatingSimpleProps
ratingSimpleCpt = here.component "ratingSimple" cpt where
cpt { docId
, corpusId
,
score
,
category
, session
} _ = do
score' <- T.useLive T.unequal score
category' <- T.useLive T.unequal category
let star' = cat2star category'
let
onClick c _ = do
let c' = score' == c ? clickAgain c $ c
-- let c' = score' == c ? clickAgain c $ c
let c' = categoryNextState category' c
-- setLocalCategories $ Map.insert r._id c'
launchAff_ do
_ <- updateNodeContextCategory session docId corpusId $
star
2score c'
liftEffect $ T.write_ c'
score
_ <- updateNodeContextCategory session docId corpusId $
cat
2score c'
liftEffect $ T.write_ c'
category
pure unit
pure $
...
...
@@ -190,17 +198,17 @@ ratingSimpleCpt = here.component "ratingSimple" cpt where
{ className: "rating-group" } $
stars <#> \s ->
B.iconButton
{ name: ratingIcon
score
' s
{ name: ratingIcon
category
' s
, callback: onClick s
, overlay: false
, variant: ratingVariant s
core
' s
, className: ratingClassName s
core
' s
, variant: ratingVariant s
tar
' s
, className: ratingClassName s
tar
' s
}
newtype RatingQuery =
RatingQuery { nodeIds :: Array Int
, rating ::
Star
, rating ::
Category
}
derive instance Generic RatingQuery _
instance JSON.WriteForeign RatingQuery where
...
...
@@ -267,6 +275,9 @@ icon cat b = btn b $ "fa fa-" <> (color $ size b $ icon' cat b)
icon' Favorite false = "heart-o"
icon' Favorite true = "heart"
icon' ToCite false = "quote-left-o"
icon' ToCite true = "quote-left"
size :: Boolean -> String -> String
size true s = s <> " btn-lg"
size false s = s <> " btn-sm"
...
...
src/Gargantext/Components/Category/Types.purs
View file @
c9d48a87
module Gargantext.Components.Category.Types where
import Data.Generic.Rep (class Generic)
import Data.Bounded.Generic (genericTop, genericBottom)
import Data.Enum (class Enum, class BoundedEnum, succ, pred, fromEnum, toEnumWithDefaults)
import Data.Enum.Generic (genericPred, genericSucc, genericCardinality, genericFromEnum, genericToEnum)
import Data.Eq.Generic (genericEq)
import Data.Generic.Rep (class Generic)
import Data.Maybe (fromMaybe)
import Data.Ord.Generic (genericCompare)
import Data.Show.Generic (genericShow)
import Simple.JSON as JSON
import Gargantext.Prelude
------------------------------------------------------------------------
data Star = Star_0 | Star_1 | Star_2 | Star_3 | Star_4
stars :: Array Star
stars = [Star_0, Star_1, Star_2, Star_3, Star_4]
derive instance Generic Star _
instance Show Star where show = genericShow
instance Eq Star where eq = genericEq
instance JSON.ReadForeign Star where
readImpl f = do
inst <- JSON.readImpl f
pure $ decodeStar inst
instance JSON.WriteForeign Star where writeImpl = JSON.writeImpl <<< star2score
decodeStar :: Int -> Star
decodeStar 0 = Star_0
decodeStar 1 = Star_1
decodeStar 2 = Star_2
decodeStar 3 = Star_3
decodeStar 4 = Star_4
decodeStar _ = Star_4
star2score :: Star -> Int
star2score Star_0 = 0
star2score Star_1 = 1
star2score Star_2 = 2
star2score Star_3 = 3
star2score Star_4 = 4
clickAgain :: Star -> Star
clickAgain Star_0 = Star_1
clickAgain s = decodeStar (star2score s - 1)
------------------------------------------------------------------------
data Category = Trash | UnRead | Checked | Topic | Favorite
data Category = Trash | UnRead | Checked | Topic | Favorite | ToCite
{-
- `UnRead` is assigned initially for new docs
- After reading a doc, `Checked` should be assigned automatically
- Both `Trash` and `UnRead` map to 0 stars in the doc list
-}
categories :: Array Category
categories = [Trash, UnRead, Checked, Topic, Favorite]
categories = [Trash, UnRead, Checked, Topic, Favorite
, ToCite
]
derive instance Generic Category _
instance Ord Category where compare = genericCompare
instance Enum Category where
pred = genericPred
succ = genericSucc
instance Bounded Category where
bottom = genericBottom
top = genericTop
instance BoundedEnum Category where
cardinality = genericCardinality
fromEnum = genericFromEnum
toEnum = genericToEnum
instance Show Category where show = genericShow
instance Eq Category where eq = genericEq
instance JSON.ReadForeign Category where
...
...
@@ -58,26 +43,75 @@ instance JSON.ReadForeign Category where
pure $ decodeCategory inst
instance JSON.WriteForeign Category where writeImpl = JSON.writeImpl <<< cat2score
catSucc :: Category -> Category
catSucc c = fromMaybe ToCite $ succ c
catPred :: Category -> Category
catPred c = fromMaybe Trash $ pred c
clickAgain :: Category -> Category
clickAgain _ = UnRead
-- | `categoryNextState :: current -> clicked -> new State`
categoryNextState :: Category -> Star -> Category
categoryNextState Trash Star_0 = UnRead
categoryNextState _ Star_0 = Trash
categoryNextState current clicked =
if (cat2star current) == clicked then
clickAgain current
else
star2catSimple clicked
favCategory :: Category -> Category
favCategory Favorite = Topic
favCategory _ = Favorite
trashCategory :: Category -> Category
trashCategory _ = Trash
-- TODO: ?
--trashCategory Trash = UnRead
trashCategory = const Trash
decodeCategory :: Int -> Category
decodeCategory 0 = Trash
decodeCategory 1 = UnRead
decodeCategory 2 = Checked
decodeCategory 3 = Topic
decodeCategory 4 = Favorite
decodeCategory _ = UnRead
decodeCategory = toEnumWithDefaults UnRead UnRead
cat2score :: Category -> Int
cat2score Trash = 0
cat2score UnRead = 1
cat2score Checked = 2
cat2score Topic = 3
cat2score Favorite = 4
cat2score = fromEnum
------------------------------------------------------------------------
-- | This is just a helper to visualize categories.
data Star = Star_0 | Star_1 | Star_2 | Star_3 | Star_4
stars :: Array Star
stars = [Star_0, Star_1, Star_2, Star_3, Star_4]
derive instance Generic Star _
instance Show Star where show = genericShow
instance Eq Star where eq = genericEq
instance Ord Star where compare = genericCompare
instance Enum Star where
pred = genericPred
succ = genericSucc
instance Bounded Star where
bottom = genericBottom
top = genericTop
instance BoundedEnum Star where
cardinality = genericCardinality
fromEnum = genericFromEnum
toEnum = genericToEnum
cat2star :: Category -> Star
cat2star Trash = Star_0
cat2star UnRead = Star_0
cat2star Checked = Star_1
cat2star Topic = Star_2
cat2star Favorite = Star_3
cat2star ToCite = Star_4
-- | This is a "reverse" of `cat2star`
star2catSimple :: Star -> Category
star2catSimple Star_0 = UnRead
star2catSimple Star_1 = Checked
star2catSimple Star_2 = Topic
star2catSimple Star_3 = Favorite
star2catSimple Star_4 = ToCite
src/Gargantext/Components/DocsTable.purs
View file @
c9d48a87
This diff is collapsed.
Click to expand it.
src/Gargantext/Components/DocsTable/Types.purs
View file @
c9d48a87
...
...
@@ -7,14 +7,14 @@ import Data.Generic.Rep (class Generic)
import Data.Map (Map)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple (Tuple(..))
import Gargantext.Components.Category.Types (Category
, Star(..), decodeStar
)
import Gargantext.Components.Category.Types (Category
(..), Star(..), decodeCategory
)
import Simple.JSON as JSON
data Action
= MarkCategory Int Category
type DocumentsViewT =
( category ::
Star
( category ::
Category
, date :: Int
, ngramCount :: Maybe Int
, score :: Maybe Int
...
...
@@ -65,8 +65,8 @@ type ResponseT =
, score :: Maybe Int
, title :: String )
newtype Response = Response
{ cid
:: Int
, category ::
Star
{ cid :: Int
, category ::
Category
| ResponseT
}
...
...
@@ -74,7 +74,7 @@ instance JSON.ReadForeign Response where
readImpl f = do
{ category, id, hyperdata, ngramCount, score, title } :: { category :: Int, id :: Int | ResponseT } <- JSON.readImpl f
--pure $ Response { category: decodeCategory category, cid, hyperdata, ngramCount, score, title }
pure $ Response { category: decode
Star
category
pure $ Response { category: decode
Category
category
, cid: id
, hyperdata
, ngramCount
...
...
@@ -110,7 +110,7 @@ sampleData' = DocumentsView { _id : 1
, date : 2010
, title : "title"
, source : Just "source"
, category :
Star_1
, category :
UnRead
, ngramCount : Just 1
, score: Just 1 }
...
...
@@ -121,7 +121,7 @@ sampleData = map (\(Tuple t s) -> DocumentsView { _id : 1
, date : 2017
, title: t
, source: Just s
, category :
Star_1
, category :
UnRead
, ngramCount : Just 10
, score: Just 1 }) sampleDocuments
...
...
src/Gargantext/Components/Document/Layout.purs
View file @
c9d48a87
...
...
@@ -16,7 +16,6 @@ import Gargantext.Components.AutoUpdate (autoUpdate)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ComponentStatus(..), SpinnerTheme(..))
import Gargantext.Components.Category (ratingSimpleLoader)
import Gargantext.Components.Category.Types (decodeStar)
import Gargantext.Components.Document.Types (DocPath, Document(..), LoadedData, initialState)
import Gargantext.Components.NgramsTable.AutoSync (useAutoSync)
import Gargantext.Components.Node (NodePoly(..))
...
...
src/Gargantext/Components/FacetsTable.purs
View file @
c9d48a87
...
...
@@ -395,6 +395,7 @@ pageCpt = here.component "page" cpt
wrapColElts = const identity
-- TODO: how to interprete other scores?
gi Trash = "fa fa-star-empty"
gi UnRead = "fa fa-star-empty"
gi _ = "fa fa-star"
documentUrl id { listId, nodeId } =
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment