From 84e0ebf1a22caedaa60a0c60ace977209d803b86 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Thu, 23 Apr 2020 21:37:03 +0200 Subject: [PATCH] Add a flag for restricting overdue items --- .../docspell/backend/ops/OUserTask.scala | 1 + .../docspell/common/NotifyDueItemsArgs.scala | 1 + .../joex/notify/NotifyDueItemsTask.scala | 1 + .../src/main/resources/docspell-openapi.yml | 12 +++++++ .../routes/NotifyDueItemsRoutes.scala | 3 ++ .../src/main/elm/Comp/NotificationForm.elm | 36 +++++++++++++++++-- modules/webapp/src/main/webjar/docspell.css | 5 ++- 7 files changed, 56 insertions(+), 3 deletions(-) diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OUserTask.scala b/modules/backend/src/main/scala/docspell/backend/ops/OUserTask.scala index 2a07b187..dc8917d8 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OUserTask.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OUserTask.scala @@ -81,6 +81,7 @@ object OUserTask { Nil, None, 5, + None, Nil, Nil ) diff --git a/modules/common/src/main/scala/docspell/common/NotifyDueItemsArgs.scala b/modules/common/src/main/scala/docspell/common/NotifyDueItemsArgs.scala index 9e6c3264..0310c295 100644 --- a/modules/common/src/main/scala/docspell/common/NotifyDueItemsArgs.scala +++ b/modules/common/src/main/scala/docspell/common/NotifyDueItemsArgs.scala @@ -17,6 +17,7 @@ case class NotifyDueItemsArgs( recipients: List[String], itemDetailUrl: Option[LenientUri], remindDays: Int, + daysBack: Option[Int], tagsInclude: List[Ident], tagsExclude: List[Ident] ) {} diff --git a/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala b/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala index bca4a017..42e82884 100644 --- a/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala +++ b/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala @@ -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) ) diff --git a/modules/restapi/src/main/resources/docspell-openapi.yml b/modules/restapi/src/main/resources/docspell-openapi.yml index 593ade9a..2b8e167a 100644 --- a/modules/restapi/src/main/resources/docspell-openapi.yml +++ b/modules/restapi/src/main/resources/docspell-openapi.yml @@ -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: diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala index fe654fdd..1d4927f4 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala @@ -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 ) diff --git a/modules/webapp/src/main/elm/Comp/NotificationForm.elm b/modules/webapp/src/main/elm/Comp/NotificationForm.elm index 3f9ca013..bf9d62a4 100644 --- a/modules/webapp/src/main/elm/Comp/NotificationForm.elm +++ b/modules/webapp/src/main/elm/Comp/NotificationForm.elm @@ -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" diff --git a/modules/webapp/src/main/webjar/docspell.css b/modules/webapp/src/main/webjar/docspell.css index 3af5ca2b..4dba30a0 100644 --- a/modules/webapp/src/main/webjar/docspell.css +++ b/modules/webapp/src/main/webjar/docspell.css @@ -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);