more changes
This commit is contained in:
parent
beaf92f7c4
commit
a3a4af7965
18 changed files with 165 additions and 24 deletions
|
|
@ -1 +0,0 @@
|
|||
benbot@darch.125027:1698169376
|
||||
|
|
@ -11,7 +11,7 @@ defmodule EzcontainerRailwayWeb.ContainerController do
|
|||
end
|
||||
|
||||
def create(conn, params) do
|
||||
|
||||
conn
|
||||
end
|
||||
|
||||
def show(conn, params) do
|
||||
|
|
|
|||
|
|
@ -1,30 +1,29 @@
|
|||
defmodule EzcontainerRailwayWeb.SessionController do
|
||||
alias EzcontainerRailway.Railway
|
||||
use EzcontainerRailwayWeb, :controller
|
||||
|
||||
def token(conn, %{"railway_token" => token}) do
|
||||
case token_valid?(token) do
|
||||
true ->
|
||||
case get_projects(token) do
|
||||
resp when is_map(resp) ->
|
||||
IO.inspect(resp)
|
||||
conn
|
||||
|> put_session(:railway_token, token)
|
||||
|> assign(:railway_token, token)
|
||||
|> redirect(to: "/containers")
|
||||
false ->
|
||||
nil ->
|
||||
conn
|
||||
|> put_flash(:error, "Invalid Token")
|
||||
|> redirect(to: "/")
|
||||
end
|
||||
end
|
||||
|
||||
defp token_valid?(token) do
|
||||
defp get_projects(token) do
|
||||
resp = EzcontainerRailway.Railway.get_projects(token).body
|
||||
|
||||
if has_errors?(resp["errors"]) do
|
||||
false
|
||||
if Railway.has_errors?(resp) do
|
||||
nil
|
||||
else
|
||||
true
|
||||
resp["data"]
|
||||
end
|
||||
end
|
||||
|
||||
defp has_errors?([_|_]), do: true
|
||||
defp has_errors?(_), do: false
|
||||
end
|
||||
|
|
|
|||
39
lib/ezcontainer_railway_web/live/container_create_live.ex
Normal file
39
lib/ezcontainer_railway_web/live/container_create_live.ex
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
defmodule EzcontainerRailwayWeb.ContainerCreateLive do
|
||||
alias Phoenix.Component
|
||||
use Phoenix.LiveView
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<%= live_flash(@flash, :error) %>
|
||||
<%= live_flash(@flash, :info) %>
|
||||
<dialog open class="modal">
|
||||
<article class="modal-box">
|
||||
<.form
|
||||
for={@form}
|
||||
method="post"
|
||||
action="/container"
|
||||
>
|
||||
<label class="label">
|
||||
<span class="label-text">Container Name</span>
|
||||
<span class="label-text-alt mr-20">Tag</span>
|
||||
</label>
|
||||
|
||||
<div class="grid grid-rows-1 grid-cols-4 gap-4">
|
||||
<input class="input input-bordered inline col-span-3" name="container_name" />
|
||||
<input class="input input-bordered inline" name="container_tag" />
|
||||
</div>
|
||||
<div class="text-center mt-6">
|
||||
<button class="btn">Test</button>
|
||||
</div>
|
||||
</.form>
|
||||
</article>
|
||||
</dialog>
|
||||
"""
|
||||
end
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
form = Component.to_form(%{"container_name" => "", "contianer_tag" => ""})
|
||||
|
||||
{:ok, socket |> assign(:form, form)}
|
||||
end
|
||||
end
|
||||
|
|
@ -21,7 +21,8 @@ defmodule EzcontainerRailwayWeb.Router do
|
|||
get "/", PageController, :home
|
||||
post "/token", SessionController, :token
|
||||
|
||||
resources("/containers", ContainerController, only: [:index, :create, :show])
|
||||
live "/containers", ContainerCreateLive
|
||||
resources("/containers", ContainerController, only: [:create, :show])
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue