Allow to give human readable summary to user tasks

This commit is contained in:
Eike Kettner 2021-03-27 22:06:44 +01:00
parent 63331b6399
commit c36073b852
16 changed files with 121 additions and 35 deletions

View File

@ -150,6 +150,7 @@ object OCollective {
LearnClassifierArgs.taskName, LearnClassifierArgs.taskName,
on, on,
timer, timer,
None,
LearnClassifierArgs(coll) LearnClassifierArgs(coll)
) )
_ <- uts.updateOneTask(AccountId(coll, LearnClassifierArgs.taskName), ut) _ <- uts.updateOneTask(AccountId(coll, LearnClassifierArgs.taskName), ut)
@ -164,6 +165,7 @@ object OCollective {
LearnClassifierArgs.taskName, LearnClassifierArgs.taskName,
true, true,
CalEvent(WeekdayComponent.All, DateEvent.All, TimeEvent.All), CalEvent(WeekdayComponent.All, DateEvent.All, TimeEvent.All),
None,
LearnClassifierArgs(collective) LearnClassifierArgs(collective)
).encode.toPeriodicTask(AccountId(collective, LearnClassifierArgs.taskName)) ).encode.toPeriodicTask(AccountId(collective, LearnClassifierArgs.taskName))
job <- ut.toJob job <- ut.toJob

View File

@ -36,7 +36,8 @@ object HouseKeepingTask {
"Docspell house-keeping", "Docspell house-keeping",
DocspellSystem.taskGroup, DocspellSystem.taskGroup,
Priority.Low, Priority.Low,
ce ce,
None
) )
.map(_.copy(id = periodicId)) .map(_.copy(id = periodicId))
} }

View File

@ -8,11 +8,11 @@ import docspell.backend.ops.OItemSearch.{Batch, ListItem, Query}
import docspell.common._ import docspell.common._
import docspell.joex.mail.EmilHeader import docspell.joex.mail.EmilHeader
import docspell.joex.scheduler.{Context, Task} import docspell.joex.scheduler.{Context, Task}
import docspell.store.queries.QItem
import docspell.store.records._
import docspell.query.Date import docspell.query.Date
import docspell.query.ItemQuery._ import docspell.query.ItemQuery._
import docspell.query.ItemQueryDsl._ import docspell.query.ItemQueryDsl._
import docspell.store.queries.QItem
import docspell.store.records._
import emil._ import emil._
import emil.builder._ import emil.builder._

View File

@ -3853,6 +3853,8 @@ components:
format: ident format: ident
enabled: enabled:
type: boolean type: boolean
summary:
type: string
imapConnection: imapConnection:
type: string type: string
format: ident format: ident
@ -4012,6 +4014,8 @@ components:
format: ident format: ident
enabled: enabled:
type: boolean type: boolean
summary:
type: string
smtpConnection: smtpConnection:
type: string type: string
format: ident format: ident

View File

