Skip to content

Commit

Permalink
Merge branch 'main' into fix/improve-navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
douglastofoli authored Mar 18, 2024
2 parents 1e04d99 + e544d17 commit 3b0bb2f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 44 deletions.
13 changes: 12 additions & 1 deletion assets/css/pages/app/researcher/relatorio/report.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
}

>form {
@apply flex flex-col;
gap: 1.5rem;

.buttons-wrapper {
display: flex;
margin-bottom: 2rem;
Expand All @@ -19,6 +22,15 @@
}
}

.input-date-group {
@apply flex;
gap: 1.5rem;

.input-date {
@apply flex flex-col;
gap: 1.5rem;
}
}

.report-field {
height: max-content;
Expand All @@ -32,7 +44,6 @@
width: 100%;
min-height: 12rem;
}

}
}
}
5 changes: 5 additions & 0 deletions lib/pescarte/modulo_pesquisa/repository.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ defmodule Pescarte.ModuloPesquisa.Repository do
Repo.replica().get_by(RelatorioPesquisa, id_publico: id_publico)
end

@implt true
def fetch_relatorio_pesquisa_by_id_and_kind(id_publico, kind) do
Repo.replica().get_by(RelatorioPesquisa, id_publico: id_publico, tipo: kind)
end

@impl true
def list_tag do
Repo.replica().all(Tag)
Expand Down
18 changes: 12 additions & 6 deletions lib/pescarte_web/live/pesquisa/relatorio_live/form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ defmodule PescarteWeb.Pesquisa.RelatorioLive.FormComponent do
<.form for={@form} id="report-form" phx-target={@myself} phx-change="validate" phx-submit="save">
<div class="input-date-group" style="display: flex;">
<.text_input type="date" label="Início período" field={@form[:data_inicio]} />
<.text_input type="date" label="Fim periodo" field={@form[:data_fim]} />
<div class="input-date">
<.text size="h3" color="text-blue-100">Início período</.text>
<.text_input type="date" field={@form[:data_inicio]} />
</div>
<div class="input-date">
<.text size="h3" color="text-blue-100">Fim período</.text>
<.text_input type="date" field={@form[:data_fim]} />
</div>
</div>
<.inputs_for :let={f} field={@form[@conteudo]}>
Expand All @@ -31,7 +37,7 @@ defmodule PescarteWeb.Pesquisa.RelatorioLive.FormComponent do
/>
</.inputs_for>
<.text_input type="hidden" field={@form[:tipo]} value={@type} />
<.text_input type="hidden" field={@form[:tipo]} value={@tipo} />
<.text_input type="hidden" field={@form[:pesquisador_id]} value={@pesquisador_id} />
<.text_input type="hidden" field={@form[:status]} value="pendente" />
Expand Down Expand Up @@ -138,7 +144,7 @@ defmodule PescarteWeb.Pesquisa.RelatorioLive.FormComponent do
assign(socket, :form, to_form(changeset))
end

defp assign_form_data(socket, %{type: "mensal"}) do
defp assign_form_data(socket, %{tipo: "mensal"}) do
today = get_formatted_today(Date.utc_today())

socket
Expand All @@ -150,7 +156,7 @@ defmodule PescarteWeb.Pesquisa.RelatorioLive.FormComponent do
|> assign(:fields, get_report_fields(:mensal))
end

defp assign_form_data(socket, %{type: "trimestral"}) do
defp assign_form_data(socket, %{tipo: "trimestral"}) do
today = get_formatted_today(Date.utc_today())

socket
Expand All @@ -162,7 +168,7 @@ defmodule PescarteWeb.Pesquisa.RelatorioLive.FormComponent do
|> assign(:fields, get_report_fields(:trimestral))
end

defp assign_form_data(socket, %{type: "anual"}) do
defp assign_form_data(socket, %{tipo: "anual"}) do
today = get_formatted_today(Date.utc_today())

socket
Expand Down
62 changes: 31 additions & 31 deletions lib/pescarte_web/live/pesquisa/relatorio_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,39 @@ defmodule PescarteWeb.Pesquisa.RelatorioLive.Index do
end

@impl true
def handle_event("mensal_report", _, socket) do
pesquisador_id = socket.assigns.current_researcher.id_publico

{:noreply,
socket
|> assign(:type, "mensal")
|> assign(:pesquisador_id, pesquisador_id)
|> push_patch(to: ~p"/app/pesquisa/relatorios/new")}
def handle_event("relatorio_mensal", _, socket) do
{:noreply, push_patch(socket, to: ~p"/app/pesquisa/relatorios/novo/mensal")}
end

