gilbertosj

gilbertosj

Problem creating button with drab

I need some help creating a trigger … with the “drab”

can you help me?

scenarios is that:

He calls this drab:

html
<li class="nav-item"><a drab="click:test_start('test')" class="nav-link"><i class="nav-link"></i><span class="nav-link-text">start</span></a></li>

He calls this drab:

  defhandler click:test_start(socket, sender, name_project) do
    user = socket.assigns.current_user.username
    user_id = socket.assigns.current_user.id
    query_password = from [p] in "test", select: p.password_project, where: p.name == ^name_project and p.user_id == ^user_id
    query_languagecode = from [p] in "test", select: p.languagecode, where: p.name == ^name_project and p.user_id == ^user_id
    passwd = Repo.one(query_password_project)
    languagecode = Repo.one(query_languagecode)
    databasedb = "#{name_project}"
    TestWeb.CustomController.create_function1(user, passwd)
    TestWeb.CustomController.create_function2(user, passwd)
    TestWeb.CustomController.create_function3(user, passwd)
    TestWeb.CustomController.create_function4(user, passwd)

    IO.puts("start!")
  end

problem is …

If the person clicks on this drab, and then immediately “refresh” the page, he cancels this function entirely.

Currently I need this drab to continue running even if the client refresh the page.

Would it be possible to do that?

First Post!

egze

egze

You need to move your logic out of your handlers. I haven’t tried drab, but in LiveView I would start a new GenServer on mount. Then if my LiveView dies, my GenServer is still running.

Most Liked

egze

egze

Sorry no specific examples. But do read up on DynamicSupervisor. Try to write a GenServer that can be started dynamically with some params (like user_id for example). Play with it in the IEx and make sure you understand how to start the process and find it later by params.

Then once you got that - do the same in Drab. In the onload callback, locate or start your GenServer like you did in IEx. Now your GenServer will survive reload of page/Drab.

Edit
I think you’d start your GenServer in the click:test_start callback. Or maybe a Task will also be fine here.

Last Post!

gilbertosj

gilbertosj

I’m reading this,
maybe I can send him …

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement