pinchflat/lib/pinchflat_web/controllers/pages/page_controller.ex
Kieran a1a568b7f7
[Enhancement] Add history table to homepage (And TZ support) (#229)
* Added basic history table to homepage

* Improved homepage history query

* Set table to use 24h time

* Added timezone support

* Updated README to reflect new TZ stuff
2024-05-07 12:16:57 -07:00

44 lines
1.1 KiB
Elixir

defmodule PinchflatWeb.Pages.PageController do
use PinchflatWeb, :controller
alias Pinchflat.Repo
alias Pinchflat.Sources.Source
alias Pinchflat.Media.MediaQuery
alias Pinchflat.Profiles.MediaProfile
def home(conn, params) do
done_onboarding = params["onboarding"] == "0"
force_onboarding = params["onboarding"] == "1"
if done_onboarding, do: Settings.set(onboarding: false)
if force_onboarding || Settings.get!(:onboarding) do
render_onboarding_page(conn)
else
render_home_page(conn)
end
end
defp render_home_page(conn) do
conn
|> render(:home,
media_profile_count: Repo.aggregate(MediaProfile, :count, :id),
source_count: Repo.aggregate(Source, :count, :id),
media_item_count:
MediaQuery.new()
|> MediaQuery.with_media_downloaded_at()
|> Repo.aggregate(:count, :id)
)
end
defp render_onboarding_page(conn) do
Settings.set(onboarding: true)
conn
|> render(:onboarding_checklist,
media_profiles_exist: Repo.exists?(MediaProfile),
sources_exist: Repo.exists?(Source),
layout: {Layouts, :onboarding}
)
end
end