Skip to content

Commit

Permalink
Add date view filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Release-Candidate committed Apr 15, 2021
1 parent 795dda7 commit 76f0fa8
Show file tree
Hide file tree
Showing 9 changed files with 658 additions and 264 deletions.
92 changes: 35 additions & 57 deletions src/Tzolkin/DateList.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ module DateList =

let dateLabelFormat (tzolkindate:TzolkinDate.T) (date:DateTime) =
View.FormattedString (
[ View.Span(text = (sprintf "%s%s " (TzolkinNumber.toUnicode tzolkindate.number)
(TzolkinGlyph.toUnicode tzolkindate.glyph)),
[ View.Span(text = (sprintf "%s%s " (TzolkinNumber.toUnicode tzolkindate.Number)
(TzolkinGlyph.toUnicode tzolkindate.Glyph)),
fontFamily = "Tzolkin",
textColor = Style.accentDarkRed,
fontSize = Style.dateListFontSize,
Expand All @@ -47,58 +47,37 @@ module DateList =
horizontalOptions = LayoutOptions.Center
)

let fullFilterList numElem model tzolkinDate =
let lastList =
TzolkinDate.getLastList numElem tzolkinDate DateTime.Today
|> List.rev

let nextList = TzolkinDate.getNextList numElem tzolkinDate DateTime.Today

let dateList = lastList @ nextList

let filterDay dateList =
match model.Filter.day with
| 0 -> dateList
| day -> List.filter (fun (elem: DateTime) -> elem.Day = day) dateList

let filterMonth dateList =
match model.Filter.month with
| 0 -> dateList
| month -> List.filter (fun (elem: DateTime) -> elem.Month = month) dateList

let filterYear dateList =
match model.Filter.year with
| "" -> dateList
| year ->
List.filter
(fun (elem: DateTime) ->
let yearStr = elem.Year.ToString ()
yearStr.Contains (year))
dateList

dateList
|> filterDay
|> filterMonth
|> filterYear
|> List.map (fun elem -> dateLabel tzolkinDate elem)

let allListView () = []

let filterListViewNum tzolkinNum = []

let filterListViewGlyph tzolkinGlyph = []
let fullFilterList model dateList =
let filterDay dateList =
match model.Filter.Day with
| 0 -> dateList
| day -> List.filter (fun (elem: DateTime) -> elem.Day = day) dateList

let filterMonth dateList =
match model.Filter.Month with
| 0 -> dateList
| month -> List.filter (fun (elem: DateTime) -> elem.Month = month) dateList

let filterYear dateList =
match model.Filter.Year with
| "" -> dateList
| year ->
List.filter
(fun (elem: DateTime) ->
let yearStr = elem.Year.ToString ()
yearStr.Contains (year))
dateList

dateList
|> filterDay
|> filterMonth
|> filterYear
|> List.map (fun elem -> dateLabel (TzolkinDate.fromDate elem) elem)

/// Fills the list view with filtered dates.
let fillListViewFilter (model: Model) =
match model.ListTzolkinNumber, model.ListTzolkinGlyph with
| None, None -> allListView ()
| None, Some tzolkinGlyph -> filterListViewGlyph tzolkinGlyph
| Some tzolkinNum, None -> filterListViewNum tzolkinNum
| Some tzolkinNum, Some tzolkinGlyph ->
fullFilterList 10
model
{ number = tzolkinNum
glyph = tzolkinGlyph }
fullFilterList model model.DateList



/// Select a Tzolk’in date.
Expand Down Expand Up @@ -133,7 +112,7 @@ module DateList =
[ View.Picker (
title = "día",
horizontalOptions = LayoutOptions.Start,
selectedIndex = model.Filter.day,
selectedIndex = model.Filter.Day,
items = "todos" :: [ for i in 1 .. 31 -> i.ToString () ],
selectedIndexChanged = (fun (i, item) -> dispatch (SetFilterDay i)),
fontSize = Style.normalFontSize,
Expand All @@ -145,7 +124,7 @@ module DateList =
View.Picker (
title = "mes",
horizontalOptions = LayoutOptions.Start,
selectedIndex = model.Filter.month,
selectedIndex = model.Filter.Month,
items = "todos" :: [ for i in 1 .. 12 -> i.ToString () ],
selectedIndexChanged = (fun (i, item) -> dispatch (SetFilterMonth i)),
fontSize = Style.normalFontSize,
Expand All @@ -156,6 +135,7 @@ module DateList =
)
View.Entry (
text = "",
placeholder = "año",
textChanged = (fun text -> SetFilterYear text.NewTextValue |> dispatch),
completed = (fun text -> SetFilterYear text |> dispatch),
keyboard = Keyboard.Numeric,
Expand All @@ -168,7 +148,6 @@ module DateList =

let dateViewLayout = GridItemsLayout (ItemsLayoutOrientation.Vertical)



///
let dateView model dispatch =
Expand All @@ -190,9 +169,8 @@ module DateList =
View.CollectionView(
ref = dateListView,
remainingItemsThreshold = 4,
remainingItemsThresholdReachedCommand = (fun () ->
Trace.TraceInformation "remainingItemsThresholdReachedCommand"
),
remainingItemsThresholdReachedCommand = (
fun () -> dispatch NewDateViewItemsNeeded),
itemsLayout = dateViewLayout,
items = fillListViewFilter model
)
Expand Down

0 comments on commit 76f0fa8

Please sign in to comment.