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(..))
import Data.Nullable (null)
import Data.Tuple (fst, Tuple(..))
import Data.Tuple.Nested ((/\))
import Data.Nullable (Nullable, null)
import DOM.Simple as DOM
import Effect (Effect)
import Effect.Aff (Aff, launchAff, launchAff_)
import Effect.Class (liftEffect)
......@@ -40,6 +42,11 @@ import URI.Extra.QueryPairs as NQP
import URI.Query as Query
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
......@@ -324,6 +331,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
where
cpt p _ = do
renameBoxOpen <- R.useState' false
iframeRef <- R.useRef null
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 }
pure $ H.div tooltipProps $
......@@ -343,7 +351,7 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
, if nodePopup.action == Just SearchBox then
H.div {}
[
searchIsTexIframe p search
searchIsTexIframe p search iframeRef
]
else
H.div {} []
......@@ -418,20 +426,38 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
, session : p.session
}
searchIsTexIframe {nodeType} search@(search' /\ _) =
searchIsTexIframe {nodeType} search@(search' /\ _) iframeRef =
if isIsTex search'.datafield then
H.div { className: "istex-search panel panel-default" }
[
H.h3 { className: GT.fldr nodeType true} []
, componentIsTex search
, componentIsTex search iframeRef
]
else
H.div {} []
componentIsTex (search /\ setSearch) =
H.iframe { src: isTexTermUrl search.term , width: "100%", height: "100%"} []
componentIsTex (search /\ setSearch) iframeRef =
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"
isTexLocalUrl = "http://localhost:8083"
-- isTexLocalUrl = "http://localhost:8083"
isTexTermUrl term = isTexUrl <> query
where
query = Query.print $ NQP.print identity identity qp
......
......@@ -3,6 +3,11 @@ module Gargantext.Components.Search.SearchBar
) where
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 Gargantext.Components.Lang (Lang)
import Gargantext.Components.Search.SearchField (Search, searchField)
......
module Gargantext.Components.Search.SearchField
( 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.String (length)
import Data.Set as Set
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\))
import Data.Nullable (Nullable, toMaybe)
import Effect.Console (logShow)
import DOM.Simple.Console (log, log2)
import Effect.Aff (launchAff_)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Effect (Effect)
import Reactix as R
......@@ -32,6 +34,7 @@ select = R.createElement "select"
type Search = { databases :: Database
, datafield :: Maybe DataField
, url :: String
, lang :: Maybe Lang
, node_id :: Maybe Int
, term :: String
......@@ -50,6 +53,7 @@ defaultSearch = { databases: Empty
, node_id : Nothing
, lang : Nothing
, term : ""
, url: ""
}
type Props =
......@@ -364,6 +368,7 @@ searchInputComponent = R.hooksComponent "G.C.S.SearchInput" cpt
pure $
H.div { className : "" }
[ H.input { defaultValue: search.term
, value: search.term
, className: "form-control"
, type: "text"
, on: { change : onChange setSearch }
......
......@@ -15,6 +15,10 @@ function stringify(j, indent) {
return JSON.stringify(j, null, indent);
}
function postMessage(obj, msg, src) {
obj.contentWindow.postMessage(msg, src);
}
function setCookie(c) {
document.cookie = c;
}
......@@ -22,4 +26,5 @@ function setCookie(c) {
exports._addRootElement = addRootElement;
exports._getSelection = getSelection;
exports._stringify = stringify;
exports._postMessage = postMessage;
exports._setCookie = setCookie;
......@@ -13,15 +13,16 @@ import Data.Argonaut as Json
import Data.Argonaut.Core (Json)
import Data.Either (hush)
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.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Console (logShow)
import Effect.Aff (Aff, launchAff, launchAff_, killFiber)
import Effect.Class (liftEffect)
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 FFI.Simple ((..), (...), (.=), defineProperty, delay, args2, args3)
import Partial.Unsafe (unsafePartial)
......@@ -296,6 +297,25 @@ useLocalStorageState key s = do
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
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