@ -112,6 +112,7 @@ object NotifyDueItemsRoutes {
NotifyDueItemsArgs.taskName, NotifyDueItemsArgs.taskName,
settings.enabled, settings.enabled,
settings.schedule, settings.schedule,
settings.summary,
NotifyDueItemsArgs( NotifyDueItemsArgs(
user, user,
settings.smtpConnection, settings.smtpConnection,
@ -144,6 +145,7 @@ object NotifyDueItemsRoutes {
} yield NotificationSettings( } yield NotificationSettings(
task.id, task.id,
task.enabled, task.enabled,
task.summary,
conn.getOrElse(Ident.unsafe("")), conn.getOrElse(Ident.unsafe("")),
task.args.recipients, task.args.recipients,
task.timer, task.timer,

View File

@ -105,6 +105,7 @@ object ScanMailboxRoutes {
ScanMailboxArgs.taskName, ScanMailboxArgs.taskName,
settings.enabled, settings.enabled,
settings.schedule, settings.schedule,
settings.summary,
ScanMailboxArgs( ScanMailboxArgs(
user, user,
settings.imapConnection, settings.imapConnection,
@ -139,6 +140,7 @@ object ScanMailboxRoutes {
} yield ScanMailboxSettings( } yield ScanMailboxSettings(
task.id, task.id,
task.enabled, task.enabled,
task.summary,
conn.getOrElse(Ident.unsafe("")), conn.getOrElse(Ident.unsafe("")),
task.args.folders, task.args.folders,
task.timer, task.timer,

View File

@ -0,0 +1,2 @@
ALTER TABLE "periodic_task"
ADD COLUMN "summary" varchar(254);

View File

@ -0,0 +1,2 @@
ALTER TABLE `periodic_task`
ADD COLUMN `summary` varchar(254);

View File

@ -0,0 +1,2 @@
ALTER TABLE "periodic_task"
ADD COLUMN "summary" varchar(254);

View File

@ -85,6 +85,6 @@ object QUserTask {
) )
def makeUserTask(r: RPeriodicTask): UserTask[String] = 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)
} }

View File

@ -30,7 +30,8 @@ case class RPeriodicTask(
marked: Option[Timestamp], marked: Option[Timestamp],
timer: CalEvent, timer: CalEvent,
nextrun: Timestamp, nextrun: Timestamp,
created: Timestamp created: Timestamp,
summary: Option[String]
) { ) {
def toJob[F[_]: Sync]: F[RJob] = def toJob[F[_]: Sync]: F[RJob] =
@ -66,7 +67,8 @@ object RPeriodicTask {
subject: String, subject: String,
submitter: Ident, submitter: Ident,
priority: Priority, priority: Priority,
timer: CalEvent timer: CalEvent,
summary: Option[String]
): F[RPeriodicTask] = ): F[RPeriodicTask] =
Ident Ident
.randomId[F] .randomId[F]
@ -91,7 +93,8 @@ object RPeriodicTask {
.map(_.toInstant) .map(_.toInstant)
.map(Timestamp.apply) .map(Timestamp.apply)
.getOrElse(Timestamp.Epoch), .getOrElse(Timestamp.Epoch),
now now,
summary
) )
} }
) )
@ -104,9 +107,20 @@ object RPeriodicTask {
subject: String, subject: String,
submitter: Ident, submitter: Ident,
priority: Priority, priority: Priority,
timer: CalEvent timer: CalEvent,
summary: Option[String]
)(implicit E: Encoder[A]): F[RPeriodicTask] = )(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 { final case class Table(alias: Option[String]) extends TableDef {
val tableName = "periodic_task" val tableName = "periodic_task"
@ -124,6 +138,7 @@ object RPeriodicTask {
val timer = Column[CalEvent]("timer", this) val timer = Column[CalEvent]("timer", this)
val nextrun = Column[Timestamp]("nextrun", this) val nextrun = Column[Timestamp]("nextrun", this)
val created = Column[Timestamp]("created", this) val created = Column[Timestamp]("created", this)
val summary = Column[String]("summary", this)
val all = NonEmptyList.of[Column[_]]( val all = NonEmptyList.of[Column[_]](
id, id,
enabled, enabled,
@ -137,7 +152,8 @@ object RPeriodicTask {
marked, marked,
timer, timer,
nextrun, nextrun,
created created,
summary
) )
} }
@ -151,7 +167,7 @@ object RPeriodicTask {
T.all, T.all,
fr"${v.id},${v.enabled},${v.task},${v.group},${v.args}," ++ fr"${v.id},${v.enabled},${v.task},${v.group},${v.args}," ++
fr"${v.subject},${v.submitter},${v.priority},${v.worker}," ++ 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] = def update(v: RPeriodicTask): ConnectionIO[Int] =
@ -168,7 +184,8 @@ object RPeriodicTask {
T.worker.setTo(v.worker), T.worker.setTo(v.worker),
T.marked.setTo(v.marked), T.marked.setTo(v.marked),
T.timer.setTo(v.timer), T.timer.setTo(v.timer),
T.nextrun.setTo(v.nextrun) T.nextrun.setTo(v.nextrun),
T.summary.setTo(v.summary)
) )
) )

View File

@ -16,6 +16,7 @@ case class UserTask[A](
name: Ident, name: Ident,
enabled: Boolean, enabled: Boolean,
timer: CalEvent, timer: CalEvent,
summary: Option[String],
args: A args: A
) { ) {
@ -47,7 +48,8 @@ object UserTask {
s"${account.user.id}: ${ut.name.id}", s"${account.user.id}: ${ut.name.id}",
account.user, account.user,
Priority.Low, Priority.Low,
ut.timer ut.timer,
ut.summary
) )
.map(r => r.copy(id = ut.id)) .map(r => r.copy(id = ut.id))
} }

View File

