defmodule ReflectOS.Core.Sections.Calendar do
use ReflectOS.Kernel.Section
require Logger
alias Scenic.Graph
alias Scenic.Scene
alias Scenic.Assets.Static
import Scenic.Primitives
alias ICalendar.Event
import Phoenix.Component, only: [sigil_H: 2]
alias ReflectOS.Kernel.{Option, OptionGroup}
import ReflectOS.Kernel.Primitives, only: [render_section_label: 3]
import ReflectOS.Kernel.Typography
alias ReflectOS.Kernel.Section.Definition
alias ReflectOS.Kernel.Settings.System
alias ReflectOS.Core.Sections.Calendar.Service
embedded_schema do
field(:show_label?, :boolean, default: false)
field(:label, :string, default: "Calendar")
field(:max_displayed_events, :integer, default: 5)
field(:polling_interval_seconds, :integer, default: 60)
field(:ical_url_1, :string)
field(:ical_url_2, :string)
field(:ical_url_3, :string)
field(:ical_url_4, :string)
field(:ical_url_5, :string)
end
@impl true
def changeset(%__MODULE__{} = section, params \\ %{}) do
section
|> cast(params, [
:show_label?,
:label,
:max_displayed_events,
:polling_interval_seconds,
:ical_url_1,
:ical_url_2,
:ical_url_3,
:ical_url_4,
:ical_url_5
])
|> validate_required([
:show_label?,
:max_displayed_events,
:polling_interval_seconds,
:ical_url_1
])
end
@impl true
def section_definition(),
do: %Definition{
name: "Calendar",
icon: """
""",
description: fn assigns ->
~H"""
This section provides an agenda view of upcoming events -
all you need to provide is an iCal calendar link.
There are number of calendar providers which have feeds you can use.
For example, Google allows you to use a “secret address” for your
calendar which works with ReflectOS - check out
the instructions.
.
"""
end
}
@impl true
def section_options(),
do: [
# Label
%OptionGroup{
label: "Label",
options: [
%Option{
key: :show_label?,
label: "Show Label",
config: %{
type: "checkbox"
}
},
%Option{
key: :label,
label: "Label Text",
hidden: fn %{show_label?: show_label?} ->
!show_label?
end
}
]
},
%OptionGroup{
label: "Calendars",
description: fn assigns ->
~H"""
Calendar Urls in iCal format (usually ends with .ics).
Many calendar systems provide this type of feed. For example,
instructions for Google Calendar can be found
here.