Commit ed4f4b47 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev' into dev-node-async

parents ec7165a2 eb6aacde
...@@ -7,6 +7,8 @@ import Data.Maybe (Maybe(..)) ...@@ -7,6 +7,8 @@ import Data.Maybe (Maybe(..))
import Data.Nullable (null) import Data.Nullable (null)
import Data.Tuple (fst, Tuple(..)) import Data.Tuple (fst, Tuple(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Data.Nullable (Nullable, null)
import DOM.Simple as DOM
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff, launchAff, launchAff_) import Effect.Aff (Aff, launchAff, launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
...@@ -40,6 +42,11 @@ import URI.Extra.QueryPairs as NQP ...@@ -40,6 +42,11 @@ import URI.Extra.QueryPairs as NQP
import URI.Query as Query import URI.Query as Query
import Web.File.FileReader.Aff (readAsText) import Web.File.FileReader.Aff (readAsText)
import DOM.Simple.Types
import DOM.Simple.Window
import DOM.Simple.EventListener
import DOM.Simple.Event
import Effect.Console
type Dispatch = Action -> Aff Unit type Dispatch = Action -> Aff Unit
...@@ -324,6 +331,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt ...@@ -324,6 +331,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
where where
cpt p _ = do cpt p _ = do
renameBoxOpen <- R.useState' false renameBoxOpen <- R.useState' false
iframeRef <- R.useRef null
nodePopupState@(nodePopup /\ setNodePopup) <- R.useState' {action: Nothing, id: p.id, name: p.name, nodeType: p.nodeType} nodePopupState@(nodePopup /\ setNodePopup) <- R.useState' {action: Nothing, id: p.id, name: p.name, nodeType: p.nodeType}
search <- R.useState' $ defaultSearch { node_id = Just p.id } search <- R.useState' $ defaultSearch { node_id = Just p.id }
pure $ H.div tooltipProps $ pure $ H.div tooltipProps $
...@@ -343,7 +351,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt ...@@ -343,7 +351,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
, if nodePopup.action == Just SearchBox then , if nodePopup.action == Just SearchBox then
H.div {} H.div {}
[ [
searchIsTexIframe p search searchIsTexIframe p search iframeRef
] ]
else else
H.div {} [] H.div {} []
...@@ -418,20 +426,38 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt ...@@ -418,20 +426,38 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
, session : p.session , session : p.session
} }
searchIsTexIframe {nodeType} search@(search' /\ _) = searchIsTexIframe {nodeType} search@(search' /\ _) iframeRef =
if isIsTex search'.datafield then if isIsTex search'.datafield then
H.div { className: "istex-search panel panel-default" } H.div { className: "istex-search panel panel-default" }
[ [
H.h3 { className: GT.fldr nodeType true} [] H.h3 { className: GT.fldr nodeType true} []
, componentIsTex search , componentIsTex search iframeRef
] ]
else else
H.div {} [] H.div {} []
componentIsTex (search /\ setSearch) = componentIsTex (search /\ setSearch) iframeRef =
H.iframe { src: isTexTermUrl search.term , width: "100%", height: "100%"} [] H.iframe { src: isTexTermUrl search.term
,width: "100%"
,height: "100%"
,ref: iframeRef
,on: {
load: \_ -> do
addEventListener window "message" changeSearchOnMessage
R2.postMessage iframeRef search.term
}
} []
where
changeSearchOnMessage :: Callback MessageEvent
changeSearchOnMessage = callback $ \m -> if R2.getMessageOrigin m == isTexUrl
then do
let {url, term} = R2.getMessageData m
setSearch $ _ {url = url, term = term}
else
pure unit
--isTexUrl = "http://0.0.0.0:8080"--"https://istex.gargantext.org"
isTexUrl = "https://istex.gargantext.org" isTexUrl = "https://istex.gargantext.org"
isTexLocalUrl = "http://localhost:8083" -- isTexLocalUrl = "http://localhost:8083"
isTexTermUrl term = isTexUrl <> query isTexTermUrl term = isTexUrl <> query
where where
query = Query.print $ NQP.print identity identity qp query = Query.print $ NQP.print identity identity qp
......
...@@ -3,6 +3,11 @@ module Gargantext.Components.Search.SearchBar ...@@ -3,6 +3,11 @@ module Gargantext.Components.Search.SearchBar
) where ) where
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Data.Nullable (Nullable)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Search.Types -- (Database, SearchQuery(..), defaultSearchQuery, performSearch, Lang(..))
import Effect (Effect) import Effect (Effect)
import Gargantext.Components.Lang (Lang) import Gargantext.Components.Lang (Lang)
import Gargantext.Components.Search.SearchField (Search, searchField) import Gargantext.Components.Search.SearchField (Search, searchField)
......
module Gargantext.Components.Search.SearchField module Gargantext.Components.Search.SearchField
( Search, Props, defaultSearch, searchField, searchFieldComponent, isIsTex) where ( Search, Props, defaultSearch, searchField, searchFieldComponent, isIsTex) where
import Data.Maybe (Maybe(..), maybe, fromMaybe) import Data.Maybe (Maybe(..), maybe, fromMaybe, isJust)
import Data.Newtype (over) import Data.Newtype (over)
import Data.String (length) import Data.String (length)
import Data.Set as Set import Data.Set as Set
import Data.Tuple (fst) import Data.Tuple (fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Data.Nullable (Nullable, toMaybe)
import Effect.Console (logShow)
import DOM.Simple.Console (log, log2) import DOM.Simple.Console (log, log2)
import Effect.Aff (launchAff_) import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect (Effect) import Effect (Effect)
import Reactix as R import Reactix as R
...@@ -32,6 +34,7 @@ select = R.createElement "select" ...@@ -32,6 +34,7 @@ select = R.createElement "select"
type Search = { databases :: Database type Search = { databases :: Database
, datafield :: Maybe DataField , datafield :: Maybe DataField
, url :: String
, lang :: Maybe Lang , lang :: Maybe Lang
, node_id :: Maybe Int , node_id :: Maybe Int
, term :: String , term :: String
...@@ -50,6 +53,7 @@ defaultSearch = { databases: Empty ...@@ -50,6 +53,7 @@ defaultSearch = { databases: Empty
, node_id : Nothing , node_id : Nothing
, lang : Nothing , lang : Nothing
, term : "" , term : ""
, url: ""
} }
type Props = type Props =
...@@ -364,6 +368,7 @@ searchInputComponent = R.hooksComponent "G.C.S.SearchInput" cpt ...@@ -364,6 +368,7 @@ searchInputComponent = R.hooksComponent "G.C.S.SearchInput" cpt
pure $ pure $
H.div { className : "" } H.div { className : "" }
[ H.input { defaultValue: search.term [ H.input { defaultValue: search.term
, value: search.term
, className: "form-control" , className: "form-control"
, type: "text" , type: "text"
, on: { change : onChange setSearch } , on: { change : onChange setSearch }
......
...@@ -15,6 +15,10 @@ function stringify(j, indent) { ...@@ -15,6 +15,10 @@ function stringify(j, indent) {
return JSON.stringify(j, null, indent); return JSON.stringify(j, null, indent);
} }
function postMessage(obj, msg, src) {
obj.contentWindow.postMessage(msg, src);
}
function setCookie(c) { function setCookie(c) {
document.cookie = c; document.cookie = c;
} }
...@@ -22,4 +26,5 @@ function setCookie(c) { ...@@ -22,4 +26,5 @@ function setCookie(c) {
exports._addRootElement = addRootElement; exports._addRootElement = addRootElement;
exports._getSelection = getSelection; exports._getSelection = getSelection;
exports._stringify = stringify; exports._stringify = stringify;
exports._postMessage = postMessage;
exports._setCookie = setCookie; exports._setCookie = setCookie;
...@@ -13,15 +13,16 @@ import Data.Argonaut as Json ...@@ -13,15 +13,16 @@ import Data.Argonaut as Json
import Data.Argonaut.Core (Json) import Data.Argonaut.Core (Json)
import Data.Either (hush) import Data.Either (hush)
import Data.Function.Uncurried (Fn2, runFn2) import Data.Function.Uncurried (Fn2, runFn2)
import Data.Maybe (Maybe(..), fromJust, fromMaybe) import Data.Maybe (Maybe(..), fromJust, fromMaybe, isJust)
import Data.Nullable (Nullable, null, toMaybe) import Data.Nullable (Nullable, null, toMaybe)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import Effect.Console (logShow)
import Effect.Aff (Aff, launchAff, launchAff_, killFiber) import Effect.Aff (Aff, launchAff, launchAff_, killFiber)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Exception (error) import Effect.Exception (error)
import Effect.Uncurried (EffectFn1, EffectFn2, mkEffectFn1, mkEffectFn2, runEffectFn1, runEffectFn2) import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, mkEffectFn1, mkEffectFn2, runEffectFn1, runEffectFn2, runEffectFn3)
import Effect.Unsafe (unsafePerformEffect) import Effect.Unsafe (unsafePerformEffect)
import FFI.Simple ((..), (...), (.=), defineProperty, delay, args2, args3) import FFI.Simple ((..), (...), (.=), defineProperty, delay, args2, args3)
import Partial.Unsafe (unsafePartial) import Partial.Unsafe (unsafePartial)
...@@ -296,6 +297,25 @@ useLocalStorageState key s = do ...@@ -296,6 +297,25 @@ useLocalStorageState key s = do
pure (Tuple state setState) pure (Tuple state setState)
getMessageDataStr :: DE.MessageEvent -> String
getMessageDataStr = getMessageData
getMessageOrigin :: DE.MessageEvent -> String
getMessageOrigin me = me .. "origin"
getMessageData :: forall o. DE.MessageEvent -> o
getMessageData me = me .. "data"
foreign import _postMessage
:: forall r. EffectFn3 r String String Unit
postMessage :: forall r. R.Ref (Nullable r) -> String -> Effect Unit
postMessage ref msg = do
case (R.readNullableRef ref) of
(Just ifr) -> do
runEffectFn3 _postMessage ifr msg (ifr .. "src")
(Nothing) -> pure unit
foreign import _setCookie :: EffectFn1 String Unit foreign import _setCookie :: EffectFn1 String Unit
setCookie :: String -> Effect Unit setCookie :: String -> Effect Unit
......
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