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: {},
|
theme: {},
|
||||||
daisyui: {
|
daisyui: {
|
||||||
themes: ["cupcake"]
|
themes: ["dracula"]
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
require("daisyui"),
|
require("daisyui"),
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ import Config
|
||||||
config :ezcontainer_railway, EzcontainerRailwayWeb.Endpoint,
|
config :ezcontainer_railway, EzcontainerRailwayWeb.Endpoint,
|
||||||
cache_static_manifest: "priv/static/cache_manifest.json"
|
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
|
# Configures Swoosh API Client
|
||||||
config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: EzcontainerRailway.Finch
|
config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: EzcontainerRailway.Finch
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<!-- App Logo/Name -->
|
<!-- App Logo/Name -->
|
||||||
<div class="flex items-center text-lg font-extrabold text-base-content">
|
<div class="flex items-center text-lg font-extrabold text-base-content">
|
||||||
<a href="#" class="hover:underline">
|
<a href="#" class="hover:underline">
|
||||||
Your App Name
|
EzContainer
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<div class="flex ml-auto space-x-4">
|
<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/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="/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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
>
|
>
|
||||||
<label class="label">
|
<label class="label">
|
||||||
<span class="label-text">Enter your railway token</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>
|
<a href="https://railway.app/account/tokens" target="_blank" rel="noopener noreferrer" class="label-text-alt underline">Get it here</a>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<input class="input input-bordered" name="railway_token" />
|
<input class="input input-bordered" name="railway_token" />
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,12 @@ defmodule EzcontainerRailwayWeb.SessionController do
|
||||||
alias EzcontainerRailway.Railway
|
alias EzcontainerRailway.Railway
|
||||||
use EzcontainerRailwayWeb, :controller
|
use EzcontainerRailwayWeb, :controller
|
||||||
|
|
||||||
|
def logout(conn, _) do
|
||||||
|
conn
|
||||||
|
|> clear_session()
|
||||||
|
|> redirect(to: "/")
|
||||||
|
end
|
||||||
|
|
||||||
def token(conn, %{"railway_token" => token}) do
|
def token(conn, %{"railway_token" => token}) do
|
||||||
case get_projects(token) do
|
case get_projects(token) do
|
||||||
resp when is_list(resp) ->
|
resp when is_list(resp) ->
|
||||||
|
|
|
||||||
|
|
@ -7,41 +7,46 @@ defmodule EzcontainerRailwayWeb.ContainerCreateLive do
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<div class="flex space-around w-full">
|
<div class="flex space-around w-full">
|
||||||
<article>
|
<article class="m-auto">
|
||||||
<%= if @target == "container" do %>
|
<%= if @target == "image" do %>
|
||||||
<.form for={@form} phx-submit="create_container">
|
<.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">
|
<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" />
|
<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" />
|
<input class="input input-bordered inline" name="tag" />
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center mt-6">
|
<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>
|
</div>
|
||||||
<input type="hidden" name="target" value="container" />
|
<input type="hidden" name="target" value="container" />
|
||||||
</.form>
|
</.form>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= if @target == "repo" do %>
|
<%= if @target == "repo" do %>
|
||||||
<.form for={@form} phx-submit="create_container">
|
<.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">
|
<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" />
|
<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" />
|
<input class="input input-bordered inline" name="tag" />
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center mt-6">
|
<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>
|
</div>
|
||||||
<input type="hidden" name="target" value="repo" />
|
<input type="hidden" name="target" value="repo" />
|
||||||
</.form>
|
</.form>
|
||||||
<% end %>
|
<% 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>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
@ -50,10 +55,10 @@ defmodule EzcontainerRailwayWeb.ContainerCreateLive do
|
||||||
def mount(_params, session, socket) do
|
def mount(_params, session, socket) do
|
||||||
form = Component.to_form(%{"name" => "", "tag" => ""})
|
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
|
end
|
||||||
|
|
||||||
def handle_event("create_container", data, socket) do
|
def handle_info({:create, data}, socket) do
|
||||||
{:ok, resp} = Railway.create_service(
|
{:ok, resp} = Railway.create_service(
|
||||||
data["name"],
|
data["name"],
|
||||||
"image",
|
"image",
|
||||||
|
|
@ -62,4 +67,17 @@ defmodule EzcontainerRailwayWeb.ContainerCreateLive do
|
||||||
|
|
||||||
{:noreply, socket |> put_flash(:info, "container deplying") |> push_redirect(to: "/containers")}
|
{:noreply, socket |> put_flash(:info, "container deplying") |> push_redirect(to: "/containers")}
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ defmodule EzcontainerRailwayWeb.ContainersLive do
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h2 class="card-title"><%= service["name"] %></h2>
|
<h2 class="card-title"><%= service["name"] %></h2>
|
||||||
<div class="card-actions justify-start">
|
<div class="card-actions justify-start">
|
||||||
<button phx-click="delete" phx-value-project_id={service["id"]} class="btn btn-xs btn-secondary">Delete</button>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -22,22 +22,34 @@ defmodule EzcontainerRailwayWeb.ContainersLive do
|
||||||
|
|
||||||
def mount(_params, session, socket) do
|
def mount(_params, session, socket) do
|
||||||
{:ok, services} = Railway.get_services(session["railway_token"])
|
{: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
|
end
|
||||||
|
|
||||||
def handle_info(:refresh, socket) do
|
def handle_info(:refresh, socket) do
|
||||||
{:ok, services} = Railway.get_services(socket.assigns.session["railway_token"])
|
{: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
|
end
|
||||||
|
|
||||||
def handle_event("delete", data, socket) do
|
def handle_info({:delete, project_id}, socket) do
|
||||||
{:ok, services} = Railway.delete_container(data["project_id"], socket.assigns.session["railway_token"])
|
{:ok, _} = Railway.delete_container(project_id, socket.assigns.session["railway_token"])
|
||||||
|
|
||||||
send(self(), :refresh)
|
send(self(), :refresh)
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("delete", data, socket) do
|
||||||
|
send(self(), {:delete, data["project_id"]})
|
||||||
|
|
||||||
|
{:noreply, socket |> assign(loading: true)}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ defmodule EzcontainerRailwayWeb.Router do
|
||||||
|
|
||||||
live "/containers/create", ContainerCreateLive
|
live "/containers/create", ContainerCreateLive
|
||||||
live "/containers", ContainersLive
|
live "/containers", ContainersLive
|
||||||
|
get "/logout", SessionController, :logout
|
||||||
resources("/containers", ContainerController, only: [:create, :show])
|
resources("/containers", ContainerController, only: [:create, :show])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue