From 4a41168bbb53dc291ce2172155802a274806d73a Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Thu, 25 Jun 2020 21:52:38 +0200 Subject: [PATCH] Allow a collective to re-index their data If something goes wrong, this might be necessary. --- modules/webapp/src/main/elm/Api.elm | 15 +++ .../main/elm/Comp/CollectiveSettingsForm.elm | 118 +++++++++++++++++- 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/modules/webapp/src/main/elm/Api.elm b/modules/webapp/src/main/elm/Api.elm index 3db77be2..b84880b0 100644 --- a/modules/webapp/src/main/elm/Api.elm +++ b/modules/webapp/src/main/elm/Api.elm @@ -78,6 +78,7 @@ module Api exposing , setUnconfirmed , startOnceNotifyDueItems , startOnceScanMailbox + , startReIndex , submitNotifyDueItems , updateNotifyDueItems , updateScanMailbox @@ -149,6 +150,20 @@ import Util.Http as Http2 +--- Full-Text + + +startReIndex : Flags -> (Result Http.Error BasicResult -> msg) -> Cmd msg +startReIndex flags receive = + Http2.authPost + { url = flags.config.baseUrl ++ "/api/v1/sec/fts/reIndex" + , account = getAccount flags + , body = Http.emptyBody + , expect = Http.expectJson receive Api.Model.BasicResult.decoder + } + + + --- Scan Mailboxes diff --git a/modules/webapp/src/main/elm/Comp/CollectiveSettingsForm.elm b/modules/webapp/src/main/elm/Comp/CollectiveSettingsForm.elm index 74a7540a..04fbe4de 100644 --- a/modules/webapp/src/main/elm/Comp/CollectiveSettingsForm.elm +++ b/modules/webapp/src/main/elm/Comp/CollectiveSettingsForm.elm @@ -7,6 +7,8 @@ module Comp.CollectiveSettingsForm exposing , view ) +import Api +import Api.Model.BasicResult exposing (BasicResult) import Api.Model.CollectiveSettings exposing (CollectiveSettings) import Comp.Dropdown import Data.Flags exposing (Flags) @@ -14,13 +16,17 @@ import Data.Language exposing (Language) import Data.UiSettings exposing (UiSettings) import Html exposing (..) import Html.Attributes exposing (..) -import Html.Events exposing (onCheck) +import Html.Events exposing (onCheck, onClick, onInput) +import Http +import Util.Http type alias Model = { langModel : Comp.Dropdown.Model Language , intEnabled : Bool , initSettings : CollectiveSettings + , fullTextConfirmText : String + , fullTextReIndexResult : Maybe BasicResult } @@ -44,6 +50,8 @@ init settings = } , intEnabled = settings.integrationEnabled , initSettings = settings + , fullTextConfirmText = "" + , fullTextReIndexResult = Nothing } @@ -61,10 +69,13 @@ getSettings model = type Msg = LangDropdownMsg (Comp.Dropdown.Msg Language) | ToggleIntegrationEndpoint + | SetFullTextConfirm String + | TriggerReIndex + | TriggerReIndexResult (Result Http.Error BasicResult) update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Maybe CollectiveSettings ) -update _ msg model = +update flags msg model = case msg of LangDropdownMsg m -> let @@ -90,17 +101,70 @@ update _ msg model = in ( nextModel, Cmd.none, Just (getSettings nextModel) ) + SetFullTextConfirm str -> + ( { model | fullTextConfirmText = str }, Cmd.none, Nothing ) + + TriggerReIndex -> + case String.toLower model.fullTextConfirmText of + "ok" -> + ( { model | fullTextReIndexResult = Nothing } + , Api.startReIndex flags TriggerReIndexResult + , Nothing + ) + + _ -> + ( { model + | fullTextReIndexResult = + Just + (BasicResult False <| + "Please type OK in the field if you really " + ++ "want to start re-indexing your data." + ) + } + , Cmd.none + , Nothing + ) + + TriggerReIndexResult (Ok br) -> + ( { model | fullTextReIndexResult = Just br }, Cmd.none, Nothing ) + + TriggerReIndexResult (Err err) -> + ( { model + | fullTextReIndexResult = + Just (BasicResult False (Util.Http.errorToString err)) + } + , Cmd.none + , Nothing + ) + view : Flags -> UiSettings -> Model -> Html Msg view flags settings model = - div [ class "ui form" ] - [ div [ class "field" ] + div + [ classList + [ ( "ui form", True ) + , ( "error", Maybe.map .success model.fullTextReIndexResult == Just False ) + , ( "success", Maybe.map .success model.fullTextReIndexResult == Just True ) + ] + ] + [ h3 [ class "ui dividing header" ] + [ text "Document Language" + ] + , div [ class "field" ] [ label [] [ text "Document Language" ] , Html.map LangDropdownMsg (Comp.Dropdown.view settings model.langModel) , span [ class "small-info" ] [ text "The language of your documents. This helps text recognition (OCR) and text analysis." ] ] + , h3 + [ classList + [ ( "ui dividing header", True ) + , ( "invisible hidden", not flags.config.integrationEnabled ) + ] + ] + [ text "Integration Endpoint" + ] , div [ classList [ ( "field", True ) @@ -121,4 +185,50 @@ view flags settings model = ] ] ] + , h3 + [ classList + [ ( "ui dividing header", True ) + , ( "invisible hidden", not flags.config.fullTextSearchEnabled ) + ] + ] + [ text "Full-Text Search" + ] + , div + [ classList + [ ( "inline field", True ) + , ( "invisible hidden", not flags.config.fullTextSearchEnabled ) + ] + ] + [ div [ class "ui action input" ] + [ input + [ type_ "text" + , value model.fullTextConfirmText + , onInput SetFullTextConfirm + ] + [] + , button + [ class "ui primary right labeled icon button" + , onClick TriggerReIndex + ] + [ i [ class "refresh icon" ] [] + , text "Re-Index All Data" + ] + ] + , div [ class "small-info" ] + [ text "This starts a task that clears the full-text index and re-indexes all your data again." + , text "You must type OK before clicking the button to avoid accidental re-indexing." + ] + , div + [ classList + [ ( "ui message", True ) + , ( "error", Maybe.map .success model.fullTextReIndexResult == Just False ) + , ( "success", Maybe.map .success model.fullTextReIndexResult == Just True ) + , ( "hidden invisible", model.fullTextReIndexResult == Nothing ) + ] + ] + [ Maybe.map .message model.fullTextReIndexResult + |> Maybe.withDefault "" + |> text + ] + ] ]