Skip to content

Commit

Permalink
Add some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Aug 2, 2023
1 parent b22ab05 commit ab233a3
Show file tree
Hide file tree
Showing 36 changed files with 1,597 additions and 184 deletions.
6 changes: 5 additions & 1 deletion assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ module.exports = {
'../lib/*_web/**/*.*ex',
],
theme: {
extend: {},
extend: {
border: {
'1': '1px'
},
},
},
plugins: [
require('@tailwindcss/forms'),
Expand Down
9 changes: 8 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
import Config

config :atomic,
ecto_repos: [Atomic.Repo]
ecto_repos: [Atomic.Repo],
generators: [binary_id: true],
owner: %{
name: "Atomic",
time_zone: "Europe/Lisbon",
day_start: 0,
day_end: 24
}

# Configures the endpoint
config :atomic, AtomicWeb.Endpoint,
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config :atomic, AtomicWeb.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 4000],
check_origin: false,
code_reloader: true,
debug_errors: false,
debug_errors: true,
secret_key_base: "YGqNjmRjNv4pslzy4DB3Roi6xeyvS2/v/YXGn62mlMqCqjWsmu2UKbtNuNaYx5OO",
watchers: [
# Start the esbuild watcher by calling Esbuild.install_and_run(:default, args)
Expand Down
13 changes: 13 additions & 0 deletions lib/atomic/activities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ defmodule Atomic.Activities do
|> Repo.all()
end

alias Atomic.Activities.Session

def list_sessions_from_to(start, finish, opts) do
from(s in Session,
join: a in Activity,
on: s.activity_id == a.id,
where: s.start >= ^start and s.start <= ^finish,
order_by: [asc: s.start]
)
|> apply_filters(opts)
|> Repo.all()
end

@doc """
Gets a single activity.
Expand Down
45 changes: 45 additions & 0 deletions lib/atomic/uploaders/partner_image.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
defmodule Atomic.Uploaders.PartnerImage do
@moduledoc """
ProductImage is used for product images.
"""

use Waffle.Definition
use Waffle.Ecto.Definition

alias Atomic.Partnerships.Partner

@versions [:original, :medium, :thumb]
@extension_whitelist ~w(.jpg .jpeg .png)

def validate({file, _}) do
file.file_name
|> Path.extname()
|> String.downcase()
|> then(&Enum.member?(@extension_whitelist, &1))
|> case do
true -> :ok
false -> {:error, "Invalid file type. Only .jpg, .jpeg and .png are allowed."}
end
end

def transform(:thumb, _) do
{:convert, "-strip -thumbnail 100x150^ -gravity center -extent 100x150 -format png", :png}
end

def transform(:medium, _) do
{:convert, "-strip -thumbnail 400x600^ -gravity center -extent 400x600 -format png", :png}
end

def filename(version, _) do
version
end

def storage_dir(_version, {_file, %Partner{} = scope}) do
"uploads/store/#{scope.id}"
end

# Provide a default URL if there hasn't been a file uploaded
def default_url(version) do
"uploads/store/partner_image_#{version}.png"
end
end
78 changes: 78 additions & 0 deletions lib/atomic_web/components/badges.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
defmodule AtomicWeb.Components.Badges do
@moduledoc false
use AtomicWeb, :component

@colors ~w(gray red orange amber yellow lime green emerald teal cyan sky blue indigo violet purple fuchsia pink rose)

def badge_dot(assigns) do
assigns =
assigns
|> assign_new(:color, fn -> "gray" end)
|> assign_new(:url, fn -> "#" end)

background =
case assigns.color do
"gray" ->
"bg-gray-900"

"red" ->
"bg-red-600"

"purple" ->
"bg-purple-600"
end

~H"""
<%= live_redirect to: @url, class: "relative inline-flex items-center rounded-full border border-gray-300 px-3 py-0.5" do %>
<div class="absolute flex flex-shrink-0 items-center justify-center">
<span class={"h-1.5 w-1.5 rounded-full #{background}"} aria-hidden="true"></span>
</div>
<div class="ml-3.5 text-sm font-medium text-gray-900">
<%= render_slot(@inner_block) %>
</div>
<% end %>
"""
end

def badge(assigns) do
assigns = assign_new(assigns, :color, fn -> :gray end)

~H"""
<span class={"inline-flex items-center px-3 py-0.5 rounded-full text-sm font-semibold #{get_color_classes(@color)}"}>
<%= @text %>
</span>
"""
end

defp get_color_classes(nil), do: "bg-neutral-100 text-neutral-800"

defp get_color_classes(color) when is_atom(color) do
color
|> Atom.to_string()
|> get_color_classes()
end

# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
defp get_color_classes(color) when color in @colors do
case color do
"gray" -> "bg-gray-100 text-gray-800"
"red" -> "bg-red-100 text-red-800"
"orange" -> "bg-orange-100 text-orange-800"
"amber" -> "bg-amber-100 text-amber-800"
"yellow" -> "bg-yellow-100 text-yellow-800"
"lime" -> "bg-lime-100 text-lime-800"
"green" -> "bg-green-100 text-green-800"
"emerald" -> "bg-emerald-100 text-emerald-800"
"teal" -> "bg-teal-100 text-teal-800"
"cyan" -> "bg-cyan-100 text-cyan-800"
"sky" -> "bg-sky-100 text-sky-800"
"blue" -> "bg-blue-100 text-blue-800"
"indigo" -> "bg-indigo-100 text-indigo-800"
"violet" -> "bg-violet-100 text-violet-800"
"purple" -> "bg-purple-100 text-purple-800"
"fuchsia" -> "bg-fuchsia-100 text-fuchsia-800"
"pink" -> "bg-pink-100 text-pink-800"
"rose" -> "bg-rose-100 text-rose-800"
end
end
end
Loading

0 comments on commit ab233a3

Please sign in to comment.