def handle_event("trimestral_report", _, socket) do
pesquisador_id = socket.assigns.current_researcher.id_publico

{:noreply,
socket
|> assign(:type, "trimestral")
|> assign(:pesquisador_id, pesquisador_id)
|> push_patch(to: ~p"/app/pesquisa/relatorios/new")}
def handle_event("relatorio_trimestral", _, socket) do
{:noreply, push_patch(socket, to: ~p"/app/pesquisa/relatorios/novo/trimestral")}
end

def handle_event("anual_report", _, socket) do
pesquisador_id = socket.assigns.current_researcher.id_publico
def handle_event("relatorio_anual", _, socket) do
{:noreply, push_patch(socket, to: ~p"/app/pesquisa/relatorios/novo/anual")}
end

{:noreply,
socket
|> assign(:type, "anual")
|> assign(:pesquisador_id, pesquisador_id)
|> push_patch(to: ~p"/app/pesquisa/relatorios/new")}
@impl true
def handle_info({FormComponent, {:saved, relatorio}}, socket) do
{:noreply, stream_insert(socket, :relatorios, relatorio)}
end

defp apply_action(socket, :edit, %{"id" => id}) do
socket
|> assign(:page_title, "Editar Relatório")
|> assign(:relatorio, Repository.fetch_relatorio_pesquisa_by_id(id))
defp apply_action(socket, :edit, %{"id" => id, "tipo" => tipo_relatorio}) do
case Repository.fetch_relatorio_pesquisa_by_id_and_kind(id, tipo_relatorio) do
nil ->
redirect_to_report_listing(socket)

relatorio ->
assign_report_to_form(socket, relatorio, tipo_relatorio)
end
end

defp apply_action(socket, :new, _params) do
defp apply_action(socket, :new, %{"tipo" => tipo_relatorio}) do
socket
|> assign(:page_title, "Novo Relatório")
|> assign(:relatorio, %RelatorioPesquisa{})
|> assign(:tipo, tipo_relatorio)
|> assign(:pesquisador_id, socket.assigns.current_researcher.id_publico)
end

defp apply_action(socket, :index, _params) do
Expand All @@ -67,8 +60,15 @@ defmodule PescarteWeb.Pesquisa.RelatorioLive.Index do
|> assign(:relatorio, nil)
end

@impl true
def handle_info({FormComponent, {:saved, relatorio}}, socket) do
{:noreply, stream_insert(socket, :relatorios, relatorio)}
defp redirect_to_report_listing(socket) do
push_patch(socket, to: ~p"/app/pesquisa/relatorios")
end

defp assign_report_to_form(socket, relatorio, tipo_relatorio) do
socket
|> assign(:page_title, "Editar Relatório")
|> assign(:relatorio, relatorio)
|> assign(:tipo, tipo_relatorio)
|> assign(:pesquisador_id, socket.assigns.current_researcher.id_publico)
end
end
8 changes: 4 additions & 4 deletions lib/pescarte_web/live/pesquisa/relatorio_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<Lucideicons.chevron_down class="text-blue-100" />
</.button>
<div class="dropdown-options">
<.report_menu_link click="mensal_report" label="Mensal"></.report_menu_link>
<.report_menu_link click="trimestral_report" label="Trimestral"></.report_menu_link>
<.report_menu_link click="anual_report" label="Anual"></.report_menu_link>
<.report_menu_link click="relatorio_mensal" label="Mensal"></.report_menu_link>
<.report_menu_link click="relatorio_trimestral" label="Trimestral"></.report_menu_link>
<.report_menu_link click="relatorio_anual" label="Anual"></.report_menu_link>
</div>
</div>

Expand Down Expand Up @@ -49,7 +49,7 @@
title={@page_title}
action={@live_action}
relatorio={@relatorio}
type={@type}
tipo={@tipo}
pesquisador_id={@pesquisador_id}
patch={~p"/app/pesquisa/relatorios"}
/>
4 changes: 2 additions & 2 deletions lib/pescarte_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ defmodule PescarteWeb.Router do

scope "/relatorios" do
live("/", RelatorioLive.Index, :index)
live("/new", RelatorioLive.Index, :new)
live("/:id/edit", RelatorioLive.Index, :edit)
live("/novo/:tipo", RelatorioLive.Index, :new)
live("/:id/editar/:tipo", RelatorioLive.Index, :edit)
end
end
end
Expand Down

0 comments on commit 3b0bb2f

Please sign in to comment.