Skip to content

Commit

Permalink
feat: added pt-br translations to activity live view
Browse files Browse the repository at this point in the history
- fixed fkey constraints in delete changeset for `Activity` and `Strand` schemas
  • Loading branch information
endoooo committed Jan 29, 2024
1 parent d3ebe3f commit e538460
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 69 deletions.
5 changes: 3 additions & 2 deletions lib/lanttern/learning_context/activity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Lanttern.LearningContext.Activity do
use Ecto.Schema
import Ecto.Changeset

import LantternWeb.Gettext
import Lanttern.SchemaHelpers

schema "activities" do
Expand Down Expand Up @@ -37,8 +38,8 @@ defmodule Lanttern.LearningContext.Activity do
|> cast(%{}, [])
|> foreign_key_constraint(
:id,
name: :activities_assessment_points_activity_id_fkey,
message: "Activity has linked assessment points."
name: :assessment_points_activity_id_fkey,
message: gettext("Activity has linked assessment points.")
)
end
end
8 changes: 7 additions & 1 deletion lib/lanttern/learning_context/strand.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Lanttern.LearningContext.Strand do
use Ecto.Schema
import Ecto.Changeset

import LantternWeb.Gettext
import Lanttern.SchemaHelpers

schema "strands" do
Expand Down Expand Up @@ -43,7 +44,12 @@ defmodule Lanttern.LearningContext.Strand do
|> foreign_key_constraint(
:id,
name: :activities_strand_id_fkey,
message: "Strand has linked activities."
message: gettext("Strand has linked activities.")
)
|> foreign_key_constraint(
:id,
name: :assessment_points_strand_id_fkey,
message: gettext("Strand has linked assessment points.")
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ defmodule LantternWeb.ActivityLive do
) do
activity when is_nil(activity) ->
socket
|> put_flash(:error, "Couldn't find activity")
|> put_flash(:error, gettext("Couldn't find activity"))
|> redirect(to: ~p"/strands")

activity ->
Expand All @@ -95,15 +95,15 @@ defmodule LantternWeb.ActivityLive do
{:ok, _activity} ->
{:noreply,
socket
|> put_flash(:info, "Activity deleted")
|> put_flash(:info, gettext("Activity deleted"))
|> push_navigate(to: ~p"/strands/#{socket.assigns.activity.strand}?tab=activities")}

