alright, that's it
This commit is contained in:
parent
a25698347d
commit
794a2c1bf3
8 changed files with 76 additions and 35 deletions
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
],
|
||||
theme: {},
|
||||
daisyui: {
|
||||
themes: ["cupcake"]
|
||||
themes: ["dracula"]
|
||||
},
|
||||
plugins: [
|
||||
require("daisyui"),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ import Config
|
|||
config :ezcontainer_railway, EzcontainerRailwayWeb.Endpoint,
|
||||
cache_static_manifest: "priv/static/cache_manifest.json"
|
||||
|
||||
# Configure your database
|
||||
config :ezcontainer_railway, EzcontainerRailway.Repo,
|
||||
database: "./db/db_prod.sqlite3"
|
||||
|
||||
# Configures Swoosh API Client
|
||||
config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: EzcontainerRailway.Finch
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<!-- App Logo/Name -->
|
||||
<div class="flex items-center text-lg font-extrabold text-base-content">
|
||||
<a href="#" class="hover:underline">
|
||||
Your App Name
|
||||
EzContainer
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
<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>
|
||||
<a class="btn btn-ghost btn-sm rounded-btn" href="/logout">Logout</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
>
|
||||
<label class="label">
|
||||
<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>
|
||||
<a href="https://railway.app/account/tokens" target="_blank" rel="noopener noreferrer" class="label-text-alt underline">Get it here</a>
|
||||
</label>
|
||||
|
||||
<input class="input input-bordered" name="railway_token" />
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@ defmodule EzcontainerRailwayWeb.SessionController do
|
|||
alias EzcontainerRailway.Railway
|
||||
use EzcontainerRailwayWeb, :controller
|
||||
|
||||
def logout(conn, _) do
|
||||
conn
|
||||
|> clear_session()
|
||||
|> redirect(to: "/")
|
||||
end
|
||||
|
||||
def token(conn, %{"railway_token" => token}) do
|
||||
case get_projects(token) do
|
||||
resp when is_list(resp) ->
|
||||
|
|
|
|||
|
|
@ -7,41 +7,46 @@ defmodule EzcontainerRailwayWeb.ContainerCreateLive do
|
|||
def render(assigns) do
|
||||
~H"""
|
||||
<div class="flex space-around w-full">
|
||||
<article>
|
||||
<%= if @target == "container" do %>
|
||||
<article class="m-auto">
|
||||
<%= if @target == "image" 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">
|
||||
<label class="label flex space-between">
|
||||
<span class="label-text">Container Name</span>
|
||||
</label>
|
||||
<input class="input input-bordered inline col-span-3" name="name" />
|
||||
<label class="label flex space-between">
|
||||
<span class="label-text-alt">Tag</span>
|
||||
</label>
|
||||
<input class="input input-bordered inline" name="tag" />
|
||||
</div>
|
||||
<div class="text-center mt-6">
|
||||
<button phx-submit class="btn btn-primary">CREATE</button>
|
||||
<button phx-submit class={"btn btn-primary #{if @loading, do: "loading-dots"}"}>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">
|
||||
<label class="label flex space-between">
|
||||
<span class="label-text">Repo</span>
|
||||
</label>
|
||||
<input class="input input-bordered inline col-span-3" name="name" />
|
||||
<label class="label flex space-between">
|
||||
<span class="label-text-alt">Branch</span>
|
||||
</label>
|
||||
<input class="input input-bordered inline" name="tag" />
|
||||
</div>
|
||||
<div class="text-center mt-6">
|
||||
<button phx-submit class="btn btn-primary">CREATE</button>
|
||||
<button phx-submit class={"btn btn-primary #{if @loading, do: "loading-spinner"}"}>CREATE</button>
|
||||
</div>
|
||||
<input type="hidden" name="target" value="repo" />
|
||||
</.form>
|
||||
<% end %>
|
||||
<div class="flex w-full mt-5 space-around">
|
||||
<button class="m-auto btn btn-secondary" phx-click="switch_target">Switch to <%= if @target == "repo", do: "Image", else: "Repo" %></button>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
"""
|
||||
|
|
@ -50,10 +55,10 @@ defmodule EzcontainerRailwayWeb.ContainerCreateLive do
|
|||
def mount(_params, session, socket) do
|
||||
form = Component.to_form(%{"name" => "", "tag" => ""})
|
||||
|
||||
{:ok, socket |> assign(form: form, target: "container", session: session)}
|
||||
{:ok, socket |> assign(form: form, target: "image", session: session, loading: false)}
|
||||
end
|
||||
|
||||
def handle_event("create_container", data, socket) do
|
||||
def handle_info({:create, data}, socket) do
|
||||
{:ok, resp} = Railway.create_service(
|
||||
data["name"],
|
||||
"image",
|
||||
|
|
@ -62,4 +67,17 @@ defmodule EzcontainerRailwayWeb.ContainerCreateLive do
|
|||
|
||||
{:noreply, socket |> put_flash(:info, "container deplying") |> push_redirect(to: "/containers")}
|
||||
end
|
||||
|
||||
def handle_event("create_container", data, socket) do
|
||||
send(self(), {:create, data})
|
||||
{:noreply, socket |> assign(loading: true)}
|
||||
end
|
||||
|
||||
def handle_event("switch_target", _, socket) do
|
||||
IO.inspect socket.assigns
|
||||
case socket.assigns.target do
|
||||
"repo" -> {:noreply, socket |> assign(target: "image")}
|
||||
"image" -> {:noreply, socket |> assign(target: "repo")}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,38 +6,50 @@ defmodule EzcontainerRailwayWeb.ContainersLive do
|
|||
def render(assigns) do
|
||||
~H"""
|
||||
<div class="grid grid-cols-4 gap-2 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 phx-click="delete" phx-value-project_id={service["id"]} class="btn btn-xs btn-secondary">Delete</button>
|
||||
</div>
|
||||
<%= 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 phx-click="delete" phx-value-project_id={service["id"]} class={"btn btn-xs btn-secondary #{if @loading, do: "loading-dots"}"}><%= if not @loading do %> DELETE <% end %></button>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def mount(_params, session, socket) do
|
||||
{:ok, services} = Railway.get_services(session["railway_token"])
|
||||
IO.inspect services
|
||||
|
||||
{:ok, socket |> assign(session: session, services: services)}
|
||||
socket = socket |> assign(session: session, services: services, loading: false)
|
||||
|
||||
case length(services) do
|
||||
0 -> {:ok, socket |> put_flash(:error, "No running containers") |> push_navigate(to: "/containers/create")}
|
||||
_ -> {:ok, socket |> assign(session: session, services: services, loading: false)}
|
||||
end
|
||||
end
|
||||
|
||||
def handle_info(:refresh, socket) do
|
||||
{:ok, services} = Railway.get_services(socket.assigns.session["railway_token"])
|
||||
|
||||
{:noreply, socket |> assign(services: services)}
|
||||
case length(services) do
|
||||
0 -> {:noreply, socket |> put_flash(:error, "No running containers") |> push_navigate(to: "/containers/create")}
|
||||
_ -> {:noreply, socket |> assign(services: services, loading: false)}
|
||||
end
|
||||
end
|
||||
|
||||
def handle_event("delete", data, socket) do
|
||||
{:ok, services} = Railway.delete_container(data["project_id"], socket.assigns.session["railway_token"])
|
||||
|
||||
def handle_info({:delete, project_id}, socket) do
|
||||
{:ok, _} = Railway.delete_container(project_id, socket.assigns.session["railway_token"])
|
||||
send(self(), :refresh)
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
def handle_event("delete", data, socket) do
|
||||
send(self(), {:delete, data["project_id"]})
|
||||
|
||||
{:noreply, socket |> assign(loading: true)}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ defmodule EzcontainerRailwayWeb.Router do
|
|||
|
||||
live "/containers/create", ContainerCreateLive
|
||||
live "/containers", ContainersLive
|
||||
get "/logout", SessionController, :logout
|
||||
resources("/containers", ContainerController, only: [:create, :show])
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue