summaryrefslogtreecommitdiff
path: root/elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-08-04 12:36:03 +0200
committerYorhel <git@yorhel.nl>2020-08-07 12:36:58 +0200
commit53196ed7a121e41c2fbe72aaecf257ca42ea7349 (patch)
treea79227f1970acd6e0c5f85258d1547c71a88e1b2 /elm
parentd08487d61c540573eede594c36d07e25c9832a23 (diff)
reviews: Implement review deletion and audit logging
Diffstat (limited to 'elm')
-rw-r--r--elm/Reviews/Edit.elm37
1 files changed, 36 insertions, 1 deletions
diff --git a/elm/Reviews/Edit.elm b/elm/Reviews/Edit.elm
index c66a5445..ae010f1f 100644
--- a/elm/Reviews/Edit.elm
+++ b/elm/Reviews/Edit.elm
@@ -11,6 +11,7 @@ import Lib.Util exposing (..)
import Lib.RDate as RDate
import Gen.Api as GApi
import Gen.ReviewsEdit as GRE
+import Gen.ReviewsDelete as GRD
maxChars = 700
@@ -35,6 +36,8 @@ type alias Model =
, summary : TP.Model
, text : TP.Model
, releases : List GRE.RecvReleases
+ , delete : Bool
+ , delState : Api.State
}
@@ -50,6 +53,8 @@ init d =
, summary = TP.bbcode d.summary
, text = TP.bbcode d.text
, releases = d.releases
+ , delete = False
+ , delState = Api.Normal
}
@@ -72,6 +77,9 @@ type Msg
| Text TP.Msg
| Submit
| Submitted GApi.Response
+ | Delete Bool
+ | DoDelete
+ | Deleted GApi.Response
update : Msg -> Model -> (Model, Cmd Msg)
@@ -87,6 +95,11 @@ update msg model =
Submitted (GApi.Redirect s) -> (model, load s)
Submitted r -> ({ model | state = Api.Error r }, Cmd.none)
+ Delete b -> ({ model | delete = b }, Cmd.none)
+ DoDelete -> ({ model | delState = Api.Loading }, GRD.send ({ id = Maybe.withDefault "" model.id }) Deleted)
+ Deleted GApi.Success -> (model, load <| "/v" ++ String.fromInt model.vid)
+ Deleted r -> ({ model | delState = Api.Error r }, Cmd.none)
+
showrel r = "[" ++ (RDate.format (RDate.expand r.released)) ++ " " ++ (String.join "," r.lang) ++ "] " ++ r.title ++ " (r" ++ String.fromInt r.id ++ ")"
@@ -143,5 +156,27 @@ view model =
]
]
, div [ class "mainbox" ]
- [ fieldset [ class "submit" ] [ submitButton "Submit" model.state (String.length model.summary.data <= maxChars) ] ]
+ [ fieldset [ class "submit" ]
+ [ submitButton "Submit" model.state (String.length model.summary.data <= maxChars)
+ ]
+ ]
+ , if model.id == Nothing then text "" else
+ div [ class "mainbox" ]
+ [ h1 [] [ text "Delete review" ]
+ , table [ class "formtable" ] [ formField ""
+ [ label [] [ inputCheck "" model.delete Delete, text " Delete this review." ]
+ , if not model.delete then text "" else span []
+ [ br [] []
+ , b [ class "standout" ] [ text "WARNING:" ]
+ , text " Deleting this review is a permanent action and can not be reverted!"
+ , br [] []
+ , br [] []
+ , inputButton "Confirm delete" DoDelete []
+ , case model.delState of
+ Api.Loading -> span [ class "spinner" ] []
+ Api.Error e -> b [ class "standout" ] [ text <| Api.showResponse e ]
+ Api.Normal -> text ""
+ ]
+ ] ]
+ ]
]