Okay that's about everything

This commit is contained in:
benbot 2023-10-25 23:19:22 -04:00
parent 023ad47ae4
commit d094ff036f
19 changed files with 236 additions and 79 deletions

View file

@ -1,32 +1,27 @@
<header class="px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between border-b border-zinc-100 py-3 text-sm">
<div class="flex items-center gap-4">
<a href="/">
<img src={~p"/images/logo.svg"} width="36" />
</a>
<p class="bg-brand/5 text-brand rounded-full px-2 font-medium leading-6">
v<%= Application.spec(:phoenix, :vsn) %>
</p>
<%= live_flash(@flash, :error) %>
<%= live_flash(@flash, :info) %>
<body class="bg-base-300 font-sans leading-normal tracking-normal w-screen h-screen">
<!-- Navbar -->
<div class="bg-primary p-3">
<div class="container mx-auto flex items-center">
<!-- App Logo/Name -->
<div class="flex items-center text-lg font-extrabold text-base-content">
<a href="#" class="hover:underline">
Your App Name
</a>
</div>
<!-- Navigation links -->
<div class="flex ml-auto space-x-4">
<a class="btn btn-ghost btn-sm rounded-btn" href="/containers/create">Create Containers</a>
<a class="btn btn-ghost btn-sm rounded-btn" href="/containers">Show Containers</a>
<a class="btn btn-ghost btn-sm rounded-btn" href="#">Logout</a>
</div>
</div>
<div class="flex items-center gap-4 font-semibold leading-6 text-zinc-900">
<a href="https://twitter.com/elixirphoenix" class="hover:text-zinc-700">
@elixirphoenix
</a>
<a href="https://github.com/phoenixframework/phoenix" class="hover:text-zinc-700">
GitHub
</a>
<a
href="https://hexdocs.pm/phoenix/overview.html"
class="rounded-lg bg-zinc-100 px-2 py-1 hover:bg-zinc-200/80"
>
Get Started <span aria-hidden="true">&rarr;</span>
</a>
</div>
</div>
</header>
<main class="px-4 py-20 sm:px-6 lg:px-8">
<div class="mx-auto max-w-2xl">
<.flash_group flash={@flash} />
</div>
<!-- Content Body -->
<div class="container mx-auto mt-10">
<%= @inner_content %>
</div>
</main>
</div>
</body>

View file

@ -11,7 +11,5 @@
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
</script>
</head>
<body>
<%= @inner_content %>
</body>
<%= @inner_content %>
</html>

View file

@ -1 +0,0 @@
benbot@darch.125027:1698169376

View file

@ -1,13 +1,14 @@
defmodule EzcontainerRailwayWeb.ContainerController do
alias EzcontainerRailway.Railway
alias Phoenix.Component
use EzcontainerRailwayWeb, :controller
def index(conn, params) do
form = Component.to_form(%{"container_name" => "", "container_tag" => ""})
{:ok, services} = Railway.get_services(conn |> get_session(:railway_token))
conn
|> assign(:form, form)
|> render(:make_container, layout: false)
|> assign(:services, services)
|> render(:containers)
end
def create(conn, params) do

View file

@ -0,0 +1,13 @@
<.flash_group flash={@flash} />
<div class="grid grid-cols-3 m-10">
<%= for service <- @services do %>
<div class="card bg-base-100 shadow-xl">
<div class="card-body">
<h2 class="card-title"><%= service["name"] %></h2>
<div class="card-actions justify-start">
<button class="btn btn-xs btn-secondary">Delete</button>
</div>
</div>
</div>
<% end %>
</div>

View file

