Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
add options when adding a fill step
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Ceolin committed Aug 4, 2024
1 parent 57106a9 commit c8c51a1
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 12 deletions.
13 changes: 11 additions & 2 deletions lib/content/content_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,19 @@ defmodule Zoonk.Content do
iex> update_lesson_step_kind(%LessonStep{}, "fill")
{:ok, %LessonStep{}}
"""
@spec update_lesson_step_kind(LessonStep.t(), String.t()) :: lesson_step_changeset()
@spec update_lesson_step_kind(LessonStep.t(), String.t()) :: {:ok, map()} | {:error, any()} | Ecto.Multi.failure()
def update_lesson_step_kind(%LessonStep{} = lesson_step, "fill") do
segments = [dgettext("orgs", "This is a"), nil, dgettext("orgs", "step.")]
lesson_step |> change_lesson_step(%{kind: :fill, segments: segments}) |> Repo.update()
changeset = change_lesson_step(lesson_step, %{kind: :fill, segments: segments})
option_attrs = %{kind: :fill, lesson_step_id: lesson_step.id}
correct_option = Map.merge(option_attrs, %{fragment: 0, title: dgettext("orgs", "fill in the blank")})
incorrect_option = Map.put(option_attrs, :title, dgettext("orgs", "incorrect option"))

Ecto.Multi.new()
|> Ecto.Multi.update(:lesson_step, changeset)
|> Ecto.Multi.insert(:opt1, change_step_option(%StepOption{}, correct_option))
|> Ecto.Multi.insert(:opt2, change_step_option(%StepOption{}, incorrect_option))
|> Repo.transaction()
end

def update_lesson_step_kind(%LessonStep{} = lesson_step, kind) do
Expand Down
2 changes: 1 addition & 1 deletion lib/content/step_option_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Zoonk.Content.StepOption do
def changeset(step_option, %{kind: :fill} = attrs) do
step_option
|> cast(attrs, [:segment, :title, :lesson_step_id])
|> validate_required([:segment, :title, :lesson_step_id])
|> validate_required([:title, :lesson_step_id])
end

def changeset(step_option, attrs) do
Expand Down
2 changes: 1 addition & 1 deletion priv/gettext/de/LC_MESSAGES/errors.po
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ msgstr "Ihre Anmeldung muss noch genehmigt werden"
msgid "must start with https://"
msgstr "muss mit https:// beginnen"

#: lib/content/content_context.ex:756
#: lib/content/content_context.ex:783
#, elixir-autogen, elixir-format, fuzzy
msgid "cannot delete the only step"
msgstr "Der einzige Schritt kann nicht gelöscht werden"
Expand Down
30 changes: 30 additions & 0 deletions priv/gettext/de/LC_MESSAGES/orgs.po
Original file line number Diff line number Diff line change
Expand Up @@ -847,3 +847,33 @@ msgstr "Sie können mehrere Optionen hinzufügen und Benutzer können eine davon
#, elixir-autogen, elixir-format, fuzzy
msgid "Choose a nickname to access your school profile"
msgstr "Wähle einen Spitznamen, um auf dein Schulprofil zuzugreifen"

#: lib/dashboard/lessons/lesson_editor.ex:210
#, elixir-autogen, elixir-format
msgid "Fill in the blank"
msgstr "Füllen Sie den Leerzeichen aus"

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "This is a"
msgstr "Dies ist ein"

#: lib/dashboard/lessons/lesson_editor.ex:211
#, elixir-autogen, elixir-format
msgid "Users can fill in the blank space in a sentence."
msgstr "Benutzer können den Leerzeichen in einer Satz ausfüllen."

#: lib/content/content_context.ex:750
#, elixir-autogen, elixir-format
msgid "fill in the blank"
msgstr "Leerzeichen ausfüllen"

#: lib/content/content_context.ex:751
#, elixir-autogen, elixir-format
msgid "incorrect option"
msgstr "falsche Option"

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "step."
msgstr "Schritt."
2 changes: 1 addition & 1 deletion priv/gettext/en/LC_MESSAGES/errors.po
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ msgstr ""
msgid "must start with https://"
msgstr ""

#: lib/content/content_context.ex:756
#: lib/content/content_context.ex:783
#, elixir-autogen, elixir-format, fuzzy
msgid "cannot delete the only step"
msgstr ""
Expand Down
30 changes: 30 additions & 0 deletions priv/gettext/en/LC_MESSAGES/orgs.po
Original file line number Diff line number Diff line change
Expand Up @@ -847,3 +847,33 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "Choose a nickname to access your school profile"
msgstr ""

#: lib/dashboard/lessons/lesson_editor.ex:210
#, elixir-autogen, elixir-format
msgid "Fill in the blank"
msgstr ""

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "This is a"
msgstr ""

#: lib/dashboard/lessons/lesson_editor.ex:211
#, elixir-autogen, elixir-format
msgid "Users can fill in the blank space in a sentence."
msgstr ""

#: lib/content/content_context.ex:750
#, elixir-autogen, elixir-format
msgid "fill in the blank"
msgstr ""

#: lib/content/content_context.ex:751
#, elixir-autogen, elixir-format
msgid "incorrect option"
msgstr ""

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "step."
msgstr ""
2 changes: 1 addition & 1 deletion priv/gettext/errors.pot
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ msgstr ""
msgid "must start with https://"
msgstr ""

#: lib/content/content_context.ex:756
#: lib/content/content_context.ex:783
#, elixir-autogen, elixir-format
msgid "cannot delete the only step"
msgstr ""
Expand Down
30 changes: 30 additions & 0 deletions priv/gettext/orgs.pot
Original file line number Diff line number Diff line change
Expand Up @@ -847,3 +847,33 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Choose a nickname to access your school profile"
msgstr ""

#: lib/dashboard/lessons/lesson_editor.ex:210
#, elixir-autogen, elixir-format
msgid "Fill in the blank"
msgstr ""

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "This is a"
msgstr ""

#: lib/dashboard/lessons/lesson_editor.ex:211
#, elixir-autogen, elixir-format
msgid "Users can fill in the blank space in a sentence."
msgstr ""

#: lib/content/content_context.ex:750
#, elixir-autogen, elixir-format
msgid "fill in the blank"
msgstr ""

#: lib/content/content_context.ex:751
#, elixir-autogen, elixir-format
msgid "incorrect option"
msgstr ""

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "step."
msgstr ""
2 changes: 1 addition & 1 deletion priv/gettext/pt/LC_MESSAGES/errors.po
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ msgstr "A sua matrícula está pendente de aprovação"
msgid "must start with https://"
msgstr "deve começar com https://"

#: lib/content/content_context.ex:756
#: lib/content/content_context.ex:783
#, elixir-autogen, elixir-format, fuzzy
msgid "cannot delete the only step"
msgstr "não pode excluir a única etapa"
Expand Down
30 changes: 30 additions & 0 deletions priv/gettext/pt/LC_MESSAGES/orgs.po
Original file line number Diff line number Diff line change
Expand Up @@ -847,3 +847,33 @@ msgstr "Você pode adicionar várias alternativas e os usuários podem seleciona
#, elixir-autogen, elixir-format, fuzzy
msgid "Choose a nickname to access your school profile"
msgstr "Escolha um apelido para acessar o perfil da sua escola"

#: lib/dashboard/lessons/lesson_editor.ex:210
#, elixir-autogen, elixir-format
msgid "Fill in the blank"
msgstr "Preencher espaço"

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "This is a"
msgstr "Esta é uma etapa de"

#: lib/dashboard/lessons/lesson_editor.ex:211
#, elixir-autogen, elixir-format
msgid "Users can fill in the blank space in a sentence."
msgstr "Os usuários podem preencher o espaço em branco em uma frase."

#: lib/content/content_context.ex:750
#, elixir-autogen, elixir-format
msgid "fill in the blank"
msgstr "preencher o espaço"

#: lib/content/content_context.ex:751
#, elixir-autogen, elixir-format
msgid "incorrect option"
msgstr "opção incorreta"

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "step."
msgstr "em branco."
2 changes: 1 addition & 1 deletion priv/gettext/zh_TW/LC_MESSAGES/errors.po
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ msgstr "您的註冊正在等待批准"
msgid "must start with https://"
msgstr "必須以 https:// 開頭"

#: lib/content/content_context.ex:756
#: lib/content/content_context.ex:783
#, elixir-autogen, elixir-format, fuzzy
msgid "cannot delete the only step"
msgstr "不能刪除唯一的步驟"
Expand Down
30 changes: 30 additions & 0 deletions priv/gettext/zh_TW/LC_MESSAGES/orgs.po
Original file line number Diff line number Diff line change
Expand Up @@ -847,3 +847,33 @@ msgstr "您可以新增多個選項,使用者可以選擇其中一個。"
#, elixir-autogen, elixir-format, fuzzy
msgid "Choose a nickname to access your school profile"
msgstr "選擇一個暱稱以存取您的學校資料"

#: lib/dashboard/lessons/lesson_editor.ex:210
#, elixir-autogen, elixir-format
msgid "Fill in the blank"
msgstr "填空"

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "This is a"
msgstr "這是"

#: lib/dashboard/lessons/lesson_editor.ex:211
#, elixir-autogen, elixir-format
msgid "Users can fill in the blank space in a sentence."
msgstr "使用者可以在句子中填入空白。"

#: lib/content/content_context.ex:750
#, elixir-autogen, elixir-format
msgid "fill in the blank"
msgstr "填空"

#: lib/content/content_context.ex:751
#, elixir-autogen, elixir-format
msgid "incorrect option"
msgstr "錯誤的選項"

#: lib/content/content_context.ex:747
#, elixir-autogen, elixir-format
msgid "step."
msgstr "步驟。"
16 changes: 12 additions & 4 deletions test/content/content_context_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Zoonk.ContentTest do
@moduledoc false
use Zoonk.DataCase, async: true

import Ecto.Query, warn: false
import Zoonk.Fixtures.Accounts
import Zoonk.Fixtures.Content
import Zoonk.Fixtures.Organizations
Expand Down Expand Up @@ -813,10 +814,17 @@ defmodule Zoonk.ContentTest do
end

test "automatically adds segments for fill kind" do
lesson_step = lesson_step_fixture(%{kind: :readonly})
assert {:ok, %LessonStep{} = updated} = Content.update_lesson_step_kind(lesson_step, "fill")
assert updated.kind == :fill
assert updated.segments == ["This is a", nil, "step."]
lesson_step = lesson_step_fixture()
assert {:ok, _updated} = Content.update_lesson_step_kind(lesson_step, "fill")
assert Repo.get(LessonStep, lesson_step.id).segments == ["This is a", nil, "step."]
end

test "automatically adds options for fill kind" do
lesson_step = lesson_step_fixture()
assert {:ok, _updated} = Content.update_lesson_step_kind(lesson_step, "fill")

options = StepOption |> where(lesson_step_id: ^lesson_step.id) |> Repo.all()
assert length(options) == 2
end
end

Expand Down

0 comments on commit c8c51a1

Please sign in to comment.