From 3fa40136d80025197941e594a1f23a77ca5eec53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Rodrigues?= Date: Tue, 4 Jul 2023 15:10:40 +0100 Subject: [PATCH 1/3] Add Contributing.md --- CONTRIBUTING.md | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..6227ba921 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,108 @@ +[asdf-vm]: https://asdf-vm.com/ + +# 🚀 Getting Started + +These instructions will get you a copy of the project up and running on your +local machine for development and testing purposes. + +## 📥 Prerequisites + +The following software is required to be installed on your system: + +- [Erlang 25+](https://www.erlang.org/downloads) +- [Elixir 1.14+](https://elixir-lang.org/install.html) +- [PostgreSQL 13+](https://www.postgresql.org/download/)(^See [this section](#-docker) for setting up with docker.) + +We recommend using [asdf version manager][asdf-vm] to install and manage all +the programming languages' requirements. + +If you prefer to use docker, see the [section below](#-docker). + +## 🔧 Setup + +First, clone the repository: + +``` +git clone git@github.com:cesium/atomic.git +cd atomic +``` + +Then, run the setup script to get all dependencies configured. Make sure the database is up and running. + +``` +bin/setup +``` + +Then you should change the `.env.dev` file as needed. Run this script again if +needed. + +## 🔨 Development + +Start the development server and then you can visit `http://localhost:4000` +from your browser. + +``` +bin/server +``` + +Run the tests. + +``` +bin/test +``` + +Lint your code. + +``` +bin/lint +``` + +Format your code. + +``` +bin/format +``` + +## 🐳 Docker + +For data persistence this project uses a PostgreSQL database. You should have +PostgreSQL up and running. + +If you want to setup the required database using docker containers you can +easily do it with [docker-compose](https://docs.docker.com/compose/install/). + +Create and start the database containers. + +``` +cp .env.dev.sample .env.dev +docker-compose -f docker-compose.dev.yml -f {linux,darwin}.yml up db +``` + +Start the previously created containers. + +``` +docker-compose -f docker-compose.dev.yml -f {linux,darwin}.yml start +``` + +Stop the containers. + +``` +docker-compose -f docker-compose.dev.yml -f {linux,darwin}.yml stop +``` + +Destroy the containers and volumes created. + +``` +docker-compose -f docker-compose.dev.yml -f {linux,darwin}.yml down -v +``` + +## 🔗 References + +You can use these resources to learn more about the technologies this project +uses. + +- [Getting Started with Elixir](https://elixir-lang.org/getting-started/introduction.html) +- [Erlang/Elixir Syntax: A Crash Course](https://elixir-lang.org/crash-course.html) +- [Elixir School Course](https://elixirschool.com/en/) +- [Phoenix Guides Overview](https://hexdocs.pm/phoenix/overview.html) +- [Phoenix Documentation](https://hexdocs.pm/phoenix) From 811f5e2fbac1954e0c1095ddd442fb48f7a51be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Rodrigues?= <93675410+MarioRodrigues10@users.noreply.github.com> Date: Sun, 9 Jul 2023 01:45:17 +0100 Subject: [PATCH 2/3] Fix departments creation (#286) --- lib/atomic_web/live/department_live/form_component.ex | 3 +++ lib/atomic_web/live/department_live/index.ex | 9 ++++++--- lib/atomic_web/live/department_live/index.html.heex | 10 +++++----- lib/atomic_web/live/department_live/show.ex | 4 +++- lib/atomic_web/live/department_live/show.html.heex | 8 ++++---- lib/atomic_web/live/organization_live/index.html.heex | 2 +- lib/atomic_web/live/organization_live/show.html.heex | 2 +- lib/atomic_web/router.ex | 10 +++++----- lib/atomic_web/templates/layout/root.html.heex | 1 - 9 files changed, 28 insertions(+), 21 deletions(-) diff --git a/lib/atomic_web/live/department_live/form_component.ex b/lib/atomic_web/live/department_live/form_component.ex index 9724b22f4..732fccdf4 100644 --- a/lib/atomic_web/live/department_live/form_component.ex +++ b/lib/atomic_web/live/department_live/form_component.ex @@ -41,6 +41,9 @@ defmodule AtomicWeb.DepartmentLive.FormComponent do end defp save_department(socket, :new, department_params) do + department_params = + Map.put(department_params, "organization_id", socket.assigns.organization.id) + case Departments.create_department(department_params) do {:ok, _department} -> {:noreply, diff --git a/lib/atomic_web/live/department_live/index.ex b/lib/atomic_web/live/department_live/index.ex index 448207478..c95dcbdaf 100644 --- a/lib/atomic_web/live/department_live/index.ex +++ b/lib/atomic_web/live/department_live/index.ex @@ -3,6 +3,7 @@ defmodule AtomicWeb.DepartmentLive.Index do alias Atomic.Departments alias Atomic.Departments.Department + alias Atomic.Organizations @impl true def mount(_params, _session, socket) do @@ -10,7 +11,7 @@ defmodule AtomicWeb.DepartmentLive.Index do end @impl true - def handle_params(params, _url, socket) do + def handle_params(%{"org" => _id} = params, _url, socket) do {:noreply, apply_action(socket, socket.assigns.live_action, params)} end @@ -20,15 +21,17 @@ defmodule AtomicWeb.DepartmentLive.Index do |> assign(:department, Departments.get_department!(id)) end - defp apply_action(socket, :new, _params) do + defp apply_action(socket, :new, %{"org" => id}) do socket |> assign(:page_title, "New Department") + |> assign(:organization, Organizations.get_organization!(id)) |> assign(:department, %Department{}) end - defp apply_action(socket, :index, _params) do + defp apply_action(socket, :index, %{"org" => id}) do socket |> assign(:page_title, "Listing Departments") + |> assign(:organization, Organizations.get_organization!(id)) |> assign(:department, nil) end diff --git a/lib/atomic_web/live/department_live/index.html.heex b/lib/atomic_web/live/department_live/index.html.heex index 475faa969..abc44402d 100644 --- a/lib/atomic_web/live/department_live/index.html.heex +++ b/lib/atomic_web/live/department_live/index.html.heex @@ -1,8 +1,8 @@

