diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js index 956158f..a4d122b 100644 --- a/assets/tailwind.config.js +++ b/assets/tailwind.config.js @@ -11,12 +11,9 @@ module.exports = { "../lib/ezcontainer_railway_web.ex", "../lib/ezcontainer_railway_web/**/*.*ex" ], - theme: { - extend: { - colors: { - brand: "#FD4F00", - } - }, + theme: {}, + daisyui: { + themes: ["cupcake"] }, plugins: [ require("daisyui"), diff --git a/lib/ezcontainer_railway/railway.ex b/lib/ezcontainer_railway/railway.ex index 6b06fe5..57c6c32 100644 --- a/lib/ezcontainer_railway/railway.ex +++ b/lib/ezcontainer_railway/railway.ex @@ -1,4 +1,5 @@ defmodule EzcontainerRailway.Railway do + alias EzcontainerRailway.Projects alias EzcontainerRailway.GraphqlClient def get_projects(token) do resp = GraphqlClient.query( @@ -23,12 +24,89 @@ defmodule EzcontainerRailway.Railway do end end - def create_service(container, token) when is_map(container) do + def get_services(token) do + project_id = Projects.get_project_by_token(token).project_id + resp = GraphqlClient.query( + """ + query getServices($projectId: String!) { + project(id: $projectId) { + services { + edges { + node { + id + name + } + } + } + } + } + """, + token: token, + variables: %{ + projectId: project_id + } + ) |> format_response + + case resp do + {:error, _} -> resp + {:ok, data} -> + final = + data["project"]["services"]["edges"] + |> Enum.map(&(&1["node"])) + + {:ok, final} + end + end + + + def create_service(source, type, token) do + resp = case type do + "repo" -> create_service_from_repo(source, token) + "image" -> create_service_from_image(source, token) + end + + case resp do + {:error, _} -> resp + {:ok, data} -> {:ok, data["serviceCreate"]} + end + end + + defp create_service_from_image(source, token) do + project_id = Projects.get_project_by_token(token).project_id GraphqlClient.query( """ + mutation createService($projectId: String!, $image: String!, $name: String!){ + serviceCreate(input: {projectId: $projectId, name: $name source: { image: $image }}) { + id + } + } """, - variables: container - ) + token: token, + variables: %{ + projectId: project_id, + image: source, + name: source + } + ) |> format_response + end + + defp create_service_from_repo(source, token) do + project_id = Projects.get_project_by_token(token).project_id + GraphqlClient.query( + """ + mutation createService($projectId: String!, $repo: String!, $name: String!){ + serviceCreate(input: {projectId: $projectId, name: $name source: { repo: $repo }}) { + id + } + } + """, + token: token, + variables: %{ + projectId: project_id, + repo: source, + name: source + } + ) |> format_response end def create_project(token) do @@ -51,6 +129,21 @@ defmodule EzcontainerRailway.Railway do end end + def delete_container(token, service_id) do + GraphqlClient.query( + """ + mutation deleteContainer(id: String!) { + serviceDelete(id: $id) + } + """, + token: token, + variables: %{ + id: service_id + } + ) + |> format_response + end + def get_user_id(token) do {:ok, resp} = GraphqlClient.query( """ diff --git a/lib/ezcontainer_railway_web/components/layouts/app.html.heex b/lib/ezcontainer_railway_web/components/layouts/app.html.heex index e23bfc8..7e39456 100644 --- a/lib/ezcontainer_railway_web/components/layouts/app.html.heex +++ b/lib/ezcontainer_railway_web/components/layouts/app.html.heex @@ -1,32 +1,27 @@ -
-
-
- - - -

- v<%= Application.spec(:phoenix, :vsn) %> -

+<%= live_flash(@flash, :error) %> +<%= live_flash(@flash, :info) %> + + + -
-
-
- <.flash_group flash={@flash} /> +
+ + +
<%= @inner_content %> -
-
+ + diff --git a/lib/ezcontainer_railway_web/components/layouts/root.html.heex b/lib/ezcontainer_railway_web/components/layouts/root.html.heex index 865c0bf..f7a7706 100644 --- a/lib/ezcontainer_railway_web/components/layouts/root.html.heex +++ b/lib/ezcontainer_railway_web/components/layouts/root.html.heex @@ -11,7 +11,5 @@ - - <%= @inner_content %> - + <%= @inner_content %> diff --git a/lib/ezcontainer_railway_web/controllers/.#page_controller.ex b/lib/ezcontainer_railway_web/controllers/.#page_controller.ex deleted file mode 120000 index 7746d29..0000000 --- a/lib/ezcontainer_railway_web/controllers/.#page_controller.ex +++ /dev/null @@ -1 +0,0 @@ -benbot@darch.125027:1698169376 \ No newline at end of file diff --git a/lib/ezcontainer_railway_web/controllers/container_controller.ex b/lib/ezcontainer_railway_web/controllers/container_controller.ex index 732a7aa..fb3e687 100644 --- a/lib/ezcontainer_railway_web/controllers/container_controller.ex +++ b/lib/ezcontainer_railway_web/controllers/container_controller.ex @@ -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 diff --git a/lib/ezcontainer_railway_web/controllers/container_html/containers.html.heex b/lib/ezcontainer_railway_web/controllers/container_html/containers.html.heex new file mode 100644 index 0000000..6b9c4cd --- /dev/null +++ b/lib/ezcontainer_railway_web/controllers/container_html/containers.html.heex @@ -0,0 +1,13 @@ +<.flash_group flash={@flash} /> +
+ <%= for service <- @services do %> +
+
+

<%= service["name"] %>

+
+ +
+
+
+ <% end %> +
diff --git a/lib/ezcontainer_railway_web/controllers/page_html/home.html.heex b/lib/ezcontainer_railway_web/controllers/page_html/home.html.heex index 19179ba..fcb1768 100644 --- a/lib/ezcontainer_railway_web/controllers/page_html/home.html.heex +++ b/lib/ezcontainer_railway_web/controllers/page_html/home.html.heex @@ -1,5 +1,5 @@ <.flash_group flash={@flash} /> - + diff --git a/lib/ezcontainer_railway_web/live/container_create_live.ex b/lib/ezcontainer_railway_web/live/container_create_live.ex index 6d27e3d..d0f317c 100644 --- a/lib/ezcontainer_railway_web/live/container_create_live.ex +++ b/lib/ezcontainer_railway_web/live/container_create_live.ex @@ -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) %> - - +
+ + +
+
+ +
+ + + <% end %> + <%= if @target == "repo" do %> + <.form for={@form} phx-submit="create_container"> + + +
+ + +
+
+ +
+ + + <% end %> + + """ 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 diff --git a/lib/ezcontainer_railway_web/plugs/no_railway_check.ex b/lib/ezcontainer_railway_web/plugs/no_railway_check.ex new file mode 100644 index 0000000..64ae406 --- /dev/null +++ b/lib/ezcontainer_railway_web/plugs/no_railway_check.ex @@ -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 diff --git a/lib/ezcontainer_railway_web/plugs/railway_check.ex b/lib/ezcontainer_railway_web/plugs/railway_check.ex index 1b03a1f..99d60b2 100644 --- a/lib/ezcontainer_railway_web/plugs/railway_check.ex +++ b/lib/ezcontainer_railway_web/plugs/railway_check.ex @@ -20,7 +20,7 @@ defmodule EzcontainerRailwayWeb.RailwayCheck do end conn - |> put_session(:project_id, p) + |> put_session(:project_id, p.id) end end end diff --git a/lib/ezcontainer_railway_web/router.ex b/lib/ezcontainer_railway_web/router.ex index 2585ef7..bfbff2f 100644 --- a/lib/ezcontainer_railway_web/router.ex +++ b/lib/ezcontainer_railway_web/router.ex @@ -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. diff --git a/priv/static/favicon-a8ca4e3a2bb8fea46a9ee9e102e7d3eb.ico b/priv/static/favicon-a8ca4e3a2bb8fea46a9ee9e102e7d3eb.ico new file mode 100644 index 0000000..73de524 Binary files /dev/null and b/priv/static/favicon-a8ca4e3a2bb8fea46a9ee9e102e7d3eb.ico differ diff --git a/priv/static/images/logo-06a11be1f2cdde2c851763d00bdd2e80.svg b/priv/static/images/logo-06a11be1f2cdde2c851763d00bdd2e80.svg new file mode 100644 index 0000000..9f26bab --- /dev/null +++ b/priv/static/images/logo-06a11be1f2cdde2c851763d00bdd2e80.svg @@ -0,0 +1,6 @@ + diff --git a/priv/static/images/logo-06a11be1f2cdde2c851763d00bdd2e80.svg.gz b/priv/static/images/logo-06a11be1f2cdde2c851763d00bdd2e80.svg.gz new file mode 100644 index 0000000..1f3179c Binary files /dev/null and b/priv/static/images/logo-06a11be1f2cdde2c851763d00bdd2e80.svg.gz differ diff --git a/priv/static/images/logo.svg.gz b/priv/static/images/logo.svg.gz new file mode 100644 index 0000000..1f3179c Binary files /dev/null and b/priv/static/images/logo.svg.gz differ diff --git a/priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt b/priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt new file mode 100644 index 0000000..26e06b5 --- /dev/null +++ b/priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt @@ -0,0 +1,5 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt.gz b/priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt.gz new file mode 100644 index 0000000..043be33 Binary files /dev/null and b/priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt.gz differ diff --git a/priv/static/robots.txt.gz b/priv/static/robots.txt.gz new file mode 100644 index 0000000..043be33 Binary files /dev/null and b/priv/static/robots.txt.gz differ