Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
alias_usage_defaults = Credo.Check.Design.AliasUsage.param_defaults()

overwrite_checks = [
{Credo.Check.Design.AliasUsage,
excluded_namespaces: alias_usage_defaults[:excluded_namespaces] ++ ["Backpex.Fields"],
excluded_lastnames: alias_usage_defaults[:excluded_lastnames] ++ ["Type"],
if_nested_deeper_than: 2,
if_called_more_often_than: 1},
{Credo.Check.Design.TagTODO, false},
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.OnePipePerLine, false},
Expand Down
7 changes: 1 addition & 6 deletions .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@ locals_without_parens = [
plugins: [Phoenix.LiveView.HTMLFormatter, Quokka],
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
locals_without_parens: locals_without_parens,
export: [locals_without_parens: locals_without_parens],
quokka: [
exclude: [
:module_directives
]
]
export: [locals_without_parens: locals_without_parens]
]
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

# System / Docker
.vscode
.bash_history
.env
/.elixir_ls/
.DS_Store
.claude/settings.local.json

# Phoenix
/_build/
Expand All @@ -19,4 +19,3 @@ backpex-*.tar
/priv/static/cache_manifest.json
npm-debug.log
/node_modules

7 changes: 1 addition & 6 deletions demo/.formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@
import_deps: [:ecto, :phoenix, :backpex],
plugins: [Phoenix.LiveView.HTMLFormatter, Quokka],
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
subdirectories: ["priv/*/migrations"],
quokka: [
exclude: [
:module_directives
]
]
subdirectories: ["priv/*/migrations"]
]
2 changes: 1 addition & 1 deletion demo/config/runtime.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Config
import System, only: [get_env: 1, get_env: 2, fetch_env!: 1]
import String, only: [to_integer: 1, to_atom: 1, to_existing_atom: 1]
import System, only: [get_env: 1, get_env: 2, fetch_env!: 1]

config :demo, Demo.Repo,
hostname: get_env("DB_HOSTNAME", "postgres"),
Expand Down
1 change: 1 addition & 0 deletions demo/lib/demo/category.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Demo.Category do
@moduledoc false

use Ecto.Schema

import Ecto.Changeset

@primary_key {:id, :binary_id, autogenerate: true}
Expand Down
1 change: 1 addition & 0 deletions demo/lib/demo/film_review.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Demo.FilmReview do
@moduledoc false

use Ecto.Schema

import Ecto.Changeset

@primary_key {:id, :binary_id, autogenerate: true}
Expand Down
1 change: 1 addition & 0 deletions demo/lib/demo/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Demo.Post do
@moduledoc false

use Ecto.Schema

import Ecto.Changeset

@primary_key {:id, :binary_id, autogenerate: true}
Expand Down
4 changes: 2 additions & 2 deletions demo/lib/demo/product.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ defmodule Demo.Product do
product
|> cast(attrs, @required_fields ++ @optional_fields)
|> cast_assoc(:suppliers,
with: &Demo.Supplier.changeset/2,
with: &Supplier.changeset/2,
sort_param: :suppliers_order,
drop_param: :suppliers_delete
)
|> cast_assoc(:short_links,
with: &Demo.ShortLink.changeset/2,
with: &ShortLink.changeset/2,
sort_param: :short_links_order,
drop_param: :short_links_delete
)
Expand Down
4 changes: 3 additions & 1 deletion demo/lib/demo/supplier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule Demo.Supplier do

import Ecto.Changeset

alias Demo.Product

@primary_key {:id, :binary_id, autogenerate: true}

@countries ["Austria", "France", "Germany", "Italy", "Spain", "Switzerland"]
Expand All @@ -18,7 +20,7 @@ defmodule Demo.Supplier do
field :minimum_order, Money.Ecto.Amount.Type
field :preferred, :boolean, default: false

belongs_to :product, Demo.Product, type: :binary_id
belongs_to :product, Product, type: :binary_id