@ -1,5 +1,5 @@
<.flash_group flash={@flash} />
<dialog open class="modal">
<dialog open class="modal bg-base-300">
<article class="modal-box">
<.form
for={@form}
@ -8,13 +8,13 @@
action="/token"
>
<label class="label">
<span class="label-text">What is your name?</span>
<span class="label-text-alt">Top Right label</span>
<span class="label-text">Enter your railway token</span>
<a href="https://railway.app/account/tokens" class="label-text-alt underline">Get it here</a>
</label>
<input class="input input-bordered" name="railway_token" />
<div class="text-center mt-6">
<button class="btn">Test</button>
<button class="btn">Begin</button>
</div>
</.form>
</article>

View file

@ -1,39 +1,65 @@
defmodule EzcontainerRailwayWeb.ContainerCreateLive do
alias EzcontainerRailway.Railway
alias Phoenix.Component
use Phoenix.LiveView
use EzcontainerRailwayWeb, :live_view
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="flex space-around w-full">
<article>
<%= if @target == "container" do %>
<.form for={@form} phx-submit="create_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>
<div class="grid grid-rows-1 grid-cols-4 gap-4">
<input class="input input-bordered inline col-span-3" name="name" />
<input class="input input-bordered inline" name="tag" />
</div>
<div class="text-center mt-6">
<button phx-submit class="btn btn-primary">CREATE</button>
</div>
<input type="hidden" name="target" value="container" />
</.form>
<% end %>
<%= if @target == "repo" do %>
<.form for={@form} phx-submit="create_container">
<label class="label">
<span class="label-text">Github Repo</span>
<span class="label-text-alt mr-20">Branch</span>
</label>
<div class="grid grid-rows-1 grid-cols-4 gap-4">
<input class="input input-bordered inline col-span-3" name="name" />
<input class="input input-bordered inline" name="tag" />
</div>
<div class="text-center mt-6">
<button phx-submit class="btn btn-primary">CREATE</button>
</div>
<input type="hidden" name="target" value="repo" />
</.form>
<% end %>
</article>
</div>
"""
end
def mount(_params, _session, socket) do
form = Component.to_form(%{"container_name" => "", "contianer_tag" => ""})
def mount(_params, session, socket) do
form = Component.to_form(%{"name" => "", "tag" => ""})
{:ok, socket |> assign(:form, form)}
{:ok, socket |> assign(form: form, target: "container", session: session)}
end
def handle_event("create_container", data, socket) do
{:ok, resp} = Railway.create_service(
data["name"],
"image",
socket.assigns.session["railway_token"]
)
{:noreply, socket |> push_redirect('/containers')}
end
end

View file

@ -0,0 +1,19 @@
defmodule EzcontainerRailwayWeb.NoRailwayCheck do
alias EzcontainerRailway.Projects
alias Phoenix.Controller
import Plug.Conn
def init(default), do: default
def call(conn, _opts) do
case get_session(conn, :railway_token) do
nil ->
conn
_ ->
conn
|> Controller.put_flash(:info, "You have a railway token")
|> Controller.redirect(to: "/containers/create")
|> halt()
end
end
end

View file

@ -20,7 +20,7 @@ defmodule EzcontainerRailwayWeb.RailwayCheck do
end
conn
|> put_session(:project_id, p)
|> put_session(:project_id, p.id)
end
end
end

View file

@ -19,8 +19,13 @@ defmodule EzcontainerRailwayWeb.Router do
plug EzcontainerRailwayWeb.RailwayCheck
end
pipeline :ensure_no_token do
plug EzcontainerRailwayWeb.NoRailwayCheck
end
scope "/", EzcontainerRailwayWeb do
pipe_through :browser
pipe_through :ensure_no_token
get "/", PageController, :home
post "/token", SessionController, :token
@ -30,8 +35,8 @@ defmodule EzcontainerRailwayWeb.Router do
pipe_through :browser
pipe_through :ensure_token
live "/containers", ContainerCreateLive
resources("/containers", ContainerController, only: [:create, :show])
live "/containers/create", ContainerCreateLive
resources("/containers", ContainerController, only: [:index, :create, :show])
end
# Other scopes may use custom stacks.