{:error, _changeset} ->
{:noreply,
socket
|> put_flash(
:error,
"Activity has linked assessments. Deleting it would cause some data loss."
gettext("Activity has linked assessments. Deleting it would cause some data loss.")
)}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<:top>
<div class="flex items-center justify-between">
<.breadcrumbs class="mt-2" item_class="text-white">
<:item link={~p"/strands"}>Strands</:item>
<:item link={~p"/strands/#{@activity.strand}"}>Details</:item>
<:item>Activity</:item>
<:item link={~p"/strands"}><%= gettext("Strands") %></:item>
<:item link={~p"/strands/#{@activity.strand}"}><%= gettext("Details") %></:item>
<:item><%= gettext("Activity") %></:item>
</.breadcrumbs>
<.nav_menu_button />
</div>
Expand All @@ -24,7 +24,9 @@
</div>
<h1 class="font-display font-black text-5xl"><%= @activity.name %></h1>
<div class="flex flex-wrap gap-2 mt-6">
<.badge :for={subject <- @activity.subjects} theme="dark"><%= subject.name %></.badge>
<.badge :for={subject <- @activity.subjects} theme="dark">
<%= Gettext.dgettext(LantternWeb.Gettext, "taxonomy", subject.name) %>
</.badge>
</div>
</.cover>
<div class="sticky top-0 z-30 border-b border-ltrn-lighter bg-white">
Expand All @@ -34,20 +36,20 @@
patch={~p"/strands/activity/#{@activity}?#{%{tab: "details"}}"}
is_current={@current_tab == :details && "true"}
>
Details & Curriculum
<%= gettext("Details & Curriculum") %>
</:tab>
<:tab
patch={~p"/strands/activity/#{@activity}?#{%{tab: "assessment"}}"}
is_current={@current_tab == :assessment && "true"}
>
Assessment
<%= gettext("Assessment") %>
</:tab>
<:tab
patch={~p"/strands/activity/#{@activity}?#{%{tab: "notes"}}"}
is_current={@current_tab == :notes && "true"}
icon_name="hero-eye-slash"
>
My notes
<%= gettext("My notes") %>
</:tab>
</.nav_tabs>
<.menu_button id={"activity-#{@activity.id}"}>
Expand All @@ -56,15 +58,15 @@
id={"edit-activity-#{@activity.id}"}
phx-click={JS.patch(~p"/strands/activity/#{@activity}/edit")}
>
Edit activity
<%= gettext("Edit activity") %>
</.menu_button_item>
<.menu_button_item
id={"remove-activity-#{@activity.id}"}
class="text-red-500"
phx-click="delete_activity"
data-confirm="Are you sure?"
data-confirm={gettext("Are you sure?")}
>
Delete
<%= gettext("Delete") %>
</.menu_button_item>
</:menu_items>
</.menu_button>
Expand Down Expand Up @@ -101,7 +103,7 @@
show={true}
on_cancel={JS.patch(~p"/strands/activity/#{@activity}")}
>
<:title>Edit activity</:title>
<:title><%= gettext("Edit activity") %></:title>
<.live_component
module={ActivityFormComponent}
id={@activity.id}
Expand All @@ -116,10 +118,10 @@
theme="ghost"
phx-click={JS.exec("data-cancel", to: "#activity-form-overlay")}
>
Cancel
<%= gettext("Cancel") %>
</.button>
<.button type="submit" form="activity-form">
Save
<%= gettext("Save") %>
</.button>
</:actions>
</.slide_over>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
<div class="flex items-end justify-between gap-6">
<%= if @classes do %>
<p class="font-display font-bold text-2xl">
Assessing
<%= gettext("Assessing") %>
<button
type="button"
class="inline text-left underline hover:text-ltrn-subtle"
Expand All @@ -36,9 +36,9 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
class="underline hover:text-ltrn-subtle"
phx-click={JS.exec("data-show", to: "#classes-filter-overlay")}
>
Select a class
<%= gettext("Select a class") %>
</button>
to assess students
<%= gettext("to assess students") %>
</p>
<% end %>
<div class="shrink-0 flex items-center gap-6">
Expand All @@ -48,27 +48,27 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
phx-click={JS.exec("data-show", to: "#activity-assessment-points-order-overlay")}
icon_name="hero-arrows-up-down"
>
Reorder
<%= gettext("Reorder") %>
</.collection_action>
<.collection_action
type="link"
patch={~p"/strands/activity/#{@activity}/assessment_point/new"}
icon_name="hero-plus-circle"
>
Create assessment point
<%= gettext("Create assessment point") %>
</.collection_action>
</div>
</div>
<%!-- if no assessment points, render empty state --%>
<div :if={@assessment_points_count == 0} class="p-10 mt-4 rounded shadow-xl bg-white">
<.empty_state>No assessment points for this activity yet</.empty_state>
<.empty_state><%= gettext("No assessment points for this activity yet") %></.empty_state>
</div>
<%!-- if no class filter is select, just render assessment points --%>
<div
:if={!@classes && @assessment_points_count > 0}
class="p-10 mt-4 rounded shadow-xl bg-white"
>
<p class="mb-6 font-bold text-ltrn-subtle">Current assessment points</p>
<p class="mb-6 font-bold text-ltrn-subtle"><%= gettext("Current assessment points") %></p>
<ol phx-update="stream" id="assessment-points-no-class" class="flex flex-col gap-4">
<li
:for={{dom_id, {assessment_point, i}} <- @streams.assessment_points}
Expand Down Expand Up @@ -123,7 +123,7 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
show={true}
on_cancel={JS.patch(~p"/strands/activity/#{@activity}?tab=assessment")}
>
<:title>Assessment Point</:title>
<:title><%= gettext("Assessment Point") %></:title>
<.live_component
module={AssessmentPointFormComponent}
id={Map.get(@assessment_point, :id) || :new}
Expand All @@ -142,10 +142,10 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
type="button"
phx-click="delete_assessment_point_and_entries"
phx-target={@myself}
data-confirm="Are you sure?"
data-confirm={gettext("Are you sure?")}
class="mt-4 font-display font-bold underline"
>
Understood. Delete anyway
<%= gettext("Understood. Delete anyway") %>
</button>
</div>
<button
Expand All @@ -154,7 +154,7 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
phx-target={@myself}
class="shrink-0"
>
<span class="sr-only">dismiss</span>
<span class="sr-only"><%= gettext("dismiss") %></span>
<.icon name="hero-x-mark" />
</button>
</div>
Expand All @@ -164,9 +164,9 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
theme="ghost"
phx-click="delete_assessment_point"
phx-target={@myself}
data-confirm="Are you sure?"
data-confirm={gettext("Are you sure?")}
>
Delete
<%= gettext("Delete") %>
</.button>
</:actions_left>
<:actions>
Expand All @@ -175,15 +175,15 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
theme="ghost"
phx-click={JS.exec("data-cancel", to: "#assessment-point-form-overlay")}
>
Cancel
<%= gettext("Cancel") %>
</.button>
<.button type="submit" form="assessment-point-form" phx-disable-with="Saving...">
Save
<%= gettext("Save") %>
</.button>
</:actions>
</.slide_over>
<.slide_over id="classes-filter-overlay">
<:title>Classes</:title>
<:title><%= gettext("Classes") %></:title>
<.live_component
module={ClassFilterFormComponent}
id={:filter}
Expand All @@ -203,19 +203,19 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
theme="ghost"
phx-click={JS.exec("data-cancel", to: "#classes-filter-overlay")}
>
Cancel
<%= gettext("Cancel") %>
</.button>
<.button
type="submit"
form="class-filter-form"
phx-click={JS.exec("data-cancel", to: "#classes-filter-overlay")}
>
Select
<%= gettext("Select") %>
</.button>
</:actions>
</.slide_over>
<.slide_over :if={@assessment_points_count > 1} id="activity-assessment-points-order-overlay">
<:title>Assessment Points Order</:title>
<:title><%= gettext("Assessment Points Order") %></:title>
<ol>
<li
:for={{assessment_point, i} <- @sortable_assessment_points}
Expand All @@ -228,7 +228,7 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
<div class="shrink-0 flex flex-col gap-2">
<.icon_button
type="button"
sr_text="Move assessment point up"
sr_text={gettext("Move assessment point up")}
name="hero-chevron-up-mini"
theme="ghost"
rounded
Expand All @@ -239,7 +239,7 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
/>
<.icon_button
type="button"
sr_text="Move assessment point down"
sr_text={gettext("Move assessment point down")}
name="hero-chevron-down-mini"
theme="ghost"
rounded
Expand All @@ -257,10 +257,10 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
theme="ghost"
phx-click={JS.exec("data-cancel", to: "#activity-assessment-points-order-overlay")}
>
Cancel
<%= gettext("Cancel") %>
</.button>
<.button type="button" phx-click="save_order" phx-target={@myself}>
Save
<%= gettext("Save") %>
</.button>
</:actions>
</.slide_over>
Expand Down Expand Up @@ -434,7 +434,9 @@ defmodule LantternWeb.ActivityLive.AssessmentComponent do
{:error, _changeset} ->
# we may have more error types, but for now we are handling only this one
message =
"This assessment point already have some entries. Deleting it will cause data loss."
gettext(
"This assessment point already have some entries. Deleting it will cause data loss."
)

{:noreply, socket |> assign(:delete_assessment_point_error, message)}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule LantternWeb.ActivityLive.DetailsComponent do
~H"""
<div class="container py-10 mx-auto lg:max-w-5xl">
<.markdown text={@activity.description} />
<h3 class="mt-16 font-display font-black text-3xl">Curriculum</h3>
<h3 class="mt-16 font-display font-black text-3xl"><%= gettext("Curriculum") %></h3>
<div :for={curriculum_item <- @curriculum_items} class="mt-6">
<.badge theme="dark"><%= curriculum_item.curriculum_component.name %></.badge>
<p class="mt-4"><%= curriculum_item.name %></p>
Expand Down
Loading

0 comments on commit e538460

Please sign in to comment.