Skip to content

Commit

Permalink
Add deleges sign writing images (#336)
Browse files Browse the repository at this point in the history
* 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
bitboxer authored Mar 4, 2019
1 parent 774c55a commit 690157f
Show file tree
Hide file tree
Showing 25 changed files with 794 additions and 149 deletions.
40 changes: 40 additions & 0 deletions assets/css/objects/_video.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,46 @@
text-overflow: ellipsis;
}

.so-video-details--si {
color: $deactive;
font-size: 0.7em;
margin-bottom: 0.5em;
}

.so-video-details--voting {
margin-top: 1em;
}

.so-video-details--signimage {
position: relative;
border: 1px solid $deactive;
padding: 1em;
margin-right: 1em;
display: inline-block;
}

.so-video-details--signimage--report {
position: absolute;
top: 0em;
right: 0em;
width: 100%;
height: 100%;
text-align: right;
padding: 0.5em;
opacity: 0;
}

.so-video-details--signimage--report:hover {
opacity: 1;
}

.so-video-details--signimage-deleges {
color: $deactive;
font-size: 0.7em;
margin-top: 1em;
margin-bottom: 0.5em;
}

@media all and (max-width: 48em) {
.so-video--player {
padding: 0;
Expand Down
1 change: 0 additions & 1 deletion assets/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ gulp.task("js", function() {
});

gulp.task("watch", function() {
gulp.series(["static", "css", "js"]);
gulp.watch("static/**/*", gulp.series("static"));
gulp.watch("css/**/*", gulp.series("css"));
gulp.watch("js/**/*", gulp.series("js"));
Expand Down
Binary file added assets/static/images/deleges/signimages-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/deleges/signimages-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/deleges/signimages-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ config :exq,
queues: [
# the transcoder queue is rate limited by jw_player => only 1 worker
{"transcoder", 1},
{"default", 3}
{"default", 3},
{"sign_writings", 1}
],
json_library: Jason

Expand Down
9 changes: 9 additions & 0 deletions lib/sign_dict/models/entry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule SignDict.Entry do
alias SignDict.Video
alias SignDict.Repo
alias SignDict.Entry
alias SignDict.SignWriting
alias Ecto.Adapters.SQL
alias SignDict.PostgresQueryHelper

Expand All @@ -15,11 +16,13 @@ defmodule SignDict.Entry do
field(:description, :string)
field(:type, :string)
field(:url, :string, virtual: true)
field(:deleges_updated_at, :utc_datetime)

belongs_to(:language, SignDict.Language)

has_many(:videos, Video)
has_many(:list_entries, SignDict.ListEntry)
has_many(:sign_writings, SignWriting)
has_many(:lists, through: [:list_entries, :list])

belongs_to(:current_video, Video)
Expand All @@ -37,6 +40,12 @@ defmodule SignDict.Entry do
|> foreign_key_constraint(:language_id)
end

def deleges_updated_at_changeset(struct, params \\ %{}) do
struct
|> cast(params, [:deleges_updated_at])
|> validate_required(:deleges_updated_at)
end

def find_by_changeset(changeset) do
if changeset.valid? do
Repo.get_by(
Expand Down
55 changes: 31 additions & 24 deletions lib/sign_dict/models/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ defmodule SignDict.List do
@types ["categorie-list"]
@sort_orders ["manual", "alphabetical_desc", "alphabetical_asc"]

@primary_key {:id, SignDict.Permalink, autogenerate: true}
@primary_key {:id, SignDict.Permalink, autogenerate: true}
schema "lists" do
field :name, :string
field :description, :string
field :type, :string
field :sort_order, :string
belongs_to :created_by, SignDict.User
has_many :list_entries, SignDict.ListEntry
has_many :entries, through: [:list_entries, :entry]
field(:name, :string)
field(:description, :string)
field(:type, :string)
field(:sort_order, :string)
belongs_to(:created_by, SignDict.User)
has_many(:list_entries, SignDict.ListEntry)
has_many(:entries, through: [:list_entries, :entry])

timestamps()
end
Expand All @@ -36,33 +36,37 @@ defmodule SignDict.List do
|> validate_inclusion(:sort_order, @sort_orders)
end

# TODO:
# * Paginate list entries
# TODO: Paginate list entries
def entries(%SignDict.List{id: id, sort_order: "manual"}) do
from(
list_entry in ListEntry,
join: entry in assoc(list_entry, :entry),
where: list_entry.list_id == ^id and not is_nil(entry.current_video_id), order_by: :sort_order
where: list_entry.list_id == ^id and not is_nil(entry.current_video_id),
order_by: :sort_order
)
|> Repo.all
|> Repo.all()
|> Repo.preload(entry: [:current_video])
end

def entries(%SignDict.List{id: id, sort_order: "alphabetical_asc"}) do
from(
list_entry in ListEntry,
join: entry in assoc(list_entry, :entry),
where: list_entry.list_id == ^id and not is_nil(entry.current_video_id), order_by: entry.text
where: list_entry.list_id == ^id and not is_nil(entry.current_video_id),
order_by: entry.text
)
|> Repo.all
|> Repo.all()
|> Repo.preload(entry: [:current_video])
end

def entries(%SignDict.List{id: id, sort_order: "alphabetical_desc"}) do
from(
list_entry in ListEntry,
join: entry in assoc(list_entry, :entry),
where: list_entry.list_id == ^id and not is_nil(entry.current_video_id), order_by: [desc: entry.text]
where: list_entry.list_id == ^id and not is_nil(entry.current_video_id),
order_by: [desc: entry.text]
)
|> Repo.all
|> Repo.all()
|> Repo.preload(entry: [:current_video])
end

Expand All @@ -79,19 +83,24 @@ defmodule SignDict.List do

def move_entry(list_entry, direction) do
target_sort_order = list_entry.sort_order + direction
swap_target = Repo.get_by(ListEntry,
list_id: list_entry.list_id,
sort_order: target_sort_order)

swap_target =
Repo.get_by(ListEntry,
list_id: list_entry.list_id,
sort_order: target_sort_order
)

swap_list_entry_position(list_entry, swap_target)
end

def swap_list_entry_position(list_entry, swap_target) when is_nil(swap_target) do
list_entry
end

def swap_list_entry_position(list_entry, swap_target) do
ListEntry.update_sort_order(list_entry, nil)
ListEntry.update_sort_order(list_entry, nil)
ListEntry.update_sort_order(swap_target, list_entry.sort_order)
ListEntry.update_sort_order(list_entry, swap_target.sort_order)
ListEntry.update_sort_order(list_entry, swap_target.sort_order)
Repo.get(ListEntry, list_entry.id)
end

Expand All @@ -101,14 +110,12 @@ defmodule SignDict.List do
join: e in ListEntry,
where: l.id == e.list_id and e.entry_id == ^entry.id and l.type == ^type
)
|> Repo.all
|> Repo.all()
end

end

defimpl Phoenix.Param, for: SignDict.List do
def to_param(%{name: name, id: id}) do
SignDict.Permalink.to_permalink(id, name)
end
end

75 changes: 75 additions & 0 deletions lib/sign_dict/models/sign_writing.ex
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
Loading

0 comments on commit 690157f

Please sign in to comment.