Listing Departments

<%= if @live_action in [:new, :edit] do %> - <.modal return_to={Routes.department_index_path(@socket, :index)}> - <.live_component module={AtomicWeb.DepartmentLive.FormComponent} id={@department.id || :new} title={@page_title} action={@live_action} department={@department} return_to={Routes.department_index_path(@socket, :index)} /> + <.modal return_to={Routes.department_index_path(@socket, :index, @organization)}> + <.live_component module={AtomicWeb.DepartmentLive.FormComponent} organization={@organization} id={@department.id || :new} title={@page_title} action={@live_action} department={@department} return_to={Routes.department_index_path(@socket, :index, @organization)} /> <% end %> @@ -20,8 +20,8 @@ <%= department.name %> - <%= live_redirect("Show", to: Routes.department_show_path(@socket, :show, department)) %> - <%= live_patch("Edit", to: Routes.department_index_path(@socket, :edit, department)) %> + <%= live_redirect("Show", to: Routes.department_show_path(@socket, :show, department.organization_id, department)) %> + <%= live_patch("Edit", to: Routes.department_index_path(@socket, :edit, department.organization_id, department)) %> <%= link("Delete", to: "#", phx_click: "delete", phx_value_id: department.id, data: [confirm: "Are you sure?"]) %> @@ -29,4 +29,4 @@ -<%= live_patch("New Department", to: Routes.department_index_path(@socket, :new)) %> +<%= live_patch("New Department", to: Routes.department_index_path(@socket, :new, @organization)) %> diff --git a/lib/atomic_web/live/department_live/show.ex b/lib/atomic_web/live/department_live/show.ex index 632373aa3..e8ff68123 100644 --- a/lib/atomic_web/live/department_live/show.ex +++ b/lib/atomic_web/live/department_live/show.ex @@ -2,6 +2,7 @@ defmodule AtomicWeb.DepartmentLive.Show do use AtomicWeb, :live_view alias Atomic.Departments + alias Atomic.Organizations @impl true def mount(_params, _session, socket) do @@ -9,10 +10,11 @@ defmodule AtomicWeb.DepartmentLive.Show do end @impl true - def handle_params(%{"id" => id}, _, socket) do + def handle_params(%{"org" => org, "id" => id}, _, socket) do {:noreply, socket |> assign(:page_title, page_title(socket.assigns.live_action)) + |> assign(:organization, Organizations.get_organization!(org)) |> assign(:department, Departments.get_department!(id, preloads: :activities))} end diff --git a/lib/atomic_web/live/department_live/show.html.heex b/lib/atomic_web/live/department_live/show.html.heex index 43b0aba44..430a0c233 100644 --- a/lib/atomic_web/live/department_live/show.html.heex +++ b/lib/atomic_web/live/department_live/show.html.heex @@ -1,8 +1,8 @@