@ -28,6 +28,7 @@ import Data.UiSettings exposing (UiSettings)
import Data.Validated exposing (Validated(..)) import Data.Validated exposing (Validated(..))
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
import Http import Http
import Styles as S import Styles as S
import Util.Http import Util.Http
@ -52,6 +53,7 @@ type alias Model =
, formMsg : Maybe BasicResult , formMsg : Maybe BasicResult
, loading : Int , loading : Int
, yesNoDelete : Comp.YesNoDimmer.Model , yesNoDelete : Comp.YesNoDimmer.Model
, summary : Maybe String
} }
@ -79,6 +81,7 @@ type Msg
| Cancel | Cancel
| RequestDelete | RequestDelete
| YesNoDeleteMsg Comp.YesNoDimmer.Msg | YesNoDeleteMsg Comp.YesNoDimmer.Msg
| SetSummary String
initWith : Flags -> NotificationSettings -> ( Model, Cmd Msg ) initWith : Flags -> NotificationSettings -> ( Model, Cmd Msg )
@ -121,6 +124,7 @@ initWith flags s =
, formMsg = Nothing , formMsg = Nothing
, loading = im.loading , loading = im.loading
, yesNoDelete = Comp.YesNoDimmer.emptyModel , yesNoDelete = Comp.YesNoDimmer.emptyModel
, summary = s.summary
} }
, Cmd.batch , Cmd.batch
[ nc [ nc
@ -158,6 +162,7 @@ init flags =
, formMsg = Nothing , formMsg = Nothing
, loading = 2 , loading = 2
, yesNoDelete = Comp.YesNoDimmer.emptyModel , yesNoDelete = Comp.YesNoDimmer.emptyModel
, summary = Nothing
} }
, Cmd.batch , Cmd.batch
[ Api.getMailSettings flags "" ConnResp [ Api.getMailSettings flags "" ConnResp
@ -203,6 +208,7 @@ makeSettings model =
, capOverdue = model.capOverdue , capOverdue = model.capOverdue
, enabled = model.enabled , enabled = model.enabled
, schedule = Data.CalEvent.makeEvent timer , schedule = Data.CalEvent.makeEvent timer
, summary = model.summary
} }
in in
Data.Validated.map4 make Data.Validated.map4 make
@ -450,6 +456,12 @@ update flags msg model =
, Cmd.none , Cmd.none
) )
SetSummary str ->
( { model | summary = Util.Maybe.fromString str }
, NoAction
, Cmd.none
)
--- View2 --- View2
@ -544,6 +556,22 @@ view2 extraClasses settings model =
, id = "notify-enabled" , 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" ] , div [ class "mb-4" ]
[ label [ class S.inputLabel ] [ label [ class S.inputLabel ]
[ text "Send via" [ text "Send via"

View File

@ -54,13 +54,13 @@ view2 _ items =
, th [ class "text-center mr-2" ] , th [ class "text-center mr-2" ]
[ i [ class "fa fa-check" ] [] [ i [ class "fa fa-check" ] []
] ]
, th [ class "text-left " ] [ text "Summary" ]
, th [ class "text-left hidden sm:table-cell mr-2" ] , th [ class "text-left hidden sm:table-cell mr-2" ]
[ text "Schedule" ] [ text "Schedule" ]
, th [ class "text-left mr-2" ] , th [ class "text-left mr-2" ]
[ text "Connection" ] [ text "Connection" ]
, th [ class "text-left hidden sm:table-cell mr-2" ] , th [ class "text-left hidden sm:table-cell mr-2" ]
[ text "Recipients" ] [ text "Recipients" ]
, th [ class "text-center " ] [ text "Remind Days" ]
] ]
] ]
, tbody [] , tbody []
@ -76,6 +76,10 @@ viewItem2 item =
, td [ class "w-px whitespace-nowrap px-2 text-center" ] , td [ class "w-px whitespace-nowrap px-2 text-center" ]
[ Util.Html.checkbox2 item.enabled [ Util.Html.checkbox2 item.enabled
] ]
, td [ class "text-left" ]
[ Maybe.withDefault "" item.summary
|> text
]
, td [ class "text-left hidden sm:table-cell mr-2" ] , td [ class "text-left hidden sm:table-cell mr-2" ]
[ code [ class "font-mono text-sm" ] [ code [ class "font-mono text-sm" ]
[ text item.schedule [ text item.schedule
@ -87,8 +91,4 @@ viewItem2 item =
, td [ class "text-left hidden sm:table-cell mr-2" ] , td [ class "text-left hidden sm:table-cell mr-2" ]
[ String.join ", " item.recipients |> text [ String.join ", " item.recipients |> text
] ]
, td [ class "text-center" ]
[ String.fromInt item.remindDays
|> text
]
] ]

View File

@ -75,6 +75,7 @@ type alias Model =
, languageModel : Comp.FixedDropdown.Model Language , languageModel : Comp.FixedDropdown.Model Language
, language : Maybe Language , language : Maybe Language
, postHandleAll : Bool , postHandleAll : Bool
, summary : Maybe String
, openTabs : Set String , openTabs : Set String
} }
@ -121,6 +122,7 @@ type Msg
| RemoveLanguage | RemoveLanguage
| TogglePostHandleAll | TogglePostHandleAll
| ToggleAkkordionTab String | ToggleAkkordionTab String
| SetSummary String
initWith : Flags -> ScanMailboxSettings -> ( Model, Cmd Msg ) initWith : Flags -> ScanMailboxSettings -> ( Model, Cmd Msg )
@ -167,6 +169,7 @@ initWith flags s =
Comp.FixedDropdown.init (List.map mkLanguageItem Data.Language.all) Comp.FixedDropdown.init (List.map mkLanguageItem Data.Language.all)
, language = Maybe.andThen Data.Language.fromString s.language , language = Maybe.andThen Data.Language.fromString s.language
, postHandleAll = Maybe.withDefault False s.postHandleAll , postHandleAll = Maybe.withDefault False s.postHandleAll
, summary = s.summary
} }
, Cmd.batch , Cmd.batch
[ Api.getImapSettings flags "" ConnResp [ Api.getImapSettings flags "" ConnResp
@ -221,6 +224,7 @@ init flags =
Comp.FixedDropdown.init (List.map mkLanguageItem Data.Language.all) Comp.FixedDropdown.init (List.map mkLanguageItem Data.Language.all)
, language = Nothing , language = Nothing
, postHandleAll = False , postHandleAll = False
, summary = Nothing
, openTabs = Set.insert (tabTitle TabGeneral) Set.empty , openTabs = Set.insert (tabTitle TabGeneral) Set.empty
} }
, Cmd.batch , Cmd.batch
@ -283,6 +287,7 @@ makeSettings model =
|> Just |> Just
, language = Maybe.map Data.Language.toIso3 model.language , language = Maybe.map Data.Language.toIso3 model.language
, postHandleAll = Just model.postHandleAll , postHandleAll = Just model.postHandleAll
, summary = model.summary
} }
in in
Data.Validated.map3 make Data.Validated.map3 make
@ -689,6 +694,12 @@ update flags msg model =
, Cmd.none , Cmd.none
) )
SetSummary str ->
( { model | summary = Util.Maybe.fromString str }
, NoAction
, Cmd.none
)
--- View2 --- View2
@ -870,6 +881,22 @@ viewGeneral2 settings model =
[ text "Mailbox" [ text "Mailbox"
, B.inputRequired , 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 , Html.map ConnMsg
(Comp.Dropdown.view2 (Comp.Dropdown.view2
DS.mainStyle DS.mainStyle

View File

@ -54,12 +54,11 @@ view2 _ items =
, th [ class "" ] , th [ class "" ]
[ i [ class "fa fa-check" ] [] [ i [ class "fa fa-check" ] []
] ]
, th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Schedule" ] , th [ class "text-left" ] [ text "Summary" ]
, th [ class "text-left mr-2" ] [ text "Connection" ] , th [ class "text-left mr-2" ] [ text "Schedule" ]
, th [ class "text-left mr-2" ] [ text "Folders" ] , th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Connection" ]
, th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Received Since" ] , th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Folders" ]
, th [ class "text-left mr-2 hidden md:table-cell" ] [ text "Target" ] , th [ class "text-left mr-2 hidden lg:table-cell" ] [ text "Received Since" ]
, th [ class "hidden md:table-cell" ] [ text "Delete" ]
] ]
] ]
, tbody [] , tbody []
@ -75,28 +74,24 @@ viewItem2 item =
, td [ class "w-px px-2" ] , td [ class "w-px px-2" ]
[ Util.Html.checkbox2 item.enabled [ 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" ] [ code [ class "font-mono text-sm" ]
[ text item.schedule [ text item.schedule
] ]
] ]
, td [ class "text-left mr-2" ] , td [ class "text-left mr-2 hidden md:table-cell" ]
[ text item.imapConnection [ text item.imapConnection
] ]
, td [ class "text-left mr-2" ] , td [ class "text-left mr-2 hidden md:table-cell" ]
[ String.join ", " item.folders |> text [ 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.map String.fromInt item.receivedSinceHours
|> Maybe.withDefault "-" |> Maybe.withDefault "-"
|> text |> text
, text " h" , 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
]
] ]