timestamps()
end
Expand Down
1 change: 1 addition & 0 deletions demo/lib/demo/tag.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Demo.Tag do
@moduledoc false

use Ecto.Schema

import Ecto.Changeset

@primary_key {:id, :binary_id, autogenerate: true}
Expand Down
13 changes: 3 additions & 10 deletions demo/lib/demo_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ defmodule DemoWeb do
quote do
use Phoenix.Router, helpers: false

# Import common connection and controller functions to use in pipelines
import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
import Plug.Conn
end
end

Expand All @@ -39,7 +38,6 @@ defmodule DemoWeb do
def controller do
quote do
use Phoenix.Controller, formats: [:html, :json]

use Gettext, backend: DemoWeb.Gettext

import Plug.Conn
Expand Down Expand Up @@ -68,28 +66,23 @@ defmodule DemoWeb do
quote do
use Phoenix.Component

# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_csrf_token: 0, view_module: 1, view_template: 1]

# Include general helpers for rendering HTML
unquote(html_helpers())
end
end

defp html_helpers do
quote do
use Gettext, backend: DemoWeb.Gettext
# HTML escaping functionality
import Phoenix.HTML
# Core UI components and translation

import DemoWeb.CoreComponents
import Phoenix.HTML

# Common modules used in templates
alias DemoWeb.Layouts
alias Phoenix.LiveView.JS

# Routes generation with the ~p sigil
unquote(verified_routes())
end
end
Expand Down
10 changes: 7 additions & 3 deletions demo/lib/demo_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ defmodule DemoWeb.Endpoint do
# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it.
alias Phoenix.Ecto.CheckRepoStatus
alias Phoenix.LiveDashboard.RequestLogger
alias Phoenix.LiveView.Socket

@session_options [
store: :cookie,
key: "_demo_key",
signing_salt: "szYoVHQC"
]

socket "/live", Phoenix.LiveView.Socket,
socket "/live", Socket,
websocket: [
connect_info: [:peer_data, :uri, :user_agent, session: @session_options]
]
Expand All @@ -35,10 +39,10 @@ defmodule DemoWeb.Endpoint do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :demo
plug CheckRepoStatus, otp_app: :demo
end

plug Phoenix.LiveDashboard.RequestLogger,
plug RequestLogger,
param_key: "request_logger",
cookie_key: "request_logger"

Expand Down
5 changes: 3 additions & 2 deletions demo/lib/demo_web/filters/post_category_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ defmodule DemoWeb.Filters.PostCategorySelect do

use Backpex.Filters.Select

alias Backpex.Filters.Select
alias Demo.Category
alias Demo.Post
alias Demo.Repo

@impl Backpex.Filter
def label, do: "Category"

@impl Backpex.Filters.Select
@impl Select
def prompt, do: "Select category ..."

@impl Backpex.Filters.Select
@impl Select
def options(_assigns) do
query =
from p in Post,
Expand Down
4 changes: 3 additions & 1 deletion demo/lib/demo_web/filters/post_published.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ defmodule DemoWeb.Filters.PostPublished do

use Backpex.Filters.Boolean

alias Backpex.Filters.Boolean

@impl Backpex.Filter
def label, do: "Published?"

