Files
docspell/modules/webapp/src/main/elm/Comp/NotificationHttpForm.elm
eikek 4ffc8d1f14 Add support for more generic notification
This is a start to have different kinds of notifications. It is
possible to be notified via e-mail, matrix or gotify. It also extends
the current "periodic query" for due items by allowing notification
over different channels. A "generic periodic query" variant is added
as well.
2021-12-11 18:57:32 +01:00

100 lines
1.9 KiB
Elm

{-
Copyright 2020 Eike K. & Contributors
SPDX-License-Identifier: AGPL-3.0-or-later
-}
module Comp.NotificationHttpForm exposing (Model, Msg, init, initWith, update, view)
import Api.Model.NotificationHttp exposing (NotificationHttp)
import Comp.Basic as B
import Data.NotificationChannel
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
import Messages.Comp.NotificationHttpForm exposing (Texts)
import Styles as S
type alias Model =
{ hook : NotificationHttp
}
init : Model
init =
{ hook =
Data.NotificationChannel.setTypeHttp
Api.Model.NotificationHttp.empty
}
initWith : NotificationHttp -> Model
initWith hook =
{ hook = Data.NotificationChannel.setTypeHttp hook
}
type Msg
= SetUrl String
--- Update
update : Msg -> Model -> ( Model, Maybe NotificationHttp )
update msg model =
let
newHook =
updateHook msg model.hook
in
( { model | hook = newHook }, check newHook )
check : NotificationHttp -> Maybe NotificationHttp
check hook =
if hook.url == "" then
Nothing
else
Just hook
updateHook : Msg -> NotificationHttp -> NotificationHttp
updateHook msg hook =
case msg of
SetUrl s ->
{ hook | url = s }
--- View
view : Texts -> Model -> Html Msg
view texts model =
div []
[ div
[ class "mb-2"
]
[ label
[ for "httpurl"
, class S.inputLabel
]
[ text texts.httpUrl
, B.inputRequired
]
, input
[ type_ "text"
, onInput SetUrl
, placeholder texts.httpUrl
, value model.hook.url
, name "httpurl"
, class S.textInput
]
[]
]
]