Put status in button, and gray it out if morse is in progress.
Fix hint button.
This commit is contained in:
parent
2cb9946faf
commit
d912ae289d
3 changed files with 33 additions and 15 deletions
|
@ -17,6 +17,10 @@ defmodule Morse.Server do
|
||||||
GenServer.call(__MODULE__, :progress)
|
GenServer.call(__MODULE__, :progress)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def in_progress? do
|
||||||
|
GenServer.call(__MODULE__, :in_progress?)
|
||||||
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def init(state) do
|
def init(state) do
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
|
@ -24,11 +28,11 @@ defmodule Morse.Server do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_call(:start, _from, {pid, _progress} = state) do
|
def handle_call(:start, _from, {pid, _progress} = state) do
|
||||||
if pid == nil or not Process.alive?(pid) do
|
if worker_alive?(pid) do
|
||||||
|
{:reply, {:error, :already_started}, state}
|
||||||
|
else
|
||||||
pid = spawn(&Morse.Worker.signal/0)
|
pid = spawn(&Morse.Worker.signal/0)
|
||||||
{:reply, :ok, {pid, 0}}
|
{:reply, :ok, {pid, 0}}
|
||||||
else
|
|
||||||
{:reply, {:error, :already_started}, state}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,6 +40,10 @@ defmodule Morse.Server do
|
||||||
{:reply, progress, state}
|
{:reply, progress, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_call(:in_progress?, _from, {pid, _progress} = state) do
|
||||||
|
{:reply, worker_alive?(pid), state}
|
||||||
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_cast({:progress, new_progress}, {pid, _progress}) do
|
def handle_cast({:progress, new_progress}, {pid, _progress}) do
|
||||||
apply(pubsub(), :broadcast, [Ui.PubSub, "morse_progress", new_progress])
|
apply(pubsub(), :broadcast, [Ui.PubSub, "morse_progress", new_progress])
|
||||||
|
@ -45,4 +53,8 @@ defmodule Morse.Server do
|
||||||
defp pubsub do
|
defp pubsub do
|
||||||
Application.fetch_env!(:morse, :pubsub)
|
Application.fetch_env!(:morse, :pubsub)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp worker_alive?(pid) do
|
||||||
|
pid != nil and Process.alive?(pid)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,13 +17,19 @@ defmodule UiWeb.MorseLive do
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("toggle_hint", _value, socket) do
|
||||||
|
{:noreply, update(socket, :hints_visible, &(not &1))}
|
||||||
|
end
|
||||||
|
|
||||||
def handle_info(progress, socket) do
|
def handle_info(progress, socket) do
|
||||||
{:noreply, assign(socket, progress: progress)}
|
{:noreply, assign(socket, progress: progress, in_progress?: Morse.Server.in_progress?())}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp default_assigns do
|
defp default_assigns do
|
||||||
[
|
[
|
||||||
progress: Morse.Server.progress(),
|
progress: Morse.Server.progress(),
|
||||||
|
in_progress?: Morse.Server.in_progress?(),
|
||||||
|
hints_visible: false
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
<h2>nl:<br>Druk op de Start knop hieronder om <span style="color:red">UVW</span><span style="color:blue">XYZ</span> te vinden. Je kunt dan de geocache vinden op N 52° 40.<span style="color:red">UVW</span>' E 004° 53.<span style="color:blue">XYZ</span>'</h2>
|
<h2>nl:<br>Druk op de Start knop hieronder om <span style="color:red">UVW</span><span style="color:blue">XYZ</span> te vinden. Je kunt dan de geocache vinden op N 52° 40.<span style="color:red">UVW</span>' E 004° 53.<span style="color:blue">XYZ</span>'</h2>
|
||||||
|
|
||||||
<div id="buttonwrap">
|
<div id="buttonwrap">
|
||||||
<button phx-click="start_morse" class="button" <%= if @progress != 100, do: ~s(disabled=disabled) %>>Start</button>
|
<%= if @in_progress? do %>
|
||||||
|
<button phx-click="start_morse" class="button" <%= if @in_progress?, do: ~s(disabled=disabled) %>>In progress...</button>
|
||||||
|
<% else %>
|
||||||
|
<button phx-click="start_morse" class="button">Start</button>
|
||||||
|
<% end %>
|
||||||
<div id="response-block">
|
<div id="response-block">
|
||||||
<h2>Response status:</h2>
|
|
||||||
<p id="response"></p>
|
|
||||||
<h2>Progress:</h2>
|
<h2>Progress:</h2>
|
||||||
<progress max="100" value="<%= @progress %>"><%= @progress %>%</progress>
|
<progress max="100" value="<%= @progress %>"><%= @progress %>%</progress>
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,16 +17,14 @@
|
||||||
<a href="http://www.geochecker.com/index.php?code=d9dbdc4542a4911a5f81a51bc9312a35&action=check&wp=47433743363432&name=4573726f6d">en: check your coordinate on GeoChecker.com nl: controleer je coördinaat op GeoChecker.</a>
|
<a href="http://www.geochecker.com/index.php?code=d9dbdc4542a4911a5f81a51bc9312a35&action=check&wp=47433743363432&name=4573726f6d">en: check your coordinate on GeoChecker.com nl: controleer je coördinaat op GeoChecker.</a>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<input type="button" onclick="givehint()" value="Click here for a hint!" id="hintbutton">
|
<button phx-click="toggle_hint" id="hintButton">Click here for a hint!</button>
|
||||||
|
<%= if @hints_visible do %>
|
||||||
|
<div id="givehint">
|
||||||
|
<% else %>
|
||||||
<div id="givehint" style="visibility: hidden">
|
<div id="givehint" style="visibility: hidden">
|
||||||
|
<% end %>
|
||||||
<p>en: Position yourself on the bridge. Watch carefully around to windows of houses, remember this is a nightly geocache. During daytime it is quite hard to see, but not impossible. After pushing the button, it takes 3
|
<p>en: Position yourself on the bridge. Watch carefully around to windows of houses, remember this is a nightly geocache. During daytime it is quite hard to see, but not impossible. After pushing the button, it takes 3
|
||||||
seconds to start. The whole process takes about 35 sec. During the process it cannot be stopped nor restarted. You can start it all over again as much as you like. In case you are really stuck, you could try to contact me via WhatsApp on number +31 6 41633689. Best of luck to you!</p>
|
seconds to start. The whole process takes about 35 sec. During the process it cannot be stopped nor restarted. You can start it all over again as much as you like. In case you are really stuck, you could try to contact me via WhatsApp on number +31 6 41633689. Best of luck to you!</p>
|
||||||
<p>nl: Ga op de brug staan. Kijk goed om je heen naar ramen van woningen en realiseer je dat dit een een nachtcache is. Overdag is het slecht te zien, maar niet onmogelijk. Na het indrukken van de knop duurt het 3 seconden
|
<p>nl: Ga op de brug staan. Kijk goed om je heen naar ramen van woningen en realiseer je dat dit een een nachtcache is. Overdag is het slecht te zien, maar niet onmogelijk. Na het indrukken van de knop duurt het 3 seconden
|
||||||
voordat het begint. Het hele proces duurt ongeveer 35 sec. Het proces kan niet gestopt of herstart worden. Je kunt het zo vaak starten als je wilt. Als het helemaal niet lukt zou je me kunnen proberen te bereiken via WhatsApp nummer 06-41633689. Veel plezier!</p>
|
voordat het begint. Het hele proces duurt ongeveer 35 sec. Het proces kan niet gestopt of herstart worden. Je kunt het zo vaak starten als je wilt. Als het helemaal niet lukt zou je me kunnen proberen te bereiken via WhatsApp nummer 06-41633689. Veel plezier!</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function givehint() {
|
|
||||||
document.getElementById("givehint").style.visibility = "visible";
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
Loading…
Reference in a new issue