Prepare notification form

This commit is contained in:
Eike Kettner 2020-04-18 00:50:46 +02:00
parent fb348b3a7c
commit e97e0db45c
7 changed files with 189 additions and 19 deletions

View File

@ -133,6 +133,9 @@ val openapiScalaSettings = Seq(
field.copy(typeDef = TypeDef("NerTag", Imports("docspell.common.NerTag")))
case "language" => field =>
field.copy(typeDef = TypeDef("Language", Imports("docspell.common.Language")))
case "calevent" => field =>
field.copy(typeDef = TypeDef("CalEvent", Imports("com.github.eikek.calev.CalEvent",
"com.github.eikek.calev.circe.CalevCirceCodec._")))
}))
)
@ -149,6 +152,7 @@ val common = project.in(file("modules/common")).
Dependencies.circe ++
Dependencies.loggingApi ++
Dependencies.calevCore ++
Dependencies.calevCirce ++
Dependencies.pureconfig.map(_ % "optional")
)
@ -205,7 +209,8 @@ val store = project.in(file("modules/store")).
Dependencies.loggingApi ++
Dependencies.emil ++
Dependencies.emilDoobie ++
Dependencies.calev
Dependencies.calevCore ++
Dependencies.calevFs2
).dependsOn(common)
val extract = project.in(file("modules/extract")).

View File

@ -1560,9 +1560,96 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/BasicResult"
/sec/notification:
get:
tags: [ Notification ]
summary: Get current notification settings
description: |
Return the current notification settings of the authenticated
user. Users can be notified on due items via e-mail. This is
done by periodically querying items.
security:
- authTokenHeader: []
responses:
200:
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/NotificationData"
post:
tags: [ Notification ]
summary: Change current notification settings
description: |
Change the current notification settings of the authenticated
user.
security:
- authTokenHeader: []
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/NotificationSettings"
responses:
200:
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/BasicResult"
components:
schemas:
NotificationSettings:
description: |
Settings for notifying about due items.
required:
- id
- enabled
- smtpConnection
- schedule
- remindDays
- tagsInclude
- tagsExclude
properties:
id:
type: string
format: ident
enabled:
type: boolean
smtpConnection:
type: string
format: ident
schedule:
type: string
format: calevent
remindDays:
type: integer
format: int32
tagsInclude:
type: array
items:
type: string
format: ident
tagsExclude:
type: array
items:
type: string
format: ident
NotificationData:
description: |
Data for the notification settings.
required:
- settings
properties:
settings:
$ref: "#/components/schemas/NotificationSettings"
nextRun:
type: integer
format: date-time
lastRun:
type: integer
format: date-time
SentMails:
description: |
A list of sent mails.

View File

@ -0,0 +1,42 @@
module Comp.NotificationForm exposing
( Model
, Msg
, init
, update
, view
)
import Api.Model.NotificationSettings exposing (NotificationSettings)
import Data.Flags exposing (Flags)
import Html exposing (..)
import Html.Attributes exposing (..)
type alias Model =
{ settings : NotificationSettings
}
type Msg
= Submit
init : Model
init =
{ settings = Api.Model.NotificationSettings.empty
}
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
update flags msg model =
( model, Cmd.none )
view : Model -> Html Msg
view model =
div
[ classList
[ ( "ui form", True )
]
]
[]

View File

@ -7,12 +7,14 @@ module Page.UserSettings.Data exposing
import Comp.ChangePasswordForm
import Comp.EmailSettingsManage
import Comp.NotificationForm
type alias Model =
{ currentTab : Maybe Tab
, changePassModel : Comp.ChangePasswordForm.Model
, emailSettingsModel : Comp.EmailSettingsManage.Model
, notificationModel : Comp.NotificationForm.Model
}
@ -21,15 +23,18 @@ emptyModel =
{ currentTab = Nothing
, changePassModel = Comp.ChangePasswordForm.emptyModel
, emailSettingsModel = Comp.EmailSettingsManage.emptyModel
, notificationModel = Comp.NotificationForm.init
}
type Tab
= ChangePassTab
| EmailSettingsTab
| NotificationTab
type Msg
= SetTab Tab
| ChangePassMsg Comp.ChangePasswordForm.Msg
| EmailSettingsMsg Comp.EmailSettingsManage.Msg
| NotificationMsg Comp.NotificationForm.Msg

