-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simple sorting on column headings for hills index
.
- Loading branch information
1 parent
4faa4f2
commit 4d74c25
Showing
11 changed files
with
154 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule Ascend.EctoHelper do | ||
def enum(values) do | ||
{:parameterized, Ecto.Enum, Ecto.Enum.init(values: values)} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule AscendWeb.Forms.SortingForm do | ||
import Ecto.Changeset | ||
alias Ascend.EctoHelper | ||
|
||
@sortable_fields [:dobih_id, :name, :metres, :feet] | ||
|
||
@fields %{ | ||
sort_by: EctoHelper.enum(@sortable_fields), | ||
sort_dir: EctoHelper.enum([:asc, :desc]) | ||
} | ||
|
||
@default_values %{ | ||
sort_by: :metres, | ||
sort_dir: :desc | ||
} | ||
|
||
def parse(params) do | ||
{@default_values, @fields} | ||
|> cast(params, Map.keys(@fields)) | ||
|> apply_action(:insert) | ||
end | ||
|
||
def default_values(), do: @default_values | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule AscendWeb.Live.SortingComponent do | ||
use AscendWeb, :live_component | ||
|
||
def render(assigns) do | ||
~H""" | ||
<div phx-click="sort" phx-target={@myself}> | ||
<%= @key %> <%= chevron(@sorting, @key) %> | ||
</div> | ||
""" | ||
end | ||
|
||
def handle_event("sort", _params, socket) do | ||
%{sorting: %{sort_dir: sort_dir}, key: key} = socket.assigns | ||
sort_dir = if sort_dir == :asc, do: :desc, else: :asc | ||
opts = %{sort_by: key, sort_dir: sort_dir} | ||
|
||
send(self(), {:update, opts}) | ||
{:noreply, assign(socket, :sorting, opts)} | ||
end | ||
|
||
def chevron(%{sort_by: sort_by, sort_dir: sort_dir}, key) when sort_by == key do | ||
if sort_dir == :asc, do: "▼", else: "▲" | ||
end | ||
|
||
def chevron(_opts, _key), do: "" | ||
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
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,20 @@ | ||
defmodule Ascend.Factory do | ||
use ExMachina.Ecto, repo: Ascend.Repo | ||
alias Ascend.Hills.Hill | ||
|
||
def hill_factory do | ||
%Hill{ | ||
area: "some area", | ||
classification: "some classification", | ||
dobih_id: sequence(:dobih_id, & &1), | ||
feet: 1640.42, | ||
grid_ref: "GR 123 456", | ||
metres: 500, | ||
munro: true, | ||
name: "some name", | ||
region: "some region", | ||
wainwright: false, | ||
wainwright_outlying_fell: false | ||
} | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.