Streamline form and input field

This commit is contained in:
Eike Kettner 2020-04-20 20:24:52 +02:00
parent c8683743d0
commit 5a2e28415a
4 changed files with 47 additions and 63 deletions

View File

@ -1636,6 +1636,8 @@ components:
type: string type: string
format: calevent format: calevent
next: next:
type: array
items:
type: integer type: integer
format: date-time format: date-time
CalEventCheck: CalEventCheck:

View File

@ -31,10 +31,12 @@ object CalEventCheckRoutes {
Timestamp.current[F].map { now => Timestamp.current[F].map { now =>
CalEvent.parse(str) match { CalEvent.parse(str) match {
case Right(ev) => case Right(ev) =>
val next = ev.nextElapse(now.toUtcDateTime).map(Timestamp.atUtc) val next = ev
.nextElapses(now.toUtcDateTime, 2)
.map(Timestamp.atUtc)
CalEventCheckResult(true, "Valid.", ev.some, next) CalEventCheckResult(true, "Valid.", ev.some, next)
case Left(err) => case Left(err) =>
CalEventCheckResult(false, err, None, None) CalEventCheckResult(false, err, None, Nil)
} }
} }
} }

View File

@ -1,8 +1,8 @@
module Comp.CalEventInput exposing module Comp.CalEventInput exposing
( Model ( Model
, Msg , Msg
, from
, init , init
, initialSchedule
, update , update
, view , view
) )
@ -42,8 +42,15 @@ type Msg
| CheckInputMsg (Result Http.Error CalEventCheckResult) | CheckInputMsg (Result Http.Error CalEventCheckResult)
init : Model initialSchedule : String
init = initialSchedule =
"*-*-01 00:00"
init : Flags -> ( Model, Cmd Msg )
init flags =
let
model =
{ year = "*" { year = "*"
, month = "*" , month = "*"
, day = "1" , day = "1"
@ -53,38 +60,8 @@ init =
, event = Nothing , event = Nothing
, checkResult = Nothing , checkResult = Nothing
} }
from : String -> Maybe Model
from event =
case String.split " " event of
date :: time :: [] ->
let
dateParts =
String.split "-" date
timeParts =
String.split ":" time
allParts =
dateParts ++ timeParts
in in
case allParts of ( model, checkInput flags model )
y :: m :: d :: h :: min :: [] ->
Just
{ init
| year = y
, month = m
, day = d
, hour = h
, minute = min
}
_ ->
Nothing
_ ->
Nothing
toEvent : Model -> String toEvent : Model -> String
@ -315,11 +292,12 @@ view extraClasses model =
[ text "Next: " [ text "Next: "
] ]
, dd [] , dd []
[ Maybe.andThen .next model.checkResult (Maybe.map .next model.checkResult
|> Maybe.map Util.Time.formatDateTime |> Maybe.withDefault []
|> Maybe.withDefault "" |> List.map Util.Time.formatDateTime
|> text |> List.map text
] |> List.intersperse (br [] [])
)
] ]
] ]
] ]

View File

@ -18,7 +18,7 @@ import Comp.IntField
import Data.Flags exposing (Flags) import Data.Flags exposing (Flags)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onCheck, onClick, onInput) import Html.Events exposing (onCheck, onClick)
import Http import Http
import Util.Http import Util.Http
import Util.Tag import Util.Tag
@ -62,13 +62,12 @@ initCmd flags =
] ]
initialSchedule : String
initialSchedule =
"*-*-1/7 12:00"
init : Flags -> ( Model, Cmd Msg ) init : Flags -> ( Model, Cmd Msg )
init flags = init flags =
let
( sm, sc ) =
Comp.CalEventInput.init flags
in
( { settings = Api.Model.NotificationSettings.empty ( { settings = Api.Model.NotificationSettings.empty
, connectionModel = , connectionModel =
Comp.Dropdown.makeSingle Comp.Dropdown.makeSingle
@ -82,13 +81,14 @@ init flags =
, remindDays = Just 1 , remindDays = Just 1
, remindDaysModel = Comp.IntField.init (Just 1) Nothing True "Remind Days" , remindDaysModel = Comp.IntField.init (Just 1) Nothing True "Remind Days"
, enabled = False , enabled = False
, schedule = initialSchedule , schedule = Comp.CalEventInput.initialSchedule
, scheduleModel = , scheduleModel = sm
Comp.CalEventInput.from initialSchedule
|> Maybe.withDefault Comp.CalEventInput.init
, formError = Nothing , formError = Nothing
} }
, initCmd flags , Cmd.batch
[ initCmd flags
, Cmd.map CalEventMsg sc
]
) )
@ -278,6 +278,8 @@ view extraClasses model =
(Comp.CalEventInput.view "" model.scheduleModel) (Comp.CalEventInput.view "" model.scheduleModel)
, span [ class "small-info" ] , span [ class "small-info" ]
[ text "Specify how often and when this task should run. " [ text "Specify how often and when this task should run. "
, text "Use English 3-letter weekdays. Either a single value, "
, text "a list or a '*' (meaning all) is allowed for each part."
] ]
] ]
, div [ class "ui divider" ] [] , div [ class "ui divider" ] []