jordan 3 rokov pred
rodič
commit
8bab2b3154

+ 1 - 1
lib/abcd.ex

@@ -26,7 +26,7 @@ defmodule ABCD.Fourletters do
     Agent.update(name, fn _ -> [] end)
   end
 
-  defp append(lines, value) when is_list(lines) and length(lines) < 101 do
+  defp append(lines, value) when is_list(lines) and length(lines) < 100 do
     lines ++ [value]
   end
 

+ 16 - 1
lib/fourletters_web/controllers/fourletters_controller.ex

@@ -19,6 +19,21 @@ defmodule FourlettersWeb.FourlettersController do
     end
   end
 
+  def getmessages(conn, %{"fourletters" => fourletters}) do
+    if String.length(fourletters) == 4 do
+
+      pid = case Supervisor.start_child(
+          Fourletters.Troll,
+          %{id: String.to_atom(fourletters), start: {ABCD.Fourletters, :start_link, [[]]}}) do
+        {:ok, pid} -> pid
+        {:error, {:already_started, pid}} -> pid
+      end
+      messages = ABCD.Fourletters.get(pid)
+      json(conn, %{fourletters: fourletters, messages: messages})
+    else
+      json(conn, %{welcome: "this is fourletters"})
+    end
+  end
 
   def addletters(conn, _params) do
     %{params: params} = conn
@@ -40,7 +55,7 @@ defmodule FourlettersWeb.FourlettersController do
       redirect(conn, to: "/#{fourletters}")
       # |> render("four.html", fourletters: fourletters, messages: messages)
     else
-      json(conn, %{error: message})
+      redirect(conn, to: "/#{fourletters}")
     end
   end
 

+ 1 - 0
lib/fourletters_web/router.ex

@@ -25,6 +25,7 @@ defmodule FourlettersWeb.Router do
     pipe_through :api
 
     post "/:fourletters", FourlettersController, :addletters
+    get "/api/:fourletters", FourlettersController, :getmessages
 
     post "/api/:fourletters", FourlettersController, :apiaddletters
 

+ 27 - 18
lib/fourletters_web/templates/fourletters/four.html.eex

@@ -1,18 +1,27 @@
-<h1>hey <%= @fourletters %></h1>
-<a href="/">go home</a><br><br>
-<form action="" method="post">
-	<label for="message">message:</label><br>
-	<input type=”text” id="message" name="message"><br><br>
-	<input type="submit" value="Submit">
-</form>
-
-<form action="/api/clear/<%= @fourletters %>" method="post">
-	<input type="submit" value="Clear">
-</form>
-<ul>
-	<%= for message <- @messages do %>
-	<li>
-		<%= message %>
-	</li>
-	<% end %>
-</ul>
+<style>
+</style>
+<div style="float: left">
+	<h1><span style="font-family: cursive">it's</span> <strong><%= @fourletters %></strong></h1>
+	<br><br>
+	<form id="new-message" action="" method="post">
+		<label for="message"></label><br>
+		<input type=”text” maxlength=100 id="message" name="message"><br><br>
+		<input type="submit" value="    &#x21E8;    ">
+	</form>
+	<br><br>
+	<form id="clear" action="/api/clear/<%= @fourletters %>" method="post">
+		<input type="submit" value="c l e a r">
+	</form>
+	<br><br>
+	<a href="/">go home</a>
+</div>
+<div id="messages" style="float: left">
+	<p><%= length(@messages) %> of 100</p>
+	<ul>
+		<%= for message <- @messages do %>
+		<li>
+			<%= message %>
+		</li>
+		<% end %>
+	</ul>
+</div>

+ 11 - 6
lib/fourletters_web/templates/fourletters/nothing.html.eex

@@ -1,6 +1,11 @@
-<h1>4-letters.net</h1>
-<form action="/" method="get">
-	<label for="fourletters">fourletters:</label><br>
-	<input type=”text” id="fourletters" name="fourletters"><br><br>
-	<input type="submit" value="Submit">
-</form>
+<div id="home">
+	<h1>4-letters.net</h1>
+	<form action="/" method="get">
+		<label for="fourletters">fourletters:</label><br>
+		<input type=”text” id="fourletters" name="fourletters"><br><br>
+		<input type="submit" value="Submit">
+	</form>
+</div>
+<footer>
+	<p>composed by <a href="http://jordandashel.com">jordyn</a> with elixir</p>
+</footer>

+ 1 - 0
lib/fourletters_web/templates/layout/app.html.eex

@@ -27,4 +27,5 @@
       <%= @inner_content %>
     </main>
   </body>
+
 </html>