Show Department

<%= if @live_action in [:edit] do %> - <.modal return_to={Routes.department_show_path(@socket, :show, @department)}> - <.live_component module={AtomicWeb.DepartmentLive.FormComponent} id={@department.id} title={@page_title} action={@live_action} department={@department} return_to={Routes.department_show_path(@socket, :show, @department)} /> + <.modal return_to={Routes.department_show_path(@socket, :show, @organization, @department)}> + <.live_component module={AtomicWeb.DepartmentLive.FormComponent} id={@department.id} title={@page_title} action={@live_action} department={@department} return_to={Routes.department_show_path(@socket, :show, @organization, @department)} /> <% end %> @@ -24,5 +24,5 @@ -<%= live_patch("Edit", to: Routes.department_show_path(@socket, :edit, @department), class: "button") %> | -<%= live_redirect("Back", to: Routes.department_index_path(@socket, :index)) %> +<%= live_patch("Edit", to: Routes.department_show_path(@socket, :edit, @organization, @department), class: "button") %> | +<%= live_redirect("Back", to: Routes.department_index_path(@socket, :index, @organization)) %> diff --git a/lib/atomic_web/live/organization_live/index.html.heex b/lib/atomic_web/live/organization_live/index.html.heex index 7275bac90..7f68e2ac1 100644 --- a/lib/atomic_web/live/organization_live/index.html.heex +++ b/lib/atomic_web/live/organization_live/index.html.heex @@ -2,7 +2,7 @@ <%= if @live_action in [:new, :edit] do %> <.modal return_to={Routes.organization_index_path(@socket, :index)}> - <.live_component module={AtomicWeb.OrganizationLive.FormComponent} id={@organization.id || :new} title={@page_title} action={@live_action} organization={@organization} return_to={Routes.organization_index_path(@socket, :index)} /> + <.live_component module={AtomicWeb.OrganizationLive.FormComponent} id={@organization || :new} title={@page_title} action={@live_action} organization={@organization} return_to={Routes.organization_index_path(@socket, :index)} /> <% end %> diff --git a/lib/atomic_web/live/organization_live/show.html.heex b/lib/atomic_web/live/organization_live/show.html.heex index bbdf72df0..f1f16830d 100644 --- a/lib/atomic_web/live/organization_live/show.html.heex +++ b/lib/atomic_web/live/organization_live/show.html.heex @@ -2,7 +2,7 @@ <%= if @live_action in [:edit] do %> <.modal return_to={Routes.organization_show_path(@socket, :show, @organization)}> - <.live_component module={AtomicWeb.OrganizationLive.FormComponent} id={@organization.id} title={@page_title} action={@live_action} organization={@organization} return_to={Routes.organization_show_path(@socket, :show, @organization)} /> + <.live_component module={AtomicWeb.OrganizationLive.FormComponent} id={@organization} title={@page_title} action={@live_action} organization={@organization} return_to={Routes.organization_show_path(@socket, :show, @organization)} /> <% end %> diff --git a/lib/atomic_web/router.ex b/lib/atomic_web/router.ex index 2885a0993..5313a2eb0 100644 --- a/lib/atomic_web/router.ex +++ b/lib/atomic_web/router.ex @@ -34,11 +34,11 @@ defmodule AtomicWeb.Router do live "/activities/:id/edit", ActivityLive.Edit, :edit live "/activities/:id", ActivityLive.Show, :show - live "/departments", DepartmentLive.Index, :index - live "/departments/new", DepartmentLive.Index, :new - live "/departments/:id/edit", DepartmentLive.Index, :edit - live "/departments/:id", DepartmentLive.Show, :show - live "/departments/:id/show/edit", DepartmentLive.Show, :edit + live "/departments/:org", DepartmentLive.Index, :index + live "/departments/:org/new", DepartmentLive.Index, :new + live "/departments/:org/:id/edit", DepartmentLive.Index, :edit + live "/departments/:org/:id", DepartmentLive.Show, :show + live "/departments/:org/:id/show/edit", DepartmentLive.Show, :edit live "/partners", PartnerLive.Index, :index live "/partners/new", PartnerLive.Index, :new diff --git a/lib/atomic_web/templates/layout/root.html.heex b/lib/atomic_web/templates/layout/root.html.heex index 6c32d70ed..c03c73b66 100644 --- a/lib/atomic_web/templates/layout/root.html.heex +++ b/lib/atomic_web/templates/layout/root.html.heex @@ -16,7 +16,6 @@