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,8 +1636,10 @@ components:
type: string
format: calevent
next:
type: integer
format: date-time
type: array
items:
type: integer
format: date-time
CalEventCheck:
description: |
A calendar event.

View File

@ -31,10 +31,12 @@ object CalEventCheckRoutes {
Timestamp.current[F].map { now =>
CalEvent.parse(str) match {
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)
case Left(err) =>
CalEventCheckResult(false, err, None, None)
CalEventCheckResult(false, err, None, Nil)
}
}
}

View File

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

View File

@ -18,7 +18,7 @@ import Comp.IntField
import Data.Flags exposing (Flags)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onCheck, onClick, onInput)
import Html.Events exposing (onCheck, onClick)
import Http
import Util.Http
import Util.Tag
@ -62,13 +62,12 @@ initCmd flags =
]
initialSchedule : String
initialSchedule =
"*-*-1/7 12:00"
init : Flags -> ( Model, Cmd Msg )
init flags =
let
( sm, sc ) =
Comp.CalEventInput.init flags
in
( { settings = Api.Model.NotificationSettings.empty
, connectionModel =
Comp.Dropdown.makeSingle
@ -82,13 +81,14 @@ init flags =
, remindDays = Just 1
, remindDaysModel = Comp.IntField.init (Just 1) Nothing True "Remind Days"
, enabled = False
, schedule = initialSchedule
, scheduleModel =
Comp.CalEventInput.from initialSchedule
|> Maybe.withDefault Comp.CalEventInput.init
, schedule = Comp.CalEventInput.initialSchedule
, scheduleModel = sm
, formError = Nothing
}
, initCmd flags
, Cmd.batch
[ initCmd flags
, Cmd.map CalEventMsg sc
]
)
@ -277,7 +277,9 @@ view extraClasses model =
, Html.map CalEventMsg
(Comp.CalEventInput.view "" model.scheduleModel)
, 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" ] []