Commit b928fd92 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

routing: corpus document view

parent 76948b36
......@@ -50,6 +50,7 @@ type Props =
, chart :: ReactElement
, tabType :: TabType
, listId :: Int
, corpusId :: Maybe Int
-- ^ tabType is not ideal here since it is too much entangled with tabs and
-- ngramtable. Let's see how this evolves.
}
......@@ -175,7 +176,7 @@ layoutDocview = simpleSpec performAction render
(_documentIdsDeleted <>~ documentIdsToDelete)
render :: Render State Props Action
render dispatch {nodeId, tabType, listId, totalRecords, chart} deletionState _ =
render dispatch {nodeId, tabType, listId, corpusId, totalRecords, chart} deletionState _ =
[ {- br'
, div [ style {textAlign : "center"}] [ text " Filter "
, input [className "form-control", style {width : "120px", display : "inline-block"}, placeholder "Filter here"]
......@@ -188,8 +189,9 @@ layoutDocview = simpleSpec performAction render
[ chart
, div [className "col-md-12"]
[ pageLoader
{ path: initialPageParams {nodeId, tabType, listId}
{ path: initialPageParams {nodeId, tabType, listId, corpusId}
, listId
, corpusId
, totalRecords
, deletionState
, dispatch
......@@ -210,14 +212,14 @@ layoutDocview = simpleSpec performAction render
mock :: Boolean
mock = false
type PageParams = {nodeId :: Int, listId :: Int, tabType :: TabType, params :: T.Params}
type PageParams = {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType, params :: T.Params}
initialPageParams :: {nodeId :: Int, listId :: Int, tabType :: TabType} -> PageParams
initialPageParams {nodeId, listId, tabType} =
{nodeId, tabType, listId, params: T.initialParams}
initialPageParams :: {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType} -> PageParams
initialPageParams {nodeId, listId, corpusId, tabType} =
{nodeId, tabType, listId, corpusId, params: T.initialParams}
loadPage :: PageParams -> Aff (Array DocumentsView)
loadPage {nodeId, tabType, listId, params: {limit, offset, orderBy}} = do
loadPage {nodeId, tabType, listId, corpusId, params: {limit, offset, orderBy}} = do
logs "loading documents page: loadPage with Offset and limit"
res <- get $ toUrl Back (Tab tabType offset limit (convOrderBy <$> orderBy)) (Just nodeId)
let docs = res2corpus <$> res
......@@ -253,25 +255,27 @@ type PageLoaderProps row =
, dispatch :: Action -> Effect Unit
, deletionState :: State
, listId :: Int
, corpusId :: Maybe Int
| row
}
renderPage :: forall props path.
Render (Loader.State {nodeId :: Int, listId :: Int, tabType :: TabType | path} (Array DocumentsView))
Render (Loader.State {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType | path} (Array DocumentsView))
{ totalRecords :: Int
, dispatch :: Action -> Effect Unit
, deletionState :: State
, listId :: Int
, corpusId :: Maybe Int
| props
}
(Loader.Action PageParams)
renderPage _ _ {loaded: Nothing} _ = [] -- TODO loading spinner
renderPage loaderDispatch { totalRecords, dispatch, listId
renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
, deletionState: {documentIdsToDelete, documentIdsDeleted, localFavorites}}
{currentPath: {nodeId, tabType}, loaded: Just res} _ =
[ T.tableElt
{ rows
, setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, params})
, setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params})
, container: T.defaultContainer { title: "Documents" }
, colNames:
T.ColumnName <$>
......@@ -287,38 +291,40 @@ renderPage loaderDispatch { totalRecords, dispatch, listId
where
gi true = "glyphicon glyphicon-star"
gi false = "glyphicon glyphicon-star-empty"
isChecked _id = Set.member _id documentIdsToDelete
toDelete (DocumentsView {_id}) = Set.member _id documentIdsToDelete
isDeleted (DocumentsView {_id}) = Set.member _id documentIdsDeleted
isFavorite {_id,fav} = maybe fav identity (localFavorites ^. at _id)
corpusDocument (Just corpusId) = R.CorpusDocument corpusId
corpusDocument _ = R.Document
rows = (\(DocumentsView r) ->
let isFav = isFavorite r in
let isFav = isFavorite r
toDel = toDelete $ DocumentsView r in
{ row:
[ div []
[ a [ className $ gi isFav
, if (toDelete $ DocumentsView r) then style {textDecoration : "line-through"}
else style {textDecoration : "none"}
, if toDel then style {textDecoration : "line-through"}
else style {textDecoration : "none"}
, onClick $ (\_-> dispatch $ MarkFavorites r._id (not isFav))] []
]
-- TODO show date: Year-Month-Day only
, if (toDelete $ DocumentsView r) then
, if toDel then
div [ style {textDecoration : "line-through"}][text (show r.date)]
else
div [ ][text (show r.date)]
, if (toDelete $ DocumentsView r) then
a [ href (toLink $ R.Document listId r._id)
, if toDel then
a [ href (toLink $ (corpusDocument corpusId) listId r._id)
, style {textDecoration : "line-through"}
, target "_blank"
] [ text r.title ]
else
a [ href (toLink $ R.Document listId r._id)
a [ href (toLink $ (corpusDocument corpusId) listId r._id)
, target "_blank" ] [ text r.title ]
, if (toDelete $ DocumentsView r) then
, if toDel then
div [style {textDecoration : "line-through"}] [ text r.source]
else
div [] [ text r.source]
, input [ _type "checkbox"
, checked (isChecked r._id)
, checked toDel
, onClick $ (\_ -> dispatch $ ToggleDocumentToDelete r._id)]
]
, delete: true
......
......@@ -210,6 +210,7 @@ routesPath R.SearchView = "search"
routesPath (R.Folder i) = "folder/" <> show i
routesPath (R.Corpus i) = "corpus/" <> show i
routesPath R.AddCorpus = "addCorpus"
routesPath (R.CorpusDocument c l i) = "corpus/" <> show c <> "/list/" <> show l <> "/document/" <> show i
routesPath (R.Document l i) = "list/" <> show l <> "/document/" <> show i
routesPath (R.PGraphExplorer i) = "#/"
routesPath R.Dashboard = "dashboard"
......
......@@ -6,6 +6,7 @@ import Prelude hiding (div)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.List (fromFoldable)
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Gargantext.Config (TabType(..), TabSubType(..), PTabNgramType(..))
......@@ -48,7 +49,8 @@ statefulTabs =
{ nodeId, chart
, tabType: TabPairing TabDocs
, totalRecords: 4736
, listId: loaded.defaultListId}) $
, listId: loaded.defaultListId
, corpusId: Nothing}) $
noState DT.docViewSpec
ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
......
......@@ -24,7 +24,7 @@ import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField
import Gargantext.Types (TermList)
import Gargantext.Utils.Reactix ( scuff )
type DocPath = { nodeId :: Int, listIds :: Array Int, tabType :: TabType }
type DocPath = { nodeId :: Int, listIds :: Array Int, corpusId :: Maybe Int, tabType :: TabType }
type NodeDocument = NodePoly Document
......@@ -333,8 +333,8 @@ docViewSpec = simpleSpec performAction render
badge s = span [className "badge badge-default badge-pill"] [text s]
NodePoly {hyperdata : Document doc} = document
layout :: Spec {} {nodeId :: Int, listId :: Int} Void
layout = cmapProps (\{nodeId, listId} -> {nodeId, listIds: [listId], tabType})
layout :: Spec {} {nodeId :: Int, listId :: Int, corpusId :: Maybe Int} Void
layout = cmapProps (\{nodeId, listId, corpusId} -> {nodeId, listIds: [listId], corpusId, tabType})
$ simpleSpec defaultPerformAction render
where
tabType = TabDocument (TabNgramType CTabTerms)
......
......@@ -8,7 +8,6 @@ import Data.List (fromFoldable)
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Gargantext.Config (TabType(..), TabSubType(..))
import Gargantext.Config (CTabNgramType(..), End(..), Path(..), TabSubType(..), TabType(..), toUrl)
import Gargantext.Pages.Corpus.Tabs.Types (Props)
......@@ -59,22 +58,24 @@ statefulTabs =
where
-- TODO totalRecords
docs = noState ( cmapProps (\{path: corpusId} -> {corpusId : corpusId, tabType: TabCorpus TabDocs}) histoSpec
docs = noState ( cmapProps (\{path: corpusId} -> {corpusId, tabType: TabCorpus TabDocs}) histoSpec
<>
(cmapProps (\{path: nodeId, loaded: loaded} ->
{ nodeId : nodeId
(cmapProps (\{path: nodeId, loaded} ->
{ nodeId
, chart : div [][]
, tabType: TabCorpus TabDocs
, totalRecords: 4737
, listId: loaded.defaultListId}) $ noState DT.docViewSpec
, listId: loaded.defaultListId
, corpusId: Just nodeId}) $ noState DT.docViewSpec
)
)
trash = cmapProps (\{path: nodeId, loaded: loaded} ->
trash = cmapProps (\{path: nodeId, loaded} ->
{ nodeId
, chart: div [][]
, tabType: TabCorpus TabTrash
, totalRecords: 4736
, listId: loaded.defaultListId}) $ noState DT.docViewSpec
, listId: loaded.defaultListId
, corpusId: Nothing}) $ noState DT.docViewSpec
ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
......@@ -86,13 +87,13 @@ ngramsViewSpec {mode} =
)
where
tabType = TabCorpus $ TabNgramType $ modeTabType mode
chart Authors = cmapProps (\{path: corpusId} -> {corpusId : corpusId, tabType}) pieSpec
chart Sources = cmapProps (\{path: corpusId} -> {corpusId : corpusId, tabType}) barSpec
chart Authors = cmapProps (\{path: corpusId} -> {corpusId, tabType}) pieSpec
chart Sources = cmapProps (\{path: corpusId} -> {corpusId, tabType}) barSpec
chart Institutes = cmapProps (\{loaded: {defaultListId}, path: corpusId} ->
{corpusId, listId: defaultListId, tabType, limit: (Just 1000)})
treeSpec
chart Terms = cmapProps (\{loaded: {defaultListId}, path: corpusId} ->
{corpusId, listId: defaultListId, tabType, limit: (Just 1000)})
-- TODO limit should be select in the chart by default it is 1000
......
......@@ -48,6 +48,9 @@ dispatchAction dispatcher _ (Annuaire id) = do
dispatchAction dispatcher _ (Folder id) = do
dispatcher $ SetRoute $ Folder id
dispatchAction dispatcher _ (CorpusDocument c i n) = do
dispatcher $ SetRoute $ CorpusDocument c i n
dispatchAction dispatcher _ (Document i n) = do
dispatcher $ SetRoute $ Document i n
......
......@@ -60,7 +60,8 @@ pagesComponent s = case s.currentRoute of
selectSpec (Corpus i) = layout0 $ cmapProps (const {nodeId: i}) $ noState Corpus.layout
selectSpec AddCorpus = layout0 $ focus _addCorpusState _addCorpusAction AC.layoutAddcorpus
selectSpec SearchView = layout0 $ focus _searchState _searchAction S.searchSpec
selectSpec (Document l i) = layout0 $ cmapProps (const {nodeId: i, listId: l}) $ noState Annotation.layout
selectSpec (CorpusDocument c l i) = layout0 $ cmapProps (const {nodeId: i, listId: l, corpusId: Just c}) $ noState Annotation.layout
selectSpec (Document l i) = layout0 $ cmapProps (const {nodeId: i, listId: l, corpusId: Nothing}) $ noState Annotation.layout
selectSpec (PGraphExplorer i)= layout1 $ focus _graphExplorerState _graphExplorerAction GE.specOld
selectSpec Dashboard = layout0 $ noState Dsh.layoutDashboard
selectSpec (Annuaire i) = layout0 $ cmapProps (const {annuaireId: i}) $ noState A.layout
......@@ -96,7 +97,6 @@ layout0 layout =
]
ls = over _render \render d p s c -> [
div [ className "col-md-2", style {paddingTop: "60px"} ] $ render d p s c
]
rs = over _render \render d p s c -> [
div [ case (s.loginState.authData) of
......
......@@ -21,6 +21,7 @@ data Routes
| Corpus Int
| AddCorpus
| Document Int Int
| CorpusDocument Int Int Int
| PGraphExplorer Int
| Dashboard
| Annuaire Int
......@@ -34,6 +35,7 @@ routing = oneOf
, AddCorpus <$ route "addCorpus"
, Folder <$> (route "folder" *> int)
, Corpus <$> (route "corpus" *> int)
, CorpusDocument <$> (route "corpus" *> int) <*> (lit "list" *> int) <*> (lit "document" *> int)
, Document <$> (route "list" *> int) <*> (lit "document" *> int)
, Dashboard <$ route "dashboard"
, PGraphExplorer <$> (route "graph" *> int)
......@@ -42,10 +44,10 @@ routing = oneOf
, ContactPage <$> (route "contact" *> int)
, Home <$ lit ""
]
where
route str = lit "" *> lit str
int :: Match Int
int = floor <$> num
......@@ -55,6 +57,7 @@ instance showRoutes :: Show Routes where
show SearchView = "Search"
show (UserPage i) = "User" <> show i
show (ContactPage i) = "Contact" <> show i
show (CorpusDocument _ _ i) = "Document" <> show i
show (Document _ i) = "Document" <> show i
show (Corpus i) = "Corpus" <> show i
show (Annuaire i) = "Annuaire" <> show i
......
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