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

Fix DateRange fields' names #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 11 additions & 25 deletions src/DatePickers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,10 @@ using Stipple, Stipple.Reexport

import Genie.Renderer.Html: HTMLString, normal_element, template, register_normal_element

export datepicker, DateRange, DatePicker
export datepicker, DatePicker

register_normal_element("q__date", context = @__MODULE__)

"""
DateRange

Represents a date interval, between `start` and `stop`, with a 1 day step.
"""
Base.@kwdef mutable struct DateRange
start::Date = today()
stop::Date = today()
end

DateRange(dr::StepRange{Date,Day}) = DateRange(dr.start, dr.stop)

"""
datepicker()

Expand All @@ -41,11 +29,11 @@ If the `fieldname` references a `Vector{DateRange}`, both the `multiple` and the
julia> @reactive mutable struct DatePickers <: ReactiveModel
date::R{Date} = today() + Day(30)
dates::R{Vector{Date}} = Date[today()+Day(10), today()+Day(20), today()+Day(30)]
daterange::R{DateRange} = DateRange(today(), (today() + Day(3)))
dateranges::R{Vector{DateRange}} = [
DateRange(today(), (today() + Day(3))),
DateRange(today() + Day(7), (today() + Day(10))),
DateRange(today() + Day(14), (today() + Day(17))),
daterange::R{StepRange{Date,Day}} = today():Day(1):(today() + Day(3)))
dateranges::R{Vector{StepRange{Date,Day}}} = [
today():Day(1):(today() + Day(3)),
(today() + Day(7)):Day(1):(today() + Day(10)),
(today() + Day(14)):Day(1):(today() + Day(17)),
]
proxydate::R{Date} = today()
inputdate::R{Date} = today()
Expand Down Expand Up @@ -132,18 +120,16 @@ function Base.parse(::Type{Date}, d::String) :: Date
Date(d)
end

function Stipple.render(dr::DateRange, _::Union{Symbol,Nothing} = nothing)
function Stipple.render(dr::StepRange{Date,Day}, _::Union{Symbol,Nothing} = nothing)
Dict(:from => dr.start, :to => dr.stop)
end

function Stipple.render(vdr::Vector{DateRange}, _::Union{Symbol,Nothing} = nothing)
[ Dict(:from => dr.start, :to => dr.stop) for dr in vdr ]
function Stipple.render(vdr::Vector{StepRange{Date,Day}}, _::Union{Symbol,Nothing} = nothing)
[ Dict(:from => dr.from, :to => dr.to) for dr in vdr ]
end

function Base.parse(::Type{DateRange}, d::Dict{String,Any})
DateRange(d["from"], d["to"])
function Base.convert(::Type{StepRange{Date,Day}}, value::Dict)
Date(value["from"]):Day(1):Date(value["to"])
end

Base.convert(::Type{DateRange}, d::Dict{String,Any}) = parse(DateRange, d)

end