Commit 169c6cf4 authored by Abinaya Sudhir's avatar Abinaya Sudhir

Docview navigation done

parent 988352b0
...@@ -15,8 +15,11 @@ import DOM.WebStorage.Storage (getItem, setItem) ...@@ -15,8 +15,11 @@ import DOM.WebStorage.Storage (getItem, setItem)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, jsonEmptyObject, (.?), (:=), (~>)) import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, jsonEmptyObject, (.?), (:=), (~>))
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.HTTP.Method (Method(..)) import Data.HTTP.Method (Method(..))
import Data.Lens (Lens', Prism', lens, over)
import Data.List (List, fold, fromFoldable, toUnfoldable)
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.MediaType.Common (applicationJSON) import Data.MediaType.Common (applicationJSON)
import Data.Tuple (Tuple(..))
import Network.HTTP.Affjax (AJAX, affjax, defaultRequest) import Network.HTTP.Affjax (AJAX, affjax, defaultRequest)
import Network.HTTP.RequestHeader (RequestHeader(..)) import Network.HTTP.RequestHeader (RequestHeader(..))
import Prelude hiding (div) import Prelude hiding (div)
...@@ -24,10 +27,11 @@ import React (ReactElement) ...@@ -24,10 +27,11 @@ import React (ReactElement)
import React.DOM (a, button, div, form, h2, h3, h4, i, input, label, li, p, span, text, ul) import React.DOM (a, button, div, form, h2, h3, h4, i, input, label, li, p, span, text, ul)
import React.DOM.Props (_id, _type, className, href, maxLength, name, onClick, onInput, placeholder, target, value) import React.DOM.Props (_id, _type, className, href, maxLength, name, onClick, onInput, placeholder, target, value)
import Routing.Hash.Aff (setHash) import Routing.Hash.Aff (setHash)
import Thermite (PerformAction, Render, Spec, cotransform, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, _render, cotransform, focus, foreach, modifyState, simpleSpec, withState)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
type State = type State =
{ select_database :: Boolean { select_database :: Boolean
, unselect_database :: Boolean -- dummy state , unselect_database :: Boolean -- dummy state
...@@ -54,6 +58,7 @@ data Action ...@@ -54,6 +58,7 @@ data Action
| SelectDatabase Boolean | SelectDatabase Boolean
| UnselectDatabase Boolean | UnselectDatabase Boolean
| LoadDatabaseDetails | LoadDatabaseDetails
| ResponseAction
performAction :: forall eff props. PerformAction (console :: CONSOLE, ajax :: AJAX,dom::DOM | eff) State props Action performAction :: forall eff props. PerformAction (console :: CONSOLE, ajax :: AJAX,dom::DOM | eff) State props Action
...@@ -74,6 +79,8 @@ performAction (LoadDatabaseDetails) _ _ = void do ...@@ -74,6 +79,8 @@ performAction (LoadDatabaseDetails) _ _ = void do
Right resData -> do Right resData -> do
cotransform $ \(state) -> state {response = resData} cotransform $ \(state) -> state {response = resData}
performAction ResponseAction _ _ = void do
modifyState id
...@@ -96,25 +103,29 @@ addcorpusviewSpec = simpleSpec performAction render ...@@ -96,25 +103,29 @@ addcorpusviewSpec = simpleSpec performAction render
[ [
h3 [] [text "Corpusview"] h3 [] [text "Corpusview"]
, ul [className "list-group"] $ map fn1 state.response , ul [className "list-group"] $ map fn1 state.response
, button [] [text "GO"]
] ]
] ]
] ]
] ]
] ]
where
fn1 (Response o) =
li [className "list-group-item justify-content-between"]
[
span [] [text o.name]
, span [className "badge badge-default badge-pill"] [ text $ show o.count]
]
fn1 :: Response -> ReactElement
fn1 (Response o) =
li [className "list-group-item justify-content-between"]
[
a [ href "#"]
[ span [] [text o.name]
, span [className "badge badge-default badge-pill"] [ text $ show o.count]
]
] -- fn1 :: Response -> ReactElement
-- fn1 (Response o) =
-- li [className "list-group-item justify-content-between"]
-- [
-- span [] [text o.name]
-- , span [className "badge badge-default badge-pill"] [ text $ show o.count]
-- ]
newtype QueryString = QueryString newtype QueryString = QueryString
......
This diff is collapsed.
...@@ -19,6 +19,8 @@ import Prelude hiding (div) ...@@ -19,6 +19,8 @@ import Prelude hiding (div)
import React.DOM (a, div, i, img, li, span, text, ul) import React.DOM (a, div, i, img, li, span, text, ul)
import React.DOM.Props (_data, _id, aria, className, href, role, src, style, tabIndex, target, title) import React.DOM.Props (_data, _id, aria, className, href, role, src, style, tabIndex, target, title)
import Thermite (PerformAction, Render, Spec, _render, defaultRender, focus, modifyState, simpleSpec, withState) import Thermite (PerformAction, Render, Spec, _render, defaultRender, focus, modifyState, simpleSpec, withState)
import DocView as DV
type E e = (dom :: DOM, ajax :: AJAX, console :: CONSOLE | e) type E e = (dom :: DOM, ajax :: AJAX, console :: CONSOLE | e)
...@@ -27,6 +29,7 @@ type AppState = ...@@ -27,6 +29,7 @@ type AppState =
, landingState :: L.State , landingState :: L.State
, loginState :: LN.State , loginState :: LN.State
, addCorpusState :: AC.State , addCorpusState :: AC.State
, docViewState :: DV.State
} }
initAppState :: AppState initAppState :: AppState
...@@ -35,6 +38,7 @@ initAppState = ...@@ -35,6 +38,7 @@ initAppState =
, landingState : L.initialState , landingState : L.initialState
, loginState : LN.initialState , loginState : LN.initialState
, addCorpusState : AC.initialState , addCorpusState : AC.initialState
, docViewState : DV.tdata
} }
...@@ -44,6 +48,7 @@ data Action ...@@ -44,6 +48,7 @@ data Action
| LoginA LN.Action | LoginA LN.Action
| SetRoute Routes | SetRoute Routes
| AddCorpusA AC.Action | AddCorpusA AC.Action
| DocViewA DV.Action
performAction :: forall eff props. PerformAction (dom :: DOM |eff) AppState props Action performAction :: forall eff props. PerformAction (dom :: DOM |eff) AppState props Action
...@@ -92,6 +97,18 @@ _addCorpusAction = prism AddCorpusA \action -> ...@@ -92,6 +97,18 @@ _addCorpusAction = prism AddCorpusA \action ->
_docViewState:: Lens' AppState DV.State
_docViewState = lens (\s -> s.docViewState) (\s ss -> s{docViewState = ss})
_docViewAction :: Prism' Action DV.Action
_docViewAction = prism DocViewA \action ->
case action of
DocViewA caction -> Right caction
_-> Left action
pagesComponent :: forall props eff. AppState -> Spec (E eff) AppState props Action pagesComponent :: forall props eff. AppState -> Spec (E eff) AppState props Action
pagesComponent s = pagesComponent s =
case s.currentRoute of case s.currentRoute of
...@@ -104,6 +121,7 @@ pagesComponent s = ...@@ -104,6 +121,7 @@ pagesComponent s =
selectSpec Home = wrap $ focus _landingState _landingAction L.loginSpec selectSpec Home = wrap $ focus _landingState _landingAction L.loginSpec
selectSpec Login = focus _loginState _loginAction LN.renderSpec selectSpec Login = focus _loginState _loginAction LN.renderSpec
selectSpec AddCorpus = wrap $ focus _addCorpusState _addCorpusAction AC.addcorpusviewSpec selectSpec AddCorpus = wrap $ focus _addCorpusState _addCorpusAction AC.addcorpusviewSpec
selectSpec DocView = wrap $ focus _docViewState _docViewAction DV.spec
routingSpec :: forall props eff. Spec (dom :: DOM |eff) AppState props Action routingSpec :: forall props eff. Spec (dom :: DOM |eff) AppState props Action
routingSpec = simpleSpec performAction defaultRender routingSpec = simpleSpec performAction defaultRender
...@@ -240,3 +258,8 @@ dispatchAction dispatcher _ AddCorpus = do ...@@ -240,3 +258,8 @@ dispatchAction dispatcher _ AddCorpus = do
_ <- dispatcher $ SetRoute $ AddCorpus _ <- dispatcher $ SetRoute $ AddCorpus
_ <- dispatcher $ AddCorpusA $ AC.LoadDatabaseDetails _ <- dispatcher $ AddCorpusA $ AC.LoadDatabaseDetails
pure unit pure unit
dispatchAction dispatcher _ DocView = do
_ <- dispatcher $ SetRoute $ DocView
_ <- dispatcher $ DocViewA $ DV.LoadData
pure unit
...@@ -18,11 +18,13 @@ data Routes ...@@ -18,11 +18,13 @@ data Routes
= Home = Home
| Login | Login
| AddCorpus | AddCorpus
| DocView
instance showRoutes :: Show Routes where instance showRoutes :: Show Routes where
show Home = "Home" show Home = "Home"
show Login = "Login" show Login = "Login"
show AddCorpus = "AddCorpus" show AddCorpus = "AddCorpus"
show DocView = "DocView"
int :: Match Int int :: Match Int
int = floor <$> num int = floor <$> num
...@@ -31,8 +33,10 @@ routing :: Match Routes ...@@ -31,8 +33,10 @@ routing :: Match Routes
routing = routing =
loginRoute loginRoute
<|> addcorpusRoute <|> addcorpusRoute
<|> docviewRoute
<|> home <|> home
where where
docviewRoute = DocView <$ route "docView"
addcorpusRoute = AddCorpus <$ route "addCorpus" addcorpusRoute = AddCorpus <$ route "addCorpus"
loginRoute = Login <$ route "login" loginRoute = Login <$ route "login"
home = Home <$ lit "" home = Home <$ lit ""
......
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