Commit 9a014261 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[docstable] refactor table/hash url function

parent a0df81cd
...@@ -368,8 +368,7 @@ type PageParams = ...@@ -368,8 +368,7 @@ type PageParams =
getPageHash :: Session -> PageParams -> Aff String getPageHash :: Session -> PageParams -> Aff String
getPageHash session { corpusId, listId, nodeId, query, tabType } = do getPageHash session { corpusId, listId, nodeId, query, tabType } = do
let p = NodeAPI Node (Just nodeId) $ "table/hash" <> "?tabType=" <> (showTabType' tabType) (get session $ tableHashRoute nodeId tabType) :: Aff String
(get session p) :: Aff String
convOrderBy (Just (T.ASC (T.ColumnName "Date"))) = Just DateAsc convOrderBy (Just (T.ASC (T.ColumnName "Date"))) = Just DateAsc
...@@ -417,7 +416,7 @@ pageLayoutCpt = R.hooksComponent "G.C.DocsTable.pageLayout" cpt where ...@@ -417,7 +416,7 @@ pageLayoutCpt = R.hooksComponent "G.C.DocsTable.pageLayout" cpt where
mkRequest :: PageParams -> GUC.Request mkRequest :: PageParams -> GUC.Request
mkRequest p@{ listId, nodeId, tabType } = mkRequest p@{ listId, nodeId, tabType } =
GUC.makeGetRequest session $ NodeAPI Node (Just nodeId) $ "table" <> "?tabType=" <> (showTabType' tabType) <> "&list=" <> (show listId) GUC.makeGetRequest session $ tableRoute nodeId tabType listId
handleResponse :: HashedResponse (TableResult Response) -> Tuple Int (Array DocumentsView) handleResponse :: HashedResponse (TableResult Response) -> Tuple Int (Array DocumentsView)
handleResponse (HashedResponse { hash, value: res }) = ret handleResponse (HashedResponse { hash, value: res }) = ret
where where
...@@ -543,13 +542,15 @@ instance encodeJsonSQuery :: EncodeJson SearchQuery where ...@@ -543,13 +542,15 @@ instance encodeJsonSQuery :: EncodeJson SearchQuery where
~> jsonEmptyObject ~> jsonEmptyObject
searchResults :: SearchQuery -> Aff Int
searchResults squery = pure 42 -- TODO post "http://localhost:8008/count" unit
documentsRoute :: Int -> SessionRoute documentsRoute :: Int -> SessionRoute
documentsRoute nodeId = NodeAPI Node (Just nodeId) "documents" documentsRoute nodeId = NodeAPI Node (Just nodeId) "documents"
tableRoute :: Int -> TabType -> Int -> SessionRoute
tableRoute nodeId tabType listId = NodeAPI Node (Just nodeId) $ "table" <> "?tabType=" <> (showTabType' tabType) <> "&list=" <> (show listId)
tableHashRoute :: Int -> TabType -> SessionRoute
tableHashRoute nodeId tabType = NodeAPI Node (Just nodeId) $ "table/hash" <> "?tabType=" <> (showTabType' tabType)
deleteAllDocuments :: Session -> Int -> Aff (Array Int) deleteAllDocuments :: Session -> Int -> Aff (Array Int)
deleteAllDocuments session = delete session <<< documentsRoute deleteAllDocuments session = delete session <<< documentsRoute
......
...@@ -78,10 +78,10 @@ cached cache req = do ...@@ -78,10 +78,10 @@ cached cache req = do
mRes <- match cache req mRes <- match cache req
case mRes of case mRes of
Just res -> do Just res -> do
liftEffect $ log2 "[cached] cache hit" req -- liftEffect $ log2 "[cached] cache hit" req
pure res pure res
Nothing -> do Nothing -> do
liftEffect $ log2 "[cached] cache miss" req -- liftEffect $ log2 "[cached] cache miss" req
_ <- add cache req _ <- add cache req
mResFresh <- match cache req mResFresh <- match cache req
case mResFresh of case mResFresh of
...@@ -91,8 +91,8 @@ cached cache req = do ...@@ -91,8 +91,8 @@ cached cache req = do
cachedJson :: forall a. DecodeJson a => Cache -> Request -> Aff a cachedJson :: forall a. DecodeJson a => Cache -> Request -> Aff a
cachedJson cache req = do cachedJson cache req = do
res <- cached cache req res <- cached cache req
liftEffect $ do -- liftEffect $ do
log2 "[cachedJson] res" res -- log2 "[cachedJson] res" res
j <- M.json res j <- M.json res
case decodeJson (F.unsafeFromForeign j) of case decodeJson (F.unsafeFromForeign j) of
......
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