tsinfo: add the delete action
3 files changed, 91 insertions(+), 44 deletions(-)

M elm/Groupinfo.elm
M elm/Info.elm
M elm/Tsinfo.elm
M elm/Groupinfo.elm +7 -42
@@ 184,22 184,6 @@ updatedchangedidatebouncer =
     }
 
 
-delete model =
-    Http.request
-        { method = "delete"
-        , headers = []
-        , timeout = Nothing
-        , tracker = Nothing
-        , url =
-            UB.crossOrigin
-                model.baseurl
-                [ "api", "group", "state" ]
-                [ UB.string "name" model.name ]
-        , body = Http.emptyBody
-        , expect = Http.expectString Deleted
-        }
-
-
 update : Msg -> Model -> ( Model, Cmd Msg )
 update msg model =
     let

          
@@ 478,7 462,7 @@ update msg model =
 
         ConfirmDeletion ->
             ( model
-            , delete model
+            , I.delete model "group" Deleted
             )
 
         Deleted (Ok _) ->

          
@@ 615,35 599,16 @@ viewbindings model =
             ]
 
 
-viewdeletion model =
-    if model.deleting then
-        div [  A.style "float" "right" ]
-            [ button
-                  [ A.type_ "button"
-                  , A.class "btn btn-warning"
-                  , onClick ConfirmDeletion
-                  ]
-                  [ text "confirm" ]
-            , button
-                  [ A.type_ "button"
-                  , A.class "btn btn-success"
-                  , onClick CancelDeletion
-                  ]
-                  [ text "cancel" ]
-            ]
-    else
-        div [ A.style "float" "right" ]
-            [ button
-                  [ A.type_ "button"
-                  , A.class "btn btn-danger"
-                  , onClick AskDeletion ]
-                  [ text "delete" ]
-            ]
+deleteevents =
+    { confirmdeletion = ConfirmDeletion
+    , canceldeletion = CancelDeletion
+    , askdeletion = AskDeletion
+    }
 
 
 view model =
     div [ A.style "margin" ".5em" ]
-        [ viewdeletion model
+        [ I.viewdeletion model "group" deleteevents
          , h1 [ ]
               [ text "Series "
               , span

          
M elm/Info.elm +45 -1
@@ 1,5 1,6 @@ 
 module Info exposing
-    ( getformula
+    ( delete
+    , getformula
     , getidates
     , getcomponents
     , getwriteperms

          
@@ 11,6 12,7 @@ module Info exposing
     , viewerrors
     , viewformula
     , viewdatespicker
+    , viewdeletion
     , viewlog
     , viewmeta
     , viewseealso

          
@@ 82,6 84,22 @@ getidates model dtype callback =
         }
 
 
+delete model dtype event =
+    Http.request
+        { method = "delete"
+        , headers = []
+        , timeout = Nothing
+        , tracker = Nothing
+        , url =
+            UB.crossOrigin
+                model.baseurl
+                [ "api", dtype, "state" ]
+                [ UB.string "name" model.name ]
+        , body = Http.emptyBody
+        , expect = Http.expectString event
+        }
+
+
 savemeta model dtype callback =
     Http.request
         { method = "PUT"

          
@@ 475,3 493,29 @@ viewlog model showtitle =
                 ]
             ]
     else H.div [ ] [ ]
+
+
+viewdeletion model dtype events =
+    if model.deleting then
+        H.div [ HA.style "float" "right" ]
+            [ H.button
+                  [ HA.type_ "button"
+                  , HA.class "btn btn-warning"
+                  , HE.onClick events.confirmdeletion
+                  ]
+                  [ H.text "confirm" ]
+            , H.button
+                  [ HA.type_ "button"
+                  , HA.class "btn btn-success"
+                  , HE.onClick events.canceldeletion
+                  ]
+                  [ H.text "cancel" ]
+            ]
+    else
+        H.div [ HA.style "float" "right" ]
+            [ H.button
+                  [ HA.type_ "button"
+                  , HA.class "btn btn-danger"
+                  , HE.onClick events.askdeletion ]
+                  [ H.text "delete" ]
+            ]

          
M elm/Tsinfo.elm +39 -1
@@ 2,6 2,7 @@ module Tsinfo exposing (main)
 
 import Array exposing (Array)
 import Browser
+import Browser.Navigation exposing (load)
 import Debouncer.Messages as Debouncer exposing
     (Debouncer
     , fromSeconds

          
@@ 73,6 74,8 @@ type alias Model =
     -- user meta edition
     , metaitem : (String, String)
     , editeditems : Dict String String
+    -- deletion
+    , deleting : Bool
     }
 
 

          
@@ 111,6 114,11 @@ type Msg
     | AddMetaItem
     | SaveMeta
     | MetaSaved (Result Http.Error String)
+    -- deletion
+    | AskDeletion
+    | CancelDeletion
+    | ConfirmDeletion
+    | Deleted (Result Http.Error String)
 
 
 logentrydecoder : D.Decoder Logentry

          
@@ 519,6 527,27 @@ update msg model =
         MetaSaved (Err err) ->
             doerr "metasaved http" <| U.unwraperror err
 
+        -- deletion
+
+        AskDeletion ->
+            U.nocmd { model | deleting = True }
+
+        CancelDeletion ->
+            U.nocmd { model | deleting = False }
+
+        ConfirmDeletion ->
+            ( model
+            , I.delete model "series" Deleted
+            )
+
+        Deleted (Ok _) ->
+            ( model
+            , load <| UB.crossOrigin model.baseurl [ "tssearch" ] [ ]
+            )
+
+        Deleted (Err err) ->
+            doerr "deletion failed" <| U.unwraperror err
+
 
 -- views
 

          
@@ 682,10 711,18 @@ metaevents =
     }
 
 
+deleteevents =
+    { confirmdeletion = ConfirmDeletion
+    , canceldeletion = CancelDeletion
+    , askdeletion = AskDeletion
+    }
+
+
 view : Model -> Html Msg
 view model =
     div [ A.style "margin" ".5em" ]
-        [ h1 [ ]
+        [ I.viewdeletion model "series" deleteevents
+        , h1 [ ]
               [ text "Series "
               , span
                     [ A.class "font-italic" ]

          
@@ 755,6 792,7 @@ main =
                            -- user meta edittion
                            ("", "")
                            Dict.empty
+                           False
                in
                ( model
                , Cmd.batch