View File

@ -2,6 +2,7 @@ module Page.UserSettings.Update exposing (update)
import Comp.ChangePasswordForm
import Comp.EmailSettingsManage
import Comp.NotificationForm
import Data.Flags exposing (Flags)
import Page.UserSettings.Data exposing (..)
@ -25,6 +26,10 @@ update flags msg model =
ChangePassTab ->
( m, Cmd.none )
NotificationTab ->
-- todo: get initial settings
( m, Cmd.none )
in
( m2, cmd )
@ -41,3 +46,12 @@ update flags msg model =
Comp.EmailSettingsManage.update flags m model.emailSettingsModel
in
( { model | emailSettingsModel = m2 }, Cmd.map EmailSettingsMsg c2 )
NotificationMsg lm ->
let
( m2, c2 ) =
Comp.NotificationForm.update flags lm model.notificationModel
in
( { model | notificationModel = m2 }
, Cmd.map NotificationMsg c2
)

View File

@ -2,6 +2,7 @@ module Page.UserSettings.View exposing (view)
import Comp.ChangePasswordForm
import Comp.EmailSettingsManage
import Comp.NotificationForm
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
@ -18,22 +19,9 @@ view model =
]
, div [ class "ui attached fluid segment" ]
[ div [ class "ui fluid vertical secondary menu" ]
[ a
[ classActive (model.currentTab == Just ChangePassTab) "link icon item"
, onClick (SetTab ChangePassTab)
, href "#"
]
[ i [ class "user secret icon" ] []
, text "Change Password"
]
, a
[ classActive (model.currentTab == Just EmailSettingsTab) "link icon item"
, onClick (SetTab EmailSettingsTab)
, href "#"
]
[ i [ class "mail icon" ] []
, text "E-Mail Settings"
]
[ makeTab model ChangePassTab "Change Password" "user secret icon"
, makeTab model EmailSettingsTab "E-Mail Settings" "mail icon"
, makeTab model NotificationTab "Notifications" "bullhorn icon"
]
]
]
@ -46,6 +34,9 @@ view model =
Just EmailSettingsTab ->
viewEmailSettings model
Just NotificationTab ->
viewNotificationForm model
Nothing ->
[]
)
@ -53,6 +44,18 @@ view model =
]
makeTab : Model -> Tab -> String -> String -> Html Msg
makeTab model tab header icon =
a
[ classActive (model.currentTab == Just tab) "link icon item"
, onClick (SetTab tab)
, href "#"
]
[ i [ class icon ] []
, text header
]
viewEmailSettings : Model -> List (Html Msg)
viewEmailSettings model =
[ h2 [ class "ui header" ]
@ -75,3 +78,15 @@ viewChangePassword model =
]
, Html.map ChangePassMsg (Comp.ChangePasswordForm.view model.changePassModel)
]
viewNotificationForm : Model -> List (Html Msg)
viewNotificationForm model =
[ h2 [ class "ui header" ]
[ i [ class "ui bullhorn icon" ] []
, div [ class "content" ]
[ text "Notification"
]
]
, Html.map NotificationMsg (Comp.NotificationForm.view model.notificationModel)
]

View File

@ -41,12 +41,14 @@ object Dependencies {
val calevCore = Seq(
"com.github.eikek" %% "calev-core" % CalevVersion,
"com.github.eikek" %% "calev-core" % CalevVersion
)
val calevFs2 = Seq(
"com.github.eikek" %% "calev-fs2" % CalevVersion
)
val calev = calevFs2 ++ calevCore
val calevCirce = Seq(
"com.github.eikek" %% "calev-circe" % CalevVersion
)
val jclOverSlf4j = Seq(
"org.slf4j" % "jcl-over-slf4j" % Slf4jVersion