Commit b22f20af authored by Cédric F.'s avatar Cédric F.

Allow to delete events

parent 9512bd8f
Pipeline #5419433 (#) passed with stage
in 1 minute and 25 seconds
......@@ -111,6 +111,7 @@ type Msg
| ShowEventForm Int
| UpdateEvent NewEventField String
| SaveEvent
| DeleteEvent
| NewConfig String
| ToggleModal
......
......@@ -152,20 +152,23 @@ update msg model =
newEvents =
if model.eventFormOpen == 0 then
newEvent :: model.events
model.events
else
List.indexedMap
(\index ->
\event ->
if index + 1 == model.eventFormOpen then
newEvent
else
event
)
model.events
deleteEvent model.eventFormOpen model.events
events =
List.sortBy (\event -> DateExtra.toISOString event.from) newEvents
(newEvent :: newEvents)
|> List.sortBy (\event -> DateExtra.toISOString event.from)
newModel =
{ model | events = events, eventFormOpen = -1 }
in
( newModel, updateUrl newModel )
DeleteEvent ->
let
events =
deleteEvent model.eventFormOpen model.events
newModel =
{ model | events = events, eventFormOpen = -1 }
......@@ -218,3 +221,17 @@ minLifeExpectancy model =
model.kidUntil
else
1
deleteEvent : Int -> List Event -> List Event
deleteEvent index events =
List.indexedMap
(\i ->
\event ->
if i + 1 == index then
Nothing
else
Just event
)
events
|> List.filterMap identity
......@@ -182,6 +182,31 @@ eventForm model index =
""
else
" hidden-xs-up"
newEvent =
index == 0
delete =
a [ href "javascript:void(0)", onClick DeleteEvent ] [ text "delete" ]
submit =
input
[ class "btn btn-primary ml-1"
, type_ "submit"
, value
(if newEvent then
"Add"
else
"Save"
)
]
[]
actions =
if newEvent then
[ submit ]
else
[ delete, submit ]
in
li [ class <| "list-group-item" ++ visibility ]
[ Html.form [ onSubmit SaveEvent ]
......@@ -227,33 +252,18 @@ eventForm model index =
[]
]
]
, div [ class "col-xs-3" ]
[ div [ class "input-group" ]
[ span [ class "input-group-addon" ] [ text "Color" ]
, input
[ class "form-control"
, type_ "color"
, required True
, value event.color
, style [ ( "height", "2.5rem" ) ]
, onInput (UpdateEvent EventColor)
]
[]
]
]
, div [ class "col-xs-3 text-xs-right" ]
, div [ class "col-xs-2" ]
[ input
[ class "btn btn-primary"
, type_ "submit"
, value
(if index == 0 then
"Add"
else
"Save"
)
[ class "form-control"
, type_ "color"
, required True
, value event.color
, style [ ( "height", "2.5rem" ) ]
, onInput (UpdateEvent EventColor)
]
[]
]
, div [ class "col-xs-4 text-xs-right" ] actions
]
]
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment