-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Nuno Miguel <[email protected]>
- Loading branch information
1 parent
12356a2
commit 082adf4
Showing
11 changed files
with
288 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule Safira.Minigames.WheelSpin do | ||
@moduledoc """ | ||
Lucky wheel minigame spin result | ||
""" | ||
|
||
use Safira.Schema | ||
|
||
@required_fields ~w(attendee_id drop_id)a | ||
|
||
schema "wheel_spins" do | ||
belongs_to :attendee, Safira.Accounts.Attendee | ||
belongs_to :drop, Safira.Minigames.WheelDrop | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(wheel_spin, attrs) do | ||
wheel_spin | ||
|> cast(attrs, @required_fields) | ||
|> validate_required(@required_fields) | ||
end | ||
end |
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,59 @@ | ||
defmodule SafiraWeb.App.WheelLive.Components.Awards do | ||
@moduledoc """ | ||
Lucky wheel awards component. | ||
""" | ||
use SafiraWeb, :component | ||
|
||
attr :entries, :list, default: [] | ||
|
||
def awards(assigns) do | ||
~H""" | ||
<table class="w-full"> | ||
<tr class="border-b-2 text-md sm:text-lg"> | ||
<th class="pr-2 text-left">Name</th> | ||
<th class="px-4 sm:block hidden text-center">Stock</th> | ||
<th class="px-4 text-center">Max. / Attendee</th> | ||
<th class="pl-2 text-right">Probability</th> | ||
</tr> | ||
<%= for entry <- @entries do %> | ||
<tr class="text-sm sm:text-md"> | ||
<td class="pr-2 py-2 font-bold text-left"><%= entry_name(entry) %></td> | ||
<td class="px-4 sm:block hidden py-2 font-bold text-center"><%= entry_stock(entry) %></td> | ||
<td class="px-4 py-2 text-center"><%= entry.max_per_attendee %></td> | ||
<td class="pl-2 py-2 text-accent font-bold text-right"> | ||
<%= format_probability(entry.probability) %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
""" | ||
end | ||
|
||
defp entry_stock(drop) do | ||
if is_nil(drop.prize) do | ||
"∞" | ||
else | ||
drop.prize.stock | ||
end | ||
end | ||
|
||
defp format_probability(probability) do | ||
"#{probability * 100} %" | ||
end | ||
|
||
defp entry_name(drop) do | ||
cond do | ||
not is_nil(drop.prize) -> | ||
drop.prize.name | ||
|
||
not is_nil(drop.badge) -> | ||
drop.badge.name | ||
|
||
drop.entries > 0 -> | ||
"#{drop.entries} Entries" | ||
|
||
drop.tokens > 0 -> | ||
"#{drop.tokens} Tokens" | ||
end | ||
end | ||
end |
37 changes: 37 additions & 0 deletions
37
lib/safira_web/live/app/wheel_live/components/latest_wins.ex
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,37 @@ | ||
defmodule SafiraWeb.App.WheelLive.Components.LatestWins do | ||
@moduledoc """ | ||
Lucky wheel latest wins component. | ||
""" | ||
use SafiraWeb, :component | ||
|
||
attr :entries, :list, default: [] | ||
|
||
def latest_wins(assigns) do | ||
~H""" | ||
<table class="w-full"> | ||
<tr class="border-b-2 text-md sm:text-lg"> | ||
<th class="pr-2 text-left"><%= gettext("Attendee") %></th> | ||
<th class="px-4 text-center"><%= gettext("Prize") %></th> | ||
<th class="pl-2 text-right"><%= gettext("When") %></th> | ||
</tr> | ||
<%= for entry <- @entries do %> | ||
<tr class="text-sm sm:text-md"> | ||
<td class="pr-2 py-2 font-bold text-left"><%= entry.attendee.user.name %></td> | ||
<td class="px-4 py-2 text-center"><%= entry_name(entry) %></td> | ||
<td class="pl-2 py-2 text-accent font-bold text-right"> | ||
<%= Timex.from_now(entry.inserted_at) %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
""" | ||
end | ||
|
||
defp entry_name(entry) do | ||
if is_nil(entry.drop.badge) do | ||
entry.drop.prize.name | ||
else | ||
entry.drop.badge.name | ||
end | ||
end | ||
end |
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
Oops, something went wrong.