Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filtering actions for detection by detection type #179

Merged
merged 1 commit into from
Aug 30, 2023
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
39 changes: 37 additions & 2 deletions server/lib/orcasite/radio/detection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,34 @@ defmodule Orcasite.Radio.Detection do
default_limit 100
end

prepare build(load: [:uuid])
prepare build(load: [:uuid], sort: [inserted_at: :desc])
end

read :read do
primary? true
prepare build(load: [:uuid])
prepare build(load: [:uuid], sort: [inserted_at: :desc])
end

read :by_detection_type do
pagination do
offset? true
countable true
default_limit 100
end

argument :detection_type, :atom do
allow_nil? false
constraints one_of: [:orca, :vessel, :other]
end

prepare build(load: [:uuid], sort: [inserted_at: :desc])

filter expr(
fragment(
"description ilike ?",
"[" <> ^arg(:detection_type) <> "]%"
)
)
end

update :update do
Expand Down Expand Up @@ -171,6 +193,19 @@ defmodule Orcasite.Radio.Detection do
end
end

admin do
table_columns [
:id,
:feed_id,
:playlist_timestamp,
:player_offset,
:listener_count,
:description,
:candidate_id,
:inserted_at
]
end

defp datetime_min(time_1, time_2) do
case DateTime.compare(time_1, time_2) do
:lt -> time_1
Expand Down
5 changes: 3 additions & 2 deletions server/lib/orcasite/radio/feed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Orcasite.Radio.Feed do
data_layer: AshPostgres.DataLayer

attributes do
uuid_attribute :id, prefix: "feed"
uuid_attribute(:id, prefix: "feed")

attribute :name, :string, allow_nil?: false
attribute :node_name, :string, allow_nil?: false
Expand Down Expand Up @@ -76,7 +76,7 @@ defmodule Orcasite.Radio.Feed do
Orcasite.Types.LatLng,
{Orcasite.Radio.Calculations.LatLng,
keys: [:location_point], select: [:location_point]},
allow_nil?: false
allow_nil?: false

calculate :lat_lng_string,
:string,
Expand All @@ -96,6 +96,7 @@ defmodule Orcasite.Radio.Feed do
table_columns [:id, :name, :slug, :node_name, :location_point]

format_fields location_point: {Jason, :encode!, []}, lat_lng: {Jason, :encode!, []}

form do
field :intro_html, type: :long_text
end
Expand Down
Loading