These are chat archives for synrc/n2o

11th
May 2016
Maruthavanan Subbaryan
@marutha
May 11 2016 03:50
What should I do to trigger a postback an event? I use the below code but postback is not happening
#'div'{class = <<"form-group">>, body = #button{class = <<"btn btn-def btn-block animated bounceIn">>, type = <<"button">>, body = <<"Login">>, postback = login, id = loginButton, source = [username, password]}},
formatted one
                    #'div'{class = <<"form-group">>,
                           body = #button{class = <<"btn btn-def btn-block animated bounceIn">>,
                                          type = <<"button">>, body =  <<"Login">>,
                                          postback = login, id = loginButton,
                                          source = [username, password]}}
skatt
@skatt
May 11 2016 03:51
Do you have event(login) -> ... defined in the module to capture?
Maruthavanan Subbaryan
@marutha
May 11 2016 03:53
I have below
event(login) ->
      io:fwrite("something~p~n", [wf:q(username)]).
I could not see the print in console.
skatt
@skatt
May 11 2016 03:56

Something like: <script>{{script}}</script>

<script src='/n2o/protocols/bert.js'></script>
<script src='/n2o/protocols/client.js'></script>
<script src='/n2o/protocols/nitrogen.js'></script>
<script src='/n2o/validation.js'></script>
<script src='/n2o/bullet.js'></script>
<script src='/n2o/utf8.js'></script>
<script src='/n2o/template.js'></script>
<script src='/n2o/n2o.js'></script>
<script>protos = [ $bert, $client ]; N2O_start();</script>

Inside dtl template?

Maruthavanan Subbaryan
@marutha
May 11 2016 03:58
I doubt, let me check agin
Maruthavanan Subbaryan
@marutha
May 11 2016 04:04
here is my dtl
<head>
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.theme.css">
<link rel="stylesheet" type="text/css" href="static/css/nexustopia.theme.css">
<link rel="stylesheet" type="text/css" href="static/css/animate.css">
</head>
<body>
<script src='/n2o/protocols/bert.js'></script>
<script src='/n2o/protocols/client.js'></script>
<script src='/n2o/protocols/nitrogen.js'></script>
<script src='/n2o/validation.js'></script>
<script src='/n2o/bullet.js'></script>
<script src='/n2o/utf8.js'></script>
<script src='/n2o/template.js'></script>
<script src='/n2o/n2o.js'></script>
<script>protos = [ $bert, $client  ]; N2O_start();</script>
{{ body }}
</body>
</html>
Is anything wrong with this?
skatt
@skatt
May 11 2016 04:05
<script>{{script}}</script>
Needed for server to wire scripts into page.
You don't need to add a field in dtl for script. It is handled by n2o.
*In #dtl record
Maruthavanan Subbaryan
@marutha
May 11 2016 04:06
I am sorry I could not follow that, I am a newbie.
skatt
@skatt
May 11 2016 04:07
<script>{{script}}</script> needs to be added above bert script.
That will fix.
Maruthavanan Subbaryan
@marutha
May 11 2016 04:08
Delete all the rest of the script or keep it?
skatt
@skatt
May 11 2016 04:09
Keep everything else. Do not add a script option to #dtl.bindings in module. It is automatically handled by n2o. Only add <script>{{script}}</script>
Maruthavanan Subbaryan
@marutha
May 11 2016 04:13
now my webpage looks like this, but still the same
<script src='/n2o/protocols/bert.js'></script>
<script src='/n2o/protocols/client.js'></script>
<script src='/n2o/protocols/nitrogen.js'></script>
<script src='/n2o/validation.js'></script>
<script src='/n2o/bullet.js'></script>
<script src='/n2o/utf8.js'></script>
<script src='/n2o/template.js'></script>
<script src='/n2o/n2o.js'></script>
<script>var transition = {pid: 'g2gCZ2QADW5vbm9kZUBub2hvc3QAAANQAAAAAABoA2IAAAW2YgAOV5piAA6+lw==', port:'8000'}</script>
<script>protos = [ $bert, $client  ]; N2O_start();</script>
skatt
@skatt
May 11 2016 04:16
Hmm, does your route include prefix for ws?
See sample generated by mad for example.
Maruthavanan Subbaryan
@marutha
May 11 2016 04:25
Sorry for the delay, yes I do have
-module(my_routes).
-include_lib("n2o/include/wf.hrl").
-export([init/2, finish/2]).


finish(State, Ctx) -> {ok, State, Ctx}.
init(State, Ctx) ->
    Path = wf:path(Ctx#cx.req),
    wf:info(?MODULE, "Route:~p~n", [Path]),
    {ok, State, Ctx#cx{path = Path, module = route_prefix(Path)}}.

route_prefix(<<"/ws/", P/binary>>) -> route(P);
route_prefix(<<"/", P/binary>>) -> route(P);
route_prefix(P) -> route(P).

route(<<"my_template">>) -> my_template;
route(<<"login">>) -> login;
route(_) -> my_index.
I doubt I missing something basic, is there a step by step tutorial for n2o?
skatt
@skatt
May 11 2016 04:27
Well, we just ran through all the basics. :P That is the minimal for message transfer.
The last thought I can think of is whether the websocket endpoint is defined in cowboy_router
Everything for the entire message flow is in that sample app.
Maruthavanan Subbaryan
@marutha
May 11 2016 17:16
I am not sure what I am missing, the below is my_web_app module, I am not sure what other information I could provide
-module(my_web_app).
-behaviour(supervisor).
-behaviour(application).
-export([init/1, start/2, stop/1, main/1, start/0]).

-include_lib("kvs/include/user.hrl").

main(A) -> mad:main(A).
start() -> start(normal, []).
start(_, _) -> supervisor:start_link({local, my_web_app}, my_web_app,[]).
stop(_) -> ok.

init([]) ->
    {ok, {{one_for_one, 5, 10}, [spec()]}}.

spec()   -> ranch:child_spec(http, 100, ranch_tcp, port(), cowboy_protocol, env()).
env()    -> [ { env, [ { dispatch, points()  }  ]  }  ].
static() ->   { dir, "apps/my_web_app/priv/static", mime()  }.
n2o()    ->   { dir, "deps/n2o/priv",           mime()  }.
mime()   -> [ { mimetypes, cow_mimetypes, all    }  ].
port()   -> [ { port, wf:config(n2o,port,8000)   }  ].
points() -> cowboy_router:compile([{'_', [

                                          {"/static/[...]",       n2o_static,  static()},
                                          {"/n2o/[...]",          n2o_static,  n2o()},
                                          {"/multipart/[...]",  n2o_multipart, []},
                                          {"/rest/:resource",     rest_cowboy, []},
                                          {"/rest/:resource/:id", rest_cowboy, []},
                                          {"/ws/[...]",           n2o_stream,  []},
                                          {'_',                   n2o_cowboy,  []}·
I can see spec() function is something different,
I shall try to import all the ones in github if that could be helpful. Let me know if I am doing any mistake