65 lines
2.3 KiB
Elixir
65 lines
2.3 KiB
Elixir
defmodule EzcontainerRailwayWeb.ContainerCreateLive do
|
|
alias EzcontainerRailway.Railway
|
|
alias Phoenix.Component
|
|
use Phoenix.LiveView
|
|
use EzcontainerRailwayWeb, :live_view
|
|
|
|
def render(assigns) do
|
|
~H"""
|
|
<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="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(%{"name" => "", "tag" => ""})
|
|
|
|
{: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
|