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.
This commit is contained in:
eikek
2021-11-22 00:22:51 +01:00
parent 93a828720c
commit 4ffc8d1f14
175 changed files with 13041 additions and 599 deletions

View File

@ -0,0 +1,146 @@
{-
Copyright 2020 Eike K. & Contributors
SPDX-License-Identifier: AGPL-3.0-or-later
-}
module Comp.NotificationTest exposing (Model, Msg, ViewConfig, init, update, view)
import Api
import Api.Model.NotificationChannelTestResult exposing (NotificationChannelTestResult)
import Comp.Basic as B
import Comp.MenuBar as MB
import Data.Flags exposing (Flags)
import Data.NotificationHook exposing (NotificationHook)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Http
type Model
= ModelInit
| ModelResp NotificationChannelTestResult
| ModelHttpError Http.Error
| ModelLoading
init : Model
init =
ModelInit
type Msg
= RunTest
| TestResp (Result Http.Error NotificationChannelTestResult)
hasResponse : Model -> Bool
hasResponse model =
case model of
ModelResp _ ->
True
_ ->
False
--- Update
update : Flags -> NotificationHook -> Msg -> Model -> ( Model, Cmd Msg )
update flags hook msg model =
case msg of
RunTest ->
case model of
ModelLoading ->
( model, Cmd.none )
_ ->
( ModelLoading, Api.testHook flags hook TestResp )
TestResp (Ok res) ->
( ModelResp res, Cmd.none )
TestResp (Err err) ->
( ModelHttpError err, Cmd.none )
--- View
type alias ViewConfig =
{ runDisabled : Bool
}
styleBase : String
styleBase =
"bg-gray-100 dark:bg-bluegray-900 text-gray-900 dark:text-gray-100 text-sm leading-5"
stylePayload : String
stylePayload =
"px-2 font-mono overflow-auto h-full whitespace-pre "
view : ViewConfig -> Model -> Html Msg
view cfg model =
div
[ class "flex flex-col w-full"
]
[ MB.view
{ start =
case model of
ModelResp res ->
[ MB.CustomElement <|
if res.success then
div [ class "text-3xl text-green-500" ]
[ i [ class "fa fa-check" ] []
]
else
div [ class "text-3xl text-red-500" ]
[ i [ class "fa fa-times" ] []
]
]
_ ->
[]
, end =
[ MB.CustomElement <|
B.primaryButton
{ label = "Test Delivery"
, disabled = cfg.runDisabled || model == ModelLoading
, icon =
if model == ModelLoading then
"fa fa-cog animate-spin"
else
"fa fa-cog"
, handler = onClick RunTest
, attrs = [ href "#" ]
}
]
, rootClasses = "mb-1"
}
, case model of
ModelResp res ->
div
[ class "flex flex-col py-5 px-2"
, class styleBase
, class stylePayload
]
[ text (String.join "\n" res.messages)
]
ModelHttpError err ->
div [ class "" ]
[]
_ ->
span [ class "hidden" ] []
]