Add a flag for restricting overdue items

This commit is contained in:
Eike Kettner 2020-04-23 21:37:03 +02:00
parent b2ca314da9
commit 84e0ebf1a2
7 changed files with 56 additions and 3 deletions

View File

@ -81,6 +81,7 @@ object OUserTask {
Nil,
None,
5,
None,
Nil,
Nil
)

View File

@ -17,6 +17,7 @@ case class NotifyDueItemsArgs(
recipients: List[String],
itemDetailUrl: Option[LenientUri],
remindDays: Int,
daysBack: Option[Int],
tagsInclude: List[Ident],
tagsExclude: List[Ident]
) {}

View File

@ -73,6 +73,7 @@ object NotifyDueItemsTask {
states = ItemState.validStates,
tagsInclude = ctx.args.tagsInclude,
tagsExclude = ctx.args.tagsExclude,
dueDateFrom = ctx.args.daysBack.map(back => now - Duration.days(back.toLong)),
dueDateTo = Some(now + Duration.days(ctx.args.remindDays.toLong)),
orderAsc = Some(_.dueDate)
)

View File

@ -1679,6 +1679,7 @@ components:
- recipients
- schedule
- remindDays
- capOverdue
- tagsInclude
- tagsExclude
properties:
@ -1701,6 +1702,17 @@ components:
remindDays:
type: integer
format: int32
description: |
Used to restrict items by their due dates. All items with
a due date lower than (now + remindDays) are searched.
capOverdue:
type: boolean
description: |
If this is true, the search is also restricted to due
dates greater than `now - remindDays'. Otherwise, due date
are not restricted in that direction (only lower than `now
+ remindDays' applies) and it is expected to restrict it
more using custom tags.
tagsInclude:
type: array
items:

View File

@ -74,6 +74,8 @@ object NotifyDueItemsRoutes {
settings.recipients,
Some(cfg.baseUrl / "app" / "item"),
settings.remindDays,
if (settings.capOverdue) Some(settings.remindDays)
else None,
settings.tagsInclude.map(_.id),
settings.tagsExclude.map(_.id)
)
@ -100,6 +102,7 @@ object NotifyDueItemsRoutes {
task.args.recipients,
task.timer,
task.args.remindDays,
task.args.daysBack.isDefined,
tinc.map(Conversions.mkTag).toList,
texc.map(Conversions.mkTag).toList
)

View File

@ -38,6 +38,7 @@ type alias Model =
, recipientsModel : Comp.EmailInput.Model
, remindDays : Maybe Int
, remindDaysModel : Comp.IntField.Model
, capOverdue : Bool
, enabled : Bool
, schedule : Validated CalEvent
, scheduleModel : Comp.CalEventInput.Model
@ -56,6 +57,7 @@ type Msg
| GetTagsResp (Result Http.Error TagList)
| RemindDaysMsg Comp.IntField.Msg
| ToggleEnabled
| ToggleCapOverdue
| CalEventMsg Comp.CalEventInput.Msg
| SetNotificationSettings (Result Http.Error NotificationSettings)
| SubmitResp (Result Http.Error BasicResult)
@ -93,6 +95,7 @@ init flags =
, remindDays = Just 1
, remindDaysModel = Comp.IntField.init (Just 1) Nothing True "Remind Days"
, enabled = False
, capOverdue = False
, schedule = initialSchedule
, scheduleModel = sm
, formMsg = Nothing
@ -139,6 +142,7 @@ makeSettings model =
, tagsExclude = Comp.Dropdown.getSelected model.tagExclModel
, recipients = rec
, remindDays = days
, capOverdue = model.capOverdue
, enabled = model.enabled
, schedule = Data.CalEvent.makeEvent timer
}
@ -316,6 +320,14 @@ update flags msg model =
, Cmd.none
)
ToggleCapOverdue ->
( { model
| capOverdue = not model.capOverdue
, formMsg = Nothing
}
, Cmd.none
)
SetNotificationSettings (Ok s) ->
let
smtp =
@ -343,6 +355,7 @@ update flags msg model =
, recipients = s.recipients
, remindDays = Just s.remindDays
, enabled = s.enabled
, capOverdue = s.capOverdue
, schedule = Data.Validated.Unknown newSchedule
, scheduleModel = sm
, formMsg = Nothing
@ -457,14 +470,14 @@ view extraClasses model =
[ label [] [ text "Tags Include (and)" ]
, Html.map TagIncMsg (Comp.Dropdown.view model.tagInclModel)
, span [ class "small-info" ]
[ text "Items must have all tags specified here."
[ text "Items must have all the tags specified here."
]
]
, div [ class "field" ]
[ label [] [ text "Tags Exclude (or)" ]
, Html.map TagExcMsg (Comp.Dropdown.view model.tagExclModel)
, span [ class "small-info" ]
[ text "Items must not have all tags specified here."
[ text "Items must not have any tag specified here."
]
]
, Html.map RemindDaysMsg
@ -472,6 +485,25 @@ view extraClasses model =
"required field"
model.remindDaysModel
)
, div [ class "required inline field" ]
[ div [ class "ui checkbox" ]
[ input
[ type_ "checkbox"
, onCheck (\_ -> ToggleCapOverdue)
, checked model.capOverdue
]
[]
, label []
[ text "Cap overdue items"
]
]
, div [ class "small-info" ]
[ text "If checked, only items with a due date"
, em [] [ text " greater than " ]
, code [] [ text "today-remindDays" ]
, text " are considered."
]
]
, div [ class "required field" ]
[ label []
[ text "Schedule"

View File

@ -165,10 +165,13 @@ label span.muted {
cursor: pointer;
}
span.small-info {
.small-info {
font-size: smaller;
color: rgba(0,0,0,0.6);
}
.small-info code {
font-size: smaller;
}
.placeholder-message {
color: rgba(0,0,0,0.4);