Skip to content

Commit

Permalink
Restore basic Admin edit functionality
Browse files Browse the repository at this point in the history
HTML report may remain broken, but it renders and the sockets
also work again due to me patching in the meta tage again.

Hope I didn't break anything, pls review ;)
  • Loading branch information
PragTob committed Sep 22, 2024
1 parent c02a2f8 commit f2c64f8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
6 changes: 4 additions & 2 deletions lib/mindwendel_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,13 @@ defmodule MindwendelWeb.CoreComponents do
multiple pattern placeholder readonly required rows size step)

def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
errors = if Phoenix.Component.used_input?(field), do: field.errors, else: []
# @jannik: According to my information this is a 1.0 feature that we're far removed from
# https://www.elixirstreams.com/tips/liveview-used-input
# errors = if Phoenix.Component.used_input?(field), do: field.errors, else: []

assigns
|> assign(field: nil, id: assigns.id || field.id)
|> assign(:errors, Enum.map(errors, &translate_error(&1)))
|> assign(:errors, Enum.map(field.errors, &translate_error(&1)))
|> assign_new(:name, fn -> if assigns.multiple, do: field.name <> "[]", else: field.name end)
|> assign_new(:value, fn -> field.value end)
|> input()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule MindwendelWeb.Admin.BrainstormingController do
)

"html" ->
# TODO: ** (ArgumentError) no "export" html template defined for MindwendelWeb.Admin.BrainstormingHTML (the module does not exist)
conn |> put_layout(false) |> put_root_layout(false) |> render("export.html", ideas: ideas)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mindwendel_web/live/admin/brainstorming_live/edit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule MindwendelWeb.Admin.BrainstormingLive.Edit do
:ok,
socket
|> assign(:brainstorming, brainstorming)
|> assign(:changeset, changeset)
|> assign(:form, to_form(changeset))
}
end

Expand Down
53 changes: 33 additions & 20 deletions lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@
<h4><%= gettext("Edit Brainstorming") %></h4>
</div>
<div class="card-body">
<.simple_form for={@changeset} phx_submit="save" phx_change="save" id="brainstorming-form">
<.simple_form for={@form} phx-submit="save" phx-change="save" id="brainstorming-form">
<.input field={@form[:name]} type="text" label="Name" />

<div class="form-check mb-3 position-relative">
<.input field={@form[:option_show_link_to_settings]} type="checkbox" id="checkbox-option-show-link-to-settings" label={gettext("Show brainstorming settings link for all users")} />
<.input
field={@form[:option_show_link_to_settings]}
type="checkbox"
id="checkbox-option-show-link-to-settings"
label={gettext("Show brainstorming settings link for all users")}
/>
<br />
<small class="form-text text-muted">
<%= gettext(
Expand All @@ -69,7 +74,12 @@
</small>
</div>
<div class="form-check mb-3 position-relative">
<.input field={@form[:option_allow_manual_ordering]} type="checkbox" id="checkbox-allow-manual-ordering-settings" label={gettext("Allow users to change the order of ideas")} />
<.input
field={@form[:option_allow_manual_ordering]}
type="checkbox"
id="checkbox-allow-manual-ordering-settings"
label={gettext("Allow users to change the order of ideas")}
/>
</div>
</.simple_form>
</div>
Expand All @@ -80,17 +90,16 @@
<h4><%= gettext("Export") %></h4>
</div>
<div class="card-body">
<%= link(gettext("Export to CSV"),
to:
Routes.admin_brainstorming_path(@socket, :export, @brainstorming.admin_url_id,
_format: "csv"
),
class: "fw-bold"
) %><br />
<%= link(gettext("Export to HTML"),
to: Routes.admin_brainstorming_path(@socket, :export, @brainstorming.admin_url_id),
class: "fw-bold"
) %>
<.link
class="fw-bold"
href={~p"/admin/brainstormings/#{@brainstorming.admin_url_id}/export?#{[_format: "csv"]}"}
>
<%= gettext("Export to CSV") %>
</.link>
<br />
<.link class="fw-bold" href={~p"/admin/brainstormings/#{@brainstorming.admin_url_id}/export"}>
<%= gettext("Export to HTML") %>
</.link>
</div>
</div>

Expand Down Expand Up @@ -131,12 +140,16 @@
"Attention: This will delete the brainstorming with all belonging ideas and other associated records to it. This cant be undone"
) %>
</p>
<%= button(gettext("Delete"),
"data-confirm": gettext("Brainstorming delete are you sure"),
class: "btn btn-danger",
method: :delete,
to: Routes.admin_brainstorming_path(@socket, :delete, @brainstorming.admin_url_id)
) %>
<%!-- Tobi Todo: I wrapped this in a link but I think in general one should style links to look like buttons instead of using buttons iirc --%>
<.link
href={~p"/admin/brainstormings/#{@brainstorming.admin_url_id}"}
data-confirm={gettext("Brainstorming delete are you sure")}
method="delete"
>
<.button class="btn btn-danger">
<%= gettext("Delete") %>
</.button>
</.link>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/mindwendel_web/templates/layout/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
/>
<meta name="csrf-token" content={get_csrf_token()} />
<.live_title>
<%= assigns[:page_title] || "Mindwendel" %>
</.live_title>
Expand Down

0 comments on commit f2c64f8

Please sign in to comment.