From c36073b852611d028fbffd988e55eacaf58c17c3 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sat, 27 Mar 2021 22:06:44 +0100 Subject: [PATCH] Allow to give human readable summary to user tasks --- .../docspell/backend/ops/OCollective.scala | 2 ++ .../docspell/joex/hk/HouseKeepingTask.scala | 3 +- .../joex/notify/NotifyDueItemsTask.scala | 4 +-- .../src/main/resources/docspell-openapi.yml | 4 +++ .../routes/NotifyDueItemsRoutes.scala | 2 ++ .../restserver/routes/ScanMailboxRoutes.scala | 2 ++ .../migration/h2/V1.22.0__add_task_name.sql | 2 ++ .../mariadb/V1.22.0__add_task_name.sql | 2 ++ .../postgresql/V1.22.0__add_task_name.sql | 2 ++ .../docspell/store/queries/QUserTask.scala | 2 +- .../store/records/RPeriodicTask.scala | 33 ++++++++++++++----- .../docspell/store/usertask/UserTask.scala | 4 ++- .../src/main/elm/Comp/NotificationForm.elm | 28 ++++++++++++++++ .../src/main/elm/Comp/NotificationList.elm | 10 +++--- .../src/main/elm/Comp/ScanMailboxForm.elm | 27 +++++++++++++++ .../src/main/elm/Comp/ScanMailboxList.elm | 29 +++++++--------- 16 files changed, 121 insertions(+), 35 deletions(-) create mode 100644 modules/store/src/main/resources/db/migration/h2/V1.22.0__add_task_name.sql create mode 100644 modules/store/src/main/resources/db/migration/mariadb/V1.22.0__add_task_name.sql create mode 100644 modules/store/src/main/resources/db/migration/postgresql/V1.22.0__add_task_name.sql diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala b/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala index 1bee773b..d7417fd9 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala @@ -150,6 +150,7 @@ object OCollective { LearnClassifierArgs.taskName, on, timer, + None, LearnClassifierArgs(coll) ) _ <- uts.updateOneTask(AccountId(coll, LearnClassifierArgs.taskName), ut) @@ -164,6 +165,7 @@ object OCollective { LearnClassifierArgs.taskName, true, CalEvent(WeekdayComponent.All, DateEvent.All, TimeEvent.All), + None, LearnClassifierArgs(collective) ).encode.toPeriodicTask(AccountId(collective, LearnClassifierArgs.taskName)) job <- ut.toJob diff --git a/modules/joex/src/main/scala/docspell/joex/hk/HouseKeepingTask.scala b/modules/joex/src/main/scala/docspell/joex/hk/HouseKeepingTask.scala index 1728045d..1670ea1b 100644 --- a/modules/joex/src/main/scala/docspell/joex/hk/HouseKeepingTask.scala +++ b/modules/joex/src/main/scala/docspell/joex/hk/HouseKeepingTask.scala @@ -36,7 +36,8 @@ object HouseKeepingTask { "Docspell house-keeping", DocspellSystem.taskGroup, Priority.Low, - ce + ce, + None ) .map(_.copy(id = periodicId)) } 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 ff0e8f5e..391fadd5 100644 --- a/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala +++ b/modules/joex/src/main/scala/docspell/joex/notify/NotifyDueItemsTask.scala @@ -8,11 +8,11 @@ import docspell.backend.ops.OItemSearch.{Batch, ListItem, Query} import docspell.common._ import docspell.joex.mail.EmilHeader import docspell.joex.scheduler.{Context, Task} -import docspell.store.queries.QItem -import docspell.store.records._ import docspell.query.Date import docspell.query.ItemQuery._ import docspell.query.ItemQueryDsl._ +import docspell.store.queries.QItem +import docspell.store.records._ import emil._ import emil.builder._ diff --git a/modules/restapi/src/main/resources/docspell-openapi.yml b/modules/restapi/src/main/resources/docspell-openapi.yml index 5d8d4bf6..d579b278 100644 --- a/modules/restapi/src/main/resources/docspell-openapi.yml +++ b/modules/restapi/src/main/resources/docspell-openapi.yml @@ -3853,6 +3853,8 @@ components: format: ident enabled: type: boolean + summary: + type: string imapConnection: type: string format: ident @@ -4012,6 +4014,8 @@ components: format: ident enabled: type: boolean + summary: + type: string smtpConnection: type: string format: ident 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 240dcc43..720634f1 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala @@ -112,6 +112,7 @@ object NotifyDueItemsRoutes { NotifyDueItemsArgs.taskName, settings.enabled, settings.schedule, + settings.summary, NotifyDueItemsArgs( user, settings.smtpConnection, @@ -144,6 +145,7 @@ object NotifyDueItemsRoutes { } yield NotificationSettings( task.id, task.enabled, + task.summary, conn.getOrElse(Ident.unsafe("")), task.args.recipients, task.timer, diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/ScanMailboxRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/ScanMailboxRoutes.scala index 1eec5f2a..3ac87316 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/ScanMailboxRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/ScanMailboxRoutes.scala @@ -105,6 +105,7 @@ object ScanMailboxRoutes { ScanMailboxArgs.taskName, settings.enabled, settings.schedule, + settings.summary, ScanMailboxArgs( user, settings.imapConnection, @@ -139,6 +140,7 @@ object ScanMailboxRoutes { } yield ScanMailboxSettings( task.id, task.enabled, + task.summary, conn.getOrElse(Ident.unsafe("")), task.args.folders, task.timer, diff --git a/modules/store/src/main/resources/db/migration/h2/V1.22.0__add_task_name.sql b/modules/store/src/main/resources/db/migration/h2/V1.22.0__add_task_name.sql new file mode 100644 index 00000000..7dfdc2f4 --- /dev/null +++ b/modules/store/src/main/resources/db/migration/h2/V1.22.0__add_task_name.sql @@ -0,0 +1,2 @@ +ALTER TABLE "periodic_task" +ADD COLUMN "summary" varchar(254); diff --git a/modules/store/src/main/resources/db/migration/mariadb/V1.22.0__add_task_name.sql b/modules/store/src/main/resources/db/migration/mariadb/V1.22.0__add_task_name.sql new file mode 100644 index 00000000..0fcd7f09 --- /dev/null +++ b/modules/store/src/main/resources/db/migration/mariadb/V1.22.0__add_task_name.sql @@ -0,0 +1,2 @@ +ALTER TABLE `periodic_task` +ADD COLUMN `summary` varchar(254); diff --git a/modules/store/src/main/resources/db/migration/postgresql/V1.22.0__add_task_name.sql b/modules/store/src/main/resources/db/migration/postgresql/V1.22.0__add_task_name.sql new file mode 100644 index 00000000..7dfdc2f4 --- /dev/null +++ b/modules/store/src/main/resources/db/migration/postgresql/V1.22.0__add_task_name.sql @@ -0,0 +1,2 @@ +ALTER TABLE "periodic_task" +ADD COLUMN "summary" varchar(254); diff --git a/modules/store/src/main/scala/docspell/store/queries/QUserTask.scala b/modules/store/src/main/scala/docspell/store/queries/QUserTask.scala index 13fbbc89..8ed3a3d0 100644 --- a/modules/store/src/main/scala/docspell/store/queries/QUserTask.scala +++ b/modules/store/src/main/scala/docspell/store/queries/QUserTask.scala @@ -85,6 +85,6 @@ object QUserTask { ) def makeUserTask(r: RPeriodicTask): UserTask[String] = - UserTask(r.id, r.task, r.enabled, r.timer, r.args) + UserTask(r.id, r.task, r.enabled, r.timer, r.summary, r.args) } diff --git a/modules/store/src/main/scala/docspell/store/records/RPeriodicTask.scala b/modules/store/src/main/scala/docspell/store/records/RPeriodicTask.scala index 8e0383cf..74c9982c 100644 --- a/modules/store/src/main/scala/docspell/store/records/RPeriodicTask.scala +++ b/modules/store/src/main/scala/docspell/store/records/RPeriodicTask.scala @@ -30,7 +30,8 @@ case class RPeriodicTask( marked: Option[Timestamp], timer: CalEvent, nextrun: Timestamp, - created: Timestamp + created: Timestamp, + summary: Option[String] ) { def toJob[F[_]: Sync]: F[RJob] = @@ -66,7 +67,8 @@ object RPeriodicTask { subject: String, submitter: Ident, priority: Priority, - timer: CalEvent + timer: CalEvent, + summary: Option[String] ): F[RPeriodicTask] = Ident .randomId[F] @@ -91,7 +93,8 @@ object RPeriodicTask { .map(_.toInstant) .map(Timestamp.apply) .getOrElse(Timestamp.Epoch), - now + now, + summary ) } ) @@ -104,9 +107,20 @@ object RPeriodicTask { subject: String, submitter: Ident, priority: Priority, - timer: CalEvent + timer: CalEvent, + summary: Option[String] )(implicit E: Encoder[A]): F[RPeriodicTask] = - create[F](enabled, task, group, E(args).noSpaces, subject, submitter, priority, timer) + create[F]( + enabled, + task, + group, + E(args).noSpaces, + subject, + submitter, + priority, + timer, + summary + ) final case class Table(alias: Option[String]) extends TableDef { val tableName = "periodic_task" @@ -124,6 +138,7 @@ object RPeriodicTask { val timer = Column[CalEvent]("timer", this) val nextrun = Column[Timestamp]("nextrun", this) val created = Column[Timestamp]("created", this) + val summary = Column[String]("summary", this) val all = NonEmptyList.of[Column[_]]( id, enabled, @@ -137,7 +152,8 @@ object RPeriodicTask { marked, timer, nextrun, - created + created, + summary ) } @@ -151,7 +167,7 @@ object RPeriodicTask { T.all, fr"${v.id},${v.enabled},${v.task},${v.group},${v.args}," ++ fr"${v.subject},${v.submitter},${v.priority},${v.worker}," ++ - fr"${v.marked},${v.timer},${v.nextrun},${v.created}" + fr"${v.marked},${v.timer},${v.nextrun},${v.created},${v.summary}" ) def update(v: RPeriodicTask): ConnectionIO[Int] = @@ -168,7 +184,8 @@ object RPeriodicTask { T.worker.setTo(v.worker), T.marked.setTo(v.marked), T.timer.setTo(v.timer), - T.nextrun.setTo(v.nextrun) + T.nextrun.setTo(v.nextrun), + T.summary.setTo(v.summary) ) ) diff --git a/modules/store/src/main/scala/docspell/store/usertask/UserTask.scala b/modules/store/src/main/scala/docspell/store/usertask/UserTask.scala index 9d038083..81d5330f 100644 --- a/modules/store/src/main/scala/docspell/store/usertask/UserTask.scala +++ b/modules/store/src/main/scala/docspell/store/usertask/UserTask.scala @@ -16,6 +16,7 @@ case class UserTask[A]( name: Ident, enabled: Boolean, timer: CalEvent, + summary: Option[String], args: A ) { @@ -47,7 +48,8 @@ object UserTask { s"${account.user.id}: ${ut.name.id}", account.user, Priority.Low, - ut.timer + ut.timer, + ut.summary ) .map(r => r.copy(id = ut.id)) } diff --git a/modules/webapp/src/main/elm/Comp/NotificationForm.elm b/modules/webapp/src/main/elm/Comp/NotificationForm.elm index eec3e045..c5c5932d 100644 --- a/modules/webapp/src/main/elm/Comp/NotificationForm.elm +++ b/modules/webapp/src/main/elm/Comp/NotificationForm.elm @@ -28,6 +28,7 @@ import Data.UiSettings exposing (UiSettings) import Data.Validated exposing (Validated(..)) import Html exposing (..) import Html.Attributes exposing (..) +import Html.Events exposing (onInput) import Http import Styles as S import Util.Http @@ -52,6 +53,7 @@ type alias Model = , formMsg : Maybe BasicResult , loading : Int , yesNoDelete : Comp.YesNoDimmer.Model + , summary : Maybe String } @@ -79,6 +81,7 @@ type Msg | Cancel | RequestDelete | YesNoDeleteMsg Comp.YesNoDimmer.Msg + | SetSummary String initWith : Flags -> NotificationSettings -> ( Model, Cmd Msg ) @@ -121,6 +124,7 @@ initWith flags s = , formMsg = Nothing , loading = im.loading , yesNoDelete = Comp.YesNoDimmer.emptyModel + , summary = s.summary } , Cmd.batch [ nc @@ -158,6 +162,7 @@ init flags = , formMsg = Nothing , loading = 2 , yesNoDelete = Comp.YesNoDimmer.emptyModel + , summary = Nothing } , Cmd.batch [ Api.getMailSettings flags "" ConnResp @@ -203,6 +208,7 @@ makeSettings model = , capOverdue = model.capOverdue , enabled = model.enabled , schedule = Data.CalEvent.makeEvent timer + , summary = model.summary } in Data.Validated.map4 make @@ -450,6 +456,12 @@ update flags msg model = , Cmd.none ) + SetSummary str -> + ( { model | summary = Util.Maybe.fromString str } + , NoAction + , Cmd.none + ) + --- View2 @@ -544,6 +556,22 @@ view2 extraClasses settings model = , id = "notify-enabled" } ] + , div [ class "mb-4" ] + [ label [ class S.inputLabel ] + [ text "Summary" + ] + , input + [ type_ "text" + , onInput SetSummary + , class S.textInput + , Maybe.withDefault "" model.summary + |> value + ] + [] + , span [ class "opacity-50 text-sm" ] + [ text "Some human readable name, only for displaying" + ] + ] , div [ class "mb-4" ] [ label [ class S.inputLabel ] [ text "Send via" diff --git a/modules/webapp/src/main/elm/Comp/NotificationList.elm b/modules/webapp/src/main/elm/Comp/NotificationList.elm index 486afe36..c87bf16b 100644 --- a/modules/webapp/src/main/elm/Comp/NotificationList.elm +++ b/modules/webapp/src/main/elm/Comp/NotificationList.elm @@ -54,13 +54,13 @@ view2 _ items = , th [ class "text-center mr-2" ] [ i [ class "fa fa-check" ] [] ] + , th [ class "text-left " ] [ text "Summary" ] , th [ class "text-left hidden sm:table-cell mr-2" ] [ text "Schedule" ] , th [ class "text-left mr-2" ] [ text "Connection" ] , th [ class "text-left hidden sm:table-cell mr-2" ] [ text "Recipients" ] - , th [ class "text-center " ] [ text "Remind Days" ] ] ] , tbody [] @@ -76,6 +76,10 @@ viewItem2 item = , td [ class "w-px whitespace-nowrap px-2 text-center" ] [ Util.Html.checkbox2 item.enabled ] + , td [ class "text-left" ] + [ Maybe.withDefault "" item.summary + |> text + ] , td [ class "text-left hidden sm:table-cell mr-2" ] [ code [ class "font-mono text-sm" ] [ text item.schedule @@ -87,8 +91,4 @@ viewItem2 item = , td [ class "text-left hidden sm:table-cell mr-2" ] [ String.join ", " item.recipients |> text ] - , td [ class "text-center" ] - [ String.fromInt item.remindDays - |> text - ] ] diff --git a/modules/webapp/src/main/elm/Comp/ScanMailboxForm.elm b/modules/webapp/src/main/elm/Comp/ScanMailboxForm.elm index 9949719b..3e23a981 100644 --- a/modules/webapp/src/main/elm/Comp/ScanMailboxForm.elm +++ b/modules/webapp/src/main/elm/Comp/ScanMailboxForm.elm @@ -75,6 +75,7 @@ type alias Model = , languageModel : Comp.FixedDropdown.Model Language , language : Maybe Language , postHandleAll : Bool + , summary : Maybe String , openTabs : Set String } @@ -121,6 +122,7 @@ type Msg | RemoveLanguage | TogglePostHandleAll | ToggleAkkordionTab String + | SetSummary String initWith : Flags -> ScanMailboxSettings -> ( Model, Cmd Msg ) @@ -167,6 +169,7 @@ initWith flags s = Comp.FixedDropdown.init (List.map mkLanguageItem Data.Language.all) , language = Maybe.andThen Data.Language.fromString s.language , postHandleAll = Maybe.withDefault False s.postHandleAll + , summary = s.summary } , Cmd.batch [ Api.getImapSettings flags "" ConnResp @@ -221,6 +224,7 @@ init flags = Comp.FixedDropdown.init (List.map mkLanguageItem Data.Language.all) , language = Nothing , postHandleAll = False + , summary = Nothing , openTabs = Set.insert (tabTitle TabGeneral) Set.empty } , Cmd.batch @@ -283,6 +287,7 @@ makeSettings model = |> Just , language = Maybe.map Data.Language.toIso3 model.language , postHandleAll = Just model.postHandleAll + , summary = model.summary } in Data.Validated.map3 make @@ -689,6 +694,12 @@ update flags msg model = , Cmd.none ) + SetSummary str -> + ( { model | summary = Util.Maybe.fromString str } + , NoAction + , Cmd.none + ) + --- View2 @@ -870,6 +881,22 @@ viewGeneral2 settings model = [ text "Mailbox" , B.inputRequired ] + , div [ class "mb-4" ] + [ label [ class S.inputLabel ] + [ text "Summary" + ] + , input + [ type_ "text" + , onInput SetSummary + , class S.textInput + , Maybe.withDefault "" model.summary + |> value + ] + [] + , span [ class "opacity-50 text-sm" ] + [ text "Some human readable name, only for displaying" + ] + ] , Html.map ConnMsg (Comp.Dropdown.view2 DS.mainStyle diff --git a/modules/webapp/src/main/elm/Comp/ScanMailboxList.elm b/modules/webapp/src/main/elm/Comp/ScanMailboxList.elm index 40a4f820..e58b33d5 100644 --- a/modules/webapp/src/main/elm/Comp/ScanMailboxList.elm +++ b/modules/webapp/src/main/elm/Comp/ScanMailboxList.elm @@ -54,12 +54,11 @@ view2 _ items = , th [ class "" ] [ i [ class "fa fa-check" ] [] ] - , th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Schedule" ] - , th [ class "text-left mr-2" ] [ text "Connection" ] - , th [ class "text-left mr-2" ] [ text "Folders" ] - , th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Received Since" ] - , th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Target" ] - , th [ class "hidden md:table-cell" ] [ text "Delete" ] + , th [ class "text-left" ] [ text "Summary" ] + , th [ class "text-left mr-2" ] [ text "Schedule" ] + , th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Connection" ] + , th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Folders" ] + , th [ class "text-left mr-2 hidden lg:table-cell" ] [ text "Received Since" ] ] ] , tbody [] @@ -75,28 +74,24 @@ viewItem2 item = , td [ class "w-px px-2" ] [ Util.Html.checkbox2 item.enabled ] - , td [ class "mr-2 hidden md:table-cell" ] + , td [ class "text-left" ] + [ Maybe.withDefault "–" item.summary |> text + ] + , td [ class "mr-2" ] [ code [ class "font-mono text-sm" ] [ text item.schedule ] ] - , td [ class "text-left mr-2" ] + , td [ class "text-left mr-2 hidden md:table-cell" ] [ text item.imapConnection ] - , td [ class "text-left mr-2" ] + , td [ class "text-left mr-2 hidden md:table-cell" ] [ String.join ", " item.folders |> text ] - , td [ class "text-left mr-2 hidden md:table-cell" ] + , td [ class "text-left mr-2 hidden lg:table-cell" ] [ Maybe.map String.fromInt item.receivedSinceHours |> Maybe.withDefault "-" |> text , text " h" ] - , td [ class "text-left mr-2 hidden md:table-cell" ] - [ Maybe.withDefault "-" item.targetFolder - |> text - ] - , td [ class "w-px px-2 hidden md:table-cell" ] - [ Util.Html.checkbox2 item.deleteMail - ] ]