From e97e0db45ca850b3e5b3ade9d1d8f948cd8a6b83 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sat, 18 Apr 2020 00:50:46 +0200 Subject: [PATCH] Prepare notification form --- build.sbt | 7 +- .../src/main/resources/docspell-openapi.yml | 87 +++++++++++++++++++ .../src/main/elm/Comp/NotificationForm.elm | 42 +++++++++ .../src/main/elm/Page/UserSettings/Data.elm | 5 ++ .../src/main/elm/Page/UserSettings/Update.elm | 14 +++ .../src/main/elm/Page/UserSettings/View.elm | 47 ++++++---- project/Dependencies.scala | 6 +- 7 files changed, 189 insertions(+), 19 deletions(-) create mode 100644 modules/webapp/src/main/elm/Comp/NotificationForm.elm diff --git a/build.sbt b/build.sbt index 6bb5c1c6..69f8dd57 100644 --- a/build.sbt +++ b/build.sbt @@ -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")). diff --git a/modules/restapi/src/main/resources/docspell-openapi.yml b/modules/restapi/src/main/resources/docspell-openapi.yml index 6df8f26a..d2067a0d 100644 --- a/modules/restapi/src/main/resources/docspell-openapi.yml +++ b/modules/restapi/src/main/resources/docspell-openapi.yml @@ -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. diff --git a/modules/webapp/src/main/elm/Comp/NotificationForm.elm b/modules/webapp/src/main/elm/Comp/NotificationForm.elm new file mode 100644 index 00000000..8c67631a --- /dev/null +++ b/modules/webapp/src/main/elm/Comp/NotificationForm.elm @@ -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 ) + ] + ] + [] diff --git a/modules/webapp/src/main/elm/Page/UserSettings/Data.elm b/modules/webapp/src/main/elm/Page/UserSettings/Data.elm index 905c6125..079ca296 100644 --- a/modules/webapp/src/main/elm/Page/UserSettings/Data.elm +++ b/modules/webapp/src/main/elm/Page/UserSettings/Data.elm @@ -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 diff --git a/modules/webapp/src/main/elm/Page/UserSettings/Update.elm b/modules/webapp/src/main/elm/Page/UserSettings/Update.elm index 8241f44c..fa66d05e 100644 --- a/modules/webapp/src/main/elm/Page/UserSettings/Update.elm +++ b/modules/webapp/src/main/elm/Page/UserSettings/Update.elm @@ -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 + ) diff --git a/modules/webapp/src/main/elm/Page/UserSettings/View.elm b/modules/webapp/src/main/elm/Page/UserSettings/View.elm index d89d1daa..11260db5 100644 --- a/modules/webapp/src/main/elm/Page/UserSettings/View.elm +++ b/modules/webapp/src/main/elm/Page/UserSettings/View.elm @@ -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) + ] diff --git a/project/Dependencies.scala b/project/Dependencies.scala index c9eb822b..c4a9ffd9 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -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