-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add deleges sign writing images (#336)
* design done for deleges * added notify button * next steps * upsert * removed unneeded series * working deleges integration * fixed spelling error * testss * finalized first version of sign_writings
- Loading branch information
Showing
25 changed files
with
794 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
defmodule SignDict.SignWriting do | ||
use SignDictWeb, :model | ||
use Arc.Ecto.Schema | ||
import StateMc.EctoSm | ||
|
||
alias SignDict.Repo | ||
|
||
@states [:active, :marked_as_wrong, :wrong] | ||
|
||
schema "sign_writings" do | ||
field(:word, :string) | ||
field(:width, :integer) | ||
field(:deleges_id, :integer) | ||
field(:state, :string, default: "active") | ||
field(:image, SignDictWeb.SignWritingImage.Type) | ||
|
||
belongs_to(:entry, SignDict.Entry) | ||
timestamps() | ||
end | ||
|
||
statemc :state do | ||
defstate(@states) | ||
|
||
defevent(:mark_as_wrong, %{from: [:active], to: :marked_as_wrong}, fn changeset -> | ||
changeset |> Repo.update() | ||
end) | ||
|
||
defevent(:wrong, %{from: [:mark_as_wrong], to: :wrong}, fn changeset -> | ||
changeset |> Repo.update() | ||
end) | ||
|
||
defevent(:correct, %{from: [:mark_as_wrong], to: :active}, fn changeset -> | ||
changeset |> Repo.update() | ||
end) | ||
end | ||
|
||
def changeset(struct, params \\ %{}) do | ||
struct | ||
|> cast(params, [ | ||
:word, | ||
:width, | ||
:deleges_id, | ||
:entry_id, | ||
:state | ||
]) | ||
|> cast_attachments(params, [:image]) | ||
|> validate_required([ | ||
:word, | ||
:width, | ||
:deleges_id, | ||
:entry_id | ||
]) | ||
|> foreign_key_constraint(:entry_id) | ||
|> validate_state() | ||
end | ||
|
||
def valid_state?(state) when is_atom(state), do: @states |> Enum.member?(state) | ||
def valid_state?(state), do: valid_state?(String.to_atom(state)) | ||
|
||
# Makes sure that the video-state is in the list of possible states. | ||
defp validate_state(changeset) do | ||
if changeset && changeset.valid? do | ||
state = get_field(changeset, :state) | ||
|
||
if valid_state?(state) do | ||
changeset | ||
else | ||
error_msg = "must be in the list of " <> Enum.join(@states, ", ") | ||
add_error(changeset, :state, error_msg) | ||
end | ||
else | ||
changeset | ||
end | ||
end | ||
end |
Oops, something went wrong.