Add priority to gotify channel

Closes: #1277
This commit is contained in:
eikek
2022-01-12 20:59:07 +01:00
parent 5f10798e86
commit 7aebc1ccdf
15 changed files with 118 additions and 38 deletions

View File

@ -149,16 +149,3 @@ view cfg model =
[ Maybe.withDefault "" model.error |> text
]
]
viewWithInfo2 : String -> String -> Maybe Int -> String -> Model -> Html Msg
viewWithInfo2 label info nval classes model =
let
cfg =
{ label = label
, info = info
, number = nval
, classes = classes
}
in
view cfg model

View File

@ -9,6 +9,8 @@ module Comp.NotificationGotifyForm exposing (Model, Msg, init, initWith, update,
import Api.Model.NotificationGotify exposing (NotificationGotify)
import Comp.Basic as B
import Comp.FixedDropdown
import Data.DropdownStyle
import Data.NotificationChannel
import Html exposing (..)
import Html.Attributes exposing (..)
@ -19,24 +21,28 @@ import Styles as S
type alias Model =
{ hook : NotificationGotify
, prioModel : Comp.FixedDropdown.Model Int
}
init : Model
init =
{ hook = Data.NotificationChannel.setTypeGotify Api.Model.NotificationGotify.empty
, prioModel = Comp.FixedDropdown.init (List.range 0 10)
}
initWith : NotificationGotify -> Model
initWith hook =
{ hook = Data.NotificationChannel.setTypeGotify hook
, prioModel = Comp.FixedDropdown.init (List.range 0 10)
}
type Msg
= SetUrl String
| SetAppKey String
| PrioMsg (Comp.FixedDropdown.Msg Int)
@ -46,10 +52,25 @@ type Msg
update : Msg -> Model -> ( Model, Maybe NotificationGotify )
update msg model =
let
newHook =
updateHook msg model.hook
hook =
model.hook
newModel =
case msg of
SetUrl s ->
{ model | hook = { hook | url = s } }
SetAppKey s ->
{ model | hook = { hook | appKey = s } }
PrioMsg lm ->
let
( m, sel ) =
Comp.FixedDropdown.update lm model.prioModel
in
{ model | hook = { hook | priority = sel }, prioModel = m }
in
( { model | hook = newHook }, check newHook )
( newModel, check newModel.hook )
check : NotificationGotify -> Maybe NotificationGotify
@ -57,22 +78,20 @@ check hook =
Just hook
updateHook : Msg -> NotificationGotify -> NotificationGotify
updateHook msg hook =
case msg of
SetUrl s ->
{ hook | url = s }
SetAppKey s ->
{ hook | appKey = s }
--- View
view : Texts -> Model -> Html Msg
view texts model =
let
cfg =
{ display = String.fromInt
, icon = \n -> Nothing
, selectPlaceholder = texts.priority
, style = Data.DropdownStyle.mainStyle
}
in
div []
[ div
[ class "mb-2"
@ -114,4 +133,18 @@ view texts model =
]
[]
]
, div
[ class "mb-2"
]
[ label
[ for "prio"
, class S.inputLabel
]
[ text texts.priority
]
, Html.map PrioMsg (Comp.FixedDropdown.viewStyled2 cfg False model.hook.priority model.prioModel)
, span [ class "text-sm opacity-75" ]
[ text texts.priorityInfo
]
]
]

View File

@ -18,6 +18,8 @@ type alias Texts =
{ basics : Messages.Basics.Texts
, gotifyUrl : String
, appKey : String
, priority : String
, priorityInfo : String
}
@ -26,6 +28,8 @@ gb =
{ basics = Messages.Basics.gb
, gotifyUrl = "Gotify URL"
, appKey = "App Key"
, priority = "Priority"
, priorityInfo = "A number denoting the importance of a message controlling notification behaviour. The higher the more important."
}
@ -34,4 +38,6 @@ de =
{ basics = Messages.Basics.de
, gotifyUrl = "Gotify URL"
, appKey = "App Key"
, priority = "Priorität"
, priorityInfo = "Eine Zahl, um die Wichtigkeit anzugeben (je höher desto wichtiger). Es steuert, wie eine Notifizierung erscheint."
}