@impl Backpex.Filters.Boolean
@impl Boolean
def options(_assigns) do
[
%{
Expand Down
5 changes: 3 additions & 2 deletions demo/lib/demo_web/filters/post_user_multi_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ defmodule DemoWeb.Filters.PostUserMultiSelect do

use Backpex.Filters.MultiSelect

alias Backpex.Filters.Select
alias Demo.Post
alias Demo.Repo

@impl Backpex.Filter
def label, do: "Users"

@impl Backpex.Filters.Select
@impl Select
def prompt, do: "Select users ..."

@impl Backpex.Filters.Select
@impl Select
def options(_assigns) do
query =
from p in Post,
Expand Down
2 changes: 2 additions & 0 deletions demo/lib/demo_web/item_actions/user_soft_delete.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ defmodule DemoWeb.ItemActions.UserSoftDelete do
use BackpexWeb, :item_action

import Ecto.Changeset

alias Backpex.ItemActions.Delete

require Logger

@impl Backpex.ItemAction
Expand Down
46 changes: 29 additions & 17 deletions demo/lib/demo_web/live/post_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,40 @@ defmodule DemoWeb.PostLive do

import Ecto.Query, warn: false

@impl Backpex.LiveResource
def layout(_assigns), do: {DemoWeb.Layouts, :admin}
alias Backpex.LiveResource
alias Backpex.Metrics.Value
alias DemoWeb.CategoryLive
alias DemoWeb.Filters.DateTimeRange
alias DemoWeb.Filters.PostCategorySelect
alias DemoWeb.Filters.PostLikeRange
alias DemoWeb.Filters.PostPublished
alias DemoWeb.Filters.PostUserMultiSelect
alias DemoWeb.Layouts
alias DemoWeb.TagLive
alias DemoWeb.UserLive

@impl Backpex.LiveResource
@impl LiveResource
def layout(_assigns), do: {Layouts, :admin}

@impl LiveResource
def singular_name, do: "Post"

@impl Backpex.LiveResource
@impl LiveResource
def plural_name, do: "Posts"

@impl Backpex.LiveResource
@impl LiveResource
def filters do
[
category_id: %{
module: DemoWeb.Filters.PostCategorySelect,
module: PostCategorySelect,
label: "Category"
},
user_id: %{
module: DemoWeb.Filters.PostUserMultiSelect,
module: PostUserMultiSelect,
label: "Users"
},
likes: %{
module: DemoWeb.Filters.PostLikeRange,
module: PostLikeRange,
label: "Likes",
presets: [
%{
Expand All @@ -46,7 +58,7 @@ defmodule DemoWeb.PostLive do
]
},
inserted_at: %{
module: DemoWeb.Filters.DateTimeRange,
module: DateTimeRange,
label: "Created at",
presets: [
%{
Expand Down Expand Up @@ -79,7 +91,7 @@ defmodule DemoWeb.PostLive do
]
},
published: %{
module: DemoWeb.Filters.PostPublished,
module: PostPublished,
label: "Published?",
default: ["published"],
presets: [
Expand All @@ -100,7 +112,7 @@ defmodule DemoWeb.PostLive do
]
end

@impl Backpex.LiveResource
@impl LiveResource
def fields do
[
title: %{
Expand Down Expand Up @@ -166,22 +178,22 @@ defmodule DemoWeb.PostLive do
end,
index_editable: true,
searchable: true,
live_resource: DemoWeb.UserLive
live_resource: UserLive
},
category: %{
module: Backpex.Fields.BelongsTo,
label: "Category",
display_field: :name,
searchable: true,
live_resource: DemoWeb.CategoryLive,
live_resource: CategoryLive,
custom_alias: :custom_category
},
tags: %{
module: Backpex.Fields.HasMany,
label: "Tags",
orderable: false,
display_field: :name,
live_resource: DemoWeb.TagLive
live_resource: TagLive
},
inserted_at: %{
module: Backpex.Fields.DateTime,
Expand All @@ -191,11 +203,11 @@ defmodule DemoWeb.PostLive do
]
end

@impl Backpex.LiveResource
@impl LiveResource
def metrics do
[
total_likes: %{
module: Backpex.Metrics.Value,
module: Value,
label: "Total likes",
class: "lg:w-1/4",
select: dynamic([p], sum(p.likes)),
Expand All @@ -204,7 +216,7 @@ defmodule DemoWeb.PostLive do
end
},
published_posts: %{
module: Backpex.Metrics.Value,
module: Value,
label: "Published Posts",
class: "lg:w-1/4",
select: dynamic([p], count(fragment("CASE WHEN ? = TRUE THEN 1 ELSE NULL END", p.published))),
Expand Down
Loading